@vived/app 2.15.1 → 2.15.2
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.
- package/lib/Entities/Babylon.js +1 -1
- package/lib/Entities/FocusCamera.js +9 -9
- package/lib/Entities/MemoizedVector2.js +1 -1
- package/lib/Entities/MemoizedVector3.js +1 -1
- package/lib/UseCases/FocusCamera/BumpDollyFocusCamera.js +3 -3
- package/lib/UseCases/FocusCamera/PinchDollyFocusCamera.js +3 -3
- package/lib/UseCases/FocusCamera/PixelDollyFocusCamera.js +3 -3
- package/lib/UseCases/FocusCamera/PixelOrbitFocusCamera.js +1 -1
- package/lib/UseCases/FocusCamera/PixelPlanePanFocusCamera.js +1 -1
- package/lib/ValueObjects/Angle.d.ts +2 -2
- package/lib/ValueObjects/Angle.js +2 -2
- package/lib/ValueObjects/Color.d.ts +4 -8
- package/lib/ValueObjects/Color.js +9 -21
- package/lib/ValueObjects/LineSegment2D.d.ts +4 -6
- package/lib/ValueObjects/LineSegment2D.js +24 -30
- package/lib/ValueObjects/ParametricLine.d.ts +1 -1
- package/lib/ValueObjects/ParametricLine.js +8 -8
- package/lib/ValueObjects/ParametricPlane.d.ts +1 -1
- package/lib/ValueObjects/ParametricPlane.js +10 -10
- package/lib/ValueObjects/Vector2.d.ts +11 -11
- package/lib/ValueObjects/Vector2.js +14 -14
- package/lib/ValueObjects/Vector3.d.ts +16 -16
- package/lib/ValueObjects/Vector3.js +18 -18
- package/package.json +1 -1
package/lib/Entities/Babylon.js
CHANGED
|
@@ -78,7 +78,7 @@ class BabylonImp {
|
|
|
78
78
|
this.sceneRay = rayer;
|
|
79
79
|
};
|
|
80
80
|
this.memoizedShowInspector = new MemoizedBoolean_1.MemoizedBoolean(false, this.observers.notify);
|
|
81
|
-
this.memoizedCanvasSize = new MemoizedVector2_1.MemoizedVector2(ValueObjects_1.Vector2.
|
|
81
|
+
this.memoizedCanvasSize = new MemoizedVector2_1.MemoizedVector2(ValueObjects_1.Vector2.One(), this.observers.notify);
|
|
82
82
|
}
|
|
83
83
|
get showInspector() {
|
|
84
84
|
return this.memoizedShowInspector.val;
|
|
@@ -14,7 +14,7 @@ class FocusCameraImp {
|
|
|
14
14
|
this.defaultAlpha = 0;
|
|
15
15
|
this.defaultBeta = 30;
|
|
16
16
|
this.defaultRadius = 8;
|
|
17
|
-
this.defaultTarget = ValueObjects_1.Vector3.
|
|
17
|
+
this.defaultTarget = ValueObjects_1.Vector3.Zero();
|
|
18
18
|
this.limitRadius = false;
|
|
19
19
|
this.minRadius = 0;
|
|
20
20
|
this.maxRadius = 0;
|
|
@@ -25,13 +25,13 @@ class FocusCameraImp {
|
|
|
25
25
|
this.minBeta = 0;
|
|
26
26
|
this.maxBeta = 0;
|
|
27
27
|
this.limitTarget = false;
|
|
28
|
-
this.maxTargetPosition = ValueObjects_1.Vector3.
|
|
29
|
-
this.minTargetPosition = ValueObjects_1.Vector3.
|
|
28
|
+
this.maxTargetPosition = ValueObjects_1.Vector3.Zero();
|
|
29
|
+
this.minTargetPosition = ValueObjects_1.Vector3.Zero();
|
|
30
30
|
this.observers = new _1.ObserverList();
|
|
31
31
|
this.memoizedAlpha = new _1.MemoizedNumber(0, this.observers.notify);
|
|
32
32
|
this.memoizedBeta = new _1.MemoizedNumber(0, this.observers.notify);
|
|
33
33
|
this.memoizedRadius = new _1.MemoizedNumber(1, this.observers.notify);
|
|
34
|
-
this.memoizedTarget = new _1.MemoizedVector3(ValueObjects_1.Vector3.
|
|
34
|
+
this.memoizedTarget = new _1.MemoizedVector3(ValueObjects_1.Vector3.Zero(), this.observers.notify);
|
|
35
35
|
this.setRadiusLimits = (min, max) => {
|
|
36
36
|
if (min < 0) {
|
|
37
37
|
throw new Error("[Orbit Camera] Mininum Radius must be greater >= 0");
|
|
@@ -103,8 +103,8 @@ class FocusCameraImp {
|
|
|
103
103
|
this.target = this.target;
|
|
104
104
|
};
|
|
105
105
|
this.clearTargetLimits = () => {
|
|
106
|
-
this.maxTargetPosition = ValueObjects_1.Vector3.
|
|
107
|
-
this.minTargetPosition = ValueObjects_1.Vector3.
|
|
106
|
+
this.maxTargetPosition = ValueObjects_1.Vector3.Zero();
|
|
107
|
+
this.minTargetPosition = ValueObjects_1.Vector3.Zero();
|
|
108
108
|
this.limitTarget = false;
|
|
109
109
|
};
|
|
110
110
|
this.registerLerp = (lerper) => {
|
|
@@ -210,7 +210,7 @@ class FocusCameraImp {
|
|
|
210
210
|
targetVals[i] = v;
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
|
-
this.memoizedTarget.val = ValueObjects_1.Vector3.
|
|
213
|
+
this.memoizedTarget.val = ValueObjects_1.Vector3.FromArray(targetVals);
|
|
214
214
|
}
|
|
215
215
|
get direction() {
|
|
216
216
|
const yLength = -Math.sin(this.degToRad(this.beta));
|
|
@@ -221,8 +221,8 @@ class FocusCameraImp {
|
|
|
221
221
|
return new ValueObjects_1.Vector3(xLength, yLength, zLength);
|
|
222
222
|
}
|
|
223
223
|
get cameraPosition() {
|
|
224
|
-
const localOffset = ValueObjects_1.Vector3.
|
|
225
|
-
return ValueObjects_1.Vector3.
|
|
224
|
+
const localOffset = ValueObjects_1.Vector3.NewVectorOfLength(this.direction, -this.radius);
|
|
225
|
+
return ValueObjects_1.Vector3.Add(this.target, localOffset);
|
|
226
226
|
}
|
|
227
227
|
degToRad(degrees) {
|
|
228
228
|
return (degrees * Math.PI) / 180;
|
|
@@ -26,10 +26,10 @@ class BumpDollyFocusCamera {
|
|
|
26
26
|
this.focusCamera.radius = this.initialRadius + range * percent;
|
|
27
27
|
if (this.pickPoint !== undefined) {
|
|
28
28
|
const percentChange = this.focusCamera.radius / currentRadius;
|
|
29
|
-
let pickToTarget = ValueObjects_1.Vector3.
|
|
29
|
+
let pickToTarget = ValueObjects_1.Vector3.Subtract(this.focusCamera.target, this.pickPoint);
|
|
30
30
|
const newLength = pickToTarget.magnitued * percentChange;
|
|
31
|
-
pickToTarget = ValueObjects_1.Vector3.
|
|
32
|
-
const newTargetPos = ValueObjects_1.Vector3.
|
|
31
|
+
pickToTarget = ValueObjects_1.Vector3.NewVectorOfLength(pickToTarget, newLength);
|
|
32
|
+
const newTargetPos = ValueObjects_1.Vector3.Add(this.pickPoint, pickToTarget);
|
|
33
33
|
this.focusCamera.target = newTargetPos;
|
|
34
34
|
}
|
|
35
35
|
if (nomralizedTime >= 1 && this.interval) {
|
|
@@ -14,10 +14,10 @@ class PinchDollyFocusCamera {
|
|
|
14
14
|
this.focusCamera.radius = currentRadius - deltaRadius;
|
|
15
15
|
if (this.pickPoint !== undefined) {
|
|
16
16
|
const percentChange = this.focusCamera.radius / currentRadius;
|
|
17
|
-
let pickToTarget = ValueObjects_1.Vector3.
|
|
17
|
+
let pickToTarget = ValueObjects_1.Vector3.Subtract(this.focusCamera.target, this.pickPoint);
|
|
18
18
|
const newLength = pickToTarget.magnitued * percentChange;
|
|
19
|
-
pickToTarget = ValueObjects_1.Vector3.
|
|
20
|
-
const newTargetPos = ValueObjects_1.Vector3.
|
|
19
|
+
pickToTarget = ValueObjects_1.Vector3.NewVectorOfLength(pickToTarget, newLength);
|
|
20
|
+
const newTargetPos = ValueObjects_1.Vector3.Add(this.pickPoint, pickToTarget);
|
|
21
21
|
this.focusCamera.target = newTargetPos;
|
|
22
22
|
}
|
|
23
23
|
this.previousDistanceBetweenTouches = distanceBetweenTouches;
|
|
@@ -14,10 +14,10 @@ class PixelDollyFocusCamera {
|
|
|
14
14
|
this.focusCamera.radius = currentRadius - deltaRadius;
|
|
15
15
|
if (this.pickPoint !== undefined) {
|
|
16
16
|
const percentChange = this.focusCamera.radius / currentRadius;
|
|
17
|
-
let pickToTarget = ValueObjects_1.Vector3.
|
|
17
|
+
let pickToTarget = ValueObjects_1.Vector3.Subtract(this.focusCamera.target, this.pickPoint);
|
|
18
18
|
const newLength = pickToTarget.magnitued * percentChange;
|
|
19
|
-
pickToTarget = ValueObjects_1.Vector3.
|
|
20
|
-
const newTargetPos = ValueObjects_1.Vector3.
|
|
19
|
+
pickToTarget = ValueObjects_1.Vector3.NewVectorOfLength(pickToTarget, newLength);
|
|
20
|
+
const newTargetPos = ValueObjects_1.Vector3.Add(this.pickPoint, pickToTarget);
|
|
21
21
|
this.focusCamera.target = newTargetPos;
|
|
22
22
|
}
|
|
23
23
|
this.previousPixelPosition = pixelPosition;
|
|
@@ -10,7 +10,7 @@ class PixelOrbitFocusCamera {
|
|
|
10
10
|
if (!this.previousPixelPos) {
|
|
11
11
|
throw new Error("[PixelOrbitFocusCamera] You must initialize first!");
|
|
12
12
|
}
|
|
13
|
-
const pixelChange = ValueObjects_1.Vector2.
|
|
13
|
+
const pixelChange = ValueObjects_1.Vector2.Subtract(pixelPosition, this.previousPixelPos);
|
|
14
14
|
this.focusCamera.alpha += pixelChange.x * this.sensitivity;
|
|
15
15
|
this.focusCamera.beta += pixelChange.y * this.sensitivity;
|
|
16
16
|
this.previousPixelPos = pixelPosition;
|
|
@@ -16,7 +16,7 @@ class PixelPlanePanFocusCamera {
|
|
|
16
16
|
const p2 = this.plane.intersectLine(finalRay);
|
|
17
17
|
if (!p1 || !p2)
|
|
18
18
|
return;
|
|
19
|
-
const delta = ValueObjects_1.Vector3.
|
|
19
|
+
const delta = ValueObjects_1.Vector3.Subtract(p2, p1);
|
|
20
20
|
const currentTarget = this.focusCamera.target;
|
|
21
21
|
const newTarget = new ValueObjects_1.Vector3(currentTarget.x - delta.x, currentTarget.y - delta.y, currentTarget.z - delta.z);
|
|
22
22
|
this.focusCamera.target = new ValueObjects_1.Vector3(newTarget.x, newTarget.y, newTarget.z);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare class Angle {
|
|
2
|
-
static
|
|
3
|
-
static
|
|
2
|
+
static FromDegrees(degrees: number): Angle;
|
|
3
|
+
static FromRadians(radians: number): Angle;
|
|
4
4
|
private _degrees;
|
|
5
5
|
get degrees(): number;
|
|
6
6
|
get radians(): number;
|
|
@@ -6,10 +6,10 @@ class Angle {
|
|
|
6
6
|
this._degrees = 0;
|
|
7
7
|
this._degrees = degrees;
|
|
8
8
|
}
|
|
9
|
-
static
|
|
9
|
+
static FromDegrees(degrees) {
|
|
10
10
|
return new Angle(degrees);
|
|
11
11
|
}
|
|
12
|
-
static
|
|
12
|
+
static FromRadians(radians) {
|
|
13
13
|
return new Angle(radians * 180 / Math.PI);
|
|
14
14
|
}
|
|
15
15
|
get degrees() {
|
|
@@ -5,14 +5,10 @@ export declare class Color {
|
|
|
5
5
|
static Hex(hex: string): Color;
|
|
6
6
|
static X11(name: string): Color;
|
|
7
7
|
static Equal(a: Color, b: Color): boolean;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
get r(): number;
|
|
13
|
-
get g(): number;
|
|
14
|
-
get b(): number;
|
|
15
|
-
get a(): number;
|
|
8
|
+
readonly r: number;
|
|
9
|
+
readonly g: number;
|
|
10
|
+
readonly b: number;
|
|
11
|
+
readonly a: number;
|
|
16
12
|
get rPercent(): number;
|
|
17
13
|
get gPercent(): number;
|
|
18
14
|
get bPercent(): number;
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Color = void 0;
|
|
4
4
|
class Color {
|
|
5
5
|
constructor(r, g, b, a) {
|
|
6
|
-
this.
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
6
|
+
this.r = this.clampVal(r);
|
|
7
|
+
this.g = this.clampVal(g);
|
|
8
|
+
this.b = this.clampVal(b);
|
|
9
|
+
this.a = this.clampVal(a);
|
|
10
10
|
}
|
|
11
11
|
static RGBA(r, g, b, a) {
|
|
12
12
|
return new Color(r, g, b, a);
|
|
@@ -51,32 +51,20 @@ class Color {
|
|
|
51
51
|
return false;
|
|
52
52
|
return true;
|
|
53
53
|
}
|
|
54
|
-
get r() {
|
|
55
|
-
return this._r;
|
|
56
|
-
}
|
|
57
|
-
get g() {
|
|
58
|
-
return this._g;
|
|
59
|
-
}
|
|
60
|
-
get b() {
|
|
61
|
-
return this._b;
|
|
62
|
-
}
|
|
63
|
-
get a() {
|
|
64
|
-
return this._a;
|
|
65
|
-
}
|
|
66
54
|
get rPercent() {
|
|
67
|
-
return this.
|
|
55
|
+
return this.r / 255;
|
|
68
56
|
}
|
|
69
57
|
get gPercent() {
|
|
70
|
-
return this.
|
|
58
|
+
return this.g / 255;
|
|
71
59
|
}
|
|
72
60
|
get bPercent() {
|
|
73
|
-
return this.
|
|
61
|
+
return this.b / 255;
|
|
74
62
|
}
|
|
75
63
|
get aPercent() {
|
|
76
|
-
return this.
|
|
64
|
+
return this.a / 255;
|
|
77
65
|
}
|
|
78
66
|
get array() {
|
|
79
|
-
return [this.
|
|
67
|
+
return [this.r, this.g, this.b, this.a];
|
|
80
68
|
}
|
|
81
69
|
clampVal(val) {
|
|
82
70
|
if (val > 255)
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { Vector2 } from "./Vector2";
|
|
2
2
|
export declare class LineSegment2D {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
static GetPositionAtPercent(line: LineSegment2D, percent: number): Vector2;
|
|
4
|
+
static Intersect(a: LineSegment2D, b: LineSegment2D, tolerance?: number): Vector2 | undefined;
|
|
5
|
+
readonly start: Vector2;
|
|
6
|
+
readonly end: Vector2;
|
|
7
7
|
get length(): number;
|
|
8
8
|
get direction(): Vector2;
|
|
9
|
-
getPositionAtPercent(percent: number): Vector2;
|
|
10
|
-
intersect(otherLine: LineSegment2D, tolerance?: number): Vector2 | undefined;
|
|
11
9
|
constructor(start: Vector2, end: Vector2);
|
|
12
10
|
}
|
|
@@ -4,55 +4,49 @@ exports.LineSegment2D = void 0;
|
|
|
4
4
|
const Vector2_1 = require("./Vector2");
|
|
5
5
|
class LineSegment2D {
|
|
6
6
|
constructor(start, end) {
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
7
|
+
this.start = start;
|
|
8
|
+
this.end = end;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
static GetPositionAtPercent(line, percent) {
|
|
11
|
+
const dir = line.direction;
|
|
12
|
+
const length = percent * line.length;
|
|
13
|
+
const localPos = Vector2_1.Vector2.NewVectorOfLength(dir, length);
|
|
14
|
+
return Vector2_1.Vector2.Add(line.start, localPos);
|
|
12
15
|
}
|
|
13
|
-
|
|
14
|
-
return this._end;
|
|
15
|
-
}
|
|
16
|
-
get length() {
|
|
17
|
-
return Vector2_1.Vector2.subtract(this._start, this._end).magnitued;
|
|
18
|
-
}
|
|
19
|
-
get direction() {
|
|
20
|
-
return Vector2_1.Vector2.subtract(this._end, this._start).unit;
|
|
21
|
-
}
|
|
22
|
-
getPositionAtPercent(percent) {
|
|
23
|
-
const dir = this.direction;
|
|
24
|
-
const length = percent * this.length;
|
|
25
|
-
const localPos = Vector2_1.Vector2.newVectorOfLength(dir, length);
|
|
26
|
-
return Vector2_1.Vector2.add(this._start, localPos);
|
|
27
|
-
}
|
|
28
|
-
intersect(otherLine, tolerance = 0) {
|
|
16
|
+
static Intersect(a, b, tolerance = 0) {
|
|
29
17
|
// See https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
|
|
30
|
-
const x1 =
|
|
31
|
-
const y1 =
|
|
32
|
-
const x2 =
|
|
33
|
-
const y2 =
|
|
34
|
-
const x3 =
|
|
35
|
-
const y3 =
|
|
36
|
-
const x4 =
|
|
37
|
-
const y4 =
|
|
18
|
+
const x1 = a.start.x;
|
|
19
|
+
const y1 = a.start.y;
|
|
20
|
+
const x2 = a.end.x;
|
|
21
|
+
const y2 = a.end.y;
|
|
22
|
+
const x3 = b.start.x;
|
|
23
|
+
const y3 = b.start.y;
|
|
24
|
+
const x4 = b.end.x;
|
|
25
|
+
const y4 = b.end.y;
|
|
38
26
|
const denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
|
|
39
27
|
if (denominator === 0) {
|
|
40
28
|
return undefined;
|
|
41
29
|
}
|
|
42
30
|
const tNumerator = (x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4);
|
|
43
31
|
const t = tNumerator / denominator;
|
|
44
|
-
const tTolearnce = tolerance /
|
|
32
|
+
const tTolearnce = tolerance / a.length;
|
|
45
33
|
if (t < -tTolearnce || t > 1 + tTolearnce) {
|
|
46
34
|
return undefined;
|
|
47
35
|
}
|
|
48
36
|
const uNumerator = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
|
|
49
37
|
const u = uNumerator / denominator;
|
|
50
|
-
const uTolearnce = tolerance /
|
|
38
|
+
const uTolearnce = tolerance / b.length;
|
|
51
39
|
if (u < -uTolearnce || u > 1 + uTolearnce)
|
|
52
40
|
return undefined;
|
|
53
41
|
const px = x1 + t * (x2 - x1);
|
|
54
42
|
const py = y1 + t * (y2 - y1);
|
|
55
43
|
return new Vector2_1.Vector2(px, py);
|
|
56
44
|
}
|
|
45
|
+
get length() {
|
|
46
|
+
return Vector2_1.Vector2.Subtract(this.start, this.end).magnitued;
|
|
47
|
+
}
|
|
48
|
+
get direction() {
|
|
49
|
+
return Vector2_1.Vector2.Subtract(this.end, this.start).unit;
|
|
50
|
+
}
|
|
57
51
|
}
|
|
58
52
|
exports.LineSegment2D = LineSegment2D;
|
|
@@ -16,7 +16,7 @@ export declare class ParametricLine {
|
|
|
16
16
|
static Down(): ParametricLine;
|
|
17
17
|
static Left(): ParametricLine;
|
|
18
18
|
static Right(): ParametricLine;
|
|
19
|
-
static
|
|
19
|
+
static GetPointAtDistance(line: ParametricLine, distance: number): Vector3;
|
|
20
20
|
readonly x0: number;
|
|
21
21
|
readonly y0: number;
|
|
22
22
|
readonly z0: number;
|
|
@@ -13,7 +13,7 @@ class ParametricLine {
|
|
|
13
13
|
}
|
|
14
14
|
// See https://planetcalc.com/8253/
|
|
15
15
|
static FromTwoPoint(p1, p2) {
|
|
16
|
-
const dir = Vector3_1.Vector3.
|
|
16
|
+
const dir = Vector3_1.Vector3.Subtract(p2, p1).unit;
|
|
17
17
|
return this.FromPointDirection(p1, dir);
|
|
18
18
|
}
|
|
19
19
|
static FromPointDirection(point, direction) {
|
|
@@ -27,36 +27,36 @@ class ParametricLine {
|
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
static Forward() {
|
|
30
|
-
const p = Vector3_1.Vector3.
|
|
30
|
+
const p = Vector3_1.Vector3.Zero();
|
|
31
31
|
const d = new Vector3_1.Vector3(0, 0, 1);
|
|
32
32
|
return this.FromPointDirection(p, d);
|
|
33
33
|
}
|
|
34
34
|
static Backward() {
|
|
35
|
-
const p = Vector3_1.Vector3.
|
|
35
|
+
const p = Vector3_1.Vector3.Zero();
|
|
36
36
|
const d = new Vector3_1.Vector3(0, 0, -1);
|
|
37
37
|
return this.FromPointDirection(p, d);
|
|
38
38
|
}
|
|
39
39
|
static Up() {
|
|
40
|
-
const p = Vector3_1.Vector3.
|
|
40
|
+
const p = Vector3_1.Vector3.Zero();
|
|
41
41
|
const d = new Vector3_1.Vector3(0, 1, 0);
|
|
42
42
|
return this.FromPointDirection(p, d);
|
|
43
43
|
}
|
|
44
44
|
static Down() {
|
|
45
|
-
const p = Vector3_1.Vector3.
|
|
45
|
+
const p = Vector3_1.Vector3.Zero();
|
|
46
46
|
const d = new Vector3_1.Vector3(0, -1, 0);
|
|
47
47
|
return this.FromPointDirection(p, d);
|
|
48
48
|
}
|
|
49
49
|
static Left() {
|
|
50
|
-
const p = Vector3_1.Vector3.
|
|
50
|
+
const p = Vector3_1.Vector3.Zero();
|
|
51
51
|
const d = new Vector3_1.Vector3(-1, 0, 0);
|
|
52
52
|
return this.FromPointDirection(p, d);
|
|
53
53
|
}
|
|
54
54
|
static Right() {
|
|
55
|
-
const p = Vector3_1.Vector3.
|
|
55
|
+
const p = Vector3_1.Vector3.Zero();
|
|
56
56
|
const d = new Vector3_1.Vector3(1, 0, 0);
|
|
57
57
|
return this.FromPointDirection(p, d);
|
|
58
58
|
}
|
|
59
|
-
static
|
|
59
|
+
static GetPointAtDistance(line, distance) {
|
|
60
60
|
const x = line.x0 + line.a * distance;
|
|
61
61
|
const y = line.y0 + line.b * distance;
|
|
62
62
|
const z = line.z0 + line.c * distance;
|
|
@@ -14,7 +14,7 @@ export declare class ParametricPlane {
|
|
|
14
14
|
static XY(): ParametricPlane;
|
|
15
15
|
static ZX(): ParametricPlane;
|
|
16
16
|
static YZ(): ParametricPlane;
|
|
17
|
-
|
|
17
|
+
GetParameters(): PlaneParameters;
|
|
18
18
|
intersectLine(line: ParametricLine): Vector3 | undefined;
|
|
19
19
|
constructor(point: Vector3, normal: Vector3);
|
|
20
20
|
}
|
|
@@ -13,31 +13,31 @@ class ParametricPlane {
|
|
|
13
13
|
}
|
|
14
14
|
static FromThreePoints(A, B, C) {
|
|
15
15
|
const point = A;
|
|
16
|
-
const AB = Vector3_1.Vector3.
|
|
17
|
-
const AC = Vector3_1.Vector3.
|
|
18
|
-
const normal = Vector3_1.Vector3.
|
|
16
|
+
const AB = Vector3_1.Vector3.Subtract(B, A);
|
|
17
|
+
const AC = Vector3_1.Vector3.Subtract(C, A);
|
|
18
|
+
const normal = Vector3_1.Vector3.Cross(AB, AC);
|
|
19
19
|
return new ParametricPlane(point, normal);
|
|
20
20
|
}
|
|
21
21
|
static XY() {
|
|
22
|
-
const p = Vector3_1.Vector3.
|
|
22
|
+
const p = Vector3_1.Vector3.Zero();
|
|
23
23
|
const n = new Vector3_1.Vector3(0, 0, 1);
|
|
24
24
|
return new ParametricPlane(p, n);
|
|
25
25
|
}
|
|
26
26
|
static ZX() {
|
|
27
|
-
const p = Vector3_1.Vector3.
|
|
27
|
+
const p = Vector3_1.Vector3.Zero();
|
|
28
28
|
const n = new Vector3_1.Vector3(0, 1, 0);
|
|
29
29
|
return new ParametricPlane(p, n);
|
|
30
30
|
}
|
|
31
31
|
static YZ() {
|
|
32
|
-
const p = Vector3_1.Vector3.
|
|
32
|
+
const p = Vector3_1.Vector3.Zero();
|
|
33
33
|
const n = new Vector3_1.Vector3(1, 0, 0);
|
|
34
34
|
return new ParametricPlane(p, n);
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
GetParameters() {
|
|
37
37
|
const a = this.normal.x;
|
|
38
38
|
const b = this.normal.y;
|
|
39
39
|
const c = this.normal.z;
|
|
40
|
-
let d = Vector3_1.Vector3.
|
|
40
|
+
let d = Vector3_1.Vector3.Dot(this.point, this.normal);
|
|
41
41
|
if (d !== 0) {
|
|
42
42
|
d *= -1;
|
|
43
43
|
}
|
|
@@ -50,14 +50,14 @@ class ParametricPlane {
|
|
|
50
50
|
}
|
|
51
51
|
intersectLine(line) {
|
|
52
52
|
const { x0, y0, z0, a, b, c } = line;
|
|
53
|
-
const { a: A, b: B, c: C, d: D } = this.
|
|
53
|
+
const { a: A, b: B, c: C, d: D } = this.GetParameters();
|
|
54
54
|
const tNumerator = -(A * x0 + B * y0 + C * z0 + D);
|
|
55
55
|
const tDenominator = A * a + B * b + C * c;
|
|
56
56
|
if (tDenominator === 0) {
|
|
57
57
|
return undefined;
|
|
58
58
|
}
|
|
59
59
|
const t = tNumerator / tDenominator;
|
|
60
|
-
const intersect = ParametricLine_1.ParametricLine.
|
|
60
|
+
const intersect = ParametricLine_1.ParametricLine.GetPointAtDistance(line, t);
|
|
61
61
|
return intersect;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { Angle } from ".";
|
|
2
2
|
export declare class Vector2 {
|
|
3
3
|
static zero(): Vector2;
|
|
4
|
-
static
|
|
5
|
-
static
|
|
6
|
-
static
|
|
7
|
-
static
|
|
8
|
-
static
|
|
9
|
-
static
|
|
10
|
-
static
|
|
11
|
-
static
|
|
12
|
-
static
|
|
13
|
-
static
|
|
14
|
-
static
|
|
4
|
+
static One(): Vector2;
|
|
5
|
+
static Equal(a: Vector2, b: Vector2): boolean;
|
|
6
|
+
static Add(a: Vector2, b: Vector2): Vector2;
|
|
7
|
+
static Subtract(a: Vector2, b: Vector2): Vector2;
|
|
8
|
+
static Close: (a: Vector2, b: Vector2, threshold?: number) => boolean;
|
|
9
|
+
static Rotate: (vec: Vector2, angle: Angle) => Vector2;
|
|
10
|
+
static Scale: (vector: Vector2, scale: number) => Vector2;
|
|
11
|
+
static NewVectorOfLength: (vector: Vector2, length: number) => Vector2;
|
|
12
|
+
static Dot: (a: Vector2, b: Vector2) => number;
|
|
13
|
+
static AngleBetween: (a: Vector2, b: Vector2) => Angle;
|
|
14
|
+
static Cross: (a: Vector2, b: Vector2) => number;
|
|
15
15
|
readonly x: number;
|
|
16
16
|
readonly y: number;
|
|
17
17
|
get magnitued(): number;
|
|
@@ -10,20 +10,20 @@ class Vector2 {
|
|
|
10
10
|
static zero() {
|
|
11
11
|
return new Vector2(0, 0);
|
|
12
12
|
}
|
|
13
|
-
static
|
|
13
|
+
static One() {
|
|
14
14
|
return new Vector2(1, 1);
|
|
15
15
|
}
|
|
16
|
-
static
|
|
16
|
+
static Equal(a, b) {
|
|
17
17
|
if (a.x !== b.x)
|
|
18
18
|
return false;
|
|
19
19
|
if (a.y !== b.y)
|
|
20
20
|
return false;
|
|
21
21
|
return true;
|
|
22
22
|
}
|
|
23
|
-
static
|
|
23
|
+
static Add(a, b) {
|
|
24
24
|
return new Vector2(a.x + b.x, a.y + b.y);
|
|
25
25
|
}
|
|
26
|
-
static
|
|
26
|
+
static Subtract(a, b) {
|
|
27
27
|
return new Vector2(a.x - b.x, a.y - b.y);
|
|
28
28
|
}
|
|
29
29
|
get magnitued() {
|
|
@@ -49,39 +49,39 @@ class Vector2 {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
exports.Vector2 = Vector2;
|
|
52
|
-
Vector2.
|
|
53
|
-
const diff = Vector2.
|
|
52
|
+
Vector2.Close = (a, b, threshold = 0.01) => {
|
|
53
|
+
const diff = Vector2.Subtract(a, b);
|
|
54
54
|
const diffMag = diff.magnitued;
|
|
55
55
|
if (diffMag < threshold)
|
|
56
56
|
return true;
|
|
57
57
|
else
|
|
58
58
|
return false;
|
|
59
59
|
};
|
|
60
|
-
Vector2.
|
|
60
|
+
Vector2.Rotate = (vec, angle) => {
|
|
61
61
|
const x = vec.x * Math.cos(angle.radians) - vec.y * Math.sin(angle.radians);
|
|
62
62
|
const y = vec.x * Math.sin(angle.radians) + vec.y * Math.cos(angle.radians);
|
|
63
63
|
return new Vector2(x, y);
|
|
64
64
|
};
|
|
65
|
-
Vector2.
|
|
65
|
+
Vector2.Scale = (vector, scale) => {
|
|
66
66
|
const x = scale * vector.x;
|
|
67
67
|
const y = scale * vector.y;
|
|
68
68
|
return new Vector2(x, y);
|
|
69
69
|
};
|
|
70
|
-
Vector2.
|
|
70
|
+
Vector2.NewVectorOfLength = (vector, length) => {
|
|
71
71
|
const unit = vector.unit;
|
|
72
72
|
const x = length * unit.x;
|
|
73
73
|
const y = length * unit.y;
|
|
74
74
|
return new Vector2(x, y);
|
|
75
75
|
};
|
|
76
|
-
Vector2.
|
|
76
|
+
Vector2.Dot = (a, b) => {
|
|
77
77
|
return a.x * b.x + a.y * b.y;
|
|
78
78
|
};
|
|
79
|
-
Vector2.
|
|
80
|
-
const dot = Vector2.
|
|
79
|
+
Vector2.AngleBetween = (a, b) => {
|
|
80
|
+
const dot = Vector2.Dot(a, b);
|
|
81
81
|
const magnitues = a.magnitued * b.magnitued;
|
|
82
82
|
const angRadians = Math.acos(dot / magnitues);
|
|
83
|
-
return _1.Angle.
|
|
83
|
+
return _1.Angle.FromRadians(angRadians);
|
|
84
84
|
};
|
|
85
|
-
Vector2.
|
|
85
|
+
Vector2.Cross = (a, b) => {
|
|
86
86
|
return a.x * b.y - a.y * b.x;
|
|
87
87
|
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
export declare class Vector3 {
|
|
2
|
-
static
|
|
3
|
-
static
|
|
4
|
-
static
|
|
5
|
-
static
|
|
6
|
-
static
|
|
7
|
-
static
|
|
8
|
-
static
|
|
9
|
-
static
|
|
10
|
-
static
|
|
11
|
-
static
|
|
12
|
-
static
|
|
13
|
-
static
|
|
14
|
-
static
|
|
15
|
-
static
|
|
16
|
-
static
|
|
17
|
-
static
|
|
2
|
+
static Zero(): Vector3;
|
|
3
|
+
static One(): Vector3;
|
|
4
|
+
static Right(length?: number): Vector3;
|
|
5
|
+
static Left(length?: number): Vector3;
|
|
6
|
+
static Up(length?: number): Vector3;
|
|
7
|
+
static Down(length?: number): Vector3;
|
|
8
|
+
static Forward(length?: number): Vector3;
|
|
9
|
+
static Backward(length?: number): Vector3;
|
|
10
|
+
static FromArray(values: [number, number, number]): Vector3;
|
|
11
|
+
static Add: (a: Vector3, b: Vector3) => Vector3;
|
|
12
|
+
static Subtract: (a: Vector3, b: Vector3) => Vector3;
|
|
13
|
+
static Equal: (a: Vector3, b: Vector3) => boolean;
|
|
14
|
+
static Close: (a: Vector3, b: Vector3, tolerance?: number) => boolean;
|
|
15
|
+
static Cross: (a: Vector3, b: Vector3) => Vector3;
|
|
16
|
+
static Dot: (a: Vector3, b: Vector3) => number;
|
|
17
|
+
static NewVectorOfLength: (vec: Vector3, length: number) => Vector3;
|
|
18
18
|
readonly x: number;
|
|
19
19
|
readonly y: number;
|
|
20
20
|
readonly z: number;
|
|
@@ -7,31 +7,31 @@ class Vector3 {
|
|
|
7
7
|
this.y = y;
|
|
8
8
|
this.z = z;
|
|
9
9
|
}
|
|
10
|
-
static
|
|
10
|
+
static Zero() {
|
|
11
11
|
return new Vector3(0, 0, 0);
|
|
12
12
|
}
|
|
13
|
-
static
|
|
13
|
+
static One() {
|
|
14
14
|
return new Vector3(1, 1, 1);
|
|
15
15
|
}
|
|
16
|
-
static
|
|
16
|
+
static Right(length = 1) {
|
|
17
17
|
return new Vector3(length, 0, 0);
|
|
18
18
|
}
|
|
19
|
-
static
|
|
19
|
+
static Left(length = 1) {
|
|
20
20
|
return new Vector3(-length, 0, 0);
|
|
21
21
|
}
|
|
22
|
-
static
|
|
22
|
+
static Up(length = 1) {
|
|
23
23
|
return new Vector3(0, length, 0);
|
|
24
24
|
}
|
|
25
|
-
static
|
|
25
|
+
static Down(length = 1) {
|
|
26
26
|
return new Vector3(0, -length, 0);
|
|
27
27
|
}
|
|
28
|
-
static
|
|
28
|
+
static Forward(length = 1) {
|
|
29
29
|
return new Vector3(0, 0, length);
|
|
30
30
|
}
|
|
31
|
-
static
|
|
31
|
+
static Backward(length = 1) {
|
|
32
32
|
return new Vector3(0, 0, -length);
|
|
33
33
|
}
|
|
34
|
-
static
|
|
34
|
+
static FromArray(values) {
|
|
35
35
|
return new Vector3(values[0], values[1], values[2]);
|
|
36
36
|
}
|
|
37
37
|
get magnitued() {
|
|
@@ -44,7 +44,7 @@ class Vector3 {
|
|
|
44
44
|
get unit() {
|
|
45
45
|
const mag = this.magnitued;
|
|
46
46
|
if (mag === 0) {
|
|
47
|
-
return Vector3.
|
|
47
|
+
return Vector3.Zero();
|
|
48
48
|
}
|
|
49
49
|
const unitX = this.x / mag;
|
|
50
50
|
const unitY = this.y / mag;
|
|
@@ -56,36 +56,36 @@ class Vector3 {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
exports.Vector3 = Vector3;
|
|
59
|
-
Vector3.
|
|
59
|
+
Vector3.Add = (a, b) => {
|
|
60
60
|
return new Vector3(a.x + b.x, a.y + b.y, a.z + b.z);
|
|
61
61
|
};
|
|
62
|
-
Vector3.
|
|
62
|
+
Vector3.Subtract = (a, b) => {
|
|
63
63
|
return new Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
|
|
64
64
|
};
|
|
65
|
-
Vector3.
|
|
65
|
+
Vector3.Equal = (a, b) => {
|
|
66
66
|
if (a.x === b.x && a.y === b.y && a.z === b.z)
|
|
67
67
|
return true;
|
|
68
68
|
else
|
|
69
69
|
return false;
|
|
70
70
|
};
|
|
71
|
-
Vector3.
|
|
72
|
-
const diff = Vector3.
|
|
71
|
+
Vector3.Close = (a, b, tolerance = 0.01) => {
|
|
72
|
+
const diff = Vector3.Subtract(a, b);
|
|
73
73
|
const diffMag = diff.magnitued;
|
|
74
74
|
if (diffMag < tolerance)
|
|
75
75
|
return true;
|
|
76
76
|
else
|
|
77
77
|
return false;
|
|
78
78
|
};
|
|
79
|
-
Vector3.
|
|
79
|
+
Vector3.Cross = (a, b) => {
|
|
80
80
|
const x = a.y * b.z - a.z * b.y;
|
|
81
81
|
const y = a.z * b.x - a.x * b.z;
|
|
82
82
|
const z = a.x * b.y - a.y * b.x;
|
|
83
83
|
return new Vector3(x, y, z);
|
|
84
84
|
};
|
|
85
|
-
Vector3.
|
|
85
|
+
Vector3.Dot = (a, b) => {
|
|
86
86
|
return a.x * b.x + a.y * b.y + a.z * b.z;
|
|
87
87
|
};
|
|
88
|
-
Vector3.
|
|
88
|
+
Vector3.NewVectorOfLength = (vec, length) => {
|
|
89
89
|
const unit = vec.unit;
|
|
90
90
|
return new Vector3(length * unit.x, length * unit.y, length * unit.z);
|
|
91
91
|
};
|