Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Renamed `Tolerance.units` to `Tolerance.unit` to better reflect the documented properties. Left `units` with deprecation warning.
* Fixed `NotImplementedErorr` when calling `BrepLoop.vertices`.
* Fixed `python -m compas` to detect extensions based on `importlib` rather than `pkg_resources`.
* Fixed `Polyhedron.vertices` setter to convert `Point` instances to `[x, y, z]` lists.

### Removed

Expand Down
2 changes: 2 additions & 0 deletions src/compas/geometry/polyhedron.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ def vertices(self):

@vertices.setter
def vertices(self, vertices):
if all(isinstance(vertex, Point) for vertex in vertices):
vertices = [[vertex.x, vertex.y, vertex.z] for vertex in vertices]
self._vertices = vertices
Comment on lines +287 to 289

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps something more like this?

Suggested change
if all(isinstance(vertex, Point) for vertex in vertices):
vertices = [[vertex.x, vertex.y, vertex.z] for vertex in vertices]
self._vertices = vertices
self._vertices = []
for vertex in vertices:
self._vertices.append([*vertex])


@property
Expand Down
16 changes: 16 additions & 0 deletions tests/compas/geometry/test_polyhedron.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from compas.geometry import Polyhedron
from compas.geometry import Point
from compas.itertools import pairwise


Expand All @@ -17,3 +18,18 @@ def test_polyhedron():
assert polyhedron.lines == [(a, b) for a, b in pairwise(vertices[-1:] + vertices)]
assert polyhedron.points[0] == vertices[0]
assert polyhedron.points[-1] != polyhedron.points[0]


def test_polyhedron_vertices():
vertices = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]]
faces = [[0, 1, 2, 3]]
name = "Test Polyhedron"
polyhedron = Polyhedron(vertices, faces, name)

polyhedron_vertices = polyhedron.vertices
assert all(isinstance(vertex, list) and len(vertex) == 3 for vertex in polyhedron_vertices)

vertices = [Point(0, 0, 0), Point(1, 0, 0), Point(1, 1, 0), Point(0, 1, 0)]
polyhedron = Polyhedron(vertices, faces, name)
polyhedron_vertices = polyhedron.vertices
assert all(isinstance(vertex, list) and len(vertex) == 3 for vertex in polyhedron_vertices)
Loading