File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed
Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -24,11 +24,13 @@ export class Ray {
2424 this . direction = n ;
2525 }
2626
27- intersect ( right : Ray ) : XYZ | undefined {
28- if ( this . direction . isParallelTo ( right . direction ) ) return undefined ;
27+ intersect ( right : Ray , tolerance = 1e-6 ) : XYZ | undefined {
28+ if ( this . direction . isParallelTo ( right . direction , tolerance ) ) return undefined ;
2929 const result = this . nearestTo ( right ) ;
3030 const vec = result . sub ( right . location ) ;
31- return vec . isParallelTo ( right . direction ) ? result : undefined ;
31+ if ( vec . length ( ) < tolerance ) return result ;
32+
33+ return vec . isParallelTo ( right . direction , tolerance ) ? result : undefined ;
3234 }
3335
3436 distanceTo ( right : Ray ) : number {
Original file line number Diff line number Diff line change @@ -26,9 +26,11 @@ describe("test ray", () => {
2626 } ) ;
2727
2828 test ( "test intersect" , ( ) => {
29- let r1 = new Ray ( XYZ . zero , XYZ . unitX ) ;
30- let r2 = new Ray ( XYZ . unitX . add ( XYZ . unitY ) , XYZ . unitY ) ;
29+ const r1 = new Ray ( XYZ . zero , XYZ . unitX ) ;
30+ const r11 = new Ray ( XYZ . zero , XYZ . unitY ) ;
31+ const r2 = new Ray ( XYZ . unitX . add ( XYZ . unitY ) , XYZ . unitY ) ;
3132 expect ( r1 . intersect ( r2 ) ) . toStrictEqual ( XYZ . unitX ) ;
33+ expect ( r1 . intersect ( r11 ) ) . toStrictEqual ( XYZ . zero ) ;
3234
3335 const r3 = new Ray ( XYZ . zero , XYZ . unitX ) ;
3436 const r4 = new Ray ( XYZ . unitY , XYZ . unitX ) ;
You can’t perform that action at this time.
0 commit comments