MCPcopy Create free account
hub / github.com/NikLever/ThreeJS-PathEditor / calcIsInsideLineSegment

Method calcIsInsideLineSegment

geometry.js:23–29  ·  view source on GitHub ↗
(line1, line2, pnt)

Source from the content-addressed store, hash-verified

21
22 //Returns bool, whether the projected point is actually inside the (finite) line segment.
23 static calcIsInsideLineSegment(line1, line2, pnt) {
24 const L2 = ( ((line2.x - line1.x) * (line2.x - line1.x)) + ((line2.y - line1.y) * (line2.y - line1.y)) );
25 if(L2 == 0) return false;
26 const r = ( ((pnt.x - line1.x) * (line2.x - line1.x)) + ((pnt.y - line1.y) * (line2.y - line1.y)) ) / L2;
27
28 return (0 <= r) && (r <= 1);
29 }
30
31 //The most useful function. Returns bool true, if the mouse point is actually inside the (finite) line, given a line thickness from the theoretical line away. It also assumes that the line end points are circular, not square.
32 static calcIsInsideThickLineSegment(line1, line2, pnt, lineThickness) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected