initialer commit
This commit is contained in:
1 parent
74776ef485
commit
a3095c2df9
18 files changed
+1073
No files matched your search
@@ -0,0 +1,60 @@
|
||||
"""Tests für project_ortho und project_perspective."""
|
||||
|
||||
import pytest
|
||||
|
||||
from matrixmania import project_ortho, project_perspective
|
||||
|
||||
|
||||
def test_project_ortho_without_scale():
|
||||
# Arrange
|
||||
point = (1.0, 2.0, 3.0)
|
||||
# Act
|
||||
result = project_ortho(point)
|
||||
# Assert
|
||||
assert result == (1.0, 2.0)
|
||||
|
||||
|
||||
def test_project_ortho_with_scale_100():
|
||||
# Arrange
|
||||
point = (1.0, 2.0, 3.0)
|
||||
# Act
|
||||
result = project_ortho(point, scale=100)
|
||||
# Assert
|
||||
assert result == pytest.approx((100.0, 200.0))
|
||||
|
||||
|
||||
def test_project_perspective_without_scale():
|
||||
# Arrange
|
||||
point = (1.0, 2.0, 3.0)
|
||||
# Act
|
||||
result = project_perspective(point, focal_length=1, scale=1)
|
||||
# Assert
|
||||
assert result == pytest.approx((1 / 7, 2 / 7))
|
||||
|
||||
|
||||
def test_project_perspective_with_scale_100_and_focal_length_2():
|
||||
# Arrange
|
||||
point = (1.0, 2.0, 3.0)
|
||||
# Act
|
||||
result = project_perspective(point, focal_length=2, scale=100)
|
||||
# Assert
|
||||
assert result == pytest.approx((200 / 7, 400 / 7))
|
||||
|
||||
|
||||
def test_project_perspective_far_point_appears_smaller():
|
||||
# Arrange
|
||||
near = (1.0, 1.0, 0.0)
|
||||
far = (1.0, 1.0, 10.0)
|
||||
# Act
|
||||
near_x, _ = project_perspective(near)
|
||||
far_x, _ = project_perspective(far)
|
||||
# Assert
|
||||
assert far_x < near_x
|
||||
|
||||
|
||||
def test_project_perspective_point_behind_camera_raises():
|
||||
# Arrange
|
||||
point = (1.0, 1.0, -4.0)
|
||||
# Act & Assert
|
||||
with pytest.raises(ValueError):
|
||||
project_perspective(point)
|
||||
@@ -0,0 +1,65 @@
|
||||
"""Tests für rot_2D und rot_3D."""
|
||||
|
||||
import math
|
||||
|
||||
import pytest
|
||||
|
||||
from matrixmania import matmul, rot_2D, rot_3D, transpose
|
||||
|
||||
|
||||
def rotate(matrix: list[list[float]], point: list[float]) -> list[float]:
|
||||
"""Dreht einen Punkt mit einer Rotationsmatrix und gibt ihn als Liste zurück."""
|
||||
result = matmul(matrix, transpose([point]))
|
||||
return [row[0] for row in result]
|
||||
|
||||
|
||||
def test_rot_2D_90_degrees():
|
||||
# Arrange
|
||||
point = [1, 0]
|
||||
# Act
|
||||
rotated = rotate(rot_2D(math.pi / 2), point)
|
||||
# Assert
|
||||
assert rotated == pytest.approx([0, 1])
|
||||
|
||||
|
||||
def test_rot_2D_zero_angle_is_identity():
|
||||
# Arrange
|
||||
angle = 0
|
||||
# Act
|
||||
matrix = rot_2D(angle)
|
||||
# Assert
|
||||
assert matrix == [[1, 0], [0, 1]]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"axis, point, expected",
|
||||
[
|
||||
("x", [0, 1, 0], [0, 0, 1]),
|
||||
("y", [0, 0, 1], [1, 0, 0]),
|
||||
("z", [1, 0, 0], [0, 1, 0]),
|
||||
],
|
||||
)
|
||||
def test_rot_3D_90_degrees(axis, point, expected):
|
||||
# Arrange
|
||||
angle = math.pi / 2
|
||||
# Act
|
||||
rotated = rotate(rot_3D(angle, axis), point)
|
||||
# Assert
|
||||
assert rotated == pytest.approx(expected)
|
||||
|
||||
|
||||
def test_rot_3D_point_on_axis_stays():
|
||||
# Arrange
|
||||
point = [1, 0, 0]
|
||||
# Act
|
||||
rotated = rotate(rot_3D(1.23, "x"), point)
|
||||
# Assert
|
||||
assert rotated == pytest.approx(point)
|
||||
|
||||
|
||||
def test_rot_3D_invalid_axis_raises():
|
||||
# Arrange
|
||||
axis = "w"
|
||||
# Act & Assert
|
||||
with pytest.raises(ValueError):
|
||||
rot_3D(1.0, axis)
|
||||
Reference in new issue
Block a user