Skip to content

Commit

Permalink
Rename 2 funcs eucledian -> eucledean (#84)
Browse files Browse the repository at this point in the history
* rename public func eucledian -> eucledean

* fix api
  • Loading branch information
almarklein authored Oct 19, 2023
1 parent 76575f6 commit 92a83a2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
34 changes: 30 additions & 4 deletions pylinalg/vector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import logging

import numpy as np

logger = logging.getLogger()


def vec_normalize(vectors, /, *, out=None, dtype=None):
"""
Expand Down Expand Up @@ -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
----------
Expand All @@ -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
-----
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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_"))
]
16 changes: 8 additions & 8 deletions tests/test_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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]]
Expand All @@ -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)
Expand All @@ -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))


Expand Down

0 comments on commit 92a83a2

Please sign in to comment.