[Arc / Ellipse] make radii hashable

This commit is contained in:
Jan Petykiewicz 2026-03-31 21:22:15 -07:00
commit 89cdd23f00
3 changed files with 24 additions and 2 deletions

View file

@ -422,7 +422,7 @@ class Arc(PositionableImpl, Shape):
rotation %= 2 * pi rotation %= 2 * pi
width = self.width width = self.width
return ((type(self), radii, norm_angles, width / norm_value), return ((type(self), tuple(radii.tolist()), norm_angles, width / norm_value),
(self.offset, scale / norm_value, rotation, False), (self.offset, scale / norm_value, rotation, False),
lambda: Arc( lambda: Arc(
radii=radii * norm_value, radii=radii * norm_value,

View file

@ -206,7 +206,7 @@ class Ellipse(PositionableImpl, Shape):
radii = self.radii[::-1] / self.radius_y radii = self.radii[::-1] / self.radius_y
scale = self.radius_y scale = self.radius_y
angle = (self.rotation + pi / 2) % pi angle = (self.rotation + pi / 2) % pi
return ((type(self), radii), return ((type(self), tuple(radii.tolist())),
(self.offset, scale / norm_value, angle, False), (self.offset, scale / norm_value, angle, False),
lambda: Ellipse(radii=radii * norm_value)) lambda: Ellipse(radii=radii * norm_value))

View file

@ -282,6 +282,28 @@ def test_library_dedup_text_preserves_scale_and_mirror_flag() -> None:
assert [cast("Text", shape).height for shape in flat.shapes[(1, 0)]] == [10, 10] assert [cast("Text", shape).height for shape in flat.shapes[(1, 0)]] == [10, 10]
def test_library_dedup_handles_arc_and_ellipse_labels() -> None:
lib = Library()
pat = Pattern()
pat.shapes[(1, 0)] += [
Arc(radii=(10, 20), angles=(0, 1), width=2, offset=(0, 0)),
Arc(radii=(10, 20), angles=(0, 1), width=2, offset=(50, 0)),
]
pat.shapes[(2, 0)] += [
Ellipse(radii=(10, 20), offset=(0, 0)),
Ellipse(radii=(10, 20), offset=(50, 0)),
]
lib["top"] = pat
lib.dedup(exclude_types=(), norm_value=1, threshold=2)
assert len(lib["top"].refs) == 2
assert lib["top"].shapes[(1, 0)] == []
assert lib["top"].shapes[(2, 0)] == []
flat = lib.flatten("top")["top"]
assert sum(isinstance(shape, Arc) for shape in flat.shapes[(1, 0)]) == 2
assert sum(isinstance(shape, Ellipse) for shape in flat.shapes[(2, 0)]) == 2
def test_library_dedup_handles_multiple_duplicate_groups() -> None: def test_library_dedup_handles_multiple_duplicate_groups() -> None: