graphics/GraphicCommons.py
branchfix_fb_resize_wire_bug
changeset 2616 7a434c8d3f3c
parent 2615 2eb66f155c2c
child 2617 93ad3db5f9df
--- a/graphics/GraphicCommons.py	Tue Jun 18 09:38:20 2019 +0200
+++ b/graphics/GraphicCommons.py	Tue Jun 18 13:58:45 2019 +0200
@@ -1967,7 +1967,21 @@
     def SetPoints(self, points, merge_segments=True):
         print("SetPoints", self)
         if len(points) > 1:
-            self.Points = [wx.Point(x, y) for x, y in points]
+
+            # filter duplicates, add corner to diagonals
+            self.Points = []
+            lx,ly = None,None
+            for x, y in points:
+                ex, ey = lx == x, ly == y
+                if ex and ey:
+                    # duplicate
+                    continue
+                if (lx,ly) != (None,None) and not ex and not ey:
+                    # diagonal
+                    self.Points.append(wx.Point(lx, y))
+                self.Points.append(wx.Point(x, y))
+                lx,ly = 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])]
@@ -1988,12 +2002,6 @@
 
                 segment = vector(self.Points[i], self.Points[i + 1])
 
-                # delete duplicates 
-                if is_null_vector(segment):
-                    self.Points.pop(i)
-                    # next point is the same, no need to rollback
-                    continue
-
                 # merge segment if requested
                 if merge_segments and 0 < i and \
                    self.Segments[-1] == segment:
@@ -2003,12 +2011,6 @@
                     i -= 1
                     continue
 
-                # add point to make a corner in case of diagonal segment
-                if segment not in [EAST, NORTH, WEST, SOUTH]:
-                    self.Points.insert(i + 1, wx.Point(
-                        self.Points[i].x, self.Points[i + 1].y))
-                    continue
-
                 # remove corner when two segments are in opposite direction
                 if i < l - 2:
                     next = vector(self.Points[i + 1], self.Points[i + 2])
@@ -2020,7 +2022,6 @@
 
                 i += 1
 
-
             self.RefreshBoundingBox()
             self.RefreshRealPoints()