Skip to content

Commit

Permalink
Make the scipy convex hull code a bit more robust just like the pure …
Browse files Browse the repository at this point in the history
…Python version.

Contributes to CURA-1512
  • Loading branch information
sedwards2009 committed May 12, 2016
1 parent f8703b4 commit 642bf79
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion UM/Math/Polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,13 @@ def intersectsPolygon(self, other):
# \return \type{Polygon} The convex hull around the points of this polygon.
if has_scipy:
def getConvexHull(self):
hull = scipy.spatial.ConvexHull(self._points)
points = self._points

This comment has been minimized.

Copy link
@fieldOfView

fieldOfView May 13, 2016

Contributor

Out of curiosity, why do you create the additional variable? Aren't they both referencing the same data in memory?

This comment has been minimized.

Copy link
@nallath

nallath May 13, 2016

Member

They are both referencing the same data in memory yeah.


if len(points) < 1:
return Polygon(numpy.zeros((0, 2), numpy.float64))
if len(points) <= 2:
return Polygon(numpy.array(points, numpy.float64))
hull = scipy.spatial.ConvexHull(points)
return Polygon(numpy.flipud(self._points[hull.vertices]))
else:
def getConvexHull(self):
Expand Down

0 comments on commit 642bf79

Please sign in to comment.