File tree Expand file tree Collapse file tree 1 file changed +19
-10
lines changed Expand file tree Collapse file tree 1 file changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -173,20 +173,29 @@ class PolyTools
173
173
174
174
/**
175
175
* Returns indices of duplicate points in `poly` (or an empty array if none are found).
176
+ * NOTE: indices in the result are guaranteed to be in ascending order.
177
+ *
178
+ * @param consecutiveOnly if true only equal adjacent points are reported
179
+ * @param wrapAround if true also first vs last point will be checked
176
180
*/
177
- static public function findDuplicatePoints (poly : Poly ): Array <Int >
181
+ static public function findDuplicatePoints (poly : Poly , consecutiveOnly : Bool = true , wrapAround : Bool = true ): Array <Int >
178
182
{
179
- var len : Int = poly .length ;
180
- if (len <= 1 ) return null ;
181
- var res = new Array <Int >();
182
-
183
- for (i in 0 ... len ) {
184
- for (j in i + 1 ... len ) {
185
- if (poly [i ].equals (poly [j ])) res .push (j );
183
+ var len = poly .length ;
184
+ if (len <= 1 ) return [];
185
+ var dupIndices = [];
186
+
187
+ for (i in 0 ... len - 1 ) {
188
+ var j = i + 1 ;
189
+ while (j < len ) {
190
+ var foundDup = poly [i ].equals (poly [j ]);
191
+ if (foundDup ) dupIndices .push (i );
192
+ if (consecutiveOnly || (foundDup && ! consecutiveOnly )) break ;
193
+ j ++ ;
186
194
}
187
195
}
188
-
189
- return res ;
196
+ if (wrapAround && consecutiveOnly && poly [0 ].equals (poly [len - 1 ])) dupIndices .push (len - 1 );
197
+
198
+ return dupIndices ;
190
199
}
191
200
192
201
/** Finds the intersection point between lines extending the segments `p1`-`p2` and `q1`-`q2`. Returns null if they're parallel. */
You can’t perform that action at this time.
0 commit comments