Skip to content

Commit b5b328e

Browse files
committed
Merge branch 'release/2.17.0'
2 parents 07f752f + ec949e9 commit b5b328e

File tree

7 files changed

+67
-8
lines changed

7 files changed

+67
-8
lines changed

.github/workflows/main.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: tox
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 10
12+
strategy:
13+
matrix:
14+
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install tox tox-gh-actions
26+
- name: Test with tox
27+
run: tox

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ numpy-stl
66
:alt: numpy-stl test status
77
:target: https://ci.appveyor.com/project/WoLpH/numpy-stl
88

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

1313
.. image:: https://badge.fury.io/py/numpy-stl.svg
1414
:alt: numpy-stl Pypi version

stl/__about__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__package_name__ = 'numpy-stl'
22
__import_name__ = 'stl'
3-
__version__ = '2.16.3'
3+
__version__ = '2.17.0'
44
__author__ = 'Rick van Hattem'
55
__author_email__ = '[email protected]'
66
__description__ = ' '.join('''

stl/base.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,16 @@ def remove_empty_areas(cls, data):
313313
squared_areas = (normals ** 2).sum(axis=1)
314314
return data[squared_areas > AREA_SIZE_THRESHOLD ** 2]
315315

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

320320
if update_areas:
321321
self.update_areas(normals)
322322

323+
if update_centroids:
324+
self.update_centroids()
325+
323326
self.normals[:] = normals
324327

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

349+
def update_centroids(self):
350+
self.centroids = numpy.mean([self.v0, self.v1, self.v2], axis=0)
351+
346352
def check(self):
347353
'''Check the mesh is valid or not'''
348354
return self.is_closed()
@@ -582,6 +588,8 @@ def _set(self, value):
582588
doc='Mesh maximum value')
583589
areas = property(_get_or_update('areas'), _set('areas'),
584590
doc='Mesh areas')
591+
centroids = property(_get_or_update('centroids'), _set('centroids'),
592+
doc='Mesh centroids')
585593
units = property(_get_or_update('units'), _set('units'),
586594
doc='Mesh unit vectors')
587595

stl/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _get_name(args):
2929
args.name,
3030
getattr(args.outfile, 'name', None),
3131
getattr(args.infile, 'name', None),
32-
'numpy-stl-%06d' % random.randint(0, 1e6),
32+
'numpy-stl-%06d' % random.randint(0, 1_000_000),
3333
]
3434

3535
for name in names: # pragma: no branch

tests/test_mesh.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def test_units_1d():
1717
mesh.update_units()
1818

1919
assert mesh.areas == 0
20+
assert numpy.allclose(mesh.centroids, [[1, 0, 0]])
2021
utils.array_equals(mesh.normals, [0, 0, 0])
2122
utils.array_equals(mesh.units, [0, 0, 0])
2223
utils.array_equals(mesh.get_unit_normals(), [0, 0, 0])
@@ -35,6 +36,9 @@ def test_units_2d():
3536
mesh.update_units()
3637

3738
assert numpy.allclose(mesh.areas, [0.5, 0.5])
39+
assert numpy.allclose(mesh.centroids, [
40+
[1 / 3, 1 / 3, 0],
41+
[2 / 3, 2 / 3, 0]])
3842
assert numpy.allclose(mesh.normals, [
3943
[0.0, 0.0, 1.0],
4044
[0.0, 0.0, -1.0]])
@@ -54,6 +58,7 @@ def test_units_3d():
5458
mesh.update_units()
5559

5660
assert (mesh.areas - 2 ** .5) < 0.0001
61+
assert numpy.allclose(mesh.centroids, [1 / 3, 1 / 3, 1 / 3])
5762
assert numpy.allclose(mesh.normals, [0.0, -1.0, 1.0])
5863
assert numpy.allclose(mesh.units[0], [0.0, -0.70710677, 0.70710677])
5964
assert numpy.allclose(numpy.linalg.norm(mesh.units, axis=-1), 1)
@@ -183,11 +188,23 @@ def test_empty_areas():
183188
mesh.areas[2] = 2
184189
assert numpy.allclose(mesh.areas, [[0.5], [1.0], [2.0]])
185190

186-
mesh.update_normals(update_areas=False)
191+
mesh.centroids[1] = [1, 2, 3]
192+
mesh.centroids[2] = [4, 5, 6]
193+
assert numpy.allclose(mesh.centroids, [[1 / 3, 1 / 3, 0],
194+
[1, 2, 3],
195+
[4, 5, 6]])
196+
197+
mesh.update_normals(update_areas=False, update_centroids=False)
187198
assert numpy.allclose(mesh.areas, [[0.5], [1.0], [2.0]])
199+
assert numpy.allclose(mesh.centroids, [[1 / 3, 1 / 3, 0],
200+
[1, 2, 3],
201+
[4, 5, 6]])
188202

189-
mesh.update_normals(update_areas=True)
203+
mesh.update_normals(update_areas=True, update_centroids=True)
190204
assert numpy.allclose(mesh.areas, [[0.5], [0.0], [0.0]])
205+
assert numpy.allclose(mesh.centroids, [[1 / 3, 1 / 3, 0],
206+
[2 / 3, 1 / 3, 0],
207+
[2 / 3, 1 / 3, 0]])
191208

192209
mesh = Mesh(data, remove_empty_areas=True)
193210
assert mesh.data.size == 1

tox.ini

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ basepython =
1616
py310: python3.10
1717
pypy3: pypy3
1818

19+
[gh-actions]
20+
python =
21+
3.6: py36
22+
3.7: py37
23+
3.8: py38
24+
3.9: py39
25+
1926
[testenv:flake8]
2027
basepython=python
2128
commands = flake8 --ignore=W391 stl tests

0 commit comments

Comments
 (0)