From 4f57053c4595d8f20aa4aaae67b83aa114eb35a5 Mon Sep 17 00:00:00 2001 From: Korijn van Golen Date: Fri, 10 Jan 2025 11:10:58 +0100 Subject: [PATCH] add test --- pylinalg/vector.py | 4 +++- tests/test_pylinalg.py | 12 ++++++------ tests/test_vectors.py | 10 ++++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/pylinalg/vector.py b/pylinalg/vector.py index b03e031..a024b0a 100644 --- a/pylinalg/vector.py +++ b/pylinalg/vector.py @@ -167,7 +167,9 @@ def vec_unproject( if out is None: out = np.empty((*result_shape, 3), dtype=dtype) - if not matrix_is_inv: + if matrix_is_inv: + inverse_projection = matrix + else: from .matrix import mat_inverse inverse_projection = mat_inverse(matrix, raise_err=True) diff --git a/tests/test_pylinalg.py b/tests/test_pylinalg.py index d67e854..1afa66c 100644 --- a/tests/test_pylinalg.py +++ b/tests/test_pylinalg.py @@ -58,9 +58,9 @@ def popattr(key): # confirm the signature of each callable sig = inspect.signature(getattr(la, key)) - assert ( - sig.return_annotation is not inspect.Signature.empty - ), f"Missing return annotation on {key}" + assert sig.return_annotation is not inspect.Signature.empty, ( + f"Missing return annotation on {key}" + ) if sig.return_annotation is bool: key_parts = key.split("_") assert key_parts[1] in ("is", "has") @@ -77,9 +77,9 @@ def popattr(key): assert param.KEYWORD_ONLY has_out = True assert has_out, f"Function {key} does not have 'out' keyword-only argument" - assert ( - has_dtype - ), f"Function {key} does not have 'dtype' keyword-only argument" + assert has_dtype, ( + f"Function {key} does not have 'dtype' keyword-only argument" + ) # assert that all callables are available in __all__ assert set(__all__) == set(callables) diff --git a/tests/test_vectors.py b/tests/test_vectors.py index e69dd68..b5e923b 100644 --- a/tests/test_vectors.py +++ b/tests/test_vectors.py @@ -303,6 +303,16 @@ def test_vec_unproject_exceptions(): la.vec_unproject(vector, matrix) +def test_vec_unproject_is_inverse(): + a = la.mat_perspective(-1, 1, -1, 1, 1, 100) + a_inv = la.mat_inverse(a) + vecs = np.array([[1, 2], [4, 5], [7, 8]]) + + expected = la.vec_unproject(vecs, a) + actual = la.vec_unproject(vecs, a_inv, matrix_is_inv=True) + npt.assert_array_equal(expected, actual) + + def test_vector_apply_rotation_ordered(): """Test that a positive pi/2 rotation about the z-axis and then the y-axis results in a different output then in standard rotation ordering."""