@vived/app 2.15.0 → 2.15.1

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.
@@ -7,6 +7,6 @@ export declare class LineSegment2D {
7
7
  get length(): number;
8
8
  get direction(): Vector2;
9
9
  getPositionAtPercent(percent: number): Vector2;
10
- intersect(otherLine: LineSegment2D): Vector2 | undefined;
10
+ intersect(otherLine: LineSegment2D, tolerance?: number): Vector2 | undefined;
11
11
  constructor(start: Vector2, end: Vector2);
12
12
  }
@@ -25,27 +25,30 @@ class LineSegment2D {
25
25
  const localPos = Vector2_1.Vector2.newVectorOfLength(dir, length);
26
26
  return Vector2_1.Vector2.add(this._start, localPos);
27
27
  }
28
- intersect(otherLine) {
28
+ intersect(otherLine, tolerance = 0) {
29
29
  // See https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
30
- const x1 = this._start.x;
31
- const y1 = this._start.y;
32
- const x2 = this._end.x;
33
- const y2 = this._end.y;
34
- const x3 = otherLine._start.x;
35
- const y3 = otherLine._start.y;
36
- const x4 = otherLine._end.x;
37
- const y4 = otherLine._end.y;
30
+ const x1 = this.start.x;
31
+ const y1 = this.start.y;
32
+ const x2 = this.end.x;
33
+ const y2 = this.end.y;
34
+ const x3 = otherLine.start.x;
35
+ const y3 = otherLine.start.y;
36
+ const x4 = otherLine.end.x;
37
+ const y4 = otherLine.end.y;
38
38
  const denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
39
39
  if (denominator === 0) {
40
40
  return undefined;
41
41
  }
42
42
  const tNumerator = (x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4);
43
43
  const t = tNumerator / denominator;
44
- if (t < 0 || t > 1)
44
+ const tTolearnce = tolerance / this.length;
45
+ if (t < -tTolearnce || t > 1 + tTolearnce) {
45
46
  return undefined;
47
+ }
46
48
  const uNumerator = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
47
49
  const u = uNumerator / denominator;
48
- if (u < 0 || u > 1)
50
+ const uTolearnce = tolerance / otherLine.length;
51
+ if (u < -uTolearnce || u > 1 + uTolearnce)
49
52
  return undefined;
50
53
  const px = x1 + t * (x2 - x1);
51
54
  const py = y1 + t * (y2 - y1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vived/app",
3
- "version": "2.15.0",
3
+ "version": "2.15.1",
4
4
  "description": "Public package for the VIVED Learning App system",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",