Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Korijn committed Jan 10, 2025
1 parent 3937cee commit 4f57053
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion pylinalg/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions tests/test_pylinalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
10 changes: 10 additions & 0 deletions tests/test_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 4f57053

Please sign in to comment.