@@ -144,16 +144,13 @@ pub fn arcline_self_intersections(arcline: &Arcline) -> Vec<(usize, usize)> {
144144 return intersections;
145145 }
146146
147- // Special case for two-element arclines: check both (0,1) and (1,0 )
147+ // Special case for two-element arclines: check (0,1) only (undirected )
148148 if n == 2 {
149149 let arc0 = & arcline[ 0 ] ;
150150 let arc1 = & arcline[ 1 ] ;
151151 if is_really_intersecting ( arc0, arc1) {
152152 intersections. push ( ( 0 , 1 ) ) ;
153153 }
154- if is_really_intersecting ( arc1, arc0) {
155- intersections. push ( ( 1 , 0 ) ) ;
156- }
157154 return intersections;
158155 }
159156
@@ -184,11 +181,12 @@ pub fn arcline_self_intersections(arcline: &Arcline) -> Vec<(usize, usize)> {
184181 }
185182
186183 // Check if last arc intersects with first arc (for closed arclines)
184+ // Only add if (n-1, 0) ordering (since we want i < j for undirected pairs)
187185 if n >= 2 {
188186 let last_arc = & arcline[ n - 1 ] ;
189187 let first_arc = & arcline[ 0 ] ;
190188 if is_really_intersecting ( last_arc, first_arc) {
191- intersections. push ( ( n - 1 , 0 ) ) ;
189+ intersections. push ( ( 0 , n - 1 ) ) ;
192190 }
193191 }
194192
@@ -266,13 +264,10 @@ mod tests {
266264 let seg1 = arcseg ( point ( 0.0 , 0.0 ) , point ( 1.0 , 1.0 ) ) ;
267265 let seg2 = arcseg ( point ( 0.0 , 1.0 ) , point ( 1.0 , 0.0 ) ) ;
268266 let arcline = vec ! [ seg1, seg2] ;
269- assert ! ( arcline_has_self_intersection( & arcline) ) ;
270- let mut ints = arcline_self_intersections ( & arcline) ;
271- ints. sort ( ) ;
272- let mut expected = vec ! [ ( 0 , 1 ) , ( 1 , 0 ) ] ;
273- expected. sort ( ) ;
274- // Accept either (0,1) or (1,0) or both, since intersection is symmetric
275- assert ! ( ints == vec![ ( 0 , 1 ) ] || ints == vec![ ( 1 , 0 ) ] || ints == expected) ;
267+ assert ! ( arcline_has_self_intersection( & arcline) ) ;
268+ let ints = arcline_self_intersections ( & arcline) ;
269+ // Should have exactly one undirected pair (0, 1)
270+ assert_eq ! ( ints, vec![ ( 0 , 1 ) ] ) ;
276271 }
277272
278273 #[ test]
@@ -291,12 +286,10 @@ mod tests {
291286 let arc1 = arc ( point ( 0.0 , 0.0 ) , point ( 1.0 , 0.0 ) , point ( 0.5 , 0.5 ) , 1.0 ) ;
292287 let seg = arcseg ( point ( 0.5 , 0.5 ) , point ( 0.5 , -1.0 ) ) ;
293288 let arcline = vec ! [ arc1, seg] ;
294- assert ! ( arcline_has_self_intersection( & arcline) ) ;
295- let mut ints = arcline_self_intersections ( & arcline) ;
296- ints. sort ( ) ;
297- let mut expected = vec ! [ ( 0 , 1 ) , ( 1 , 0 ) ] ;
298- expected. sort ( ) ;
299- assert ! ( ints == vec![ ( 0 , 1 ) ] || ints == vec![ ( 1 , 0 ) ] || ints == expected) ;
289+ assert ! ( arcline_has_self_intersection( & arcline) ) ;
290+ let ints = arcline_self_intersections ( & arcline) ;
291+ // Should have exactly one undirected pair (0, 1)
292+ assert_eq ! ( ints, vec![ ( 0 , 1 ) ] ) ;
300293 }
301294
302295 #[ test]
@@ -305,12 +298,10 @@ mod tests {
305298 let seg = arcseg ( point ( 0.5 , 0.5 ) , point ( 0.5 , -1.0 ) ) ;
306299 let arc1 = arc ( point ( 0.0 , 0.0 ) , point ( 1.0 , 0.0 ) , point ( 0.5 , 0.5 ) , 1.0 ) ;
307300 let arcline = vec ! [ seg, arc1] ;
308- assert ! ( arcline_has_self_intersection( & arcline) ) ;
309- let mut ints = arcline_self_intersections ( & arcline) ;
310- ints. sort ( ) ;
311- let mut expected = vec ! [ ( 0 , 1 ) , ( 1 , 0 ) ] ;
312- expected. sort ( ) ;
313- assert ! ( ints == vec![ ( 0 , 1 ) ] || ints == vec![ ( 1 , 0 ) ] || ints == expected) ;
301+ assert ! ( arcline_has_self_intersection( & arcline) ) ;
302+ let ints = arcline_self_intersections ( & arcline) ;
303+ // Should have exactly one undirected pair (0, 1)
304+ assert_eq ! ( ints, vec![ ( 0 , 1 ) ] ) ;
314305 }
315306 use super :: * ;
316307
@@ -389,4 +380,31 @@ mod tests {
389380 // This depends on the exact geometry, may or may not intersect
390381 let _ = intersections; // Just verify the function works
391382 }
383+
384+ #[ test]
385+ fn test_arcseg_arc_asymmetry ( ) {
386+ let seg = arcseg ( point ( 0.5 , 0.5 ) , point ( 0.5 , -1.0 ) ) ;
387+ let arc1 = arc ( point ( 0.0 , 0.0 ) , point ( 1.0 , 0.0 ) , point ( 0.5 , 0.5 ) , 1.0 ) ;
388+ let ab = is_really_intersecting ( & arc1, & seg) ;
389+ let ba = is_really_intersecting ( & seg, & arc1) ;
390+ assert_eq ! ( ab, ba, "is_really_intersecting not symmetric for arc/seg" ) ;
391+ }
392+
393+ #[ test]
394+ fn test_arc_arc_asymmetry ( ) {
395+ let arc1 = arc ( point ( -1.0 , 0.0 ) , point ( 1.0 , 0.0 ) , point ( 0.0 , 1.0 ) , 1.0 ) ;
396+ let arc2 = arc ( point ( 0.0 , -1.0 ) , point ( 0.0 , 1.0 ) , point ( 1.0 , 0.0 ) , 1.0 ) ;
397+ let ab = is_really_intersecting ( & arc1, & arc2) ;
398+ let ba = is_really_intersecting ( & arc2, & arc1) ;
399+ assert_eq ! ( ab, ba, "is_really_intersecting not symmetric for arc/arc" ) ;
400+ }
401+
402+ #[ test]
403+ fn test_arcseg_arcseg_asymmetry ( ) {
404+ let seg1 = arcseg ( point ( 0.0 , 0.0 ) , point ( 1.0 , 1.0 ) ) ;
405+ let seg2 = arcseg ( point ( 0.0 , 1.0 ) , point ( 1.0 , 0.0 ) ) ;
406+ let ab = is_really_intersecting ( & seg1, & seg2) ;
407+ let ba = is_really_intersecting ( & seg2, & seg1) ;
408+ assert_eq ! ( ab, ba, "is_really_intersecting not symmetric for seg/seg" ) ;
409+ }
392410}
0 commit comments