@@ -45,15 +45,15 @@ exports.segmentDistance = function segmentDistance(x1, y1, x2, y2, x3, y3, x4, y
4545 var y12 = y2 - y1 ;
4646 var x34 = x4 - x3 ;
4747 var y34 = y4 - y3 ;
48- var l2_12 = x12 * x12 + y12 * y12 ;
49- var l2_34 = x34 * x34 + y34 * y34 ;
48+ var ll12 = x12 * x12 + y12 * y12 ;
49+ var ll34 = x34 * x34 + y34 * y34 ;
5050
5151 // calculate distance squared, then take the sqrt at the very end
5252 var dist2 = Math . min (
53- perpDistance2 ( x12 , y12 , l2_12 , x3 - x1 , y3 - y1 ) ,
54- perpDistance2 ( x12 , y12 , l2_12 , x4 - x1 , y4 - y1 ) ,
55- perpDistance2 ( x34 , y34 , l2_34 , x1 - x3 , y1 - y3 ) ,
56- perpDistance2 ( x34 , y34 , l2_34 , x2 - x3 , y2 - y3 )
53+ perpDistance2 ( x12 , y12 , ll12 , x3 - x1 , y3 - y1 ) ,
54+ perpDistance2 ( x12 , y12 , ll12 , x4 - x1 , y4 - y1 ) ,
55+ perpDistance2 ( x34 , y34 , ll34 , x1 - x3 , y1 - y3 ) ,
56+ perpDistance2 ( x34 , y34 , ll34 , x2 - x3 , y2 - y3 )
5757 ) ;
5858
5959 return Math . sqrt ( dist2 ) ;
@@ -63,15 +63,15 @@ exports.segmentDistance = function segmentDistance(x1, y1, x2, y2, x3, y3, x4, y
6363 * distance squared from segment ab to point c
6464 * [xab, yab] is the vector b-a
6565 * [xac, yac] is the vector c-a
66- * l2_ab is the length squared of (b-a), just to simplify calculation
66+ * llab is the length squared of (b-a), just to simplify calculation
6767 */
68- function perpDistance2 ( xab , yab , l2_ab , xac , yac ) {
69- var fc_ab = ( xac * xab + yac * yab ) ;
70- if ( fc_ab < 0 ) {
68+ function perpDistance2 ( xab , yab , llab , xac , yac ) {
69+ var fcAB = ( xac * xab + yac * yab ) ;
70+ if ( fcAB < 0 ) {
7171 // point c is closer to point a
7272 return xac * xac + yac * yac ;
7373 }
74- else if ( fc_ab > l2_ab ) {
74+ else if ( fcAB > llab ) {
7575 // point c is closer to point b
7676 var xbc = xac - xab ;
7777 var ybc = yac - yab ;
@@ -80,7 +80,7 @@ function perpDistance2(xab, yab, l2_ab, xac, yac) {
8080 else {
8181 // perpendicular distance is the shortest
8282 var crossProduct = xac * yab - yac * xab ;
83- return crossProduct * crossProduct / l2_ab ;
83+ return crossProduct * crossProduct / llab ;
8484 }
8585}
8686
0 commit comments