Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance Fixing Build Errors and Add Support for Python 3.7 & 3.8 #37

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ python:
- 3.4
- 3.5
- 3.6
- 3.7
- 3.8

sudo: false

Expand Down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ vectormath
:alt: Code test coverage


Vector math utilities for Python built on `NumPy <http://www.numpy.org/>`_
Vector math utilities for Python built on `NumPy <https://numpy.org/>`_


Why
---

The :code:`vectormath` package provides a fast, simple library of vector math
utilities by leveraging NumPy. This allows explicit
utilities by leveraging NumPy_. This allows explicit
geometric constructs to be created (for example, :code:`Vector3` and :code:`Plane`)
without redefining the underlying array math.

Expand All @@ -40,7 +40,7 @@ The :code:`vectormath` package includes :code:`Vector3`/:code:`Vector2` and
Goals
-----

* Speed: All low-level operations rely on NumPy arrays. These are densely packed,
* Speed: All low-level operations rely on NumPy_ arrays. These are densely packed,
typed, and partially implemented in C. The :code:`VectorArray` classes in particular
take advantage of this speed by performing vector operations on all Vectors at
once, rather than in a loop.
Expand All @@ -51,7 +51,7 @@ Goals
Alternatives
------------

* `NumPy <http://www.numpy.org/>`_ can be used for any array operations
* NumPy_ can be used for any array operations
* Many small libraries on PyPI (e.g. `vectors <https://github.com/allelos/vectors>`_)
implement vector math operations but are are only built with single vectors
in mind.
Expand Down
34 changes: 19 additions & 15 deletions vectormath/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def rho(self, value):
def theta(self):
"""Angular coordinate / azimuthal angle of this vector in radians

Based on polar coordinate space (or sperical coordinate space for `Vector3`)
Based on polar coordinate space (or spherical coordinate space for `Vector3`)
returns angle between this vector and the positive x-axis
range: (-pi <= theta <= pi)
"""
Expand All @@ -79,7 +79,7 @@ def theta(self):
def theta_deg(self):
"""Angular coordinate / azimuthal angle of this vector in degrees

Based on polar coordinate space (or sperical coordinate space for `Vector3`)
Based on polar coordinate space (or spherical coordinate space for `Vector3`)
returns angle between this vector and the positive x-axis
range: (-180 <= theta_deg <= 180)
"""
Expand All @@ -100,15 +100,15 @@ def as_percent(self, value):
def as_unit(self):
"""Return a new vector scaled to length 1"""
new_vec = self.copy()
new_vec.normalize()
new_vec.normalize() # pylint: disable=no-member
return new_vec

def normalize(self):
"""Scale the length of a vector to 1 in place"""
self.length = 1
return self

def dot(self, vec):
def dot(self, vec): # pylint: disable=arguments-differ
"""Dot product with another vector"""
if not isinstance(vec, self.__class__):
raise TypeError('Dot product operand must be a vector')
Expand Down Expand Up @@ -179,7 +179,8 @@ def read_array(X, Y, Z):

return read_array(x, y, z)

def __array_wrap__(self, out_arr, context=None): #pylint: disable=no-self-use, unused-argument
@staticmethod
def __array_wrap__(out_arr, context=None): # pylint: disable=arguments-differ, unused-argument
"""This is called at the end of ufuncs

If the output is the wrong shape, return the ndarray view
Expand Down Expand Up @@ -220,8 +221,8 @@ def z(self, value):
def phi(self):
"""Polar angle / inclination of this vector in radians

Based on sperical coordinate space
returns angle between this vector and the positive z-azis
Based on spherical coordinate space
returns angle between this vector and the positive z-axis
range: (0 <= phi <= pi)
"""
return np.arctan2(np.sqrt(self.x**2 + self.y**2), self.z)
Expand All @@ -236,8 +237,8 @@ def phi(self):
def phi_deg(self):
"""Polar angle / inclination of this vector in degrees

Based on sperical coordinate space
returns angle between this vector and the positive z-azis
Based on spherical coordinate space
returns angle between this vector and the positive z-axis
range: (0 <= phi <= pi)
"""
return self.phi * 180 / np.pi
Expand Down Expand Up @@ -287,7 +288,8 @@ def read_array(X, Y):

return read_array(x, y)

def __array_wrap__(self, out_arr, context=None): #pylint: disable=no-self-use, unused-argument
@staticmethod
def __array_wrap__(out_arr, context=None): # pylint: disable=arguments-differ, unused-argument
if out_arr.shape != (2,):
out_arr = out_arr.view(np.ndarray)
return out_arr
Expand All @@ -304,7 +306,7 @@ def cross(self, vec):
"""Cross product with another vector"""
if not isinstance(vec, self.__class__):
raise TypeError('Cross product operand must be a vector')
return Vector3(0, 0, np.asscalar(np.cross(self, vec)))
return Vector3(0, 0, np.cross(self, vec).item(0))


class BaseVectorArray(BaseVector):
Expand Down Expand Up @@ -385,7 +387,7 @@ def dot(self, vec):
if self.nV != 1 and vec.nV != 1 and self.nV != vec.nV:
raise ValueError('Dot product operands must have the same '
'number of elements.')
return np.sum((getattr(self, d)*getattr(vec, d) for d in self.dims), 1)
return sum((getattr(self, d)*getattr(vec, d) for d in self.dims))

def angle(self, vec, unit='rad'):
"""Angle method is only for Vectors, not VectorArrays"""
Expand Down Expand Up @@ -448,7 +450,8 @@ def read_array(X, Y, Z):

return read_array(x, y, z)

def __array_wrap__(self, out_arr, context=None): #pylint: disable=no-self-use, unused-argument
@staticmethod
def __array_wrap__(out_arr, context=None): # pylint: disable=arguments-differ, unused-argument
if len(out_arr.shape) != 2 or out_arr.shape[1] != 3:
out_arr = out_arr.view(np.ndarray)
return out_arr
Expand All @@ -463,7 +466,7 @@ def __array_finalize__(self, obj):
)

def __getitem__(self, i):
"""Overriding _getitem__ allows coersion to Vector3 or ndarray"""
"""Overriding __getitem__ allows coercion to Vector3 or ndarray"""
item_out = super(Vector3Array, self).__getitem__(i)
if np.isscalar(i):
return item_out.view(Vector3)
Expand Down Expand Up @@ -548,7 +551,8 @@ def read_array(X, Y):

return read_array(x, y)

def __array_wrap__(self, out_arr, context=None): #pylint: disable=no-self-use, unused-argument
@staticmethod
def __array_wrap__(out_arr, context=None): # pylint: disable=arguments-differ, unused-argument
if len(out_arr.shape) != 2 or out_arr.shape[1] != 2:
out_arr = out_arr.view(np.ndarray)
return out_arr
Expand Down