(line1, line2, pnt)
| 1 | export class Geometry{ |
| 2 | //Returns {.x, .y}, a projected point perpendicular on the (infinite) line. |
| 3 | static calcNearestPointOnLine(line1, line2, pnt) { |
| 4 | const L2 = ( ((line2.x - line1.x) * (line2.x - line1.x)) + ((line2.y - line1.y) * (line2.y - line1.y)) ); |
| 5 | if(L2 == 0) return false; |
| 6 | const r = ( ((pnt.x - line1.x) * (line2.x - line1.x)) + ((pnt.y - line1.y) * (line2.y - line1.y)) ) / L2; |
| 7 | |
| 8 | return { |
| 9 | x: line1.x + (r * (line2.x - line1.x)), |
| 10 | y: line1.y + (r * (line2.y - line1.y)) |
| 11 | }; |
| 12 | } |
| 13 | |
| 14 | //Returns float, the shortest distance to the (infinite) line. |
| 15 | static calcDistancePointToLine(line1, line2, pnt) { |
nothing calls this directly
no outgoing calls
no test coverage detected