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):
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).
"""
connector1 = other_polygon.get_lines()[0]
connector2 = other_polygon.get_lines()[-1]
if other_polygon.is_closed:
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'
connectables = []
for lg in self._line_groups:
if lg is other_polygon:
continue
if lg.is_connectable(connector1) or lg.is_connectable(connector2):
connectables.append(lg)
for connector in connectors:
if lg.is_connectable(connector):
connectables.append(lg)
break
# merge 'other_polygon' with all other connectable polygons
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():
other_polygon.append(line)
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.reverse()
for line in lines:
......
......@@ -122,18 +122,28 @@ class Polygon(TransformableContainer):
result.reverse_direction()
return result
def is_connectable(self, line):
def is_connectable(self, line_or_point):
if self.is_closed:
return False
elif not self._points:
# empty polygons can be connected with any line
return True
elif line.p1 == self._points[-1]:
return True
elif line.p2 == self._points[0]:
return True
if hasattr(line_or_point, "get_length_line"):
# it is a line
line = line_or_point
if line.p1 == self._points[-1]:
return True
elif line.p2 == self._points[0]:
return True
else:
return False
else:
return False
# 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):
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