[utils] canonicalize rotation matrices before caching

This commit is contained in:
Jan Petykiewicz 2026-07-16 08:35:42 -07:00
commit e397b3f96e
2 changed files with 41 additions and 10 deletions

View file

@ -89,6 +89,23 @@ def test_rotation_matrix_non_manhattan() -> None:
assert_allclose(m, [[s, -s], [s, s]], atol=1e-10)
def test_rotation_matrix_canonicalizes_before_caching() -> None:
expected = rotation_matrix_2d(pi / 2)
for angle in (pi / 2 + 1e-12, pi / 2 - 1e-12, -3 * pi / 2, 5 * pi / 2):
assert rotation_matrix_2d(angle) is expected
assert not expected.flags.writeable
def test_rotation_matrix_does_not_snap_non_manhattan_angle() -> None:
cardinal = rotation_matrix_2d(pi / 2)
nearby = rotation_matrix_2d(pi / 2 + 2e-3)
assert nearby is not cardinal
assert not numpy.array_equal(nearby, cardinal)
def test_apply_transforms() -> None:
# cumulative [x_offset, y_offset, rotation (rad), mirror_x (0 or 1)]
t1 = [10, 20, 0, 0]