Skip to content

Commit

Permalink
Merge branch 'release/2.17.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed May 13, 2022
2 parents 07f752f + ec949e9 commit b5b328e
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 8 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: tox

on:
push:
pull_request:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ numpy-stl
:alt: numpy-stl test status
:target: https://ci.appveyor.com/project/WoLpH/numpy-stl

.. image:: https://travis-ci.org/WoLpH/numpy-stl.svg?branch=master
.. image:: https://github.com/WoLpH/numpy-stl/actions/workflows/main.yml/badge.svg
:alt: numpy-stl test status
:target: https://travis-ci.org/WoLpH/numpy-stl
:target: https://github.com/WoLpH/numpy-stl/actions

.. image:: https://badge.fury.io/py/numpy-stl.svg
:alt: numpy-stl Pypi version
Expand Down
2 changes: 1 addition & 1 deletion stl/__about__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__package_name__ = 'numpy-stl'
__import_name__ = 'stl'
__version__ = '2.16.3'
__version__ = '2.17.0'
__author__ = 'Rick van Hattem'
__author_email__ = '[email protected]'
__description__ = ' '.join('''
Expand Down
12 changes: 10 additions & 2 deletions stl/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,16 @@ def remove_empty_areas(cls, data):
squared_areas = (normals ** 2).sum(axis=1)
return data[squared_areas > AREA_SIZE_THRESHOLD ** 2]

def update_normals(self, update_areas=True):
'''Update the normals and areas for all points'''
def update_normals(self, update_areas=True, update_centroids=True):
'''Update the normals, areas, and centroids for all points'''
normals = numpy.cross(self.v1 - self.v0, self.v2 - self.v0)

if update_areas:
self.update_areas(normals)

if update_centroids:
self.update_centroids()

self.normals[:] = normals

def get_unit_normals(self):
Expand All @@ -343,6 +346,9 @@ def update_areas(self, normals=None):
areas = .5 * numpy.sqrt((normals ** 2).sum(axis=1))
self.areas = areas.reshape((areas.size, 1))

def update_centroids(self):
self.centroids = numpy.mean([self.v0, self.v1, self.v2], axis=0)

def check(self):
'''Check the mesh is valid or not'''
return self.is_closed()
Expand Down Expand Up @@ -582,6 +588,8 @@ def _set(self, value):
doc='Mesh maximum value')
areas = property(_get_or_update('areas'), _set('areas'),
doc='Mesh areas')
centroids = property(_get_or_update('centroids'), _set('centroids'),
doc='Mesh centroids')
units = property(_get_or_update('units'), _set('units'),
doc='Mesh unit vectors')

Expand Down
2 changes: 1 addition & 1 deletion stl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _get_name(args):
args.name,
getattr(args.outfile, 'name', None),
getattr(args.infile, 'name', None),
'numpy-stl-%06d' % random.randint(0, 1e6),
'numpy-stl-%06d' % random.randint(0, 1_000_000),
]

for name in names: # pragma: no branch
Expand Down
21 changes: 19 additions & 2 deletions tests/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def test_units_1d():
mesh.update_units()

assert mesh.areas == 0
assert numpy.allclose(mesh.centroids, [[1, 0, 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])
Expand All @@ -35,6 +36,9 @@ def test_units_2d():
mesh.update_units()

assert numpy.allclose(mesh.areas, [0.5, 0.5])
assert numpy.allclose(mesh.centroids, [
[1 / 3, 1 / 3, 0],
[2 / 3, 2 / 3, 0]])
assert numpy.allclose(mesh.normals, [
[0.0, 0.0, 1.0],
[0.0, 0.0, -1.0]])
Expand All @@ -54,6 +58,7 @@ def test_units_3d():
mesh.update_units()

assert (mesh.areas - 2 ** .5) < 0.0001
assert numpy.allclose(mesh.centroids, [1 / 3, 1 / 3, 1 / 3])
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)
Expand Down Expand Up @@ -183,11 +188,23 @@ def test_empty_areas():
mesh.areas[2] = 2
assert numpy.allclose(mesh.areas, [[0.5], [1.0], [2.0]])

mesh.update_normals(update_areas=False)
mesh.centroids[1] = [1, 2, 3]
mesh.centroids[2] = [4, 5, 6]
assert numpy.allclose(mesh.centroids, [[1 / 3, 1 / 3, 0],
[1, 2, 3],
[4, 5, 6]])

mesh.update_normals(update_areas=False, update_centroids=False)
assert numpy.allclose(mesh.areas, [[0.5], [1.0], [2.0]])
assert numpy.allclose(mesh.centroids, [[1 / 3, 1 / 3, 0],
[1, 2, 3],
[4, 5, 6]])

mesh.update_normals(update_areas=True)
mesh.update_normals(update_areas=True, update_centroids=True)
assert numpy.allclose(mesh.areas, [[0.5], [0.0], [0.0]])
assert numpy.allclose(mesh.centroids, [[1 / 3, 1 / 3, 0],
[2 / 3, 1 / 3, 0],
[2 / 3, 1 / 3, 0]])

mesh = Mesh(data, remove_empty_areas=True)
assert mesh.data.size == 1
Expand Down
7 changes: 7 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ basepython =
py310: python3.10
pypy3: pypy3

[gh-actions]
python =
3.6: py36
3.7: py37
3.8: py38
3.9: py39

[testenv:flake8]
basepython=python
commands = flake8 --ignore=W391 stl tests
Expand Down

0 comments on commit b5b328e

Please sign in to comment.