@openglobus/og 0.12.4 → 0.13.0
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 +888 -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 +603 -603
- package/src/og/shaders/label.js +596 -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/Vec4.js
CHANGED
|
@@ -1,261 +1,261 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module og/math/Vec4
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
import { Vec3 } from "./Vec3.js";
|
|
8
|
-
import { frac } from "../math.js";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Class represents a 4d vector.
|
|
12
|
-
* @class
|
|
13
|
-
* @param {number} [x] - First value.
|
|
14
|
-
* @param {number} [y] - Second value.
|
|
15
|
-
* @param {number} [z] - Third value.
|
|
16
|
-
* @param {number} [w] - Fourth value.
|
|
17
|
-
*/
|
|
18
|
-
export class Vec4 {
|
|
19
|
-
constructor(x, y, z, w) {
|
|
20
|
-
/**
|
|
21
|
-
* @public
|
|
22
|
-
* @type {number}
|
|
23
|
-
*/
|
|
24
|
-
this.x = x || 0.0;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @public
|
|
28
|
-
* @type {number}
|
|
29
|
-
*/
|
|
30
|
-
this.y = y || 0.0;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @public
|
|
34
|
-
* @type {number}
|
|
35
|
-
*/
|
|
36
|
-
this.z = z || 0.0;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @public
|
|
40
|
-
* @type {number}
|
|
41
|
-
*/
|
|
42
|
-
this.w = w || 0.0;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Identity vector [0,0,0,1].
|
|
47
|
-
* @const
|
|
48
|
-
* @type {Vec4}
|
|
49
|
-
*/
|
|
50
|
-
static get identity() {
|
|
51
|
-
return new Vec4(0, 0, 0, 1);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Creates 4d vector from array.
|
|
56
|
-
* @function
|
|
57
|
-
* @param {Array.<number>} - (exactly 4 entries)
|
|
58
|
-
* @returns {Vec4}
|
|
59
|
-
*/
|
|
60
|
-
static fromVec(arr) {
|
|
61
|
-
return new Vec4(arr[0], arr[1], arr[2], arr[3]);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Converts to 3d vector, without fourth value.
|
|
66
|
-
* @public
|
|
67
|
-
* @returns {Vec3}
|
|
68
|
-
*/
|
|
69
|
-
toVec3() {
|
|
70
|
-
return new Vec3(this.x, this.y, this.z);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Returns clone vector.
|
|
75
|
-
* @public
|
|
76
|
-
* @returns {Vec4}
|
|
77
|
-
*/
|
|
78
|
-
clone(
|
|
79
|
-
return new Vec4(this.x, this.y, this.z, this.w);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Compares with vector. Returns true if it equals another.
|
|
84
|
-
* @public
|
|
85
|
-
* @param {Vec4} p - Vector to compare.
|
|
86
|
-
* @returns {boolean}
|
|
87
|
-
*/
|
|
88
|
-
equal(v) {
|
|
89
|
-
return this.x === v.x && this.y === v.y && this.z === v.z && this.w === v.w;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Copy input vector's values.
|
|
94
|
-
* @param {Vec4} v - Vector to copy.
|
|
95
|
-
* @returns {Vec4}
|
|
96
|
-
*/
|
|
97
|
-
copy(v) {
|
|
98
|
-
this.x = v.x;
|
|
99
|
-
this.y = v.y;
|
|
100
|
-
this.z = v.z;
|
|
101
|
-
this.w = v.w;
|
|
102
|
-
return this;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Converts vector to a number array.
|
|
107
|
-
* @public
|
|
108
|
-
* @returns {Array.<number>} - (exactly 4 entries)
|
|
109
|
-
* @deprecated
|
|
110
|
-
*/
|
|
111
|
-
toVec() {
|
|
112
|
-
return [this.x, this.y, this.z, this.w];
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Converts vector to a number array.
|
|
117
|
-
* @public
|
|
118
|
-
* @returns {Array.<number>} - (exactly 4 entries)
|
|
119
|
-
*/
|
|
120
|
-
toArray() {
|
|
121
|
-
return [this.x, this.y, this.z, this.w];
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Sets vector's values.
|
|
126
|
-
* @public
|
|
127
|
-
* @param {number} x - Value X.
|
|
128
|
-
* @param {number} y - Value Y.
|
|
129
|
-
* @param {number} z - Value Z.
|
|
130
|
-
* @param {number} w - Value W.
|
|
131
|
-
* @returns {Vec4}
|
|
132
|
-
*/
|
|
133
|
-
set(x, y, z, w) {
|
|
134
|
-
this.x = x;
|
|
135
|
-
this.y = y;
|
|
136
|
-
this.z = z;
|
|
137
|
-
this.w = w;
|
|
138
|
-
return this;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Adds vector to the current.
|
|
143
|
-
* @public
|
|
144
|
-
* @param {Vec4}
|
|
145
|
-
* @returns {Vec4}
|
|
146
|
-
*/
|
|
147
|
-
addA(v) {
|
|
148
|
-
this.x += v.x;
|
|
149
|
-
this.y += v.y;
|
|
150
|
-
this.z += v.z;
|
|
151
|
-
this.w += v.w;
|
|
152
|
-
return this;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Subtract vector from the current.
|
|
157
|
-
* @public
|
|
158
|
-
* @param {Vec4} v - Subtract vector.
|
|
159
|
-
* @returns {Vec4}
|
|
160
|
-
*/
|
|
161
|
-
subA(v) {
|
|
162
|
-
this.x -= v.x;
|
|
163
|
-
this.y -= v.y;
|
|
164
|
-
this.z -= v.z;
|
|
165
|
-
this.w -= v.w;
|
|
166
|
-
return this;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Scale current vector.
|
|
171
|
-
* @public
|
|
172
|
-
* @param {number} scale - Scale value.
|
|
173
|
-
* @returns {Vec4}
|
|
174
|
-
*/
|
|
175
|
-
scale(scale) {
|
|
176
|
-
this.x *= scale;
|
|
177
|
-
this.y *= scale;
|
|
178
|
-
this.z *= scale;
|
|
179
|
-
this.w *= scale;
|
|
180
|
-
return this;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Makes vector affinity. Thereby fourh component becomes to 1.0.
|
|
185
|
-
* @public
|
|
186
|
-
* @returns {Vec4}
|
|
187
|
-
*/
|
|
188
|
-
affinity() {
|
|
189
|
-
var iw = 1 / this.w;
|
|
190
|
-
this.x *= iw;
|
|
191
|
-
this.y *= iw;
|
|
192
|
-
this.z *= iw;
|
|
193
|
-
this.w = 1.0;
|
|
194
|
-
return this;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Scale current vector to another instance.
|
|
199
|
-
* @public
|
|
200
|
-
* @param {number} scale - Scale value.
|
|
201
|
-
* @returns {Vec3}
|
|
202
|
-
*/
|
|
203
|
-
scaleTo(scale) {
|
|
204
|
-
return new Vec4(this.x * scale, this.y * scale, this.z * scale, this.w * scale);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Vector's edge function that returns vector where each component is 0.0 if it's smaller then edge and otherwise 1.0.
|
|
209
|
-
* @public
|
|
210
|
-
* @returns {Vec4}
|
|
211
|
-
*/
|
|
212
|
-
getStep(edge) {
|
|
213
|
-
return new Vec4(
|
|
214
|
-
this.x < edge ? 0.0 : 1.0,
|
|
215
|
-
this.y < edge ? 0.0 : 1.0,
|
|
216
|
-
this.z < edge ? 0.0 : 1.0,
|
|
217
|
-
this.w < edge ? 0.0 : 1.0
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* The vector fract function returns the vector of fractional parts of each value, i.e. x minus floor(x).
|
|
223
|
-
* @public
|
|
224
|
-
* @returns {Vec4}
|
|
225
|
-
*/
|
|
226
|
-
getFrac(v) {
|
|
227
|
-
return new Vec4(frac(v.x), frac(v.y), frac(v.z), frac(v.w));
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Gets vectors dot production.
|
|
232
|
-
* @public
|
|
233
|
-
* @param {math.Vec4} v - Another vector.
|
|
234
|
-
* @returns {number} - Dot product.
|
|
235
|
-
*/
|
|
236
|
-
dot(v) {
|
|
237
|
-
return v.x * this.x + v.y * this.y + v.z * this.z + v.w * this.w;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Returns true if vector's values are zero.
|
|
242
|
-
* @public
|
|
243
|
-
* @returns {boolean} -
|
|
244
|
-
*/
|
|
245
|
-
isZero() {
|
|
246
|
-
return !(this.x || this.y || this.z || this.w);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Vector 4d object creator.
|
|
252
|
-
* @function
|
|
253
|
-
* @param {number} [x] - First cvalue.
|
|
254
|
-
* @param {number} [y] - Second value.
|
|
255
|
-
* @param {number} [z] - Third value.
|
|
256
|
-
* @param {number} [w] - Fourth value.
|
|
257
|
-
* @returns {Vec4}
|
|
258
|
-
*/
|
|
259
|
-
export function vec4(x, y, z, w) {
|
|
260
|
-
return new Vec4(x, y, z, w);
|
|
261
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @module og/math/Vec4
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
import { Vec3 } from "./Vec3.js";
|
|
8
|
+
import { frac } from "../math.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Class represents a 4d vector.
|
|
12
|
+
* @class
|
|
13
|
+
* @param {number} [x] - First value.
|
|
14
|
+
* @param {number} [y] - Second value.
|
|
15
|
+
* @param {number} [z] - Third value.
|
|
16
|
+
* @param {number} [w] - Fourth value.
|
|
17
|
+
*/
|
|
18
|
+
export class Vec4 {
|
|
19
|
+
constructor(x = 0.0, y = 0.0, z = 0.0, w = 0.0) {
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
* @type {number}
|
|
23
|
+
*/
|
|
24
|
+
this.x = x || 0.0;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @public
|
|
28
|
+
* @type {number}
|
|
29
|
+
*/
|
|
30
|
+
this.y = y || 0.0;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @public
|
|
34
|
+
* @type {number}
|
|
35
|
+
*/
|
|
36
|
+
this.z = z || 0.0;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @public
|
|
40
|
+
* @type {number}
|
|
41
|
+
*/
|
|
42
|
+
this.w = w || 0.0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Identity vector [0,0,0,1].
|
|
47
|
+
* @const
|
|
48
|
+
* @type {Vec4}
|
|
49
|
+
*/
|
|
50
|
+
static get identity() {
|
|
51
|
+
return new Vec4(0, 0, 0, 1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Creates 4d vector from array.
|
|
56
|
+
* @function
|
|
57
|
+
* @param {Array.<number>} - (exactly 4 entries)
|
|
58
|
+
* @returns {Vec4}
|
|
59
|
+
*/
|
|
60
|
+
static fromVec(arr) {
|
|
61
|
+
return new Vec4(arr[0], arr[1], arr[2], arr[3]);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Converts to 3d vector, without fourth value.
|
|
66
|
+
* @public
|
|
67
|
+
* @returns {Vec3}
|
|
68
|
+
*/
|
|
69
|
+
toVec3() {
|
|
70
|
+
return new Vec3(this.x, this.y, this.z);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Returns clone vector.
|
|
75
|
+
* @public
|
|
76
|
+
* @returns {Vec4}
|
|
77
|
+
*/
|
|
78
|
+
clone() {
|
|
79
|
+
return new Vec4(this.x, this.y, this.z, this.w);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Compares with vector. Returns true if it equals another.
|
|
84
|
+
* @public
|
|
85
|
+
* @param {Vec4} p - Vector to compare.
|
|
86
|
+
* @returns {boolean}
|
|
87
|
+
*/
|
|
88
|
+
equal(v) {
|
|
89
|
+
return this.x === v.x && this.y === v.y && this.z === v.z && this.w === v.w;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Copy input vector's values.
|
|
94
|
+
* @param {Vec4} v - Vector to copy.
|
|
95
|
+
* @returns {Vec4}
|
|
96
|
+
*/
|
|
97
|
+
copy(v) {
|
|
98
|
+
this.x = v.x;
|
|
99
|
+
this.y = v.y;
|
|
100
|
+
this.z = v.z;
|
|
101
|
+
this.w = v.w;
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Converts vector to a number array.
|
|
107
|
+
* @public
|
|
108
|
+
* @returns {Array.<number>} - (exactly 4 entries)
|
|
109
|
+
* @deprecated
|
|
110
|
+
*/
|
|
111
|
+
toVec() {
|
|
112
|
+
return [this.x, this.y, this.z, this.w];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Converts vector to a number array.
|
|
117
|
+
* @public
|
|
118
|
+
* @returns {Array.<number>} - (exactly 4 entries)
|
|
119
|
+
*/
|
|
120
|
+
toArray() {
|
|
121
|
+
return [this.x, this.y, this.z, this.w];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Sets vector's values.
|
|
126
|
+
* @public
|
|
127
|
+
* @param {number} x - Value X.
|
|
128
|
+
* @param {number} y - Value Y.
|
|
129
|
+
* @param {number} z - Value Z.
|
|
130
|
+
* @param {number} w - Value W.
|
|
131
|
+
* @returns {Vec4}
|
|
132
|
+
*/
|
|
133
|
+
set(x, y, z, w) {
|
|
134
|
+
this.x = x;
|
|
135
|
+
this.y = y;
|
|
136
|
+
this.z = z;
|
|
137
|
+
this.w = w;
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Adds vector to the current.
|
|
143
|
+
* @public
|
|
144
|
+
* @param {Vec4}
|
|
145
|
+
* @returns {Vec4}
|
|
146
|
+
*/
|
|
147
|
+
addA(v) {
|
|
148
|
+
this.x += v.x;
|
|
149
|
+
this.y += v.y;
|
|
150
|
+
this.z += v.z;
|
|
151
|
+
this.w += v.w;
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Subtract vector from the current.
|
|
157
|
+
* @public
|
|
158
|
+
* @param {Vec4} v - Subtract vector.
|
|
159
|
+
* @returns {Vec4}
|
|
160
|
+
*/
|
|
161
|
+
subA(v) {
|
|
162
|
+
this.x -= v.x;
|
|
163
|
+
this.y -= v.y;
|
|
164
|
+
this.z -= v.z;
|
|
165
|
+
this.w -= v.w;
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Scale current vector.
|
|
171
|
+
* @public
|
|
172
|
+
* @param {number} scale - Scale value.
|
|
173
|
+
* @returns {Vec4}
|
|
174
|
+
*/
|
|
175
|
+
scale(scale) {
|
|
176
|
+
this.x *= scale;
|
|
177
|
+
this.y *= scale;
|
|
178
|
+
this.z *= scale;
|
|
179
|
+
this.w *= scale;
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Makes vector affinity. Thereby fourh component becomes to 1.0.
|
|
185
|
+
* @public
|
|
186
|
+
* @returns {Vec4}
|
|
187
|
+
*/
|
|
188
|
+
affinity() {
|
|
189
|
+
var iw = 1 / this.w;
|
|
190
|
+
this.x *= iw;
|
|
191
|
+
this.y *= iw;
|
|
192
|
+
this.z *= iw;
|
|
193
|
+
this.w = 1.0;
|
|
194
|
+
return this;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Scale current vector to another instance.
|
|
199
|
+
* @public
|
|
200
|
+
* @param {number} scale - Scale value.
|
|
201
|
+
* @returns {Vec3}
|
|
202
|
+
*/
|
|
203
|
+
scaleTo(scale) {
|
|
204
|
+
return new Vec4(this.x * scale, this.y * scale, this.z * scale, this.w * scale);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Vector's edge function that returns vector where each component is 0.0 if it's smaller then edge and otherwise 1.0.
|
|
209
|
+
* @public
|
|
210
|
+
* @returns {Vec4}
|
|
211
|
+
*/
|
|
212
|
+
getStep(edge) {
|
|
213
|
+
return new Vec4(
|
|
214
|
+
this.x < edge ? 0.0 : 1.0,
|
|
215
|
+
this.y < edge ? 0.0 : 1.0,
|
|
216
|
+
this.z < edge ? 0.0 : 1.0,
|
|
217
|
+
this.w < edge ? 0.0 : 1.0
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* The vector fract function returns the vector of fractional parts of each value, i.e. x minus floor(x).
|
|
223
|
+
* @public
|
|
224
|
+
* @returns {Vec4}
|
|
225
|
+
*/
|
|
226
|
+
getFrac(v) {
|
|
227
|
+
return new Vec4(frac(v.x), frac(v.y), frac(v.z), frac(v.w));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Gets vectors dot production.
|
|
232
|
+
* @public
|
|
233
|
+
* @param {math.Vec4} v - Another vector.
|
|
234
|
+
* @returns {number} - Dot product.
|
|
235
|
+
*/
|
|
236
|
+
dot(v) {
|
|
237
|
+
return v.x * this.x + v.y * this.y + v.z * this.z + v.w * this.w;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Returns true if vector's values are zero.
|
|
242
|
+
* @public
|
|
243
|
+
* @returns {boolean} -
|
|
244
|
+
*/
|
|
245
|
+
isZero() {
|
|
246
|
+
return !(this.x || this.y || this.z || this.w);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Vector 4d object creator.
|
|
252
|
+
* @function
|
|
253
|
+
* @param {number} [x] - First cvalue.
|
|
254
|
+
* @param {number} [y] - Second value.
|
|
255
|
+
* @param {number} [z] - Third value.
|
|
256
|
+
* @param {number} [w] - Fourth value.
|
|
257
|
+
* @returns {Vec4}
|
|
258
|
+
*/
|
|
259
|
+
export function vec4(x, y, z, w) {
|
|
260
|
+
return new Vec4(x, y, z, w);
|
|
261
|
+
}
|