misc cleanup (mostly type-related)

This commit is contained in:
jan 2026-02-16 17:58:34 -08:00
commit ebfe1b559c
16 changed files with 57 additions and 21 deletions

View file

@ -1,3 +1,4 @@
from typing import cast, TYPE_CHECKING
from numpy.testing import assert_equal, assert_allclose
from numpy import pi
@ -5,6 +6,9 @@ from ..pattern import Pattern
from ..ref import Ref
from ..repetition import Grid
if TYPE_CHECKING:
from ..shapes import Polygon
def test_ref_init() -> None:
ref = Ref(offset=(10, 20), rotation=pi / 4, mirrored=True, scale=2.0)
@ -22,7 +26,7 @@ def test_ref_as_pattern() -> None:
transformed_pat = ref.as_pattern(sub_pat)
# Check transformed shape
shape = transformed_pat.shapes[(1, 0)][0]
shape = cast("Polygon", transformed_pat.shapes[(1, 0)][0])
# ref.as_pattern deepcopies sub_pat then applies transformations:
# 1. pattern.scale_by(2) -> vertices [[0,0], [2,0], [0,2]]
# 2. pattern.rotate_around((0,0), pi/2) -> vertices [[0,0], [0,2], [-2,0]]
@ -42,7 +46,7 @@ def test_ref_with_repetition() -> None:
# Should have 4 shapes
assert len(repeated_pat.shapes[(1, 0)]) == 4
first_verts = sorted([tuple(s.vertices[0]) for s in repeated_pat.shapes[(1, 0)]])
first_verts = sorted([tuple(cast("Polygon", s).vertices[0]) for s in repeated_pat.shapes[(1, 0)]])
assert first_verts == [(0.0, 0.0), (0.0, 10.0), (10.0, 0.0), (10.0, 10.0)]