MCPcopy Index your code
hub / github.com/plotly/plotly.js / perpDistance2

Function perpDistance2

src/lib/geometry2d.js:60–75  ·  view source on GitHub ↗
(xab, yab, llab, xac, yac)

Source from the content-addressed store, hash-verified

58 * llab is the length squared of (b-a), just to simplify calculation
59 */
60function 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

Callers 1

geometry2d.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…