Make rotation matrix immutable and cache the value

master
jan 1 year ago
parent 93ab0a942d
commit 234264c0af

@ -2,11 +2,13 @@
Geometric transforms Geometric transforms
""" """
from typing import Sequence from typing import Sequence
from functools import lru_cache
import numpy import numpy
from numpy.typing import NDArray from numpy.typing import NDArray
@lru_cache
def rotation_matrix_2d(theta: float) -> NDArray[numpy.float64]: def rotation_matrix_2d(theta: float) -> NDArray[numpy.float64]:
""" """
2D rotation matrix for rotating counterclockwise around the origin. 2D rotation matrix for rotating counterclockwise around the origin.
@ -17,8 +19,10 @@ def rotation_matrix_2d(theta: float) -> NDArray[numpy.float64]:
Returns: Returns:
rotation matrix rotation matrix
""" """
return numpy.array([[numpy.cos(theta), -numpy.sin(theta)], arr = numpy.array([[numpy.cos(theta), -numpy.sin(theta)],
[numpy.sin(theta), +numpy.cos(theta)]]) [numpy.sin(theta), +numpy.cos(theta)]])
arr.flags.writeable = False
return arr
def normalize_mirror(mirrored: Sequence[bool]) -> tuple[bool, float]: def normalize_mirror(mirrored: Sequence[bool]) -> tuple[bool, float]:

Loading…
Cancel
Save