Add perspective projection and tests

This commit is contained in:
Amalia Sucipto committed 2026-10-29 11:11:19 +01:00
1 parent 4931d5e7dc
commit 72d00b4c01
2 files changed
+84 -4

No files matched your search

+46 -2
View File
@@ -1,4 +1,6 @@
from compute import project_ortho
import pytest
from compute import project_ortho, project_perspective
def test_project_ortho_without_scaling() -> None:
@@ -25,4 +27,46 @@ def test_project_ortho_with_scaling() -> None:
result = project_ortho(point, scale)
# Assert
assert result == expected
assert result == expected
def test_project_perspective_without_scaling() -> None:
"""Test perspective projection with default parameters."""
# Arrange
point = (1.0, 2.0, 3.0)
expected = (1 / 7, 2 / 7)
# Act
result = project_perspective(point)
# Assert
assert result == pytest.approx(expected)
def test_project_perspective_with_scaling() -> None:
"""Test perspective projection with scaling and focal length."""
# Arrange
point = (1.0, 2.0, 3.0)
focal_length = 2.0
scale = 100.0
expected = (200 / 7, 400 / 7)
# Act
result = project_perspective(
point,
focal_length=focal_length,
scale=scale,
)
# Assert
assert result == pytest.approx(expected)
def test_project_perspective_zero_depth() -> None:
"""Test that zero projection depth raises an error."""
# Arrange
point = (1.0, 2.0, -4.0)
# Act & Assert
with pytest.raises(ValueError):
project_perspective(point)
# python -m pytest test_matrixmania/test_projection.py -v