From ff9289c7671879add54f2c4fdf46875078193c15 Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 4 Nov 2026 23:54:48 +0100 Subject: [PATCH] project_ortho + tests laufen --- src/matrixmania/__init__.py | 1 + src/matrixmania/projection.py | 12 ++++++++++ test/test_matrixmania/test_projection.py | 28 ++++++++++++++++++++++++ test/test_matrixmania/test_rot.py | 3 +-- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/matrixmania/projection.py diff --git a/src/matrixmania/__init__.py b/src/matrixmania/__init__.py index e3601ab..57ef826 100644 --- a/src/matrixmania/__init__.py +++ b/src/matrixmania/__init__.py @@ -1 +1,2 @@ from .compute import matmul, transpose, rot_2D, rot_3D +from .projection import project_ortho diff --git a/src/matrixmania/projection.py b/src/matrixmania/projection.py new file mode 100644 index 0000000..9bc0a7c --- /dev/null +++ b/src/matrixmania/projection.py @@ -0,0 +1,12 @@ + + +def project_ortho(point: tuple[float, float, float], scale: float = 1) -> tuple[float, float]: + """ projected 3D-Point orthogonal auf 2D (xy), z Koordinate wird ignoriert + + point : tuple[float, float, float] + 3-D point (x, y, z). + scale : float, optional + Scaling factor applied (default 1) + """ + x, y, _ = point + return (x * scale, y * scale) \ No newline at end of file diff --git a/test/test_matrixmania/test_projection.py b/test/test_matrixmania/test_projection.py index e69de29..417080b 100644 --- a/test/test_matrixmania/test_projection.py +++ b/test/test_matrixmania/test_projection.py @@ -0,0 +1,28 @@ +import pytest + +from matrixmania import project_ortho + +def test_project_ortho_ohne_skalierung(): + # Arrange + punkt = (1.0, 2.0, 3.0) + erwartet = (1.0, 2.0) + + # Act + ergebnis = project_ortho(punkt) + + # Assert + assert ergebnis == pytest.approx(erwartet) + + +def test_project_ortho_mit_skalierung_100(): + # Arrange + punkt = (1.0, 2.0, 3.0) + scale = 100 + erwartet = (100.0, 200.0) + + # Act + ergebnis = project_ortho(punkt, scale=scale) + + # Assert + assert ergebnis == pytest.approx(erwartet) #würde hier auch ohne approx gehen + diff --git a/test/test_matrixmania/test_rot.py b/test/test_matrixmania/test_rot.py index 0eb0c7e..caa7b05 100644 --- a/test/test_matrixmania/test_rot.py +++ b/test/test_matrixmania/test_rot.py @@ -1,5 +1,4 @@ -import math -import pytest +import math, pytest from matrixmania import rot_2D, rot_3D