Bug with wire error while loading diagram fixed
authorlbessard
Fri, 19 Dec 2008 15:08:54 +0100
changeset 296 919f72861bfb
parent 295 c6ef6d92ce16
child 297 e837b67cb184
Bug with wire error while loading diagram fixed
graphics/GraphicCommons.py
--- a/graphics/GraphicCommons.py	Fri Dec 19 15:07:54 2008 +0100
+++ b/graphics/GraphicCommons.py	Fri Dec 19 15:08:54 2008 +0100
@@ -119,10 +119,6 @@
 Basic vector operations for calculate wire points
 """
 
-# Calculate the scalar product of two vectors
-def product(v1, v2):
-    return v1[0] * v2[0] + v1[1] * v2[1]
-
 # Create a vector from two points and define if vector must be normal
 def vector(p1, p2, normal = True):
     vector = (p2.x - p1.x, p2.y - p1.y)
@@ -143,6 +139,18 @@
     else:
         return v
 
+# Calculate the scalar product of two vectors
+def is_null_vector(v):
+    return v == (0, 0)
+
+# Calculate the scalar product of two vectors
+def add_vectors(v1, v2):
+    return (v1[0] + v2[0], v1[1] + v2[1])
+
+# Calculate the scalar product of two vectors
+def product(v1, v2):
+    return v1[0] * v2[0] + v1[1] * v2[1]
+
 
 """
 Function that calculates the nearest point of the grid defined by scaling for the given point
@@ -1635,8 +1643,17 @@
             self.Points[-1] = self.EndPoint[0]
             # Calculate the segments directions
             self.Segments = []
-            for i in xrange(len(self.Points) - 1):
-                self.Segments.append(vector(self.Points[i], self.Points[i + 1]))
+            i = 0
+            while i < len(self.Points) - 1:
+                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].x, self.Points[i].y))
+                self.Segments.append(segment)
+                i += 1
             self.RefreshBoundingBox()
             self.RefreshRealPoints()