File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -153,9 +153,12 @@ def remove_colinear_vertices(self, tolerance):
153
153
skip = 0 # track the number of vertices being skipped/removed
154
154
# loop through vertices and remove all cases of colinear verts
155
155
for i , _v in enumerate (self .vertices [1 :- 1 ]):
156
- _a = self [i - skip ].determinant (_v ) + _v .determinant (self [i + 2 ]) + \
157
- self [i + 2 ].determinant (self [i - skip ])
158
- if abs (_a ) >= tolerance :
156
+ _v2 , _v1 = self [i - skip ], self [i + 2 ]
157
+ _a = _v2 .determinant (_v ) + _v .determinant (_v1 ) + _v1 .determinant (_v2 )
158
+ b_dist = _v1 .distance_to_point (_v2 )
159
+ b_dist = tolerance if b_dist < tolerance else b_dist
160
+ tri_tol = (b_dist * tolerance ) / 2 # area of triangle with tolerance height
161
+ if abs (_a ) >= tri_tol : # triangle area > tolerance; not colinear
159
162
new_vertices .append (_v )
160
163
skip = 0
161
164
else :
Original file line number Diff line number Diff line change @@ -136,11 +136,21 @@ def remove_colinear_vertices(self, tolerance):
136
136
before it is considered colinear.
137
137
"""
138
138
if len (self .vertices ) == 3 :
139
- return self # Polyline3D cannot have fewer than 3 vertices
139
+ return self # Polyline3D cannot have fewer than 3 vertices
140
140
new_vertices = [self .vertices [0 ]] # first vertex is always ok
141
+ skip = 0 # track the number of vertices being skipped/removed
142
+ # loop through vertices and remove all cases of colinear verts
141
143
for i , _v in enumerate (self .vertices [1 :- 1 ]):
142
- if (self [i ] - _v ).cross (self [i + 2 ] - _v ).magnitude >= tolerance :
144
+ _v2 , _v1 = self [i - skip ], self [i + 2 ]
145
+ _a = (_v2 - _v ).cross (_v1 - _v ).magnitude
146
+ b_dist = _v1 .distance_to_point (_v2 )
147
+ b_dist = tolerance if b_dist < tolerance else b_dist
148
+ tri_tol = (b_dist * tolerance ) / 2 # area of triangle with tolerance height
149
+ if abs (_a ) >= tri_tol : # triangle area > tolerance; not colinear
143
150
new_vertices .append (_v )
151
+ skip = 0
152
+ else :
153
+ skip += 1
144
154
new_vertices .append (self [- 1 ]) # last vertex is always ok
145
155
_new_poly = Polyline3D (new_vertices )
146
156
self ._transfer_properties (_new_poly )
You can’t perform that action at this time.
0 commit comments