117 |
117 |
118 """ |
118 """ |
119 Basic vector operations for calculate wire points |
119 Basic vector operations for calculate wire points |
120 """ |
120 """ |
121 |
121 |
122 # Calculate the scalar product of two vectors |
|
123 def product(v1, v2): |
|
124 return v1[0] * v2[0] + v1[1] * v2[1] |
|
125 |
|
126 # Create a vector from two points and define if vector must be normal |
122 # Create a vector from two points and define if vector must be normal |
127 def vector(p1, p2, normal = True): |
123 def vector(p1, p2, normal = True): |
128 vector = (p2.x - p1.x, p2.y - p1.y) |
124 vector = (p2.x - p1.x, p2.y - p1.y) |
129 if normal: |
125 if normal: |
130 return normalize(vector) |
126 return normalize(vector) |
140 # Verifie if it is not a null vector |
136 # Verifie if it is not a null vector |
141 if v_norm > 0: |
137 if v_norm > 0: |
142 return (v[0] / v_norm, v[1] / v_norm) |
138 return (v[0] / v_norm, v[1] / v_norm) |
143 else: |
139 else: |
144 return v |
140 return v |
|
141 |
|
142 # Calculate the scalar product of two vectors |
|
143 def is_null_vector(v): |
|
144 return v == (0, 0) |
|
145 |
|
146 # Calculate the scalar product of two vectors |
|
147 def add_vectors(v1, v2): |
|
148 return (v1[0] + v2[0], v1[1] + v2[1]) |
|
149 |
|
150 # Calculate the scalar product of two vectors |
|
151 def product(v1, v2): |
|
152 return v1[0] * v2[0] + v1[1] * v2[1] |
145 |
153 |
146 |
154 |
147 """ |
155 """ |
148 Function that calculates the nearest point of the grid defined by scaling for the given point |
156 Function that calculates the nearest point of the grid defined by scaling for the given point |
149 """ |
157 """ |
1633 self.Points[-1].y + CONNECTOR_SIZE * self.EndPoint[1][1]) |
1641 self.Points[-1].y + CONNECTOR_SIZE * self.EndPoint[1][1]) |
1634 self.Points[0] = self.StartPoint[0] |
1642 self.Points[0] = self.StartPoint[0] |
1635 self.Points[-1] = self.EndPoint[0] |
1643 self.Points[-1] = self.EndPoint[0] |
1636 # Calculate the segments directions |
1644 # Calculate the segments directions |
1637 self.Segments = [] |
1645 self.Segments = [] |
1638 for i in xrange(len(self.Points) - 1): |
1646 i = 0 |
1639 self.Segments.append(vector(self.Points[i], self.Points[i + 1])) |
1647 while i < len(self.Points) - 1: |
|
1648 segment = vector(self.Points[i], self.Points[i + 1]) |
|
1649 if is_null_vector(segment) and i > 0: |
|
1650 segment = (self.Segments[-1][1], self.Segments[-1][0]) |
|
1651 if i < len(self.Points) - 2: |
|
1652 next = vector(self.Points[i + 1], self.Points[i + 2]) |
|
1653 if next == segment or is_null_vector(add_vectors(segment, next)): |
|
1654 self.Points.insert(i + 1, wx.Point(self.Points[i].x, self.Points[i].y)) |
|
1655 self.Segments.append(segment) |
|
1656 i += 1 |
1640 self.RefreshBoundingBox() |
1657 self.RefreshBoundingBox() |
1641 self.RefreshRealPoints() |
1658 self.RefreshRealPoints() |
1642 |
1659 |
1643 # Returns the position of the point indicated |
1660 # Returns the position of the point indicated |
1644 def GetPoint(self, index): |
1661 def GetPoint(self, index): |