Make rotation matrix immutable and cache the value
This commit is contained in:
parent
152dea9b60
commit
fe3a373807
@ -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…
Reference in New Issue
Block a user