add rotation tests
This commit is contained in:
1 parent
6f600738d0
commit
4a838bfdc8
3 files changed
+42
-2
No files matched your search
+4
-1
@@ -1,4 +1,7 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "matrixmania"
|
name = "matrixmania"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = ["tabulate", "ruff", "pytest-cov"]
|
dependencies = ["tabulate", "ruff", "pytest-cov"]
|
||||||
|
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
pythonpath = "src"
|
||||||
@@ -76,7 +76,7 @@ def matmul(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def rot_2D(matrix: list[list[float]], angle:int) -> list[list[float]]:
|
def rot_2D(matrix: list[list[float]], angle:float) -> list[list[float]]:
|
||||||
"""Apply a rotation matrix to a base matrix.
|
"""Apply a rotation matrix to a base matrix.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
@@ -140,6 +140,10 @@ def rot_3D(angle:float, axis: str) -> list[list[float]]:
|
|||||||
return [row_1, row_2, row_3]
|
return [row_1, row_2, row_3]
|
||||||
|
|
||||||
|
|
||||||
|
def project_ortho(point: tuple[float, float, float], scale: float = 1) -> tuple[float, float, float]:
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def transpose(matrix: list[list[float]]) -> list[list[float]]:
|
def transpose(matrix: list[list[float]]) -> list[list[float]]:
|
||||||
"""Return the transpose of a 2‑D list.
|
"""Return the transpose of a 2‑D list.
|
||||||
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import math
|
||||||
|
|
||||||
|
from src.compute import rot_2D, rot_3D
|
||||||
|
|
||||||
|
def test_get_2D_rotation_matrix():
|
||||||
|
|
||||||
|
#Arrange
|
||||||
|
mat = [[0], [0]]
|
||||||
|
angle = math.pi
|
||||||
|
expected_matrix = [[math.cos(math.pi), -math.sin(math.pi)], [math.sin(math.pi), math.cos(math.pi)]]
|
||||||
|
|
||||||
|
#Act
|
||||||
|
rot = rot_2D(mat, angle)
|
||||||
|
|
||||||
|
#Assert
|
||||||
|
assert rot == expected_matrix
|
||||||
|
|
||||||
|
def test_get_3D_rotation_matrix():
|
||||||
|
|
||||||
|
#Arrange
|
||||||
|
angle = math.pi
|
||||||
|
axis = "x"
|
||||||
|
expected_matrix = [
|
||||||
|
[1, 0, 0],
|
||||||
|
[0, math.cos(math.pi), -math.sin(math.pi)],
|
||||||
|
[0, math.sin(math.pi), math.cos(math.pi)]]
|
||||||
|
|
||||||
|
#Act
|
||||||
|
rot = rot_3D(angle, axis)
|
||||||
|
|
||||||
|
#Assert
|
||||||
|
assert rot == expected_matrix
|
||||||
|
|
||||||
Reference in new issue
Block a user