@pirireis/webglobeplugins 0.9.1 → 0.9.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.
- package/Math/arc.ts +74 -245
- package/Math/constants.ts +4 -1
- package/Math/frustum/camera.ts +32 -0
- package/Math/frustum/from-globeinfo.ts +63 -0
- package/Math/frustum/types.ts +11 -0
- package/Math/globe-util/horizon-plane.ts +137 -0
- package/Math/juction/arc-plane.ts +90 -0
- package/Math/juction/line-sphere.ts +30 -0
- package/Math/juction/plane-plane.ts +66 -0
- package/Math/line.ts +70 -0
- package/Math/methods.js +29 -1
- package/Math/plane.ts +57 -138
- package/Math/quaternion.ts +108 -144
- package/Math/types.ts +39 -30
- package/Math/vec3.ts +155 -0
- package/altitude-locator/plugin.js +1 -1
- package/bearing-line/plugin.js +1 -1
- package/circle-line-chain/plugin.js +1 -1
- package/globe-types.ts +13 -0
- package/heatwave/plugins/heatwaveglobeshell.js +5 -9
- package/index.js +3 -0
- package/package.json +1 -1
- package/programs/interface.ts +7 -0
- package/programs/line-on-globe/circle-accurate-3d.js +1 -1
- package/programs/line-on-globe/degree-padding-around-circle-3d.js +1 -1
- package/programs/line-on-globe/lines-color-instanced-flat.js +1 -1
- package/programs/line-on-globe/linestrip.ts +228 -0
- package/programs/line-on-globe/naive-accurate-flexible.js +1 -1
- package/programs/line-on-globe/to-the-surface.js +1 -1
- package/programs/picking/pickable-renderer.js +1 -1
- package/programs/point-on-globe/element-globe-surface-glow.js +1 -1
- package/programs/point-on-globe/element-point-glow.js +1 -1
- package/programs/totems/camerauniformblock.js +24 -1
- package/programs/vectorfields/logics/drawrectangleparticles.js +1 -1
- package/shape-on-terrain/arc/naive/plugin.ts +304 -0
- package/tests/Math/junction/arc-plane.test.ts +129 -0
- package/tests/Math/junction/plane-plane.test.ts +82 -0
- package/tests/Math/plane.test.ts +30 -32
- package/tests/Math/vec3.test.ts +14 -0
- package/timetracks/plugin-line-strip.js +3 -1
- package/{types.js → types.ts} +2 -1
- package/util/account/{index.js → index.ts} +1 -2
- package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +0 -31
- package/util/account/single-attribute-buffer-management/index.ts +13 -0
- package/util/gl-util/buffer/{integrate-buffer.js → attribute-loader.ts} +17 -6
- package/util/gl-util/buffer/index.ts +6 -0
- package/util/gl-util/buffer/types.ts +13 -0
- package/util/gl-util/draw-options/methods.js +4 -4
- package/util/gl-util/draw-options/{types.js → types.ts} +10 -0
- package/util/gl-util/uniform-block/{manager.js → manager.ts} +24 -13
- package/util/gl-util/uniform-block/types.ts +27 -0
- package/util/heatwavedatamanager/pointcoordinatesdatacalculator.js +17 -17
- package/waveparticles/plugin.js +3 -0
- package/wind/plugin.js +6 -19
- package/Math/methodology/arc-part-on-screen.ts +0 -47
- package/Math/ray.ts +0 -101
- package/Math/vector3d.ts +0 -241
- package/shape-on-terrain/tree-search.js +0 -0
- package/surface-cover-shapes/arc/naive/data-manager.ts +0 -0
- package/surface-cover-shapes/arc/naive/plugin.ts +0 -0
- package/tests/Math/arc.test.ts +0 -112
- package/tests/Math/quaternion.test.ts +0 -98
- package/tests/Math/ray-plane.test.ts +0 -176
- package/tests/Math/vector3d.test.ts +0 -104
- package/util/account/single-attribute-buffer-management/index.js +0 -4
- package/util/gl-util/uniform-block/types.js +0 -7
- /package/{shape-on-terrain/intersection.js → Math/matrix4.ts} +0 -0
|
@@ -114,20 +114,20 @@ export default class PointCoordinatesDataCalculator {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
function test() {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
117
|
+
// function test() {
|
|
118
|
+
// const cp = window.plugin.getPointCoordinatesDataCalculator();
|
|
119
|
+
// const bbox = [-15, 25, 70, 60];
|
|
120
|
+
// cp.registerPoint("left up", -15, 60, (data0, data1, interpolated) => {
|
|
121
|
+
// console.log("left up", data0, data1, interpolated);
|
|
122
|
+
// });
|
|
123
|
+
// cp.registerPoint("right up", 70, 60, (data0, data1, interpolated) => {
|
|
124
|
+
// console.log("right up", data0, data1, interpolated);
|
|
125
|
+
// });
|
|
126
|
+
// cp.registerPoint("left down", -15, 25, (data0, data1, interpolated) => {
|
|
127
|
+
// console.log("right down", data0, data1, interpolated);
|
|
128
|
+
// });
|
|
129
|
+
// cp.registerPoint("right down", 70, 25, (data0, data1, interpolated) => {
|
|
130
|
+
// console.log("right down", data0, data1, interpolated);
|
|
131
|
+
// });
|
|
132
|
+
// return cp;
|
|
133
|
+
// }
|
package/waveparticles/plugin.js
CHANGED
|
@@ -48,6 +48,7 @@ export default class Plugin {
|
|
|
48
48
|
}
|
|
49
49
|
this._stepIndex = 0;
|
|
50
50
|
this._fullCycleStepCount = 3;
|
|
51
|
+
this._isFreed = false;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
init(globe, gl) {
|
|
@@ -96,6 +97,7 @@ export default class Plugin {
|
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
draw3D() {
|
|
100
|
+
if (this._isFreed) return;
|
|
99
101
|
const { gl, moveParticle, drawParticle, bufferManager, globeShellWiggle, waveUbo, fadeAway, _rgVectorFieldTexture } = this;
|
|
100
102
|
|
|
101
103
|
gl.disable(gl.DEPTH_TEST);
|
|
@@ -168,6 +170,7 @@ export default class Plugin {
|
|
|
168
170
|
// TODO: free all resources
|
|
169
171
|
free() {
|
|
170
172
|
const { gl, fadeAway, globeShellWiggle, _rgVectorFieldTexture, bufferManager, waveUbo, _drawTextures, _frameBuffer } = this;
|
|
173
|
+
this._isFreed = true;
|
|
171
174
|
fadeAway.free();
|
|
172
175
|
globeShellWiggle.free();
|
|
173
176
|
gl.deleteTexture(_rgVectorFieldTexture);
|
package/wind/plugin.js
CHANGED
|
@@ -300,18 +300,6 @@ void main() {
|
|
|
300
300
|
}`;
|
|
301
301
|
|
|
302
302
|
|
|
303
|
-
const reverseDefaultRampColors = [
|
|
304
|
-
[0.0, '#d53e4f'],
|
|
305
|
-
[0.2, '#f46d43'],
|
|
306
|
-
[0.3, '#fdae61'],
|
|
307
|
-
[0.4, '#fee08b'],
|
|
308
|
-
[0.5, '#e6f598'],
|
|
309
|
-
[0.6, '#abdda4'],
|
|
310
|
-
[0.7, '#66c2a5'],
|
|
311
|
-
[0.9, '#3288bd'],
|
|
312
|
-
// 1.0 deep purple
|
|
313
|
-
[1.0, '#5e4fa2']
|
|
314
|
-
];
|
|
315
303
|
|
|
316
304
|
const defaultRampColors = [
|
|
317
305
|
[0.0, '#5e4fa2'],
|
|
@@ -492,7 +480,6 @@ export default class WindPlugin {
|
|
|
492
480
|
}
|
|
493
481
|
|
|
494
482
|
setColorRampDefault() {
|
|
495
|
-
const { gl } = this;
|
|
496
483
|
const { uMax, uMin, vMax, vMin } = this.windData;
|
|
497
484
|
const maxSpeed = Math.sqrt(
|
|
498
485
|
uMax * uMax + vMax * vMax
|
|
@@ -516,11 +503,11 @@ export default class WindPlugin {
|
|
|
516
503
|
*/
|
|
517
504
|
setLegend(legendData) {
|
|
518
505
|
const { gl } = this;
|
|
519
|
-
if (gl
|
|
506
|
+
if (gl === null) {
|
|
520
507
|
throw new Error("wind plugin. setColorRampFromService is called before plugin is registered.");
|
|
521
508
|
}
|
|
522
509
|
const { thresholds, values } = legendData;
|
|
523
|
-
if (thresholds.length
|
|
510
|
+
if (thresholds.length === 0 || values.length === 0) {
|
|
524
511
|
return;
|
|
525
512
|
}
|
|
526
513
|
thresholds.push(thresholds[thresholds.length - 1]);
|
|
@@ -591,7 +578,7 @@ export default class WindPlugin {
|
|
|
591
578
|
* @param {number} windData.vMax - maximum v value
|
|
592
579
|
*/
|
|
593
580
|
setWind(windData) {
|
|
594
|
-
if (windData
|
|
581
|
+
if (windData === null) {
|
|
595
582
|
return;
|
|
596
583
|
}
|
|
597
584
|
const windDataMeta = this._windDataMeta;
|
|
@@ -693,10 +680,10 @@ export default class WindPlugin {
|
|
|
693
680
|
|
|
694
681
|
_doDraw() {
|
|
695
682
|
const globe = this.globe;
|
|
696
|
-
if (this.windData
|
|
683
|
+
if (this.windData === null) {
|
|
697
684
|
return false;
|
|
698
685
|
}
|
|
699
|
-
if (globe.api_IsScreenMoving() || this._lastLOD
|
|
686
|
+
if (globe.api_IsScreenMoving() || this._lastLOD !== globe.api_GetCurrentLODWithDecimal()) {
|
|
700
687
|
if (!this._screenMoved) {
|
|
701
688
|
this._screenMoved = true;
|
|
702
689
|
}
|
|
@@ -850,7 +837,7 @@ export default class WindPlugin {
|
|
|
850
837
|
// globe calls `setGeometry` method on map projection change. FLAT or SPHERE
|
|
851
838
|
|
|
852
839
|
setGeometry() {
|
|
853
|
-
if (this.windData
|
|
840
|
+
if (this.windData === null) {
|
|
854
841
|
return;
|
|
855
842
|
}
|
|
856
843
|
const { globe, gl } = this;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Plane } from "../plane";
|
|
2
|
-
import { Vector3D } from "../vector3d";
|
|
3
|
-
import { Arc } from "../arc";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const Radians = Math.PI / 180;
|
|
8
|
-
|
|
9
|
-
export class ArcPartOnScreen {
|
|
10
|
-
private _oldLookInfo: { CenterLong: number, CenterLat: number, Distance: number, Tilt: number, NorthAng: number };
|
|
11
|
-
private _boundPlane: Plane;
|
|
12
|
-
|
|
13
|
-
constructor() {
|
|
14
|
-
this._boundPlane = new Plane(new Vector3D(0, 0, 0), 0);
|
|
15
|
-
this._oldLookInfo = { CenterLong: 0, CenterLat: -190, Distance: 0, Tilt: 0, NorthAng: 0 };
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
updateBoundPlane(lookInfo): boolean {
|
|
20
|
-
if (this._oldLookInfo && this._oldLookInfo.CenterLong === lookInfo.CenterLong && this._oldLookInfo.CenterLat === lookInfo.CenterLat) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* lookInfo {CenterLong: 47.75355881750585, CenterLat: 42.3417076206803, Distance: 2286603.4020860917, Tilt: 0.05, NorthAng: -13.829359965098265}
|
|
25
|
-
*/
|
|
26
|
-
this._oldLookInfo.CenterLong = lookInfo.CenterLong;
|
|
27
|
-
this._oldLookInfo.CenterLat = lookInfo.CenterLat;
|
|
28
|
-
this._oldLookInfo.Distance = lookInfo.Distance;
|
|
29
|
-
this._oldLookInfo.Tilt = lookInfo.Tilt;
|
|
30
|
-
this._oldLookInfo.NorthAng = lookInfo.NorthAng;
|
|
31
|
-
|
|
32
|
-
Plane.fromGlobeLookInfo(Radians * lookInfo.CenterLong, Radians * lookInfo.CenterLat, lookInfo.Distance, this._boundPlane);
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
getArcPartOnScreen(arc: Arc, target: Arc): boolean {
|
|
39
|
-
// _imaginaryPlane.set(arc.greatCirclePlaneNormalVector, arc.pointA.dot(arc.greatCirclePlaneNormalVector));
|
|
40
|
-
// const intersection = _imaginaryPlane.intersectionPlane(this._boundPlane);
|
|
41
|
-
// if (!(intersection instanceof Ray)) return false;
|
|
42
|
-
// _ray.copy(intersection as Ray);
|
|
43
|
-
// const [point1, point2] = _ray.intersectionSphere(_unitShphereCenter, _unitShphereRadius) as [Vector3D, Vector3D];
|
|
44
|
-
const result = arc.intersectionMedium(this._boundPlane, target);
|
|
45
|
-
return !(result === null);
|
|
46
|
-
}
|
|
47
|
-
}
|
package/Math/ray.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { Vector3D } from './vector3d';
|
|
2
|
-
import { Plane } from './plane';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const _0vector = /*@__PURE__*/ new Vector3D(0, 0, 0);
|
|
6
|
-
const _1vector = /*@__PURE__*/ new Vector3D(0, 0, 0);
|
|
7
|
-
const _3vector = /*@__PURE__*/ new Vector3D(0, 0, 0);
|
|
8
|
-
export class Ray {
|
|
9
|
-
|
|
10
|
-
origin: Vector3D;
|
|
11
|
-
direction: Vector3D;
|
|
12
|
-
|
|
13
|
-
constructor(origin: Vector3D, direction: Vector3D) {
|
|
14
|
-
this.origin = origin;
|
|
15
|
-
this.direction = direction.normalize();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
copy(ray: Ray): Ray {
|
|
19
|
-
this.origin.copy(ray.origin);
|
|
20
|
-
this.direction.copy(ray.direction);
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
clone(): Ray {
|
|
25
|
-
return new Ray(this.origin.clone(), this.direction.clone());
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
at(distance: number, out: Vector3D): Vector3D {
|
|
30
|
-
return out.copy(this.direction).multiplyByScaler(distance).add(this.origin);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
set(origin: Vector3D, direction: Vector3D): Ray {
|
|
35
|
-
this.origin.copy(origin);
|
|
36
|
-
this.direction.copy(direction).normalize();
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
intersectionSphere(sphereOrigin: Vector3D, sphereRadius: number): [Vector3D, Vector3D] | null {
|
|
41
|
-
|
|
42
|
-
const l = this.direction.clone().normalize();
|
|
43
|
-
const s = this.origin.clone().subtract(sphereOrigin);
|
|
44
|
-
const b = l.dot(s);
|
|
45
|
-
|
|
46
|
-
const c = s.dot(s) - sphereRadius * sphereRadius;
|
|
47
|
-
const d = b * b - c;
|
|
48
|
-
|
|
49
|
-
if (d < 0) {
|
|
50
|
-
return null; // no intersection
|
|
51
|
-
} else {
|
|
52
|
-
const x = Math.sqrt(d);
|
|
53
|
-
const t1 = -b - x;
|
|
54
|
-
const t2 = -b + x;
|
|
55
|
-
// l and s are used as output vectors
|
|
56
|
-
return [this.at(t1, l), this.at(t2, s)];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
contains(point: Vector3D): boolean {
|
|
62
|
-
const x = this.origin.x - point.x;
|
|
63
|
-
const y = this.origin.y - point.y;
|
|
64
|
-
const z = this.origin.z - point.z;
|
|
65
|
-
const distance = Math.sqrt(x * x + y * y + z * z);
|
|
66
|
-
if (distance < 0.0001) {
|
|
67
|
-
return true; // point is very close to the origin
|
|
68
|
-
}
|
|
69
|
-
return Math.abs(_0vector.set(x / distance, y / distance, z / distance).dot(this.direction)) > 0.9999; // point direction towards origin
|
|
70
|
-
// is very close to the ray direction
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// TODO: Applay this approach to other static methods on other Math classes.
|
|
74
|
-
static fromTwoPlanes(planeA: Plane, planeB: Plane, target: Ray | null = null): Ray | null {
|
|
75
|
-
const intersection = planeA.intersectionPlane(planeB);
|
|
76
|
-
if (intersection === null || intersection instanceof Plane) {
|
|
77
|
-
return null; // planes are parallel
|
|
78
|
-
}
|
|
79
|
-
if (target === null) {
|
|
80
|
-
target = new Ray(intersection.origin, intersection.direction);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
target.set(intersection.origin, intersection.direction);
|
|
84
|
-
}
|
|
85
|
-
return target;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
static fromTwoPoints(pointA: Vector3D, pointB: Vector3D, target: Ray | null = null): Ray {
|
|
90
|
-
if (target === null) {
|
|
91
|
-
target = new Ray(pointA, pointB.clone().subtract(pointA).normalize());
|
|
92
|
-
} else {
|
|
93
|
-
target.set(pointA, pointB.clone().subtract(pointA).normalize());
|
|
94
|
-
}
|
|
95
|
-
return target;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
package/Math/vector3d.ts
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import { Vector3D as IVector3D, Radians } from "./types";
|
|
2
|
-
import { Quaternion } from "./quaternion";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export class Vector3D implements IVector3D {
|
|
7
|
-
x: number;
|
|
8
|
-
y: number;
|
|
9
|
-
z: number;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
constructor(x: number = 0, y: number = 0, z: number = 0) {
|
|
13
|
-
this.x = x;
|
|
14
|
-
this.y = y;
|
|
15
|
-
this.z = z;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
normalize(): Vector3D {
|
|
21
|
-
this.divideByScaler(this.length() || 1);
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
dot(other: Vector3D) {
|
|
28
|
-
return this.x * other.x + this.y * other.y + this.z * other.z;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
equals(other: Vector3D, epsilon: number = 0.0000001): boolean {
|
|
34
|
-
// TODO: consider coppying other in case is true to avoid difference accumulation.
|
|
35
|
-
return Math.abs(this.x - other.x) < epsilon &&
|
|
36
|
-
Math.abs(this.y - other.y) < epsilon &&
|
|
37
|
-
Math.abs(this.z - other.z) < epsilon;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
static crossVectors(a: Vector3D, b: Vector3D, c: Vector3D = new Vector3D): Vector3D {
|
|
44
|
-
const x = a.y * b.z - a.z * b.y;
|
|
45
|
-
const y = a.z * b.x - a.x * b.z;
|
|
46
|
-
const z = a.x * b.y - a.y * b.x;
|
|
47
|
-
|
|
48
|
-
c.set(x, y, z);
|
|
49
|
-
|
|
50
|
-
return c;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
cross(other: Vector3D): Vector3D {
|
|
56
|
-
return Vector3D.crossVectors(this, other, this);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
angle(other: Vector3D): number {
|
|
62
|
-
const a = this.length();
|
|
63
|
-
const b = other.length();
|
|
64
|
-
const c = this.dot(other);
|
|
65
|
-
const angle = Math.acos(c / (a * b));
|
|
66
|
-
|
|
67
|
-
return isNaN(angle) ? 0 : angle;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
lerpVectors(a: Vector3D, b: Vector3D, t: number): Vector3D {
|
|
71
|
-
this.x = a.x + (b.x - a.x) * t;
|
|
72
|
-
this.y = a.y + (b.y - a.y) * t;
|
|
73
|
-
this.z = a.z + (b.z - a.z) * t;
|
|
74
|
-
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
lerp(other: Vector3D, t: number): Vector3D {
|
|
81
|
-
return this.lerpVectors(this, other, t);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
scale(scalar: number): Vector3D {
|
|
87
|
-
this.x *= scalar;
|
|
88
|
-
this.y *= scalar;
|
|
89
|
-
this.z *= scalar;
|
|
90
|
-
|
|
91
|
-
return this;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
dotProduct(other: Vector3D): number {
|
|
95
|
-
return this.x * other.x + this.y * other.y + this.z * other.z;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
dotDivide(other: Vector3D): number {
|
|
100
|
-
return this.x / other.x + this.y / other.y + this.z / other.z;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
add(other: Vector3D): Vector3D {
|
|
105
|
-
this.x += other.x;
|
|
106
|
-
this.y += other.y;
|
|
107
|
-
this.z += other.z;
|
|
108
|
-
|
|
109
|
-
return this;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
negate(): Vector3D {
|
|
115
|
-
this.x = -this.x;
|
|
116
|
-
this.y = -this.y;
|
|
117
|
-
this.z = -this.z;
|
|
118
|
-
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
length(): number {
|
|
125
|
-
return Math.sqrt(this.x ** 2 + this.y ** 2 + this.z ** 2);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
subtract(other: Vector3D): Vector3D {
|
|
131
|
-
this.x -= other.x;
|
|
132
|
-
this.y -= other.y;
|
|
133
|
-
this.z -= other.z;
|
|
134
|
-
|
|
135
|
-
return this;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
applyQuaternion(q: Quaternion): Vector3D {
|
|
141
|
-
const x = this.x, y = this.y, z = this.z;
|
|
142
|
-
const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
|
|
143
|
-
// calculate quat * vector
|
|
144
|
-
const ix = qw * x + qy * z - qz * y;
|
|
145
|
-
const iy = qw * y + qz * x - qx * z;
|
|
146
|
-
const iz = qw * z + qx * y - qy * x;
|
|
147
|
-
const iw = -qx * x - qy * y - qz * z;
|
|
148
|
-
// calculate result * inverse quat
|
|
149
|
-
this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
|
|
150
|
-
this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
|
|
151
|
-
this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
|
|
152
|
-
return this;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
multiplyByScaler(scalar: number): Vector3D {
|
|
158
|
-
this.x *= scalar;
|
|
159
|
-
this.y *= scalar;
|
|
160
|
-
this.z *= scalar;
|
|
161
|
-
|
|
162
|
-
return this;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
divideByScaler(scalar: number): Vector3D {
|
|
168
|
-
this.x /= scalar;
|
|
169
|
-
this.y /= scalar;
|
|
170
|
-
this.z /= scalar;
|
|
171
|
-
|
|
172
|
-
return this;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
copy(other: Vector3D): Vector3D {
|
|
178
|
-
this.x = other.x;
|
|
179
|
-
this.y = other.y;
|
|
180
|
-
this.z = other.z;
|
|
181
|
-
|
|
182
|
-
return this
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
set(x: number, y: number, z: number): Vector3D {
|
|
188
|
-
this.x = x;
|
|
189
|
-
this.y = y;
|
|
190
|
-
this.z = z;
|
|
191
|
-
|
|
192
|
-
return this
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
clone(): Vector3D {
|
|
198
|
-
return new Vector3D(this.x, this.y, this.z);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
randomUnit(): Vector3D {
|
|
204
|
-
const x = Math.random() * 2 - 1;
|
|
205
|
-
const y = Math.random() * 2 - 1;
|
|
206
|
-
const z = Math.random() * 2 - 1;
|
|
207
|
-
|
|
208
|
-
return this.set(x, y, z).normalize();
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
setFromLonLat(lon: Radians, lat: Radians): Vector3D {
|
|
214
|
-
const x = Math.cos(lat) * Math.cos(lon);
|
|
215
|
-
const y = Math.cos(lat) * Math.sin(lon);
|
|
216
|
-
const z = Math.sin(lat);
|
|
217
|
-
|
|
218
|
-
return this.set(x, y, z);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
toLonLat(): { lon: Radians, lat: Radians } {
|
|
225
|
-
const len = this.length();
|
|
226
|
-
const x = this.x / len;
|
|
227
|
-
const y = this.y / len;
|
|
228
|
-
const z = this.z / len;
|
|
229
|
-
const lon = Math.atan2(y, x);
|
|
230
|
-
const lat = Math.asin(z);
|
|
231
|
-
|
|
232
|
-
return { lon, lat };
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
static fromLonLatRadians(lon: Radians, lat: Radians): Vector3D {
|
|
238
|
-
return new Vector3D().setFromLonLat(lon, lat);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/tests/Math/arc.test.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { Arc } from '../../Math/arc';
|
|
2
|
-
import { Vector3D } from '../../Math/vector3d';
|
|
3
|
-
import { Quaternion } from '../../Math/quaternion';
|
|
4
|
-
import { Plane } from '../../Math/plane';
|
|
5
|
-
|
|
6
|
-
let _0vector: Vector3D;
|
|
7
|
-
let _1vector: Vector3D;
|
|
8
|
-
let _0arc: Arc;
|
|
9
|
-
let _1arc: Arc;
|
|
10
|
-
let _0quaternion: Quaternion;
|
|
11
|
-
let _medium: Plane;
|
|
12
|
-
|
|
13
|
-
beforeAll(() => {
|
|
14
|
-
|
|
15
|
-
_0vector = new Vector3D(0, 0, 0);
|
|
16
|
-
_1vector = new Vector3D(1, 1, 1).normalize();
|
|
17
|
-
_0arc = new Arc(_0vector, _1vector);
|
|
18
|
-
_1arc = new Arc(_0vector, _1vector);
|
|
19
|
-
_0quaternion = new Quaternion(0, 0, 0, 1);
|
|
20
|
-
_medium = new Plane(new Vector3D(0, 0, 1), 0);
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
test("intersectionMedium", () => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
_0quaternion.setFromAxisAngle(_0vector.set(1, 0, 0), -Math.PI / 3);
|
|
30
|
-
const A = _0vector.set(0, 1, 0).applyQuaternion(_0quaternion).clone();
|
|
31
|
-
_0quaternion.setFromAxisAngle(_0vector.set(1, 0, 0), Math.PI / 3);
|
|
32
|
-
const B = _0vector.set(0, 1, 0).applyQuaternion(_0quaternion).clone();
|
|
33
|
-
_0arc.setFromUnitVectors(A, B);
|
|
34
|
-
const _1arc = _0arc.intersectionMedium(_medium)!;
|
|
35
|
-
|
|
36
|
-
expect(_1arc !== null).toBeTruthy();
|
|
37
|
-
expect([A, B].some((v) => v.equals(_1arc.pointA) || v.equals(_1arc.pointB))).toBeTruthy();
|
|
38
|
-
expect([_1arc.pointA, _1arc.pointB].some((v) => v.equals(new Vector3D(0, 1, 0)))).toBeTruthy();
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
test("intersectionMedium 2 - single point arc", () => {
|
|
44
|
-
_0arc.setFromUnitVectors(new Vector3D(0, 1, 0), new Vector3D(0, 1, 0));
|
|
45
|
-
const result = _0arc.intersectionMedium(_medium);
|
|
46
|
-
expect(result).toBeNull();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
describe(`intersectionMedium 3 - return full arc`, () => {
|
|
51
|
-
let i = 0;
|
|
52
|
-
test(`intersectionMedium 3 - return full arc ${i} `, () => {
|
|
53
|
-
for (let i = 0; i < 100; i++) {
|
|
54
|
-
_medium.set(new Vector3D(0, 0, 1), 0);
|
|
55
|
-
_0vector.randomUnit();
|
|
56
|
-
_0vector.z = Math.abs(_0vector.z); // make sure point is above the plane
|
|
57
|
-
_1vector.randomUnit();
|
|
58
|
-
_1vector.z = Math.abs(_1vector.z); // make sure point is above the plane
|
|
59
|
-
expect(Math.abs(_0vector.length() - 1) < 0.0001).toBeTruthy();
|
|
60
|
-
expect(Math.abs(_1vector.length() - 1) < 0.0001).toBeTruthy();
|
|
61
|
-
_0arc.setFromUnitVectors(_0vector, _1vector);
|
|
62
|
-
|
|
63
|
-
const _1arc = _0arc.intersectionMedium(_medium)!;
|
|
64
|
-
// if (_1arc === null) {
|
|
65
|
-
// console.log(_0arc, _medium);
|
|
66
|
-
// }
|
|
67
|
-
expect(_1arc !== null).toBeTruthy();
|
|
68
|
-
expect(_0arc.equals(_1arc)).toBeTruthy();
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
describe(`intersectionMedium 4 - return half arc`, () => {
|
|
75
|
-
let i = 0;
|
|
76
|
-
test(`intersectionMedium 4 - return half arc ${i} `, () => {
|
|
77
|
-
for (let i = 0; i < 100; i++) {
|
|
78
|
-
_medium.set(new Vector3D(0, 0, 1), 0);
|
|
79
|
-
|
|
80
|
-
_0vector.randomUnit();
|
|
81
|
-
_1vector.copy(_0vector);
|
|
82
|
-
_1vector.z *= -1;
|
|
83
|
-
|
|
84
|
-
expect(Math.abs(_0vector.length() - 1) < 0.0001).toBeTruthy();
|
|
85
|
-
expect(Math.abs(_1vector.length() - 1) < 0.0001).toBeTruthy();
|
|
86
|
-
_0arc.setFromUnitVectors(_0vector, _1vector);
|
|
87
|
-
|
|
88
|
-
const _1arc = _0arc.intersectionMedium(_medium)!;
|
|
89
|
-
// if (_1arc === null) {
|
|
90
|
-
// console.log(_0arc, _medium);
|
|
91
|
-
// }
|
|
92
|
-
expect(_1arc !== null).toBeTruthy();
|
|
93
|
-
|
|
94
|
-
expect([_1arc.pointA.z, _1arc.pointB.z].some((v) => v === 0)).toBeTruthy();
|
|
95
|
-
|
|
96
|
-
// expect(_0arc.equals(_1arc)).toBeTruthy();
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
test("populatePoints3D 1", () => {
|
|
104
|
-
_0arc.setFromUnitVectors(new Vector3D(0, 1, 0), new Vector3D(0, 1, 0));
|
|
105
|
-
const result = _0arc.populatePoints3D(10);
|
|
106
|
-
expect(result.length).toBe(10 * 3);
|
|
107
|
-
_0vector.set(result[0], result[1], result[2]);
|
|
108
|
-
expect(_0vector.equals(_0arc.pointA)).toBeTruthy();
|
|
109
|
-
_0vector.set(result[27 + 0], result[27 + 1], result[27 + 2]);
|
|
110
|
-
expect(_0vector.equals(_0arc.pointB)).toBeTruthy();
|
|
111
|
-
});
|
|
112
|
-
|