diff --git a/matrixmania/__pycache__/__init__.cpython-312.pyc b/matrixmania/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..c22d1e9 Binary files /dev/null and b/matrixmania/__pycache__/__init__.cpython-312.pyc differ diff --git a/matrixmania/__pycache__/compute.cpython-312.pyc b/matrixmania/__pycache__/compute.cpython-312.pyc new file mode 100644 index 0000000..0b5681a Binary files /dev/null and b/matrixmania/__pycache__/compute.cpython-312.pyc differ diff --git a/matrixmania/compute.py b/matrixmania/compute.py index ce30e61..17469cb 100644 --- a/matrixmania/compute.py +++ b/matrixmania/compute.py @@ -1,6 +1,7 @@ from typing import List import math from tabulate import tabulate +from typing import Tuple def matmul(mat1: List[List[int]], mat2: List[List[int]]) -> List[List[int]]: """ @@ -119,6 +120,18 @@ def rot_3D(angle: float, axis: str) -> List[List[float]]: else: raise ValueError("Axis must be 'x', 'y', or 'z'.") +def project_ortho(point: Tuple[float, float, float], scale: float = 1) -> Tuple[float, float]: + """ + Retruns a 2d point with optional scaling + + ignores the z axis and if scaling needed scales the 2d point + + :param point: Coordinates of a 3d point + :param scale: scaling factor (else 1) + :return: A 2d point + """ + return scale * point[0], scale * point[1] + def main(): # Test matrix multiplication @@ -150,7 +163,6 @@ def main(): print("Matrix A:") print(tabulate(matrix_a)) - if __name__ == "__main__": main() diff --git a/tests/__pycache__/test_matmul.cpython-312-pytest-8.4.2.pyc b/tests/__pycache__/test_matmul.cpython-312-pytest-8.4.2.pyc new file mode 100644 index 0000000..1c66b0b Binary files /dev/null and b/tests/__pycache__/test_matmul.cpython-312-pytest-8.4.2.pyc differ diff --git a/tests/__pycache__/test_projection.cpython-312-pytest-8.4.2.pyc b/tests/__pycache__/test_projection.cpython-312-pytest-8.4.2.pyc new file mode 100644 index 0000000..55f8c7d Binary files /dev/null and b/tests/__pycache__/test_projection.cpython-312-pytest-8.4.2.pyc differ diff --git a/tests/__pycache__/test_rot.cpython-312-pytest-8.4.2.pyc b/tests/__pycache__/test_rot.cpython-312-pytest-8.4.2.pyc new file mode 100644 index 0000000..d50aa87 Binary files /dev/null and b/tests/__pycache__/test_rot.cpython-312-pytest-8.4.2.pyc differ diff --git a/tests/__pycache__/test_rot3D.cpython-312-pytest-8.4.2.pyc b/tests/__pycache__/test_rot3D.cpython-312-pytest-8.4.2.pyc new file mode 100644 index 0000000..f5ed064 Binary files /dev/null and b/tests/__pycache__/test_rot3D.cpython-312-pytest-8.4.2.pyc differ diff --git a/tests/__pycache__/test_transpose.cpython-312-pytest-8.4.2.pyc b/tests/__pycache__/test_transpose.cpython-312-pytest-8.4.2.pyc new file mode 100644 index 0000000..7ffc1a6 Binary files /dev/null and b/tests/__pycache__/test_transpose.cpython-312-pytest-8.4.2.pyc differ diff --git a/tests/test_projection.py b/tests/test_projection.py new file mode 100644 index 0000000..f6f0e80 --- /dev/null +++ b/tests/test_projection.py @@ -0,0 +1,14 @@ +from matrixmania.compute import project_ortho + +def test_project_ortho_no_scale(): + point = (1.0, 2.0, 3.0) + result = project_ortho(point) + expected = (1.0, 2.0) + assert result == expected + + +def test_project_ortho_with_scale(): + point = (1.0, 2.0, 3.0) + result = project_ortho(point, scale=100) + expected = (100.0, 200.0) + assert result == expected