diff --git a/CHANGELOG.md b/CHANGELOG.md index 6229fd504c1d..cf30d3318708 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Updated workflows to v2. * Changed deepcopy of `RhinoBrep` to use the native `Rhino.Geometry` mechanism. * The normal of the cutting plane is no longer flipped in `compas_rhino.geometry.RhinoBrep`. +* Fixed `Polygon` constructor to not modify the input list of points. ### Removed diff --git a/src/compas/geometry/primitives/polygon.py b/src/compas/geometry/primitives/polygon.py index 1c1cc1e61cfd..79e163668fe3 100644 --- a/src/compas/geometry/primitives/polygon.py +++ b/src/compas/geometry/primitives/polygon.py @@ -132,7 +132,7 @@ def points(self): @points.setter def points(self, points): if points[-1] == points[0]: - del points[-1] + points = points[:-1] self._points = [Point(*xyz) for xyz in points] self._lines = None diff --git a/tests/compas/geometry/test_polygon.py b/tests/compas/geometry/test_polygon.py index faca266b0078..db621bdbe28a 100644 --- a/tests/compas/geometry/test_polygon.py +++ b/tests/compas/geometry/test_polygon.py @@ -25,6 +25,14 @@ def test_polygon(): assert polygon.lines == [(a, b) for a, b in pairwise(points + points[:1])] +def test_ctor_does_not_modify_input_params(): + pts = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 0, 0]] + + polygon = Polygon(pts) + assert len(pts) == 5 + assert len(polygon.points) == 4, "The last point (matching the first) should have been removed" + + def test_equality(): points1 = [[0, 0, x] for x in range(5)] polygon1 = Polygon(points1)