From f8d6527586687bdc83cc53866efcac15e772474d Mon Sep 17 00:00:00 2001 From: jan Date: Fri, 14 Apr 2023 22:33:31 -0700 Subject: [PATCH] improve accuracy of manhattan rotations --- masque/utils/transform.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/masque/utils/transform.py b/masque/utils/transform.py index ccdf3d2..fb84052 100644 --- a/masque/utils/transform.py +++ b/masque/utils/transform.py @@ -6,6 +6,7 @@ from functools import lru_cache import numpy from numpy.typing import NDArray +from numpy import pi @lru_cache @@ -21,6 +22,11 @@ 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): + arr = numpy.round(arr) + arr.flags.writeable = False return arr