From 71733c9099d1306d6ac11bdda30a70e491f51185 Mon Sep 17 00:00:00 2001 From: tilo Date: Thu, 13 Nov 2025 14:36:46 +0100 Subject: [PATCH] add orthogonal projection --- pyproject.toml | 2 +- src/matrixmania/compute.py | 8 +++++++- test/test_matrixmania/test_projection.py | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/test_matrixmania/test_projection.py diff --git a/pyproject.toml b/pyproject.toml index 05127d7..320ec1e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "matrixmania_brockmannti" -version = "0.1.1" +version = "0.1.3" description = "MatrixMania: Simple linear algebra functions for teaching (matmul, transpose, rot_2D)." authors = [ { name="Tilo Brockmann", email="brockmannti93157@th-nuernberg.de" } diff --git a/src/matrixmania/compute.py b/src/matrixmania/compute.py index 86f1140..863ee93 100644 --- a/src/matrixmania/compute.py +++ b/src/matrixmania/compute.py @@ -1,6 +1,8 @@ -from typing import List +from typing import List, Tuple import math +import pygame + def product(factors: List[int]) -> int: """ @@ -113,3 +115,7 @@ def rot_3D(angle: float, axis: str) -> List[List[float]]: ] else: raise ValueError("axis must be either x, y or z") + + +def project_ortho(point: Tuple[float, float, float], scale: float = 1) -> Tuple[float, float]: + return point[0] * scale, point[1] * scale \ No newline at end of file diff --git a/test/test_matrixmania/test_projection.py b/test/test_matrixmania/test_projection.py new file mode 100644 index 0000000..2d422bb --- /dev/null +++ b/test/test_matrixmania/test_projection.py @@ -0,0 +1,14 @@ +import pytest +from src.matrixmania.compute import project_ortho + +def test_projection(): + point = (1.0, 2.0, 3.0) + expected = (1.0, 2.0) + + assert project_ortho(point) == expected + +def test_projection_with_scale(): + point = (1.0, 2.0, 3.0) + expected = (100.0, 200.0) + + assert project_ortho(point, 100) == expected \ No newline at end of file