@@ -359,3 +359,86 @@ impl ConvexPolyhedron for Segment {
359359 }
360360}
361361*/
362+
363+ #[ cfg( test) ]
364+ mod test {
365+ use crate :: query:: { Ray , RayCast } ;
366+
367+ pub use super :: * ;
368+ #[ test]
369+ fn segment_intersect_zero_length_issue_31 ( ) {
370+ // never intersect each other
371+ let ray = Ray :: new ( Point :: origin ( ) , Vector :: x ( ) ) ;
372+ let segment = Segment {
373+ a : Point :: new (
374+ 10.0 ,
375+ 10.0 ,
376+ #[ cfg( feature = "dim3" ) ]
377+ 10.0 ,
378+ ) ,
379+ b : Point :: new (
380+ 10.0 ,
381+ 10.0 ,
382+ #[ cfg( feature = "dim3" ) ]
383+ 10.0 ,
384+ ) ,
385+ } ;
386+
387+ let hit = segment. intersects_ray ( & Isometry :: identity ( ) , & ray, Real :: MAX ) ;
388+ assert_eq ! ( hit, false ) ;
389+ }
390+ #[ test]
391+ fn segment_very_close_points_hit ( ) {
392+ let epsilon = 1.1920929e-7 ;
393+ // intersect each other
394+ let ray = Ray :: new (
395+ Point :: new (
396+ epsilon * 0.5 ,
397+ 0.3 ,
398+ #[ cfg( feature = "dim3" ) ]
399+ 0.0 ,
400+ ) ,
401+ -Vector :: y ( ) ,
402+ ) ;
403+ let segment = Segment {
404+ a : Point :: origin ( ) ,
405+ b : Point :: new (
406+ // Theoretically, epsilon would suffice but imprecisions force us to add some more offset.
407+ epsilon * 1.01 ,
408+ 0.0 ,
409+ #[ cfg( feature = "dim3" ) ]
410+ 0.0 ,
411+ ) ,
412+ } ;
413+
414+ let hit = segment. intersects_ray ( & Isometry :: identity ( ) , & ray, Real :: MAX ) ;
415+ assert_eq ! ( hit, true ) ;
416+ }
417+ #[ test]
418+ fn segment_very_close_points_no_hit ( ) {
419+ let epsilon = 1.1920929e-7 ;
420+ // never intersect each other
421+ let ray = Ray :: new (
422+ Point :: new (
423+ // Theoretically, epsilon would suffice but imprecisions force us to add some more offset.
424+ epsilon * 11.0 ,
425+ 0.1 ,
426+ #[ cfg( feature = "dim3" ) ]
427+ 0.0 ,
428+ ) ,
429+ -Vector :: y ( ) ,
430+ ) ;
431+ let segment = Segment {
432+ a : Point :: origin ( ) ,
433+ b : Point :: new (
434+ epsilon * 0.9 ,
435+ 0.0 ,
436+ #[ cfg( feature = "dim3" ) ]
437+ 0.0 ,
438+ ) ,
439+ } ;
440+
441+ let hit = segment. intersects_ray ( & Isometry :: identity ( ) , & ray, Real :: MAX ) ;
442+ assert_eq ! ( hit, false ) ;
443+ }
444+ }
0 commit comments