45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
import pytest
|
|
|
|
from matrixmania.compute import project_ortho, project_perspective
|
|
|
|
|
|
def test_project_ortho_default():
|
|
"""Projektionsfunktion ohne Skalierung"""
|
|
point = (1.0, 2.0, 3.0)
|
|
assert project_ortho(point) == (1.0, 2.0)
|
|
|
|
|
|
def test_project_perspective_default():
|
|
"""Test project_perspective with default scale and focal_length=1"""
|
|
# Arrange
|
|
point = (1.0, 2.0, 3.0)
|
|
# Act
|
|
result = project_perspective(point)
|
|
# depth = z + camera_distance = 3 + 4 = 7
|
|
# Expected x = 1 * 1 / 7 * 1 = 1/7
|
|
# Expected y = 2 * 1 / 7 * 1 = 2/7
|
|
expected = (1/7, 2/7)
|
|
# Assert
|
|
assert result == pytest.approx(expected)
|
|
|
|
|
|
def test_project_perspective_scaled():
|
|
"""Test project_perspective with scale=100 and focal_length=2"""
|
|
# Arrange
|
|
point = (1.0, 2.0, 3.0)
|
|
scale = 100
|
|
focal_length = 2
|
|
# Act
|
|
result = project_perspective(point, focal_length=focal_length, scale=scale)
|
|
# depth = 3 + 4 = 7
|
|
# Expected x = 1 * 2 / 7 * 100 = 200/7
|
|
# Expected y = 2 * 2 / 7 * 100 = 400/7
|
|
expected = (200/7, 400/7)
|
|
# Assert
|
|
assert result == pytest.approx(expected)
|
|
|
|
"""Projektionsfunktion mit Skalierung"""
|
|
point = (1.0, 2.0, 3.0)
|
|
assert project_ortho(point, scale=100) == (100.0, 200.0)
|
|
|