diff --git a/test/test_matrixmania/test_projection.py b/test/test_matrixmania/test_projection.py index 43f9d7e..a0c6b7b 100644 --- a/test/test_matrixmania/test_projection.py +++ b/test/test_matrixmania/test_projection.py @@ -1,4 +1,7 @@ -from matrixmania import project_ortho +import pytest + +from matrixmania import project_ortho, project_perspective + def test_project_ortho_without_scale() -> None: """Orthogonal projection ignores z when scale is omitted.""" @@ -11,6 +14,7 @@ def test_project_ortho_without_scale() -> None: # Assert assert result == (1.0, 2.0) + def test_project_ortho_with_scale() -> None: """Orthogonal projection scales x and y and ignores z.""" # Arrange @@ -18,7 +22,44 @@ def test_project_ortho_with_scale() -> None: scale = 100 # Act - result = (project_ortho(point, scale=scale)) + result = project_ortho(point, scale=scale) # Assert assert result == (100.0, 200.0) + + +def test_project_perspective_with_defaults() -> None: + """Perspective projection uses the default focal length and distance.""" + # Arrange + point = (1.0, 2.0, 3.0) + + # Act + result = project_perspective(point) + + # Assert + assert result == pytest.approx((1 / 7, 2 / 7)) + + +def test_project_perspective_with_scale_and_focal_length() -> None: + """Perspective projection applies scale and focal length.""" + # Arrange + point = (1.0, 2.0, 3.0) + + # Act + result = project_perspective(point, scale=100, focal_length=2) + + # Assert + assert result == pytest.approx((200 / 7, 400 / 7)) + + +def test_project_perspective_with_custom_camera_distance() -> None: + """Perspective projection uses the supplied camera distance.""" + # Arrange + point = (2.0, 4.0, 2.0) + camera_distance = 6.0 + + # Act + result = project_perspective(point, camera_distance=camera_distance) + + # Assert + assert result == pytest.approx((0.25, 0.5))