fix: negate y-axis in graphics transform for correct symbol bounding boxes

Library symbols use y-up coordinates while schematics use y-down. The
_transform_local_point function was not negating y, causing asymmetric
symbols (e.g. power:VEE) to have their bounding boxes computed in the
wrong direction — missing overlaps with adjacent components.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Eugene Mikhantyev
2026-03-15 14:37:35 +00:00
parent 1ef4ce5cab
commit be11948a44
2 changed files with 11 additions and 4 deletions

View File

@@ -332,8 +332,12 @@ def _transform_local_point(
) -> Tuple[float, float]:
"""
Transform a point from local symbol coordinates to absolute schematic
coordinates using KiCad's transform order: mirror → rotate → translate.
coordinates using KiCad's transform order:
negate-y (lib y-up → schematic y-down) → mirror → rotate → translate.
"""
# Library symbols use y-up; schematic uses y-down
ly = -ly
# Apply mirroring in local coords
if mirror_x:
ly = -ly

View File

@@ -749,21 +749,24 @@ class TestTransformLocalPoint:
"""Test local→absolute coordinate transform."""
def test_no_transform(self):
# ly is negated (lib y-up → schematic y-down)
x, y = _transform_local_point(1.0, 2.0, 100.0, 200.0, 0, False, False)
assert x == pytest.approx(101.0)
assert y == pytest.approx(202.0)
assert y == pytest.approx(198.0)
def test_mirror_x(self):
# y-negate then mirror_x cancel out → net ly unchanged
x, y = _transform_local_point(1.0, 2.0, 0.0, 0.0, 0, True, False)
assert x == pytest.approx(1.0)
assert y == pytest.approx(-2.0)
assert y == pytest.approx(2.0)
def test_mirror_y(self):
x, y = _transform_local_point(1.0, 2.0, 0.0, 0.0, 0, False, True)
assert x == pytest.approx(-1.0)
assert y == pytest.approx(2.0)
assert y == pytest.approx(-2.0)
def test_rotation_90(self):
# ly=0 negated is still 0, then rotate lx=1 by 90°
x, y = _transform_local_point(1.0, 0.0, 0.0, 0.0, 90, False, False)
assert x == pytest.approx(0.0, abs=1e-9)
assert y == pytest.approx(1.0, abs=1e-9)