Skip to content

Commit

Permalink
Merge branch 'release/2.12.0' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Oct 16, 2020
2 parents 3cc52e2 + ecc2e63 commit e91d2e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion stl/__about__.py
@@ -1,6 +1,6 @@
__package_name__ = 'numpy-stl'
__import_name__ = 'stl'
__version__ = '2.11.3'
__version__ = '2.12.0'
__author__ = 'Rick van Hattem'
__author_email__ = 'Wolph@Wol.ph'
__description__ = ' '.join('''
Expand Down
6 changes: 5 additions & 1 deletion stl/base.py
Expand Up @@ -320,11 +320,15 @@ def update_normals(self, update_areas=True):
if update_areas:
self.update_areas(normals)

self.normals[:] = normals

def get_unit_normals(self):
normals = self.normals.copy()
normal = numpy.linalg.norm(normals, axis=1)
non_zero = normal > 0
if non_zero.any():
normals[non_zero] /= normal[non_zero][:, None]
self.normals[:] = normals
return normals

def update_min(self):
self._min = self.vectors.min(axis=(0, 1))
Expand Down
11 changes: 9 additions & 2 deletions tests/test_mesh.py
Expand Up @@ -19,6 +19,7 @@ def test_units_1d():
assert mesh.areas == 0
utils.array_equals(mesh.normals, [0, 0, 0])
utils.array_equals(mesh.units, [0, 0, 0])
utils.array_equals(mesh.get_unit_normals(), [0, 0, 0])


def test_units_2d():
Expand All @@ -38,6 +39,9 @@ def test_units_2d():
[0.0, 0.0, 1.0],
[0.0, 0.0, -1.0]])
assert numpy.allclose(mesh.units, [[0, 0, 1], [0, 0, -1]])
assert numpy.allclose(mesh.get_unit_normals(), [
[0.0, 0.0, 1.0],
[0.0, 0.0, -1.0]])


def test_units_3d():
Expand All @@ -50,8 +54,11 @@ def test_units_3d():
mesh.update_units()

assert (mesh.areas - 2 ** .5) < 0.0001
assert numpy.allclose(mesh.normals, [0.0, -0.70710677, 0.70710677])
assert numpy.allclose(mesh.units[0], [0.0, -0.5, 0.5])
assert numpy.allclose(mesh.normals, [0.0, -1.0, 1.0])
assert numpy.allclose(mesh.units[0], [0.0, -0.70710677, 0.70710677])
assert numpy.allclose(numpy.linalg.norm(mesh.units, axis=-1), 1)
assert numpy.allclose(mesh.get_unit_normals(),
[0.0, -0.70710677, 0.70710677])


def test_duplicate_polygons():
Expand Down

0 comments on commit e91d2e1

Please sign in to comment.