Make rotation matrix immutable and cache the value

This commit is contained in:
jan 2023-04-12 18:21:18 -07:00
parent 152dea9b60
commit fe3a373807

View File

@ -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]: