--- a/graphics/GraphicCommons.py Thu Jun 13 15:49:48 2019 +0200
+++ b/graphics/GraphicCommons.py Tue Jun 18 14:09:23 2019 +0200
@@ -1964,9 +1964,23 @@
- def SetPoints(self, points, verify=True):
+ def SetPoints(self, points, merge_segments=True): - self.Points = [wx.Point(x, y) for x, y in points]
+ # filter duplicates, add corner to diagonals + ex, ey = lx == x, ly == y + if (lx,ly) != (None,None) and not ex and not ey: + self.Points.append(wx.Point(lx, y)) + self.Points.append(wx.Point(x, y)) # Calculate the start and end directions
self.StartPoint = [None, vector(self.Points[0], self.Points[1])]
self.EndPoint = [None, vector(self.Points[-1], self.Points[-2])]
@@ -1980,22 +1994,33 @@
# Calculate the segments directions
- while i < len(self.Points) - 1:
- if verify and 0 < i < len(self.Points) - 2 and \
- self.Points[i] == self.Points[i + 1] and \
- self.Segments[-1] == vector(self.Points[i + 1], self.Points[i + 2]):
- for dummy in xrange(2):
- segment = vector(self.Points[i], self.Points[i + 1])
- if is_null_vector(segment) and i > 0:
- segment = (self.Segments[-1][1], self.Segments[-1][0])
- if i < len(self.Points) - 2:
- next = vector(self.Points[i + 1], self.Points[i + 2])
- if next == segment or is_null_vector(add_vectors(segment, next)):
- self.Points.insert(i + 1, wx.Point(self.Points[i + 1].x, self.Points[i + 1].y))
- self.Segments.append(segment)
+ segment = vector(self.Points[i], self.Points[i + 1]) + # merge segment if requested + if merge_segments and 0 < i and \ + self.Segments[-1] == segment: + # remove corner when two segments are in opposite direction + next = vector(self.Points[i + 1], self.Points[i + 2]) + if is_null_vector(add_vectors(segment, next)): + self.Segments.append(segment) self.RefreshBoundingBox()