(xab, yab, llab, xac, yac)
| 58 | * llab is the length squared of (b-a), just to simplify calculation |
| 59 | */ |
| 60 | function perpDistance2(xab, yab, llab, xac, yac) { |
| 61 | var fcAB = (xac * xab + yac * yab); |
| 62 | if(fcAB < 0) { |
| 63 | // point c is closer to point a |
| 64 | return xac * xac + yac * yac; |
| 65 | } else if(fcAB > llab) { |
| 66 | // point c is closer to point b |
| 67 | var xbc = xac - xab; |
| 68 | var ybc = yac - yab; |
| 69 | return xbc * xbc + ybc * ybc; |
| 70 | } else { |
| 71 | // perpendicular distance is the shortest |
| 72 | var crossProduct = xac * yab - yac * xab; |
| 73 | return crossProduct * crossProduct / llab; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // a very short-term cache for getTextLocation, just because |
| 78 | // we're often looping over the same locations multiple times |
no outgoing calls
no test coverage detected
searching dependent graphs…