Skip to content

Commit b03002c

Browse files
authored
Merge pull request #1113 from compas-dev/fix-1112-polygon-input
fix #1112: do not modify input list when assigning points
2 parents 5a688ac + 62cb9cf commit b03002c

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
* Updated workflows to v2.
1919
* Changed deepcopy of `RhinoBrep` to use the native `Rhino.Geometry` mechanism.
2020
* The normal of the cutting plane is no longer flipped in `compas_rhino.geometry.RhinoBrep`.
21+
* Fixed `Polygon` constructor to not modify the input list of points.
2122

2223
### Removed
2324

src/compas/geometry/primitives/polygon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def points(self):
132132
@points.setter
133133
def points(self, points):
134134
if points[-1] == points[0]:
135-
del points[-1]
135+
points = points[:-1]
136136
self._points = [Point(*xyz) for xyz in points]
137137
self._lines = None
138138

tests/compas/geometry/test_polygon.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ def test_polygon():
2525
assert polygon.lines == [(a, b) for a, b in pairwise(points + points[:1])]
2626

2727

28+
def test_ctor_does_not_modify_input_params():
29+
pts = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 0, 0]]
30+
31+
polygon = Polygon(pts)
32+
assert len(pts) == 5
33+
assert len(polygon.points) == 4, "The last point (matching the first) should have been removed"
34+
35+
2836
def test_equality():
2937
points1 = [[0, 0, x] for x in range(5)]
3038
polygon1 = Polygon(points1)

0 commit comments

Comments
 (0)