glmaths 0.0.1 → 0.0.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 +2 -2
- package/dist/cjs/glmaths.js.map +1 -1
- package/dist/cjs/glmaths.min.js.map +1 -1
- package/dist/esm/glmaths.js.map +1 -1
- package/dist/esm/glmaths.min.js.map +1 -1
- package/dist/glmaths.js.map +1 -1
- package/dist/glmaths.min.js.map +1 -1
- package/package.json +2 -2
- package/src/internalUtils.ts +2 -2
- package/src/mat2.ts +10 -10
- package/src/mat2x3.ts +9 -9
- package/src/mat3.ts +12 -12
- package/src/mat4.ts +26 -26
- package/src/quat.ts +22 -22
- package/src/quat2.ts +8 -8
- package/src/vec2.ts +29 -29
- package/src/vec3.ts +30 -30
- package/src/vec4.ts +28 -28
package/src/vec3.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import glmaths from '.'
|
|
2
2
|
import { equals, defineSwizzles } from './internalUtils'
|
|
3
3
|
import { Vec2 } from './vec2'
|
|
4
4
|
import { Vec4 } from './vec4'
|
|
@@ -56,7 +56,7 @@ export class Vec3 extends Float32Array {
|
|
|
56
56
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
57
57
|
* @returns {Vec3} out
|
|
58
58
|
*/
|
|
59
|
-
plus(b: number | Vec3, out =
|
|
59
|
+
plus(b: number | Vec3, out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
60
60
|
if (typeof b === 'number') {
|
|
61
61
|
out[0] = this[0] + b
|
|
62
62
|
out[1] = this[1] + b
|
|
@@ -76,7 +76,7 @@ export class Vec3 extends Float32Array {
|
|
|
76
76
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
77
77
|
* @returns {Vec3} out
|
|
78
78
|
*/
|
|
79
|
-
minus(b: number | Vec3, out =
|
|
79
|
+
minus(b: number | Vec3, out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
80
80
|
if (typeof b === 'number') {
|
|
81
81
|
out[0] = this[0] - b
|
|
82
82
|
out[1] = this[1] - b
|
|
@@ -96,7 +96,7 @@ export class Vec3 extends Float32Array {
|
|
|
96
96
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
97
97
|
* @returns {Vec3} out
|
|
98
98
|
*/
|
|
99
|
-
mult(b: number | Vec3, out =
|
|
99
|
+
mult(b: number | Vec3, out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
100
100
|
if (typeof b === 'number') {
|
|
101
101
|
out[0] = this[0] * b
|
|
102
102
|
out[1] = this[1] * b
|
|
@@ -116,7 +116,7 @@ export class Vec3 extends Float32Array {
|
|
|
116
116
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
117
117
|
* @returns {Vec3} out
|
|
118
118
|
*/
|
|
119
|
-
div(b: number | Vec3, out =
|
|
119
|
+
div(b: number | Vec3, out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
120
120
|
if (typeof b === 'number') {
|
|
121
121
|
out[0] = this[0] / b
|
|
122
122
|
out[1] = this[1] / b
|
|
@@ -128,7 +128,7 @@ export class Vec3 extends Float32Array {
|
|
|
128
128
|
}
|
|
129
129
|
return out
|
|
130
130
|
}
|
|
131
|
-
invDiv(b: number | Vec3, out =
|
|
131
|
+
invDiv(b: number | Vec3, out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
132
132
|
if (typeof b === 'number') {
|
|
133
133
|
out[0] = b / this[0]
|
|
134
134
|
out[1] = b / this[1]
|
|
@@ -147,13 +147,13 @@ export class Vec3 extends Float32Array {
|
|
|
147
147
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
148
148
|
* @returns {Vec3} out
|
|
149
149
|
*/
|
|
150
|
-
negate(out =
|
|
150
|
+
negate(out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
151
151
|
out[0] = -this[0]
|
|
152
152
|
out[1] = -this[1]
|
|
153
153
|
out[2] = -this[2]
|
|
154
154
|
return out
|
|
155
155
|
}
|
|
156
|
-
unaryPlus(out =
|
|
156
|
+
unaryPlus(out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
157
157
|
if (out != this) {
|
|
158
158
|
out[0] = this[0]
|
|
159
159
|
out[1] = this[1]
|
|
@@ -184,7 +184,7 @@ export class Vec3 extends Float32Array {
|
|
|
184
184
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
185
185
|
* @returns {Vec3} out
|
|
186
186
|
*/
|
|
187
|
-
normalize(out =
|
|
187
|
+
normalize(out = glmaths.ALWAYS_COPY ? new Vec3() : this): Vec3 {
|
|
188
188
|
const x = this[0], y = this[1], z = this[2]
|
|
189
189
|
let len = x * x + y * y + z * z
|
|
190
190
|
if (len > 0) len = 1.0 / Math.sqrt(len)
|
|
@@ -279,7 +279,7 @@ export class Vec3 extends Float32Array {
|
|
|
279
279
|
*
|
|
280
280
|
* @returns {Vec3} this
|
|
281
281
|
*/
|
|
282
|
-
floor(out =
|
|
282
|
+
floor(out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
283
283
|
out[0] = Math.floor(this[0])
|
|
284
284
|
out[1] = Math.floor(this[1])
|
|
285
285
|
out[2] = Math.floor(this[2])
|
|
@@ -290,7 +290,7 @@ export class Vec3 extends Float32Array {
|
|
|
290
290
|
*
|
|
291
291
|
* @returns {Vec3} this
|
|
292
292
|
*/
|
|
293
|
-
round(out =
|
|
293
|
+
round(out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
294
294
|
out[0] = Math.round(this[0])
|
|
295
295
|
out[1] = Math.round(this[1])
|
|
296
296
|
out[2] = Math.round(this[2])
|
|
@@ -301,7 +301,7 @@ export class Vec3 extends Float32Array {
|
|
|
301
301
|
*
|
|
302
302
|
* @returns {Vec3} this
|
|
303
303
|
*/
|
|
304
|
-
ceil(out =
|
|
304
|
+
ceil(out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
305
305
|
out[0] = Math.ceil(this[0])
|
|
306
306
|
out[1] = Math.ceil(this[1])
|
|
307
307
|
out[2] = Math.ceil(this[2])
|
|
@@ -325,7 +325,7 @@ export class Vec3 extends Float32Array {
|
|
|
325
325
|
*
|
|
326
326
|
* @returns {Vec3} this
|
|
327
327
|
*/
|
|
328
|
-
inverse(out =
|
|
328
|
+
inverse(out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
329
329
|
out[0] = 1.0 / this[0]
|
|
330
330
|
out[1] = 1.0 / this[1]
|
|
331
331
|
out[2] = 1.0 / this[2]
|
|
@@ -357,8 +357,8 @@ export class Vec3 extends Float32Array {
|
|
|
357
357
|
* @returns {Vec3} a new random vector
|
|
358
358
|
*/
|
|
359
359
|
static random(scale = 1.0) {
|
|
360
|
-
const r =
|
|
361
|
-
const z =
|
|
360
|
+
const r = glmaths.RANDOM() * 2.0 * Math.PI
|
|
361
|
+
const z = glmaths.RANDOM() * 2.0 - 1.0
|
|
362
362
|
const zScale = Math.sqrt(1.0 - z * z) * scale
|
|
363
363
|
return new Vec3(
|
|
364
364
|
Math.cos(r) * zScale,
|
|
@@ -594,7 +594,7 @@ export class Vec3 extends Float32Array {
|
|
|
594
594
|
* @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
|
|
595
595
|
* @returns {Vec3} a rotated vector
|
|
596
596
|
*/
|
|
597
|
-
rotateX(rad: number, origin: Vec3 = Vec3.zero, out =
|
|
597
|
+
rotateX(rad: number, origin: Vec3 = Vec3.zero, out = glmaths.ALWAYS_COPY ? new Vec3() : this): Vec3 {
|
|
598
598
|
const p1 = this[1] - origin[1]
|
|
599
599
|
const p2 = this[2] - origin[2]
|
|
600
600
|
out[0] = this[0]
|
|
@@ -624,7 +624,7 @@ export class Vec3 extends Float32Array {
|
|
|
624
624
|
* @param {Number} rad the angle of rotation in radians
|
|
625
625
|
* @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
|
|
626
626
|
*/
|
|
627
|
-
rotateY(rad: number, origin: Vec3 = Vec3.zero, out =
|
|
627
|
+
rotateY(rad: number, origin: Vec3 = Vec3.zero, out = glmaths.ALWAYS_COPY ? new Vec3() : this) : Vec3 {
|
|
628
628
|
const p0 = this[0] - origin[0]
|
|
629
629
|
const p2 = this[2] - origin[2]
|
|
630
630
|
out[0] = p2 * Math.sin(rad) + p0 * Math.cos(rad) + origin[0]
|
|
@@ -654,7 +654,7 @@ export class Vec3 extends Float32Array {
|
|
|
654
654
|
* @param {Number} rad the angle of rotation in radians
|
|
655
655
|
* @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
|
|
656
656
|
*/
|
|
657
|
-
rotateZ(rad: number, origin: Vec3 = Vec3.zero, out =
|
|
657
|
+
rotateZ(rad: number, origin: Vec3 = Vec3.zero, out = glmaths.ALWAYS_COPY ? new Vec3() : this) : Vec3 {
|
|
658
658
|
const p0 = this[0] - origin[0]
|
|
659
659
|
const p1 = this[1] - origin[1]
|
|
660
660
|
out[0] = p0 * Math.cos(rad) - p1 * Math.sin(rad) + origin[0]
|
|
@@ -822,7 +822,7 @@ export class Vec3 extends Float32Array {
|
|
|
822
822
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
823
823
|
* @returns {Vec3} out
|
|
824
824
|
*/
|
|
825
|
-
scaleAndAdd(b: Vec3, scale: number, out =
|
|
825
|
+
scaleAndAdd(b: Vec3, scale: number, out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
826
826
|
out[0] = this[0] + b[0] * scale
|
|
827
827
|
out[1] = this[1] + b[1] * scale
|
|
828
828
|
out[2] = this[2] + b[2] * scale
|
|
@@ -834,7 +834,7 @@ export class Vec3 extends Float32Array {
|
|
|
834
834
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
835
835
|
* @returns {Vec3} out
|
|
836
836
|
*/
|
|
837
|
-
abs(out =
|
|
837
|
+
abs(out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
838
838
|
out[0] = Math.abs(this[0])
|
|
839
839
|
out[1] = Math.abs(this[1])
|
|
840
840
|
out[2] = Math.abs(this[2])
|
|
@@ -848,7 +848,7 @@ export class Vec3 extends Float32Array {
|
|
|
848
848
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
849
849
|
* @returns {Vec3} out
|
|
850
850
|
*/
|
|
851
|
-
clamp(min: Vec3 | number, max: Vec3 | number, out =
|
|
851
|
+
clamp(min: Vec3 | number, max: Vec3 | number, out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
852
852
|
const minX = typeof min === 'number' ? min : min[0]
|
|
853
853
|
const minY = typeof min === 'number' ? min : min[1]
|
|
854
854
|
const minZ = typeof min === 'number' ? min : min[2]
|
|
@@ -868,7 +868,7 @@ export class Vec3 extends Float32Array {
|
|
|
868
868
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
869
869
|
* @returns {Vec3} out
|
|
870
870
|
*/
|
|
871
|
-
mix(b: Vec3, t: Vec3 | number, out =
|
|
871
|
+
mix(b: Vec3, t: Vec3 | number, out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
872
872
|
if (typeof t === 'number') {
|
|
873
873
|
out[0] = this[0] + (b[0] - this[0]) * t
|
|
874
874
|
out[1] = this[1] + (b[1] - this[1]) * t
|
|
@@ -887,7 +887,7 @@ export class Vec3 extends Float32Array {
|
|
|
887
887
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
888
888
|
* @returns {Vec3} out
|
|
889
889
|
*/
|
|
890
|
-
step(edge: Vec3 | number, out =
|
|
890
|
+
step(edge: Vec3 | number, out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
891
891
|
if (typeof edge === 'number') {
|
|
892
892
|
out[0] = this[0] < edge ? 0 : 1
|
|
893
893
|
out[1] = this[1] < edge ? 0 : 1
|
|
@@ -907,7 +907,7 @@ export class Vec3 extends Float32Array {
|
|
|
907
907
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
908
908
|
* @returns {Vec3} out
|
|
909
909
|
*/
|
|
910
|
-
smoothstep(edge0: Vec3 | number, edge1: Vec3 | number, out =
|
|
910
|
+
smoothstep(edge0: Vec3 | number, edge1: Vec3 | number, out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
911
911
|
const e0x = typeof edge0 === 'number' ? edge0 : edge0[0]
|
|
912
912
|
const e0y = typeof edge0 === 'number' ? edge0 : edge0[1]
|
|
913
913
|
const e0z = typeof edge0 === 'number' ? edge0 : edge0[2]
|
|
@@ -928,7 +928,7 @@ export class Vec3 extends Float32Array {
|
|
|
928
928
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
929
929
|
* @returns {Vec3} out
|
|
930
930
|
*/
|
|
931
|
-
fract(out =
|
|
931
|
+
fract(out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
932
932
|
out[0] = this[0] - Math.floor(this[0])
|
|
933
933
|
out[1] = this[1] - Math.floor(this[1])
|
|
934
934
|
out[2] = this[2] - Math.floor(this[2])
|
|
@@ -940,7 +940,7 @@ export class Vec3 extends Float32Array {
|
|
|
940
940
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
941
941
|
* @returns {Vec3} out
|
|
942
942
|
*/
|
|
943
|
-
sign(out =
|
|
943
|
+
sign(out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
944
944
|
out[0] = this[0] > 0 ? 1 : this[0] < 0 ? -1 : 0
|
|
945
945
|
out[1] = this[1] > 0 ? 1 : this[1] < 0 ? -1 : 0
|
|
946
946
|
out[2] = this[2] > 0 ? 1 : this[2] < 0 ? -1 : 0
|
|
@@ -952,7 +952,7 @@ export class Vec3 extends Float32Array {
|
|
|
952
952
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
953
953
|
* @returns {Vec3} out
|
|
954
954
|
*/
|
|
955
|
-
saturate(out =
|
|
955
|
+
saturate(out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
956
956
|
out[0] = Math.min(Math.max(this[0], 0), 1)
|
|
957
957
|
out[1] = Math.min(Math.max(this[1], 0), 1)
|
|
958
958
|
out[2] = Math.min(Math.max(this[2], 0), 1)
|
|
@@ -965,7 +965,7 @@ export class Vec3 extends Float32Array {
|
|
|
965
965
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
966
966
|
* @returns {Vec3} out
|
|
967
967
|
*/
|
|
968
|
-
transformMat3(m: Mat3, out =
|
|
968
|
+
transformMat3(m: Mat3, out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
969
969
|
const x = this[0], y = this[1], z = this[2]
|
|
970
970
|
out[0] = x * m[0] + y * m[3] + z * m[6]
|
|
971
971
|
out[1] = x * m[1] + y * m[4] + z * m[7]
|
|
@@ -980,7 +980,7 @@ export class Vec3 extends Float32Array {
|
|
|
980
980
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
981
981
|
* @returns {Vec3} out
|
|
982
982
|
*/
|
|
983
|
-
transformMat4(m: Mat4, out =
|
|
983
|
+
transformMat4(m: Mat4, out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
984
984
|
const x = this[0], y = this[1], z = this[2]
|
|
985
985
|
let w = m[3] * x + m[7] * y + m[11] * z + m[15]
|
|
986
986
|
w = w || 1.0
|
|
@@ -997,7 +997,7 @@ export class Vec3 extends Float32Array {
|
|
|
997
997
|
* @param {Vec3} out the receiving vector, defaults to this
|
|
998
998
|
* @returns {Vec3} out
|
|
999
999
|
*/
|
|
1000
|
-
transformQuat(q: Quat, out =
|
|
1000
|
+
transformQuat(q: Quat, out = glmaths.ALWAYS_COPY ? new Vec3() : this) {
|
|
1001
1001
|
const qx = q[0], qy = q[1], qz = q[2], qw = q[3]
|
|
1002
1002
|
const x = this[0], y = this[1], z = this[2]
|
|
1003
1003
|
let uvx = qy * z - qz * y, uvy = qz * x - qx * z, uvz = qx * y - qy * x
|
package/src/vec4.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import glmaths from '.'
|
|
2
2
|
import { equals, defineSwizzles } from './internalUtils'
|
|
3
3
|
import { Vec2 } from './vec2'
|
|
4
4
|
import { Vec3 } from './vec3'
|
|
@@ -53,7 +53,7 @@ export class Vec4 extends Float32Array {
|
|
|
53
53
|
* @param {Vec4} out the receiving vector, defaults to this
|
|
54
54
|
* @returns {Vec4} out
|
|
55
55
|
*/
|
|
56
|
-
plus(b: Vec4 | number, out =
|
|
56
|
+
plus(b: Vec4 | number, out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
57
57
|
if (typeof b === 'number') {
|
|
58
58
|
out[0] = this[0] + b
|
|
59
59
|
out[1] = this[1] + b
|
|
@@ -75,7 +75,7 @@ export class Vec4 extends Float32Array {
|
|
|
75
75
|
* @param {Vec4} out the receiving vector, defaults to this
|
|
76
76
|
* @returns {Vec4} out
|
|
77
77
|
*/
|
|
78
|
-
minus(b: Vec4 | number, out =
|
|
78
|
+
minus(b: Vec4 | number, out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
79
79
|
if (typeof b === 'number') {
|
|
80
80
|
out[0] = this[0] - b
|
|
81
81
|
out[1] = this[1] - b
|
|
@@ -97,7 +97,7 @@ export class Vec4 extends Float32Array {
|
|
|
97
97
|
* @param {Vec4} out the receiving vector, defaults to this
|
|
98
98
|
* @returns {Vec4} out
|
|
99
99
|
*/
|
|
100
|
-
mult(b: Vec4 | number, out =
|
|
100
|
+
mult(b: Vec4 | number, out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
101
101
|
if (typeof b === 'number') {
|
|
102
102
|
out[0] = this[0] * b
|
|
103
103
|
out[1] = this[1] * b
|
|
@@ -119,7 +119,7 @@ export class Vec4 extends Float32Array {
|
|
|
119
119
|
* @param {Vec4} out the receiving vector, defaults to this
|
|
120
120
|
* @returns {Vec4} out
|
|
121
121
|
*/
|
|
122
|
-
div(b: Vec4 | number, out =
|
|
122
|
+
div(b: Vec4 | number, out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
123
123
|
if (typeof b === 'number') {
|
|
124
124
|
out[0] = this[0] / b
|
|
125
125
|
out[1] = this[1] / b
|
|
@@ -134,7 +134,7 @@ export class Vec4 extends Float32Array {
|
|
|
134
134
|
return out
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
invDiv(b: Vec4 | number, out =
|
|
137
|
+
invDiv(b: Vec4 | number, out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
138
138
|
if (typeof b === 'number') {
|
|
139
139
|
out[0] = b / this[0]
|
|
140
140
|
out[1] = b / this[1]
|
|
@@ -155,14 +155,14 @@ export class Vec4 extends Float32Array {
|
|
|
155
155
|
* @param {Vec4} out the receiving vector, defaults to this
|
|
156
156
|
* @returns {Vec4} out
|
|
157
157
|
*/
|
|
158
|
-
negate(out =
|
|
158
|
+
negate(out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
159
159
|
out[0] = -this[0]
|
|
160
160
|
out[1] = -this[1]
|
|
161
161
|
out[2] = -this[2]
|
|
162
162
|
out[3] = -this[3]
|
|
163
163
|
return out
|
|
164
164
|
}
|
|
165
|
-
unaryPlus(out =
|
|
165
|
+
unaryPlus(out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
166
166
|
if (out != this) {
|
|
167
167
|
out[0] = this[0]
|
|
168
168
|
out[1] = this[1]
|
|
@@ -178,7 +178,7 @@ export class Vec4 extends Float32Array {
|
|
|
178
178
|
* @param {Vec4} out the receiving vector, defaults to this
|
|
179
179
|
* @returns {Vec4} out
|
|
180
180
|
*/
|
|
181
|
-
normalize(out =
|
|
181
|
+
normalize(out = glmaths.ALWAYS_COPY ? new Vec4() : this): Vec4 {
|
|
182
182
|
const x = this[0], y = this[1], z = this[2], w = this[3]
|
|
183
183
|
let len = x * x + y * y + z * z + w * w
|
|
184
184
|
if (len > 0) {
|
|
@@ -239,7 +239,7 @@ export class Vec4 extends Float32Array {
|
|
|
239
239
|
* @param {Vec4} out the receiving vector, defaults to this
|
|
240
240
|
* @returns {Vec4} out
|
|
241
241
|
*/
|
|
242
|
-
floor(out =
|
|
242
|
+
floor(out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
243
243
|
out[0] = Math.floor(this[0])
|
|
244
244
|
out[1] = Math.floor(this[1])
|
|
245
245
|
out[2] = Math.floor(this[2])
|
|
@@ -252,7 +252,7 @@ export class Vec4 extends Float32Array {
|
|
|
252
252
|
* @param {Vec4} out the receiving vector, defaults to this
|
|
253
253
|
* @returns {Vec4} out
|
|
254
254
|
*/
|
|
255
|
-
round(out =
|
|
255
|
+
round(out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
256
256
|
out[0] = Math.round(this[0])
|
|
257
257
|
out[1] = Math.round(this[1])
|
|
258
258
|
out[2] = Math.round(this[2])
|
|
@@ -265,7 +265,7 @@ export class Vec4 extends Float32Array {
|
|
|
265
265
|
* @param {Vec4} out the receiving vector, defaults to this
|
|
266
266
|
* @returns {Vec4} out
|
|
267
267
|
*/
|
|
268
|
-
ceil(out =
|
|
268
|
+
ceil(out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
269
269
|
out[0] = Math.ceil(this[0])
|
|
270
270
|
out[1] = Math.ceil(this[1])
|
|
271
271
|
out[2] = Math.ceil(this[2])
|
|
@@ -279,7 +279,7 @@ export class Vec4 extends Float32Array {
|
|
|
279
279
|
* @param {Vec4} out the receiving vector, defaults to this
|
|
280
280
|
* @returns {Vec4} out
|
|
281
281
|
*/
|
|
282
|
-
inverse(out =
|
|
282
|
+
inverse(out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
283
283
|
out[0] = 1.0 / this[0]
|
|
284
284
|
out[1] = 1.0 / this[1]
|
|
285
285
|
out[2] = 1.0 / this[2]
|
|
@@ -320,14 +320,14 @@ export class Vec4 extends Float32Array {
|
|
|
320
320
|
let s1, s2
|
|
321
321
|
let rand
|
|
322
322
|
|
|
323
|
-
rand =
|
|
323
|
+
rand = glmaths.RANDOM()
|
|
324
324
|
v1 = rand * 2 - 1
|
|
325
|
-
v2 = (4 *
|
|
325
|
+
v2 = (4 * glmaths.RANDOM() - 2) * Math.sqrt(rand * -rand + rand)
|
|
326
326
|
s1 = v1 * v1 + v2 * v2
|
|
327
327
|
|
|
328
|
-
rand =
|
|
328
|
+
rand = glmaths.RANDOM()
|
|
329
329
|
v3 = rand * 2 - 1
|
|
330
|
-
v4 = (4 *
|
|
330
|
+
v4 = (4 * glmaths.RANDOM() - 2) * Math.sqrt(rand * -rand + rand)
|
|
331
331
|
s2 = v3 * v3 + v4 * v4
|
|
332
332
|
|
|
333
333
|
const d = Math.sqrt((1 - s1) / s2)
|
|
@@ -539,7 +539,7 @@ export class Vec4 extends Float32Array {
|
|
|
539
539
|
* @param {Vec4} out the receiving vector
|
|
540
540
|
* @returns {Vec4} out
|
|
541
541
|
*/
|
|
542
|
-
scaleAndAdd(b: Vec4, scale: number, out =
|
|
542
|
+
scaleAndAdd(b: Vec4, scale: number, out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
543
543
|
out[0] = this[0] + b[0] * scale
|
|
544
544
|
out[1] = this[1] + b[1] * scale
|
|
545
545
|
out[2] = this[2] + b[2] * scale
|
|
@@ -553,7 +553,7 @@ export class Vec4 extends Float32Array {
|
|
|
553
553
|
* @param {Vec4} out the receiving vector
|
|
554
554
|
* @returns {Vec4} out
|
|
555
555
|
*/
|
|
556
|
-
abs(out =
|
|
556
|
+
abs(out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
557
557
|
out[0] = Math.abs(this[0])
|
|
558
558
|
out[1] = Math.abs(this[1])
|
|
559
559
|
out[2] = Math.abs(this[2])
|
|
@@ -569,7 +569,7 @@ export class Vec4 extends Float32Array {
|
|
|
569
569
|
* @param {Vec4} out the receiving vector
|
|
570
570
|
* @returns {Vec4} out
|
|
571
571
|
*/
|
|
572
|
-
clamp(min: Vec4 | number, max: Vec4 | number, out =
|
|
572
|
+
clamp(min: Vec4 | number, max: Vec4 | number, out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
573
573
|
const minX = typeof min === 'number' ? min : min[0]
|
|
574
574
|
const minY = typeof min === 'number' ? min : min[1]
|
|
575
575
|
const minZ = typeof min === 'number' ? min : min[2]
|
|
@@ -593,7 +593,7 @@ export class Vec4 extends Float32Array {
|
|
|
593
593
|
* @param {Vec4} out the receiving vector
|
|
594
594
|
* @returns {Vec4} out
|
|
595
595
|
*/
|
|
596
|
-
mix(b: Vec4, t: Vec4 | number, out =
|
|
596
|
+
mix(b: Vec4, t: Vec4 | number, out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
597
597
|
if (typeof t === 'number') {
|
|
598
598
|
out[0] = this[0] + (b[0] - this[0]) * t
|
|
599
599
|
out[1] = this[1] + (b[1] - this[1]) * t
|
|
@@ -615,7 +615,7 @@ export class Vec4 extends Float32Array {
|
|
|
615
615
|
* @param {Vec4} out the receiving vector
|
|
616
616
|
* @returns {Vec4} out
|
|
617
617
|
*/
|
|
618
|
-
step(edge: Vec4 | number, out =
|
|
618
|
+
step(edge: Vec4 | number, out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
619
619
|
if (typeof edge === 'number') {
|
|
620
620
|
out[0] = this[0] < edge ? 0 : 1
|
|
621
621
|
out[1] = this[1] < edge ? 0 : 1
|
|
@@ -638,7 +638,7 @@ export class Vec4 extends Float32Array {
|
|
|
638
638
|
* @param {Vec4} out the receiving vector
|
|
639
639
|
* @returns {Vec4} out
|
|
640
640
|
*/
|
|
641
|
-
smoothstep(edge0: Vec4 | number, edge1: Vec4 | number, out =
|
|
641
|
+
smoothstep(edge0: Vec4 | number, edge1: Vec4 | number, out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
642
642
|
const e0x = typeof edge0 === 'number' ? edge0 : edge0[0]
|
|
643
643
|
const e0y = typeof edge0 === 'number' ? edge0 : edge0[1]
|
|
644
644
|
const e0z = typeof edge0 === 'number' ? edge0 : edge0[2]
|
|
@@ -664,7 +664,7 @@ export class Vec4 extends Float32Array {
|
|
|
664
664
|
* @param {Vec4} out the receiving vector
|
|
665
665
|
* @returns {Vec4} out
|
|
666
666
|
*/
|
|
667
|
-
fract(out =
|
|
667
|
+
fract(out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
668
668
|
out[0] = this[0] - Math.floor(this[0])
|
|
669
669
|
out[1] = this[1] - Math.floor(this[1])
|
|
670
670
|
out[2] = this[2] - Math.floor(this[2])
|
|
@@ -678,7 +678,7 @@ export class Vec4 extends Float32Array {
|
|
|
678
678
|
* @param {Vec4} out the receiving vector
|
|
679
679
|
* @returns {Vec4} out
|
|
680
680
|
*/
|
|
681
|
-
sign(out =
|
|
681
|
+
sign(out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
682
682
|
out[0] = this[0] > 0 ? 1 : this[0] < 0 ? -1 : 0
|
|
683
683
|
out[1] = this[1] > 0 ? 1 : this[1] < 0 ? -1 : 0
|
|
684
684
|
out[2] = this[2] > 0 ? 1 : this[2] < 0 ? -1 : 0
|
|
@@ -692,7 +692,7 @@ export class Vec4 extends Float32Array {
|
|
|
692
692
|
* @param {Vec4} out the receiving vector
|
|
693
693
|
* @returns {Vec4} out
|
|
694
694
|
*/
|
|
695
|
-
saturate(out =
|
|
695
|
+
saturate(out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
696
696
|
out[0] = Math.min(Math.max(this[0], 0), 1)
|
|
697
697
|
out[1] = Math.min(Math.max(this[1], 0), 1)
|
|
698
698
|
out[2] = Math.min(Math.max(this[2], 0), 1)
|
|
@@ -707,7 +707,7 @@ export class Vec4 extends Float32Array {
|
|
|
707
707
|
* @param {Vec4} out the receiving vector
|
|
708
708
|
* @returns {Vec4} out
|
|
709
709
|
*/
|
|
710
|
-
transformMat4(m: Mat4, out =
|
|
710
|
+
transformMat4(m: Mat4, out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
711
711
|
const x = this[0], y = this[1], z = this[2], w = this[3]
|
|
712
712
|
out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w
|
|
713
713
|
out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w
|
|
@@ -723,7 +723,7 @@ export class Vec4 extends Float32Array {
|
|
|
723
723
|
* @param {Vec4} out the receiving vector
|
|
724
724
|
* @returns {Vec4} out
|
|
725
725
|
*/
|
|
726
|
-
transformQuat(q: Quat, out =
|
|
726
|
+
transformQuat(q: Quat, out = glmaths.ALWAYS_COPY ? new Vec4() : this) {
|
|
727
727
|
const qx = q[0], qy = q[1], qz = q[2], qw = q[3]
|
|
728
728
|
const x = this[0], y = this[1], z = this[2]
|
|
729
729
|
let uvx = qy * z - qz * y, uvy = qz * x - qx * z, uvz = qx * y - qy * x
|