From 781fab0344047b83582074a0c9a954e9c5b97630 Mon Sep 17 00:00:00 2001 From: steph Date: Thu, 22 Oct 2026 19:04:02 +0200 Subject: [PATCH] Praktikum 3: Post Tests Added DocStrings --- src/compute.py | 27 +++++++++++++++++++++++++++ test/test_pro_pers.py | 21 +++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 test/test_pro_pers.py diff --git a/src/compute.py b/src/compute.py index 832c095..a6b016a 100644 --- a/src/compute.py +++ b/src/compute.py @@ -103,10 +103,37 @@ def rot_3d(angle: float, axis: str) -> list[list[float]]: raise ValueError +# For Both below add the Doc String! def project_ortho(point: tuple[float, float, float], scale: float = 1) -> tuple[float, float]: + """ + Projects a 3D Position into an orthogonal 2D View + :param point: The 3D Point + :type point: tuple[float, float, float] + :param scale: The scale by which the point gets scaled; regular is 1.0 + :type scale: float + :return: The 3D Point on a 2D plane + :rtype: tuple[float, float] + """ return (point[0] * scale, point[1] * scale) +def project_perspective(point: tuple[float, float, float], focal_length: float = 1.0, + scale: float = 1.0, camera_distance: float = 4.0) -> tuple[float, float]: + """ + Projects a 3D Position into a perspective 2D View + :param point: The 3D Point + :type point: tuple[float, float, float] + :param focal_length: strength of perspective; regular is 1.0 + :type focal_length: float + :param scale: The scale by which the point gets scaled; regular is 1.0 + :type scale: float + :param camera_distance: How far the Camera is away from the point; regular is 4.0 + :return: The 3D Point on a 2D plane + :rtype: tuple[float, float] + """ + return (point[0] * focal_length * scale / (point[2] + camera_distance), + point[1] * focal_length * scale / (point[2] + camera_distance), ) + def print_matrix(matrix:list[list[float]]) -> None: for row in matrix: diff --git a/test/test_pro_pers.py b/test/test_pro_pers.py new file mode 100644 index 0000000..1340dd5 --- /dev/null +++ b/test/test_pro_pers.py @@ -0,0 +1,21 @@ +from src.compute import project_perspective + +def test_pers_1(): + + point = (1.0, 2.0, 3.0) + exp_point = (1/7, 2/7) + + result = project_perspective(point) + + assert result == exp_point + + +def test_pers_2(): + + point = (1.0, 2.0, 3.0) + exp_point = (200/7, 400/7) + + result = project_perspective(point, focal_length=2.0, scale=100) + + assert result == exp_point +