diff --git a/pylinalg/vector.py b/pylinalg/vector.py index 928b629..0f905a5 100644 --- a/pylinalg/vector.py +++ b/pylinalg/vector.py @@ -1,5 +1,9 @@ +import logging + import numpy as np +logger = logging.getLogger() + def vec_normalize(vectors, /, *, out=None, dtype=None): """ @@ -219,8 +223,8 @@ def vec_transform_quat(vector, quaternion, /, *, out=None, dtype=None): return out -def vec_spherical_to_euclidian(spherical, /, *, out=None, dtype=None): - """Convert spherical -> euclidian coordinates. +def vec_spherical_to_euclidean(spherical, /, *, out=None, dtype=None): + """Convert spherical -> euclidean coordinates. Parameters ---------- @@ -238,7 +242,7 @@ def vec_spherical_to_euclidian(spherical, /, *, out=None, dtype=None): Returns ------- euclidean : ndarray, [3] - A vector in euclidian coordinates. + A vector in euclidean coordinates. Notes ----- @@ -383,7 +387,7 @@ def mat_decompose_translation(homogeneous_matrix, /, *, out=None, dtype=None): return out -def vec_euclidian_to_spherical(euclidean, /, *, out=None, dtype=None): +def vec_euclidean_to_spherical(euclidean, /, *, out=None, dtype=None): """Convert euclidean -> spherical coordinates Parameters @@ -527,6 +531,28 @@ def quat_to_euler(quaternion, /, *, out=None, dtype=None): return out +_warned_about_eucledian = False + + +def _warn_about_eucledian(): + global _warned_about_eucledian + if not _warned_about_eucledian: + _warned_about_eucledian = True + m = "methods vec_spherical_to_euclidian() and vec_euclidian_to_spherical()" + m += " have been renamed, because its eucledEan, not eucledIan." + logger.warning("pylinalg deprecation warning: " + m) + + +def vec_euclidian_to_spherical(euclidean, /, *, out=None, dtype=None): + _warn_about_eucledian() + return vec_euclidean_to_spherical(euclidean, out=out, dtype=dtype) + + +def vec_spherical_to_euclidian(spherical, /, *, out=None, dtype=None): + _warn_about_eucledian() + return vec_spherical_to_euclidean(spherical, out=out, dtype=dtype) + + __all__ = [ name for name in globals() if name.startswith(("vec_", "mat_", "quat_", "aabb_")) ] diff --git a/tests/test_vectors.py b/tests/test_vectors.py index a0f2030..109ccda 100644 --- a/tests/test_vectors.py +++ b/tests/test_vectors.py @@ -96,15 +96,15 @@ def test_vec_transform_out(): @example((1, 0, np.pi / 2), (0, 0, 1)) @example((1, np.pi / 2, np.pi / 2), (1, 0, 0)) @example((1, 0, 0), (0, 1, 0)) -def test_vec_euclidian_to_spherical(expected, vector): +def test_vec_euclidean_to_spherical(expected, vector): if vector is None: assume(abs(expected[0]) > 1e-10) - vector = la.vec_spherical_to_euclidian(expected) + vector = la.vec_spherical_to_euclidean(expected) else: expected = np.asarray(expected) vector = np.asarray(vector) - actual = la.vec_euclidian_to_spherical(vector) + actual = la.vec_euclidean_to_spherical(vector) assert np.allclose(actual, expected, rtol=1e-10) @@ -177,7 +177,7 @@ def test_vec_transform_out_dtype(): @given(ct.test_spherical) -def test_vec_spherical_to_euclidian(spherical): +def test_vec_spherical_to_euclidean(spherical): # accuracy of trigonometric ops close to 0, 90, 180, 270, 360 deg dependes a # lot on the underlying hardware. Let's avoid it here. angles = spherical[..., [1, 2]] @@ -191,7 +191,7 @@ def test_vec_spherical_to_euclidian(spherical): # we can't do a simple round trip test. Instead we ensure that we are # rotating in the right direction and that the radius/length match - result = la.vec_spherical_to_euclidian(spherical) + result = la.vec_spherical_to_euclidean(spherical) # ensure azimuth rotates CCW expected_sign = np.where(spherical[1] < np.pi / 2, 1, -1) @@ -209,12 +209,12 @@ def test_vec_spherical_to_euclidian(spherical): assert np.allclose(length, spherical[0], rtol=1e-16, atol=np.inf) -def test_vec_spherical_to_euclidian_refs(): +def test_vec_spherical_to_euclidean_refs(): # ensure that the reference axes get transformed as expected - result = la.vec_spherical_to_euclidian((1, 0, 0)) + result = la.vec_spherical_to_euclidean((1, 0, 0)) assert np.allclose(result, (0, 1, 0)) - result = la.vec_spherical_to_euclidian((1, 0, np.pi / 2)) + result = la.vec_spherical_to_euclidean((1, 0, np.pi / 2)) assert np.allclose(result, (0, 0, 1))