Paketstruktur, rot_3D, Projektionen und pytest-Tests
- compute.py nach src/matrixmania verschoben, __init__.py exportiert die Funktionen - rot_3D, project_ortho und project_perspective ergänzt - Tests in test/test_matrixmania (test_rot.py, test_projection.py) - pyproject.toml: dev-Abhängigkeiten und pytest-pythonpath Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
892ec5e2c9
commit
7b8c76c554
9 files changed
+450
-3
No files matched your search
@@ -0,0 +1,78 @@
|
||||
"""Tests für project_ortho und project_perspective."""
|
||||
|
||||
import pytest
|
||||
|
||||
from matrixmania import project_ortho, project_perspective
|
||||
|
||||
|
||||
def test_project_ortho_without_scale() -> None:
|
||||
"""Ohne Skalierung wird nur die z-Koordinate weggelassen."""
|
||||
# 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() -> None:
|
||||
"""Mit scale=100 werden x und y verhundertfacht."""
|
||||
# Arrange
|
||||
point = (1.0, 2.0, 3.0)
|
||||
|
||||
# Act
|
||||
result = project_ortho(point, scale=100)
|
||||
|
||||
# Assert
|
||||
assert result == (100.0, 200.0)
|
||||
|
||||
|
||||
def test_project_perspective_without_scale() -> None:
|
||||
"""Punkt (1, 2, 3), focal_length=1, scale=1: Teilen durch 3 + 4 = 7."""
|
||||
# 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_and_focal_length() -> None:
|
||||
"""Punkt (1, 2, 3), focal_length=2, scale=100: Faktor 2 / 7 * 100."""
|
||||
# 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() -> None:
|
||||
"""Ein weiter entfernter Punkt landet näher am Ursprung."""
|
||||
# Arrange
|
||||
near_point = (1.0, 1.0, 0.0)
|
||||
far_point = (1.0, 1.0, 10.0)
|
||||
|
||||
# Act
|
||||
near = project_perspective(near_point)
|
||||
far = project_perspective(far_point)
|
||||
|
||||
# Assert
|
||||
assert abs(far[0]) < abs(near[0])
|
||||
assert abs(far[1]) < abs(near[1])
|
||||
|
||||
|
||||
def test_project_perspective_point_in_camera_raises_value_error() -> None:
|
||||
"""Liegt der Punkt genau in der Kamera (Tiefe 0), kommt ein ValueError."""
|
||||
# Arrange
|
||||
point = (1.0, 1.0, -4.0)
|
||||
|
||||
# Act / Assert
|
||||
with pytest.raises(ValueError):
|
||||
project_perspective(point, camera_distance=4.0)
|
||||
Reference in new issue
Block a user