@vived/app 2.15.2 → 2.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@ import { Vector2 } from "./Vector2";
2
2
  export declare class LineSegment2D {
3
3
  static GetPositionAtPercent(line: LineSegment2D, percent: number): Vector2;
4
4
  static Intersect(a: LineSegment2D, b: LineSegment2D, tolerance?: number): Vector2 | undefined;
5
+ static ClosestPointOnLine(line: LineSegment2D, point: Vector2): Vector2;
5
6
  readonly start: Vector2;
6
7
  readonly end: Vector2;
7
8
  get length(): number;
@@ -42,6 +42,25 @@ class LineSegment2D {
42
42
  const py = y1 + t * (y2 - y1);
43
43
  return new Vector2_1.Vector2(px, py);
44
44
  }
45
+ static ClosestPointOnLine(line, point) {
46
+ // see https://monkeyproofsolutions.nl/wordpress/how-to-calculate-the-shortest-distance-between-a-point-and-a-line/
47
+ let direction = Vector2_1.Vector2.Subtract(line.end, line.start);
48
+ const pointToStart = Vector2_1.Vector2.Subtract(point, line.start);
49
+ const tNumerator = Vector2_1.Vector2.Dot(direction, pointToStart);
50
+ const tDenominator = Vector2_1.Vector2.Dot(direction, direction);
51
+ const t = tNumerator / tDenominator;
52
+ if (t < 0) {
53
+ return line.start;
54
+ }
55
+ else if (t > 1) {
56
+ return line.end;
57
+ }
58
+ else {
59
+ const length = t * direction.magnitued;
60
+ direction = Vector2_1.Vector2.NewVectorOfLength(direction, length);
61
+ return Vector2_1.Vector2.Add(line.start, direction);
62
+ }
63
+ }
45
64
  get length() {
46
65
  return Vector2_1.Vector2.Subtract(this.start, this.end).magnitued;
47
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vived/app",
3
- "version": "2.15.2",
3
+ "version": "2.15.3",
4
4
  "description": "Public package for the VIVED Learning App system",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",