Commit f16bc543 authored by sumpfralle's avatar sumpfralle

fixed a problem of the "merge polygons" code


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1016 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 2a5d10fe
...@@ -328,22 +328,27 @@ class ContourModel(BaseModel): ...@@ -328,22 +328,27 @@ class ContourModel(BaseModel):
This function should be called after any "append" event, if the lines to This function should be called after any "append" event, if the lines to
be added are given in a random order (e.g. by the "waterline" function). be added are given in a random order (e.g. by the "waterline" function).
""" """
connector1 = other_polygon.get_lines()[0] if other_polygon.is_closed:
connector2 = other_polygon.get_lines()[-1] return
connectors = []
connectors.append(other_polygon.get_points()[0])
connectors.append(other_polygon.get_points()[-1])
# filter all polygons that can be combined with 'other_polygon' # filter all polygons that can be combined with 'other_polygon'
connectables = [] connectables = []
for lg in self._line_groups: for lg in self._line_groups:
if lg is other_polygon: if lg is other_polygon:
continue continue
if lg.is_connectable(connector1) or lg.is_connectable(connector2): for connector in connectors:
if lg.is_connectable(connector):
connectables.append(lg) connectables.append(lg)
break
# merge 'other_polygon' with all other connectable polygons # merge 'other_polygon' with all other connectable polygons
for polygon in connectables: for polygon in connectables:
if other_polygon.is_connectable(polygon.get_lines()[0]): if other_polygon.get_points()[-1] == polygon.get_points()[0]:
for line in polygon.get_lines(): for line in polygon.get_lines():
other_polygon.append(line) other_polygon.append(line)
self._line_groups.remove(polygon) self._line_groups.remove(polygon)
elif other_polygon.is_connectable(polygon.get_lines()[-1]): elif other_polygon.get_points()[0] == polygon.get_points()[-1]:
lines = polygon.get_lines() lines = polygon.get_lines()
lines.reverse() lines.reverse()
for line in lines: for line in lines:
......
...@@ -122,18 +122,28 @@ class Polygon(TransformableContainer): ...@@ -122,18 +122,28 @@ class Polygon(TransformableContainer):
result.reverse_direction() result.reverse_direction()
return result return result
def is_connectable(self, line): def is_connectable(self, line_or_point):
if self.is_closed: if self.is_closed:
return False return False
elif not self._points: elif not self._points:
# empty polygons can be connected with any line # empty polygons can be connected with any line
return True return True
elif line.p1 == self._points[-1]: if hasattr(line_or_point, "get_length_line"):
# it is a line
line = line_or_point
if line.p1 == self._points[-1]:
return True return True
elif line.p2 == self._points[0]: elif line.p2 == self._points[0]:
return True return True
else: else:
return False return False
else:
# it is a point
point = line_or_point
if (point == self._points[-1]) or (point == self._points[0]):
return True
else:
return False
def next(self): def next(self):
for point in self._points: for point in self._points:
......
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