-
-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'support_lines' into dev
- Loading branch information
Showing
4 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Coord2D, CoordDistance2D, DotVector2D, SubCoord2D } from './coord2d.js'; | ||
import { IsZero } from './geometry.js'; | ||
|
||
export class Segment2D | ||
{ | ||
constructor (beg, end) | ||
{ | ||
this.beg = beg; | ||
this.end = end; | ||
} | ||
|
||
Clone () | ||
{ | ||
return new Segment2D (this.beg, this.end); | ||
} | ||
} | ||
|
||
export function ProjectPointToSegment2D (segment, point) | ||
{ | ||
let begToEndVec = SubCoord2D (segment.end, segment.beg); | ||
let begToPointVec = SubCoord2D (point, segment.beg); | ||
let nom = DotVector2D (begToEndVec, begToPointVec); | ||
let denom = DotVector2D (begToEndVec, begToEndVec); | ||
if (IsZero (denom)) { | ||
return segment.beg.Clone (); | ||
} | ||
let t = nom / denom; | ||
t = Math.max (0.0, Math.min (1.0, t)); | ||
return new Coord2D ( | ||
segment.beg.x + t * begToEndVec.x, | ||
segment.beg.y + t * begToEndVec.y | ||
); | ||
} | ||
|
||
export function SegmentPointDistance2D (segment, point) | ||
{ | ||
let projected = ProjectPointToSegment2D (segment, point); | ||
return CoordDistance2D (projected, point); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters