From 169f66cc854b8971d34a2289f12dac1f18b351b0 Mon Sep 17 00:00:00 2001 From: jan Date: Mon, 9 Mar 2026 01:16:54 -0700 Subject: [PATCH] [rotation_matrix_2d] improve manhattan angle detection modulo causes issues with negative numbers --- masque/utils/transform.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/masque/utils/transform.py b/masque/utils/transform.py index 90647b1..62e0f1e 100644 --- a/masque/utils/transform.py +++ b/masque/utils/transform.py @@ -28,8 +28,9 @@ def rotation_matrix_2d(theta: float) -> NDArray[numpy.float64]: arr = numpy.array([[numpy.cos(theta), -numpy.sin(theta)], [numpy.sin(theta), +numpy.cos(theta)]]) - # If this was a manhattan rotation, round to remove some inacuraccies in sin & cos - if numpy.isclose(theta % (pi / 2), 0): + # If this was a manhattan rotation, round to remove some inaccuracies in sin & cos + # cos(4*theta) is 1 for any multiple of pi/2. + if numpy.isclose(numpy.cos(4 * theta), 1, atol=1e-12): arr = numpy.round(arr) arr.flags.writeable = False