@pirireis/webglobeplugins 0.8.19 → 0.8.21
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 +11 -5
- package/Math/vector3d.ts +2 -0
- package/package.json +1 -1
- package/tests/Math/arc.test.ts +22 -0
- package/waveparticles/plugin.js +38 -1
package/Math/arc.ts
CHANGED
|
@@ -79,8 +79,6 @@ export class Arc {
|
|
|
79
79
|
|
|
80
80
|
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
// TODO: EDGE CASE: the points are on same location
|
|
84
82
|
intersectionMedium(medium: Plane, target: Arc | null = null): Arc | null {
|
|
85
83
|
// Orianted in right hand rule
|
|
86
84
|
if (this.pointA.equals(this.pointB)) return null; // arc is too short
|
|
@@ -97,6 +95,10 @@ export class Arc {
|
|
|
97
95
|
return null; // no intersection
|
|
98
96
|
}
|
|
99
97
|
|
|
98
|
+
// think as this.pointA is on y=1 on a x-y space. this.pointB is on the x>0 part of the space.
|
|
99
|
+
// any point on x<0 is outside. Any point y<this._dot is outside.
|
|
100
|
+
|
|
101
|
+
// A is before B with right hand rule
|
|
100
102
|
const [A, B] = (() => {
|
|
101
103
|
Vector3D.crossVectors(...intersectionPoints, _AxB);
|
|
102
104
|
if (_AxB.dot(this._AxB) >= 0) {
|
|
@@ -109,8 +111,7 @@ export class Arc {
|
|
|
109
111
|
|
|
110
112
|
Vector3D.crossVectors(this.pointA, A, _A_x_otherA);
|
|
111
113
|
Vector3D.crossVectors(this.pointA, B, _A_x_otherB);
|
|
112
|
-
|
|
113
|
-
// any point on x<0 is outside. Any point y<this._dot is outside.
|
|
114
|
+
|
|
114
115
|
const _yA = this.pointA.dot(A);
|
|
115
116
|
const _yB = this.pointA.dot(B);
|
|
116
117
|
|
|
@@ -119,6 +120,9 @@ export class Arc {
|
|
|
119
120
|
|
|
120
121
|
|
|
121
122
|
if (_xA < 0 && _xB < 0) {
|
|
123
|
+
if (_yA > _yB) {
|
|
124
|
+
throw new Error("A is before B with right hand rule but A is on the left side of the arc. This should not happen.");
|
|
125
|
+
}
|
|
122
126
|
return null; // no intersection
|
|
123
127
|
}
|
|
124
128
|
if (_yA < this._dot && _yB < this._dot) {
|
|
@@ -131,8 +135,10 @@ export class Arc {
|
|
|
131
135
|
];
|
|
132
136
|
if (target === null) {
|
|
133
137
|
target = new Arc(...resultPoints);
|
|
134
|
-
} else {
|
|
138
|
+
} else if (target instanceof Arc) {
|
|
135
139
|
target.setFromUnitVectors(...resultPoints);
|
|
140
|
+
} else {
|
|
141
|
+
throw new Error("target is not null or an Arc instance");
|
|
136
142
|
}
|
|
137
143
|
|
|
138
144
|
return target;
|
package/Math/vector3d.ts
CHANGED
package/package.json
CHANGED
package/tests/Math/arc.test.ts
CHANGED
|
@@ -47,6 +47,28 @@ test("intersectionMedium 2 - single point arc", () => {
|
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
|
|
50
|
+
describe(`intersectionMedium 3 - return full arc`, () => {
|
|
51
|
+
|
|
52
|
+
for (let i = 0; i < 100; i++) {
|
|
53
|
+
test(`intersectionMedium 3 - return full arc ${i} `, () => {
|
|
54
|
+
_medium.set(new Vector3D(0, 0, 1), 0.001);
|
|
55
|
+
_0vector.randomUnit();
|
|
56
|
+
_0vector.z = Math.abs(_0vector.z);
|
|
57
|
+
_1vector.randomUnit();
|
|
58
|
+
_1vector.z = Math.abs(_1vector.z);
|
|
59
|
+
_0arc.setFromUnitVectors(_0vector, _1vector);
|
|
60
|
+
|
|
61
|
+
const _1arc = _0arc.intersectionMedium(_medium)!;
|
|
62
|
+
if (_1arc === null) {
|
|
63
|
+
console.log(_0arc, _medium);
|
|
64
|
+
}
|
|
65
|
+
expect(_1arc !== null).toBeTruthy();
|
|
66
|
+
expect(_0arc.equals(_1arc)).toBeTruthy();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
|
|
50
72
|
test(" populatePoints3D", () => {
|
|
51
73
|
|
|
52
74
|
});
|
package/waveparticles/plugin.js
CHANGED
|
@@ -146,6 +146,23 @@ export default class Plugin {
|
|
|
146
146
|
this._fullCycleStepCount = value;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
|
|
150
|
+
setFlipY(value) {
|
|
151
|
+
if (typeof value === "boolean") {
|
|
152
|
+
if (this._flipY === value) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
// TODO: read data from texture and write it back instead of keeping on the cpu memory
|
|
156
|
+
this._flipY = value;
|
|
157
|
+
this.gl.deleteTexture(this._rgVectorFieldTexture);
|
|
158
|
+
this._rgVectorFieldTexture = this._createRGTexture();
|
|
159
|
+
this.setVectorFieldData(this.__data);
|
|
160
|
+
this.globe.DrawRender();
|
|
161
|
+
} else {
|
|
162
|
+
throw new Error("flipY must be a boolean value");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
149
166
|
_createRGTexture() {
|
|
150
167
|
const { gl, _dataWidth, _dataHeight, } = this;
|
|
151
168
|
const texture = gl.createTexture();
|
|
@@ -193,7 +210,7 @@ export default class Plugin {
|
|
|
193
210
|
this._dataWidth = dataWidth;
|
|
194
211
|
this._dataHeight = dataHeight;
|
|
195
212
|
}
|
|
196
|
-
|
|
213
|
+
this.__data = data;
|
|
197
214
|
const { gl, _dataWidth, _dataHeight } = this;
|
|
198
215
|
gl.bindTexture(gl.TEXTURE_2D, this._rgVectorFieldTexture);
|
|
199
216
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RG32F, _dataWidth, _dataHeight, 0, gl.RG, gl.FLOAT, data);
|
|
@@ -210,6 +227,26 @@ export default class Plugin {
|
|
|
210
227
|
}
|
|
211
228
|
|
|
212
229
|
|
|
230
|
+
__readAndWriteTextureData() {
|
|
231
|
+
const { gl, _rgVectorFieldTexture, _dataWidth, _dataHeight } = this;
|
|
232
|
+
|
|
233
|
+
// Step 1: Bind the texture to a framebuffer
|
|
234
|
+
|
|
235
|
+
// Step 2: Read the texture data into a Float32Array
|
|
236
|
+
gl.bindTexture(gl.TEXTURE_2D, _rgVectorFieldTexture);
|
|
237
|
+
const textureData = new Float32Array(_dataWidth * _dataHeight * 2); // RG32F has 2 components per pixel
|
|
238
|
+
gl.readPixels(0, 0, _dataWidth, _dataHeight, gl.RG, gl.FLOAT, textureData);
|
|
239
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
240
|
+
// Step 3: Create a new texture and write the data back
|
|
241
|
+
|
|
242
|
+
// Step 4: Clean up
|
|
243
|
+
|
|
244
|
+
gl.deleteTexture(this._rgVectorFieldTexture);
|
|
245
|
+
|
|
246
|
+
// Replace the old texture with the new one
|
|
247
|
+
this._rgVectorFieldTexture = this._createRGTexture();
|
|
248
|
+
this.setVectorFieldData(textureData);
|
|
249
|
+
}
|
|
213
250
|
|
|
214
251
|
_drawTextureSizeFromBbox({ minLon, minLat, maxLon, maxLat }) {
|
|
215
252
|
let horizon;
|