@openglobus/og 0.12.4 → 0.13.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/README.md +0 -2
- package/dist/@openglobus/og.esm.js +2 -2
- package/dist/@openglobus/og.esm.js.map +1 -1
- package/dist/@openglobus/og.umd.js +2 -2
- package/dist/@openglobus/og.umd.js.map +1 -1
- package/package.json +7 -7
- package/src/og/Extent.js +3 -3
- package/src/og/Globe.js +277 -275
- package/src/og/ImageCanvas.js +3 -3
- package/src/og/LonLat.js +9 -9
- package/src/og/QueueArray.js +2 -2
- package/src/og/Rectangle.js +5 -5
- package/src/og/bv/Box.js +1 -1
- package/src/og/bv/Sphere.js +2 -2
- package/src/og/camera/Camera.js +1 -1
- package/src/og/camera/PlanetCamera.js +649 -646
- package/src/og/control/LayerSwitcher.js +1 -1
- package/src/og/control/MouseNavigation.js +22 -13
- package/src/og/control/MouseWheelZoomControl.js +2 -2
- package/src/og/control/ScaleControl.js +1 -1
- package/src/og/control/TouchNavigation.js +319 -319
- package/src/og/control/ZoomControl.js +132 -132
- package/src/og/control/visibleExtent/Segment.js +12 -12
- package/src/og/ellipsoid/Ellipsoid.js +577 -567
- package/src/og/entity/BillboardHandler.js +878 -1051
- package/src/og/entity/Entity.js +1 -1
- package/src/og/entity/EntityCollection.js +847 -857
- package/src/og/entity/GeoObjectHandler.js +2 -2
- package/src/og/entity/LabelHandler.js +887 -1040
- package/src/og/entity/LabelWorker.js +0 -6
- package/src/og/entity/PointCloud.js +495 -495
- package/src/og/entity/Polyline.js +2218 -2222
- package/src/og/entity/RayHandler.js +1 -1
- package/src/og/layer/CanvasTiles.js +6 -3
- package/src/og/layer/GeoImage.js +1 -1
- package/src/og/layer/KML.js +5 -5
- package/src/og/layer/Layer.js +800 -752
- package/src/og/layer/Vector.js +997 -1010
- package/src/og/layer/XYZ.js +359 -357
- package/src/og/math/Line2.js +4 -4
- package/src/og/math/Quat.js +2 -2
- package/src/og/math/Ray.js +2 -2
- package/src/og/math/Vec2.js +524 -524
- package/src/og/math/Vec3.js +900 -900
- package/src/og/math/Vec4.js +261 -261
- package/src/og/math.js +397 -398
- package/src/og/quadTree/EntityCollectionNode.js +389 -387
- package/src/og/renderer/Renderer.js +14 -20
- package/src/og/renderer/RendererEvents.js +1034 -1045
- package/src/og/scene/Planet.js +12 -9
- package/src/og/scene/RenderNode.js +347 -354
- package/src/og/segment/Segment.js +3 -1
- package/src/og/segment/SegmentLonLat.js +1 -4
- package/src/og/shaders/billboard.js +220 -204
- package/src/og/shaders/drawnode.js +607 -603
- package/src/og/shaders/label.js +576 -456
- package/src/og/shaders/polyline.js +365 -361
- package/src/og/terrain/MapboxTerrain.js +1 -1
- package/src/og/utils/FontAtlas.js +209 -200
- package/src/og/utils/GeoImageCreator.js +4 -5
- package/src/og/utils/TextureAtlas.js +4 -4
- package/src/og/utils/VectorTileCreator.js +414 -414
- package/src/og/utils/shared.js +1 -1
- package/src/og/webgl/Handler.js +28 -60
- package/src/og/webgl/Multisample.js +260 -260
- package/src/og/webgl/Program.js +411 -396
- package/types/bv/Box.d.ts +1 -1
- package/types/bv/Sphere.d.ts +1 -1
- package/types/camera/PlanetCamera.d.ts +3 -3
- package/types/control/LayerSwitcher.d.ts +1 -1
- package/types/ellipsoid/Ellipsoid.d.ts +9 -2
- package/types/entity/BillboardHandler.d.ts +0 -4
- package/types/entity/EntityCollection.d.ts +0 -8
- package/types/entity/LabelHandler.d.ts +0 -2
- package/types/entity/Polyline.d.ts +1 -1
- package/types/layer/KML.d.ts +11 -11
- package/types/layer/Layer.d.ts +4 -0
- package/types/layer/Vector.d.ts +1 -8
- package/types/math/Line2.d.ts +4 -4
- package/types/math/Ray.d.ts +2 -2
- package/types/math/Vec2.d.ts +1 -1
- package/types/math/Vec3.d.ts +1 -1
- package/types/math/Vec4.d.ts +2 -2
- package/types/math.d.ts +1 -1
- package/types/renderer/Renderer.d.ts +1 -1
- package/types/renderer/RendererEvents.d.ts +1 -1
- package/types/shaders/label.d.ts +1 -1
- package/types/utils/FontAtlas.d.ts +3 -2
- package/types/utils/TextureAtlas.d.ts +3 -3
- package/types/utils/VectorTileCreator.d.ts +4 -4
- package/types/utils/shared.d.ts +1 -1
- package/types/webgl/Handler.d.ts +6 -31
- package/types/webgl/Program.d.ts +2 -0
package/src/og/math.js
CHANGED
|
@@ -1,398 +1,397 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module og/math
|
|
3
|
-
*/
|
|
4
|
-
"use strict";
|
|
5
|
-
|
|
6
|
-
/** @const */
|
|
7
|
-
export const TWO_PI = 2.0 * Math.PI;
|
|
8
|
-
|
|
9
|
-
/** @const */
|
|
10
|
-
export const PI_TWO = Math.PI / 2.0;
|
|
11
|
-
|
|
12
|
-
export const X = 0;
|
|
13
|
-
export const Y = 1;
|
|
14
|
-
export const Z = 2;
|
|
15
|
-
export const W = 3;
|
|
16
|
-
|
|
17
|
-
export const MAX_FLOAT = Number.MAX_VALUE || 1.7976931348623157e308;
|
|
18
|
-
|
|
19
|
-
/** @const */
|
|
20
|
-
export const LOG2 = Math.log(2);
|
|
21
|
-
/** @const */
|
|
22
|
-
export const MAX32 = 2147483647;
|
|
23
|
-
/** @const */
|
|
24
|
-
export const MAX = 549755748352;
|
|
25
|
-
/** @const */
|
|
26
|
-
export const MIN = -MAX;
|
|
27
|
-
|
|
28
|
-
/** @const */
|
|
29
|
-
export const RADIANS = Math.PI / 180.0;
|
|
30
|
-
/** @const */
|
|
31
|
-
export const DEGREES = 180.0 / Math.PI;
|
|
32
|
-
|
|
33
|
-
/** @const */
|
|
34
|
-
export const DEGREES_DOUBLE = 2.0 * DEGREES;
|
|
35
|
-
/** @const */
|
|
36
|
-
export const RADIANS_HALF = 0.5 * RADIANS;
|
|
37
|
-
|
|
38
|
-
/** @const */
|
|
39
|
-
export const ARCSECONDS_TO_RADIANS = 0.00000484813681109536;
|
|
40
|
-
/** @const */
|
|
41
|
-
export const RADIANS_TO_HOURS = 3.8197186342054880584532103209403;
|
|
42
|
-
/** @const */
|
|
43
|
-
export const HOURS_TO_RADIANS = 0.26179938779914943653855361527329;
|
|
44
|
-
/** @const */
|
|
45
|
-
export const HOURS_TO_DEGREES = 15.0;
|
|
46
|
-
/** @const */
|
|
47
|
-
export const DEGREES_TO_HOURS = 1.0 / 15.0;
|
|
48
|
-
|
|
49
|
-
/** @const */
|
|
50
|
-
export const SQRT_HALF = Math.sqrt(0.5);
|
|
51
|
-
|
|
52
|
-
export const EPSILON1 = 0.1;
|
|
53
|
-
export const EPSILON2 = 0.01;
|
|
54
|
-
export const EPSILON3 = 0.001;
|
|
55
|
-
export const EPSILON4 = 0.0001;
|
|
56
|
-
export const EPSILON5 = 0.00001;
|
|
57
|
-
export const EPSILON6 = 0.000001;
|
|
58
|
-
export const EPSILON7 = 1e-7;
|
|
59
|
-
export const EPSILON8 = 1e-8;
|
|
60
|
-
export const EPSILON9 = 1e-9;
|
|
61
|
-
export const EPSILON10 = 1e-10;
|
|
62
|
-
export const EPSILON11 = 1e-11;
|
|
63
|
-
export const EPSILON12 = 1e-12;
|
|
64
|
-
export const EPSILON13 = 1e-13;
|
|
65
|
-
export const EPSILON14 = 1e-14;
|
|
66
|
-
export const EPSILON15 = 1e-15;
|
|
67
|
-
export const EPSILON16 = 1e-16;
|
|
68
|
-
export const EPSILON17 = 1e-17;
|
|
69
|
-
export const EPSILON18 = 1e-18;
|
|
70
|
-
export const EPSILON19 = 1e-19;
|
|
71
|
-
export const EPSILON20 = 1e-20;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* The log function returns the power to which the base value has to be raised to produce n.
|
|
75
|
-
* @function
|
|
76
|
-
* @param {number} n - Produce value.
|
|
77
|
-
* @param {number} base - Base value.
|
|
78
|
-
* @returns {number} -
|
|
79
|
-
* @example
|
|
80
|
-
* log(64, 2)
|
|
81
|
-
* //returns 6
|
|
82
|
-
*/
|
|
83
|
-
export function log(n, base) {
|
|
84
|
-
return Math.log(n) / Math.log(base);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Clamp the number.
|
|
89
|
-
* @function
|
|
90
|
-
* @param {number} number - Input number.
|
|
91
|
-
* @param {number} min - Minimal edge.
|
|
92
|
-
* @param {number} max - Maximal edge.
|
|
93
|
-
* @returns {number} -
|
|
94
|
-
* @example
|
|
95
|
-
* clamp(12, 1, 5)
|
|
96
|
-
* //returns 5
|
|
97
|
-
*/
|
|
98
|
-
export function clamp(number, min, max) {
|
|
99
|
-
return Math.max(min, Math.min(number, max));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Converts degrees value to radians.
|
|
104
|
-
* @function
|
|
105
|
-
* @param {number} degrees - Degree value.
|
|
106
|
-
* @returns {number} -
|
|
107
|
-
*/
|
|
108
|
-
export function DEG2RAD(degrees) {
|
|
109
|
-
return degrees * RADIANS;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Converts radians value to degrees.
|
|
114
|
-
* @function
|
|
115
|
-
* @param {number} angle - Degree value.
|
|
116
|
-
* @returns {number} -
|
|
117
|
-
*/
|
|
118
|
-
export function RAD2DEG(angle) {
|
|
119
|
-
return angle * DEGREES;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Check the number is a power of two.
|
|
124
|
-
* @function
|
|
125
|
-
* @param {number} x - Input value.
|
|
126
|
-
* @returns {boolean} -
|
|
127
|
-
*/
|
|
128
|
-
export function isPowerOfTwo(x) {
|
|
129
|
-
return (x & (x - 1)) === 0;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Returns next value that is power of two.
|
|
134
|
-
* @function
|
|
135
|
-
* @param {number} x - Input value.
|
|
136
|
-
* @returns {number} -
|
|
137
|
-
*/
|
|
138
|
-
export function nextHighestPowerOfTwo(x) {
|
|
139
|
-
--x;
|
|
140
|
-
for (var i = 1; i < 32; i <<= 1) {
|
|
141
|
-
x = x | (x >> i);
|
|
142
|
-
}
|
|
143
|
-
return x + 1;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Returns random integer number within the bounds.
|
|
148
|
-
* @function
|
|
149
|
-
* @param {number} min - Minimal bound.
|
|
150
|
-
* @param {number} max - Maximal bound.
|
|
151
|
-
* @returns {number} -
|
|
152
|
-
*/
|
|
153
|
-
export function randomi(min = 0, max = 1) {
|
|
154
|
-
return Math.floor(Math.random() * (max - min)) + min;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Returns random number within the bounds.
|
|
159
|
-
* @function
|
|
160
|
-
* @param {number} [min=0] - Minimal bound.
|
|
161
|
-
* @param {number} [max=1] - Maximal bound.
|
|
162
|
-
* @returns {number} -
|
|
163
|
-
*/
|
|
164
|
-
export function random(min = 0, max = 1) {
|
|
165
|
-
return Math.random() * (max - min) + min;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Converts degrees value to decimal.
|
|
170
|
-
* @function
|
|
171
|
-
* @param {number} d - Degrees.
|
|
172
|
-
* @param {number} m - Minutes.
|
|
173
|
-
* @param {number} s - Seconds.
|
|
174
|
-
* @param {boolean} [p] - Positive flag. False - default.
|
|
175
|
-
* @returns {number} -
|
|
176
|
-
**/
|
|
177
|
-
export function degToDec(d, m, s, p) {
|
|
178
|
-
if (p) {
|
|
179
|
-
return d + m / 60.0 + s / 3600.0;
|
|
180
|
-
} else {
|
|
181
|
-
return -d - m / 60.0 - s / 3600.0;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* The modulo operation that also works for negative dividends.
|
|
187
|
-
* @function
|
|
188
|
-
* @param {number} m - The dividend.
|
|
189
|
-
* @param {number} n - The divisor.
|
|
190
|
-
* @returns {number} The remainder.
|
|
191
|
-
*/
|
|
192
|
-
export function mod(m, n) {
|
|
193
|
-
return ((m % n) + n) % n;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Returns an angle in the range 0 <= angle <= 2Pi which is equivalent to the provided angle.
|
|
198
|
-
* @function
|
|
199
|
-
* @param {number} a - Angle in radians
|
|
200
|
-
* @returns {number} -
|
|
201
|
-
*/
|
|
202
|
-
export function zeroTwoPI(a) {
|
|
203
|
-
var mod = mod(a, TWO_PI);
|
|
204
|
-
if (Math.abs(mod) < EPSILON14 && Math.abs(a) > EPSILON14) {
|
|
205
|
-
return TWO_PI;
|
|
206
|
-
}
|
|
207
|
-
return mod;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Returns 0.0 if x is smaller then edge and otherwise 1.0.
|
|
212
|
-
* @function
|
|
213
|
-
* @param {number} edge -
|
|
214
|
-
* @param {number} x - Value to edge.
|
|
215
|
-
* @returns {number} -
|
|
216
|
-
*/
|
|
217
|
-
export function step(edge, x) {
|
|
218
|
-
return x < edge ? 0.0 : 1.0;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* The fract function returns the fractional part of x, i.e. x minus floor(x).
|
|
223
|
-
* @function
|
|
224
|
-
* @param {number} x - Input value.
|
|
225
|
-
* @returns {number} -
|
|
226
|
-
*/
|
|
227
|
-
export function frac(x) {
|
|
228
|
-
return x - Math.floor(x);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Returns Math.log(x) / Math.log(2)
|
|
233
|
-
* @function
|
|
234
|
-
* @param {number} x - Input value.
|
|
235
|
-
* @returns {number} -
|
|
236
|
-
*/
|
|
237
|
-
export function log2(x) {
|
|
238
|
-
return Math.log(x) / LOG2;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Returns two power of n.
|
|
243
|
-
* @function
|
|
244
|
-
* @param {number} n - Power value.
|
|
245
|
-
* @returns {number} -
|
|
246
|
-
*/
|
|
247
|
-
export function exp2(n) {
|
|
248
|
-
return Math.pow(2, n);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Returns two power of integer n.
|
|
253
|
-
* @function
|
|
254
|
-
* @param {number} n - Integer power value.
|
|
255
|
-
* @returns {number} -
|
|
256
|
-
*/
|
|
257
|
-
export function pow2i(n) {
|
|
258
|
-
return 2 << (n - 1);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Returns a slice of linear interpolation t * (h1 - h0)
|
|
263
|
-
* @param {number} t - A value that linearly interpolates between the h0 parameter and the h1 parameter.
|
|
264
|
-
* @param {number} h1 - End value.
|
|
265
|
-
* @param {number} h0 - Start value.
|
|
266
|
-
* @returns {number} -
|
|
267
|
-
*/
|
|
268
|
-
export function slice(t, h1, h0) {
|
|
269
|
-
return t * (h1 - h0);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Performs a linear interpolation.
|
|
274
|
-
* @function
|
|
275
|
-
* @param {number} t - A value that linearly interpolates between the h0 parameter and the h1 parameter.
|
|
276
|
-
* @param {number} h1 - End value.
|
|
277
|
-
* @param {number} h0 - Start value.
|
|
278
|
-
* @returns {number} -
|
|
279
|
-
*/
|
|
280
|
-
export function lerp(t, h1, h0) {
|
|
281
|
-
return h0 + t * (h1 - h0);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
export function cube(f) {
|
|
285
|
-
return f * f * f;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
export function square(f) {
|
|
289
|
-
return f * f;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
export function bezier1v(t, p0, p1, p2, p3) {
|
|
293
|
-
return (
|
|
294
|
-
cube(1 - t) * p0 + 3 * square(1 - t) * t * p1 + 3 * (1 - t) * square(t) * p2 + cube(t) * p3
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Performs a 3D bezier interpolation.
|
|
300
|
-
* @function
|
|
301
|
-
* @param {number} t - Interpolation value.
|
|
302
|
-
* @param {Vec3} p0 - First control point.
|
|
303
|
-
* @param {Vec3} p1 - Second control point.
|
|
304
|
-
* @param {Vec3} p2 - Third control point.
|
|
305
|
-
* @param {Vec3} p3 - Fourth control point.
|
|
306
|
-
* @returns {Vec3} -
|
|
307
|
-
*/
|
|
308
|
-
export function bezier3v(t, p0, p1, p2, p3) {
|
|
309
|
-
var u = 1 - t;
|
|
310
|
-
var tt = t * t;
|
|
311
|
-
var uu = u * u;
|
|
312
|
-
var uuu = uu * u;
|
|
313
|
-
var ttt = tt * t;
|
|
314
|
-
|
|
315
|
-
return p0
|
|
316
|
-
.scaleTo(uuu)
|
|
317
|
-
.addA(p1.scaleTo(3 * uu * t))
|
|
318
|
-
.addA(p2.scaleTo(3 * u * tt))
|
|
319
|
-
.addA(p3.scaleTo(ttt));
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Clamp angle value within 360.
|
|
324
|
-
* @function
|
|
325
|
-
* @param {number} x - Input angle.
|
|
326
|
-
* @returns {number} -
|
|
327
|
-
*/
|
|
328
|
-
export function rev(x) {
|
|
329
|
-
return x - Math.floor(x / 360.0) * 360.0;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Clamp longitude within: -180 to +180 degrees.
|
|
334
|
-
* @function
|
|
335
|
-
* @param {number} lon - Longitude.
|
|
336
|
-
* @returns {number} -
|
|
337
|
-
*/
|
|
338
|
-
export function norm_lon(lon) {
|
|
339
|
-
return lon > 180 ? ((lon + 180) % 360) - 180 : lon < -180 ? ((lon - 180) % 360) + 180 : lon;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* Returns an angle in the range -Pi <= angle <= Pi which is equivalent to the provided angle.
|
|
344
|
-
* @function
|
|
345
|
-
* @param {number} a - Angle in radians.
|
|
346
|
-
* @returns {number} -
|
|
347
|
-
*/
|
|
348
|
-
export function negativePItoPI(a) {
|
|
349
|
-
return zeroTwoPI(a + Math.PI) - Math.PI;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Solve using iteration method and a fixed number of steps.
|
|
354
|
-
* @function
|
|
355
|
-
* @param {equationCallback} f - Equation. Used in Euler's equation(see og.orbit) solving.
|
|
356
|
-
* @param {number} x0 - First approximation.
|
|
357
|
-
* @param {number} maxIter - Maximum iterations.
|
|
358
|
-
* @returns {number} -
|
|
359
|
-
*/
|
|
360
|
-
export function solve_iteration_fixed(f, x0, maxIter) {
|
|
361
|
-
var x = 0;
|
|
362
|
-
var x2 = x0;
|
|
363
|
-
for (var i = 0; i < maxIter; i++) {
|
|
364
|
-
x = x2;
|
|
365
|
-
x2 = f(x);
|
|
366
|
-
}
|
|
367
|
-
return x2;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Solve using iteration; terminate when error is below err or the maximum
|
|
372
|
-
* number of iterations is reached. Used in Euler's equation(see og.orbit) solving.
|
|
373
|
-
* @function
|
|
374
|
-
* @param {equationCallback} f - Equation.
|
|
375
|
-
* @param {number} x0 - First approximation.
|
|
376
|
-
* @param {number} err - Maximal accepted error value.
|
|
377
|
-
* @param {number} maxIter - Maximum iterations.
|
|
378
|
-
* @returns {number} -
|
|
379
|
-
*/
|
|
380
|
-
export function solve_iteration(f, x0, err, maxIter) {
|
|
381
|
-
|
|
382
|
-
var
|
|
383
|
-
var
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
x2
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
*
|
|
396
|
-
* @
|
|
397
|
-
|
|
398
|
-
*/
|
|
1
|
+
/**
|
|
2
|
+
* @module og/math
|
|
3
|
+
*/
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
/** @const */
|
|
7
|
+
export const TWO_PI = 2.0 * Math.PI;
|
|
8
|
+
|
|
9
|
+
/** @const */
|
|
10
|
+
export const PI_TWO = Math.PI / 2.0;
|
|
11
|
+
|
|
12
|
+
export const X = 0;
|
|
13
|
+
export const Y = 1;
|
|
14
|
+
export const Z = 2;
|
|
15
|
+
export const W = 3;
|
|
16
|
+
|
|
17
|
+
export const MAX_FLOAT = Number.MAX_VALUE || 1.7976931348623157e308;
|
|
18
|
+
|
|
19
|
+
/** @const */
|
|
20
|
+
export const LOG2 = Math.log(2);
|
|
21
|
+
/** @const */
|
|
22
|
+
export const MAX32 = 2147483647;
|
|
23
|
+
/** @const */
|
|
24
|
+
export const MAX = 549755748352;
|
|
25
|
+
/** @const */
|
|
26
|
+
export const MIN = -MAX;
|
|
27
|
+
|
|
28
|
+
/** @const */
|
|
29
|
+
export const RADIANS = Math.PI / 180.0;
|
|
30
|
+
/** @const */
|
|
31
|
+
export const DEGREES = 180.0 / Math.PI;
|
|
32
|
+
|
|
33
|
+
/** @const */
|
|
34
|
+
export const DEGREES_DOUBLE = 2.0 * DEGREES;
|
|
35
|
+
/** @const */
|
|
36
|
+
export const RADIANS_HALF = 0.5 * RADIANS;
|
|
37
|
+
|
|
38
|
+
/** @const */
|
|
39
|
+
export const ARCSECONDS_TO_RADIANS = 0.00000484813681109536;
|
|
40
|
+
/** @const */
|
|
41
|
+
export const RADIANS_TO_HOURS = 3.8197186342054880584532103209403;
|
|
42
|
+
/** @const */
|
|
43
|
+
export const HOURS_TO_RADIANS = 0.26179938779914943653855361527329;
|
|
44
|
+
/** @const */
|
|
45
|
+
export const HOURS_TO_DEGREES = 15.0;
|
|
46
|
+
/** @const */
|
|
47
|
+
export const DEGREES_TO_HOURS = 1.0 / 15.0;
|
|
48
|
+
|
|
49
|
+
/** @const */
|
|
50
|
+
export const SQRT_HALF = Math.sqrt(0.5);
|
|
51
|
+
|
|
52
|
+
export const EPSILON1 = 0.1;
|
|
53
|
+
export const EPSILON2 = 0.01;
|
|
54
|
+
export const EPSILON3 = 0.001;
|
|
55
|
+
export const EPSILON4 = 0.0001;
|
|
56
|
+
export const EPSILON5 = 0.00001;
|
|
57
|
+
export const EPSILON6 = 0.000001;
|
|
58
|
+
export const EPSILON7 = 1e-7;
|
|
59
|
+
export const EPSILON8 = 1e-8;
|
|
60
|
+
export const EPSILON9 = 1e-9;
|
|
61
|
+
export const EPSILON10 = 1e-10;
|
|
62
|
+
export const EPSILON11 = 1e-11;
|
|
63
|
+
export const EPSILON12 = 1e-12;
|
|
64
|
+
export const EPSILON13 = 1e-13;
|
|
65
|
+
export const EPSILON14 = 1e-14;
|
|
66
|
+
export const EPSILON15 = 1e-15;
|
|
67
|
+
export const EPSILON16 = 1e-16;
|
|
68
|
+
export const EPSILON17 = 1e-17;
|
|
69
|
+
export const EPSILON18 = 1e-18;
|
|
70
|
+
export const EPSILON19 = 1e-19;
|
|
71
|
+
export const EPSILON20 = 1e-20;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The log function returns the power to which the base value has to be raised to produce n.
|
|
75
|
+
* @function
|
|
76
|
+
* @param {number} n - Produce value.
|
|
77
|
+
* @param {number} base - Base value.
|
|
78
|
+
* @returns {number} -
|
|
79
|
+
* @example
|
|
80
|
+
* log(64, 2)
|
|
81
|
+
* //returns 6
|
|
82
|
+
*/
|
|
83
|
+
export function log(n, base) {
|
|
84
|
+
return Math.log(n) / Math.log(base);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Clamp the number.
|
|
89
|
+
* @function
|
|
90
|
+
* @param {number} number - Input number.
|
|
91
|
+
* @param {number} min - Minimal edge.
|
|
92
|
+
* @param {number} max - Maximal edge.
|
|
93
|
+
* @returns {number} -
|
|
94
|
+
* @example
|
|
95
|
+
* clamp(12, 1, 5)
|
|
96
|
+
* //returns 5
|
|
97
|
+
*/
|
|
98
|
+
export function clamp(number, min, max) {
|
|
99
|
+
return Math.max(min, Math.min(number, max));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Converts degrees value to radians.
|
|
104
|
+
* @function
|
|
105
|
+
* @param {number} degrees - Degree value.
|
|
106
|
+
* @returns {number} -
|
|
107
|
+
*/
|
|
108
|
+
export function DEG2RAD(degrees) {
|
|
109
|
+
return degrees * RADIANS;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Converts radians value to degrees.
|
|
114
|
+
* @function
|
|
115
|
+
* @param {number} angle - Degree value.
|
|
116
|
+
* @returns {number} -
|
|
117
|
+
*/
|
|
118
|
+
export function RAD2DEG(angle) {
|
|
119
|
+
return angle * DEGREES;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Check the number is a power of two.
|
|
124
|
+
* @function
|
|
125
|
+
* @param {number} x - Input value.
|
|
126
|
+
* @returns {boolean} -
|
|
127
|
+
*/
|
|
128
|
+
export function isPowerOfTwo(x) {
|
|
129
|
+
return (x & (x - 1)) === 0;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Returns next value that is power of two.
|
|
134
|
+
* @function
|
|
135
|
+
* @param {number} x - Input value.
|
|
136
|
+
* @returns {number} -
|
|
137
|
+
*/
|
|
138
|
+
export function nextHighestPowerOfTwo(x) {
|
|
139
|
+
--x;
|
|
140
|
+
for (var i = 1; i < 32; i <<= 1) {
|
|
141
|
+
x = x | (x >> i);
|
|
142
|
+
}
|
|
143
|
+
return x + 1;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Returns random integer number within the bounds.
|
|
148
|
+
* @function
|
|
149
|
+
* @param {number} min - Minimal bound.
|
|
150
|
+
* @param {number} max - Maximal bound.
|
|
151
|
+
* @returns {number} -
|
|
152
|
+
*/
|
|
153
|
+
export function randomi(min = 0, max = 1) {
|
|
154
|
+
return Math.floor(Math.random() * (max - min)) + min;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Returns random number within the bounds.
|
|
159
|
+
* @function
|
|
160
|
+
* @param {number} [min=0] - Minimal bound.
|
|
161
|
+
* @param {number} [max=1] - Maximal bound.
|
|
162
|
+
* @returns {number} -
|
|
163
|
+
*/
|
|
164
|
+
export function random(min = 0, max = 1) {
|
|
165
|
+
return Math.random() * (max - min) + min;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Converts degrees value to decimal.
|
|
170
|
+
* @function
|
|
171
|
+
* @param {number} d - Degrees.
|
|
172
|
+
* @param {number} m - Minutes.
|
|
173
|
+
* @param {number} s - Seconds.
|
|
174
|
+
* @param {boolean} [p] - Positive flag. False - default.
|
|
175
|
+
* @returns {number} -
|
|
176
|
+
**/
|
|
177
|
+
export function degToDec(d, m, s, p) {
|
|
178
|
+
if (p) {
|
|
179
|
+
return d + m / 60.0 + s / 3600.0;
|
|
180
|
+
} else {
|
|
181
|
+
return -d - m / 60.0 - s / 3600.0;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The modulo operation that also works for negative dividends.
|
|
187
|
+
* @function
|
|
188
|
+
* @param {number} m - The dividend.
|
|
189
|
+
* @param {number} n - The divisor.
|
|
190
|
+
* @returns {number} The remainder.
|
|
191
|
+
*/
|
|
192
|
+
export function mod(m, n) {
|
|
193
|
+
return ((m % n) + n) % n;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Returns an angle in the range 0 <= angle <= 2Pi which is equivalent to the provided angle.
|
|
198
|
+
* @function
|
|
199
|
+
* @param {number} a - Angle in radians
|
|
200
|
+
* @returns {number} -
|
|
201
|
+
*/
|
|
202
|
+
export function zeroTwoPI(a) {
|
|
203
|
+
var mod = mod(a, TWO_PI);
|
|
204
|
+
if (Math.abs(mod) < EPSILON14 && Math.abs(a) > EPSILON14) {
|
|
205
|
+
return TWO_PI;
|
|
206
|
+
}
|
|
207
|
+
return mod;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Returns 0.0 if x is smaller then edge and otherwise 1.0.
|
|
212
|
+
* @function
|
|
213
|
+
* @param {number} edge -
|
|
214
|
+
* @param {number} x - Value to edge.
|
|
215
|
+
* @returns {number} -
|
|
216
|
+
*/
|
|
217
|
+
export function step(edge, x) {
|
|
218
|
+
return x < edge ? 0.0 : 1.0;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* The fract function returns the fractional part of x, i.e. x minus floor(x).
|
|
223
|
+
* @function
|
|
224
|
+
* @param {number} x - Input value.
|
|
225
|
+
* @returns {number} -
|
|
226
|
+
*/
|
|
227
|
+
export function frac(x) {
|
|
228
|
+
return x - Math.floor(x);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Returns Math.log(x) / Math.log(2)
|
|
233
|
+
* @function
|
|
234
|
+
* @param {number} x - Input value.
|
|
235
|
+
* @returns {number} -
|
|
236
|
+
*/
|
|
237
|
+
export function log2(x) {
|
|
238
|
+
return Math.log(x) / LOG2;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Returns two power of n.
|
|
243
|
+
* @function
|
|
244
|
+
* @param {number} n - Power value.
|
|
245
|
+
* @returns {number} -
|
|
246
|
+
*/
|
|
247
|
+
export function exp2(n) {
|
|
248
|
+
return Math.pow(2, n);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Returns two power of integer n.
|
|
253
|
+
* @function
|
|
254
|
+
* @param {number} n - Integer power value.
|
|
255
|
+
* @returns {number} -
|
|
256
|
+
*/
|
|
257
|
+
export function pow2i(n) {
|
|
258
|
+
return 2 << (n - 1);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Returns a slice of linear interpolation t * (h1 - h0)
|
|
263
|
+
* @param {number} t - A value that linearly interpolates between the h0 parameter and the h1 parameter.
|
|
264
|
+
* @param {number} h1 - End value.
|
|
265
|
+
* @param {number} h0 - Start value.
|
|
266
|
+
* @returns {number} -
|
|
267
|
+
*/
|
|
268
|
+
export function slice(t, h1, h0) {
|
|
269
|
+
return t * (h1 - h0);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Performs a linear interpolation.
|
|
274
|
+
* @function
|
|
275
|
+
* @param {number} t - A value that linearly interpolates between the h0 parameter and the h1 parameter.
|
|
276
|
+
* @param {number} h1 - End value.
|
|
277
|
+
* @param {number} h0 - Start value.
|
|
278
|
+
* @returns {number} -
|
|
279
|
+
*/
|
|
280
|
+
export function lerp(t, h1, h0) {
|
|
281
|
+
return h0 + t * (h1 - h0);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export function cube(f) {
|
|
285
|
+
return f * f * f;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function square(f) {
|
|
289
|
+
return f * f;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function bezier1v(t, p0, p1, p2, p3) {
|
|
293
|
+
return (
|
|
294
|
+
cube(1 - t) * p0 + 3 * square(1 - t) * t * p1 + 3 * (1 - t) * square(t) * p2 + cube(t) * p3
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Performs a 3D bezier interpolation.
|
|
300
|
+
* @function
|
|
301
|
+
* @param {number} t - Interpolation value.
|
|
302
|
+
* @param {Vec3} p0 - First control point.
|
|
303
|
+
* @param {Vec3} p1 - Second control point.
|
|
304
|
+
* @param {Vec3} p2 - Third control point.
|
|
305
|
+
* @param {Vec3} p3 - Fourth control point.
|
|
306
|
+
* @returns {Vec3} -
|
|
307
|
+
*/
|
|
308
|
+
export function bezier3v(t, p0, p1, p2, p3) {
|
|
309
|
+
var u = 1 - t;
|
|
310
|
+
var tt = t * t;
|
|
311
|
+
var uu = u * u;
|
|
312
|
+
var uuu = uu * u;
|
|
313
|
+
var ttt = tt * t;
|
|
314
|
+
|
|
315
|
+
return p0
|
|
316
|
+
.scaleTo(uuu)
|
|
317
|
+
.addA(p1.scaleTo(3 * uu * t))
|
|
318
|
+
.addA(p2.scaleTo(3 * u * tt))
|
|
319
|
+
.addA(p3.scaleTo(ttt));
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Clamp angle value within 360.
|
|
324
|
+
* @function
|
|
325
|
+
* @param {number} x - Input angle.
|
|
326
|
+
* @returns {number} -
|
|
327
|
+
*/
|
|
328
|
+
export function rev(x) {
|
|
329
|
+
return x - Math.floor(x / 360.0) * 360.0;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Clamp longitude within: -180 to +180 degrees.
|
|
334
|
+
* @function
|
|
335
|
+
* @param {number} lon - Longitude.
|
|
336
|
+
* @returns {number} -
|
|
337
|
+
*/
|
|
338
|
+
export function norm_lon(lon) {
|
|
339
|
+
return lon > 180 ? ((lon + 180) % 360) - 180 : lon < -180 ? ((lon - 180) % 360) + 180 : lon;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Returns an angle in the range -Pi <= angle <= Pi which is equivalent to the provided angle.
|
|
344
|
+
* @function
|
|
345
|
+
* @param {number} a - Angle in radians.
|
|
346
|
+
* @returns {number} -
|
|
347
|
+
*/
|
|
348
|
+
export function negativePItoPI(a) {
|
|
349
|
+
return zeroTwoPI(a + Math.PI) - Math.PI;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Solve using iteration method and a fixed number of steps.
|
|
354
|
+
* @function
|
|
355
|
+
* @param {equationCallback} f - Equation. Used in Euler's equation(see og.orbit) solving.
|
|
356
|
+
* @param {number} x0 - First approximation.
|
|
357
|
+
* @param {number} maxIter - Maximum iterations.
|
|
358
|
+
* @returns {number} -
|
|
359
|
+
*/
|
|
360
|
+
export function solve_iteration_fixed(f, x0, maxIter) {
|
|
361
|
+
var x = 0;
|
|
362
|
+
var x2 = x0;
|
|
363
|
+
for (var i = 0; i < maxIter; i++) {
|
|
364
|
+
x = x2;
|
|
365
|
+
x2 = f(x);
|
|
366
|
+
}
|
|
367
|
+
return x2;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Solve using iteration; terminate when error is below err or the maximum
|
|
372
|
+
* number of iterations is reached. Used in Euler's equation(see og.orbit) solving.
|
|
373
|
+
* @function
|
|
374
|
+
* @param {equationCallback} f - Equation.
|
|
375
|
+
* @param {number} x0 - First approximation.
|
|
376
|
+
* @param {number} err - Maximal accepted error value.
|
|
377
|
+
* @param {number} maxIter - Maximum iterations.
|
|
378
|
+
* @returns {number} -
|
|
379
|
+
*/
|
|
380
|
+
export function solve_iteration(f, x0, err, maxIter = 50) {
|
|
381
|
+
var x = 0;
|
|
382
|
+
var x2 = x0;
|
|
383
|
+
for (var i = 0; i < maxIter; i++) {
|
|
384
|
+
x = x2;
|
|
385
|
+
x2 = f(x);
|
|
386
|
+
if (Math.abs(x2 - x) < err) {
|
|
387
|
+
return x2;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return x2;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Equation function.
|
|
395
|
+
* @callback equationCallback
|
|
396
|
+
* @param {number} x - Equation variable.
|
|
397
|
+
*/
|