Commit c7b8920f authored by sumpfralle's avatar sumpfralle

fixed a small bug in "get_reversed" function: the "is_closed" attribute was not kept

fixed simplification of polygons


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@887 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 00a17c74
...@@ -69,7 +69,7 @@ class Polygon(TransformableContainer): ...@@ -69,7 +69,7 @@ class Polygon(TransformableContainer):
self._update_limits(line.p2) self._update_limits(line.p2)
elif self._points[-1] == line.p1: elif self._points[-1] == line.p1:
# the new Line can be added to the end of the polygon # the new Line can be added to the end of the polygon
if line.dir == line.p1.sub(self._points[-1]).normalized(): if line.dir == self._points[-1].sub(self._points[-2]).normalized():
# Remove the last point, if the previous point combination # Remove the last point, if the previous point combination
# is in line with the new Line. This avoids unnecessary # is in line with the new Line. This avoids unnecessary
# points on straight lines. # points on straight lines.
...@@ -81,7 +81,8 @@ class Polygon(TransformableContainer): ...@@ -81,7 +81,8 @@ class Polygon(TransformableContainer):
self.is_closed = True self.is_closed = True
else: else:
# the new Line can be added to the beginning of the polygon # the new Line can be added to the beginning of the polygon
if line.dir == self._points[0].sub(line.p2).normalized(): if (len(self._points) > 1) \
and (line.dir == self._points[1].sub(self._points[0]).normalized()):
# Avoid points on straight lines - see above. # Avoid points on straight lines - see above.
self._points.pop(0) self._points.pop(0)
if line.p1 != self._points[-1]: if line.p1 != self._points[-1]:
...@@ -107,6 +108,7 @@ class Polygon(TransformableContainer): ...@@ -107,6 +108,7 @@ class Polygon(TransformableContainer):
def get_reversed(self): def get_reversed(self):
result = Polygon(plane=self.plane) result = Polygon(plane=self.plane)
result._points = self._points[:] result._points = self._points[:]
result.is_closed = self.is_closed
result.reverse_direction() result.reverse_direction()
return result return result
...@@ -259,8 +261,7 @@ class Polygon(TransformableContainer): ...@@ -259,8 +261,7 @@ class Polygon(TransformableContainer):
""" Caching is necessary to avoid constant recalculation due to """ Caching is necessary to avoid constant recalculation due to
the "to_OpenGL" method. the "to_OpenGL" method.
""" """
if (self._lines_cache is None) \ if self._lines_cache is None:
or (len(self) != len(self._lines_cache)):
# recalculate the line cache # recalculate the line cache
lines = [] lines = []
for index in range(len(self._points) - 1): for index in range(len(self._points) - 1):
...@@ -300,6 +301,7 @@ class Polygon(TransformableContainer): ...@@ -300,6 +301,7 @@ class Polygon(TransformableContainer):
self.maxy = max(self.maxy, point.y) self.maxy = max(self.maxy, point.y)
self.minz = min(self.minz, point.z) self.minz = min(self.minz, point.z)
self.maxz = max(self.maxz, point.z) self.maxz = max(self.maxz, point.z)
self._lines_cache = None
def reset_cache(self): def reset_cache(self):
self._cached_offset_polygons = {} self._cached_offset_polygons = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment