66 lines
1.5 KiB
Python
66 lines
1.5 KiB
Python
import pytest
|
|
|
|
from matrixmania import project_ortho, project_perspective
|
|
|
|
|
|
def test_project_ortho_without_scale() -> None:
|
|
"""Orthogonal projection ignores z when scale is omitted."""
|
|
# 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() -> None:
|
|
"""Orthogonal projection scales x and y and ignores z."""
|
|
# Arrange
|
|
point = (1.0, 2.0, 3.0)
|
|
scale = 100
|
|
|
|
# Act
|
|
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))
|