@@ -487,15 +487,15 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
487
487
// to get the parity of the number of intersections.
488
488
if ( edges . reduce ( function ( a , x ) {
489
489
return a ^
490
- ! ! lineIntersect ( headX , headY , headX + 1e6 , headY + 1e6 ,
490
+ ! ! Lib . segmentsIntersect ( headX , headY , headX + 1e6 , headY + 1e6 ,
491
491
x [ 0 ] , x [ 1 ] , x [ 2 ] , x [ 3 ] ) ;
492
492
} , false ) ) {
493
493
// no line or arrow - so quit drawArrow now
494
494
return ;
495
495
}
496
496
497
497
edges . forEach ( function ( x ) {
498
- var p = lineIntersect ( tailX , tailY , headX , headY ,
498
+ var p = Lib . segmentsIntersect ( tailX , tailY , headX , headY ,
499
499
x [ 0 ] , x [ 1 ] , x [ 2 ] , x [ 3 ] ) ;
500
500
if ( p ) {
501
501
tailX = p . x ;
@@ -701,24 +701,3 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
701
701
}
702
702
else annText . call ( textLayout ) ;
703
703
}
704
-
705
- // look for intersection of two line segments
706
- // (1->2 and 3->4) - returns array [x,y] if they do, null if not
707
- function lineIntersect ( x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4 ) {
708
- var a = x2 - x1 ,
709
- b = x3 - x1 ,
710
- c = x4 - x3 ,
711
- d = y2 - y1 ,
712
- e = y3 - y1 ,
713
- f = y4 - y3 ,
714
- det = a * f - c * d ;
715
- // parallel lines? intersection is undefined
716
- // ignore the case where they are colinear
717
- if ( det === 0 ) return null ;
718
- var t = ( b * f - c * e ) / det ,
719
- u = ( b * d - a * e ) / det ;
720
- // segments do not intersect?
721
- if ( u < 0 || u > 1 || t < 0 || t > 1 ) return null ;
722
-
723
- return { x : x1 + a * t , y : y1 + d * t } ;
724
- }
0 commit comments