@vived/app 2.15.2 → 2.15.5

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.
@@ -11,20 +11,25 @@ class DevicePreviewImp {
11
11
  constructor() {
12
12
  this.observers = new _1.ObserverList();
13
13
  this._usePreview = false;
14
- this._previewSize = ValueObjects_1.Vector2.zero();
14
+ this._previewSize = ValueObjects_1.Vector2.Zero();
15
15
  this.setDevicePreview = (x, y) => {
16
- if (this._usePreview &&
17
- this._previewSize.x === x &&
16
+ if (this._previewSize.x === x &&
18
17
  this._previewSize.y === y)
19
18
  return;
20
19
  this._usePreview = true;
21
20
  this._previewSize = new ValueObjects_1.Vector2(x, y);
21
+ if (x > 0 && y > 0) {
22
+ this._usePreview = true;
23
+ }
24
+ else {
25
+ this._usePreview = false;
26
+ }
22
27
  this.observers.notify();
23
28
  };
24
29
  this.clearDevicePreview = () => {
25
30
  if (!this._usePreview)
26
31
  return;
27
- this._previewSize = ValueObjects_1.Vector2.zero();
32
+ this._previewSize = ValueObjects_1.Vector2.Zero();
28
33
  this._usePreview = false;
29
34
  this.observers.notify();
30
35
  };
@@ -18,7 +18,7 @@ class TouchInputImp {
18
18
  this.getTouchOffsetPosition = (touch) => {
19
19
  if (!this.eventElementBounds) {
20
20
  console.warn("No target bounds");
21
- return ValueObjects_1.Vector2.zero();
21
+ return ValueObjects_1.Vector2.Zero();
22
22
  }
23
23
  const x = touch.clientX - this.eventElementBounds.x;
24
24
  const y = touch.clientY - this.eventElementBounds.y;
@@ -6,7 +6,7 @@ class PixelDollyFocusCamera {
6
6
  constructor(focusCamera) {
7
7
  this.focusCamera = focusCamera;
8
8
  this.sensitivity = 0.05;
9
- this.previousPixelPosition = ValueObjects_1.Vector2.zero();
9
+ this.previousPixelPosition = ValueObjects_1.Vector2.Zero();
10
10
  this.doDolly = (pixelPosition) => {
11
11
  const pixelDeltaY = pixelPosition.y - this.previousPixelPosition.y;
12
12
  const deltaRadius = pixelDeltaY * this.sensitivity;
@@ -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
  }
@@ -1,6 +1,6 @@
1
1
  import { Angle } from ".";
2
2
  export declare class Vector2 {
3
- static zero(): Vector2;
3
+ static Zero(): Vector2;
4
4
  static One(): Vector2;
5
5
  static Equal(a: Vector2, b: Vector2): boolean;
6
6
  static Add(a: Vector2, b: Vector2): Vector2;
@@ -7,7 +7,7 @@ class Vector2 {
7
7
  this.x = x;
8
8
  this.y = y;
9
9
  }
10
- static zero() {
10
+ static Zero() {
11
11
  return new Vector2(0, 0);
12
12
  }
13
13
  static One() {
@@ -35,7 +35,7 @@ class Vector2 {
35
35
  get unit() {
36
36
  const mag = this.magnitued;
37
37
  if (mag === 0) {
38
- return Vector2.zero();
38
+ return Vector2.Zero();
39
39
  }
40
40
  const unitX = this.x / mag;
41
41
  const unitY = this.y / mag;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vived/app",
3
- "version": "2.15.2",
3
+ "version": "2.15.5",
4
4
  "description": "Public package for the VIVED Learning App system",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",