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/quat.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import glmaths from '.'
|
|
2
2
|
import { vec3, Vec3 } from './vec3'
|
|
3
3
|
import { vec4, Vec4 } from './vec4'
|
|
4
4
|
import { Mat3 } from './mat3'
|
|
@@ -37,7 +37,7 @@ export class Quat extends Float32Array {
|
|
|
37
37
|
* @param {Quat} out the receiving quaternion, defaults to this
|
|
38
38
|
* @returns {Quat} out
|
|
39
39
|
*/
|
|
40
|
-
multiply(b: Quat | number, out: Quat =
|
|
40
|
+
multiply(b: Quat | number, out: Quat = glmaths.ALWAYS_COPY ? new Quat() : this): Quat {
|
|
41
41
|
if (typeof b === 'number') {
|
|
42
42
|
out[0] = this[0] * b
|
|
43
43
|
out[1] = this[1] * b
|
|
@@ -80,7 +80,7 @@ export class Quat extends Float32Array {
|
|
|
80
80
|
* @param {Quat} out the receiving quaternion, defaults to this
|
|
81
81
|
* @returns {Quat} out
|
|
82
82
|
*/
|
|
83
|
-
setAxisAngle(axis: Vec3, rad: number, out =
|
|
83
|
+
setAxisAngle(axis: Vec3, rad: number, out = glmaths.ALWAYS_COPY ? quat() : this): Quat {
|
|
84
84
|
rad *= 0.5
|
|
85
85
|
const s = Math.sin(rad)
|
|
86
86
|
out[0] = s * axis[0]
|
|
@@ -106,7 +106,7 @@ export class Quat extends Float32Array {
|
|
|
106
106
|
const rad = Math.acos(this[3]) * 2.0
|
|
107
107
|
const s = Math.sin(rad / 2.0)
|
|
108
108
|
if (out_axis) {
|
|
109
|
-
if (s >
|
|
109
|
+
if (s > glmaths.EPSILON) {
|
|
110
110
|
out_axis[0] = this[0] / s
|
|
111
111
|
out_axis[1] = this[1] / s
|
|
112
112
|
out_axis[2] = this[2] / s
|
|
@@ -146,7 +146,7 @@ export class Quat extends Float32Array {
|
|
|
146
146
|
* @param {Quat} out the receiving quaternion, defaults to this
|
|
147
147
|
* @returns {Quat} out
|
|
148
148
|
*/
|
|
149
|
-
rotateX(rad: number, out =
|
|
149
|
+
rotateX(rad: number, out = glmaths.ALWAYS_COPY ? quat() : this) {
|
|
150
150
|
rad *= 0.5
|
|
151
151
|
const ax = this[0], ay = this[1], az = this[2], aw = this[3]
|
|
152
152
|
const bx = Math.sin(rad), bw = Math.cos(rad)
|
|
@@ -164,7 +164,7 @@ export class Quat extends Float32Array {
|
|
|
164
164
|
* @param {Quat} out the receiving quaternion, defaults to this
|
|
165
165
|
* @returns {Quat} out
|
|
166
166
|
*/
|
|
167
|
-
rotateY(rad: number, out =
|
|
167
|
+
rotateY(rad: number, out = glmaths.ALWAYS_COPY ? quat() : this) {
|
|
168
168
|
rad *= 0.5
|
|
169
169
|
const ax = this[0], ay = this[1], az = this[2], aw = this[3]
|
|
170
170
|
const by = Math.sin(rad), bw = Math.cos(rad)
|
|
@@ -181,7 +181,7 @@ export class Quat extends Float32Array {
|
|
|
181
181
|
* @param {Quat} out the receiving quaternion, defaults to this
|
|
182
182
|
* @returns {Quat} out
|
|
183
183
|
*/
|
|
184
|
-
rotateZ(rad: number, out =
|
|
184
|
+
rotateZ(rad: number, out = glmaths.ALWAYS_COPY ? quat() : this) {
|
|
185
185
|
rad *= 0.5
|
|
186
186
|
const ax = this[0], ay = this[1], az = this[2], aw = this[3]
|
|
187
187
|
const bz = Math.sin(rad), bw = Math.cos(rad)
|
|
@@ -226,7 +226,7 @@ export class Quat extends Float32Array {
|
|
|
226
226
|
* @param {Quat} out the receiving quaternion, defaults to this
|
|
227
227
|
* @returns {Quat} out
|
|
228
228
|
*/
|
|
229
|
-
exp(out =
|
|
229
|
+
exp(out = glmaths.ALWAYS_COPY ? quat() : this): Quat {
|
|
230
230
|
const x = this[0], y = this[1], z = this[2], w = this[3]
|
|
231
231
|
const r = Math.sqrt(x * x + y * y + z * z)
|
|
232
232
|
const et = Math.exp(w)
|
|
@@ -261,7 +261,7 @@ export class Quat extends Float32Array {
|
|
|
261
261
|
* @param {Quat} out the receiving quaternion, defaults to this
|
|
262
262
|
* @returns {Quat} out
|
|
263
263
|
*/
|
|
264
|
-
ln(out =
|
|
264
|
+
ln(out = glmaths.ALWAYS_COPY ? quat() : this): Quat {
|
|
265
265
|
const x = this[0], y = this[1], z = this[2], w = this[3]
|
|
266
266
|
const r = Math.sqrt(x * x + y * y + z * z)
|
|
267
267
|
const t = r > 0 ? Math.atan2(r, w) / r : 0
|
|
@@ -310,7 +310,7 @@ export class Quat extends Float32Array {
|
|
|
310
310
|
bw = -bw;
|
|
311
311
|
}
|
|
312
312
|
// calculate coefficients
|
|
313
|
-
if (1.0 - cosom >
|
|
313
|
+
if (1.0 - cosom > glmaths.EPSILON) {
|
|
314
314
|
// standard case (slerp)
|
|
315
315
|
omega = Math.acos(cosom);
|
|
316
316
|
sinom = Math.sin(omega);
|
|
@@ -337,7 +337,7 @@ export class Quat extends Float32Array {
|
|
|
337
337
|
* @param {Quat} out the receiving quaternion, defaults to this
|
|
338
338
|
* @returns {Quat} out
|
|
339
339
|
*/
|
|
340
|
-
slerp(b: Quat, t: number, out =
|
|
340
|
+
slerp(b: Quat, t: number, out = glmaths.ALWAYS_COPY ? quat() : this): Quat {
|
|
341
341
|
let ax = this[0], ay = this[1], az = this[2], aw = this[3]
|
|
342
342
|
let bx = b[0], by = b[1], bz = b[2], bw = b[3]
|
|
343
343
|
|
|
@@ -353,7 +353,7 @@ export class Quat extends Float32Array {
|
|
|
353
353
|
bw = -bw;
|
|
354
354
|
}
|
|
355
355
|
// calculate coefficients
|
|
356
|
-
if (1.0 - cosom >
|
|
356
|
+
if (1.0 - cosom > glmaths.EPSILON) {
|
|
357
357
|
// standard case (slerp)
|
|
358
358
|
omega = Math.acos(cosom);
|
|
359
359
|
sinom = Math.sin(omega);
|
|
@@ -382,9 +382,9 @@ export class Quat extends Float32Array {
|
|
|
382
382
|
static random(out = quat()) {
|
|
383
383
|
// Implementation of http://planning.cs.uiuc.edu/node198.html
|
|
384
384
|
// TODO: Calling random 3 times is probably not the fastest solution
|
|
385
|
-
let u1 =
|
|
386
|
-
let u2 =
|
|
387
|
-
let u3 =
|
|
385
|
+
let u1 = glmaths.RANDOM()
|
|
386
|
+
let u2 = glmaths.RANDOM()
|
|
387
|
+
let u3 = glmaths.RANDOM()
|
|
388
388
|
let sqrt1MinusU1 = Math.sqrt(1 - u1)
|
|
389
389
|
let sqrtU1 = Math.sqrt(u1)
|
|
390
390
|
out[0] = sqrt1MinusU1 * Math.sin(2.0 * Math.PI * u2)
|
|
@@ -418,7 +418,7 @@ export class Quat extends Float32Array {
|
|
|
418
418
|
* @param {Quat} out the receiving quaternion, defaults to this
|
|
419
419
|
* @returns {Quat} out
|
|
420
420
|
*/
|
|
421
|
-
invert(out =
|
|
421
|
+
invert(out = glmaths.ALWAYS_COPY ? quat() : this) {
|
|
422
422
|
const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3]
|
|
423
423
|
const dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;
|
|
424
424
|
const invDot = dot ? 1.0 / dot : 0;
|
|
@@ -450,7 +450,7 @@ export class Quat extends Float32Array {
|
|
|
450
450
|
* @param {Quat} out the receiving quaternion, defaults to this
|
|
451
451
|
* @returns {Quat} out
|
|
452
452
|
*/
|
|
453
|
-
conjugate(out =
|
|
453
|
+
conjugate(out = glmaths.ALWAYS_COPY ? quat() : this): Quat {
|
|
454
454
|
out[0] = -this[0]
|
|
455
455
|
out[1] = -this[1]
|
|
456
456
|
out[2] = -this[2]
|
|
@@ -504,7 +504,7 @@ export class Quat extends Float32Array {
|
|
|
504
504
|
* @param {Quat} out the receiving quaternion, defaults to quat()
|
|
505
505
|
* @returns {Quat} out
|
|
506
506
|
*/
|
|
507
|
-
static fromEuler(x: number, y: number, z: number, order =
|
|
507
|
+
static fromEuler(x: number, y: number, z: number, order = glmaths.ANGLE_ORDER, out = quat()) {
|
|
508
508
|
let halfToRad = Math.PI / 360
|
|
509
509
|
x *= halfToRad
|
|
510
510
|
z *= halfToRad
|
|
@@ -596,7 +596,7 @@ export class Quat extends Float32Array {
|
|
|
596
596
|
* @returns {Boolean} true if the quaternions represent the same rotation
|
|
597
597
|
*/
|
|
598
598
|
equals(b: Quat) {
|
|
599
|
-
return Math.abs(Quat.dot(this, b)) >= 1 -
|
|
599
|
+
return Math.abs(Quat.dot(this, b)) >= 1 - glmaths.EPSILON
|
|
600
600
|
}
|
|
601
601
|
|
|
602
602
|
private static tmpVec3 = vec3()
|
|
@@ -668,7 +668,7 @@ export class Quat extends Float32Array {
|
|
|
668
668
|
Quat.tmpMat3[4] = up[1]
|
|
669
669
|
Quat.tmpMat3[7] = up[2]
|
|
670
670
|
|
|
671
|
-
const vs =
|
|
671
|
+
const vs = glmaths.LEFT_HANDED ? 1 : -1
|
|
672
672
|
Quat.tmpMat3[2] = vs * view[0]
|
|
673
673
|
Quat.tmpMat3[5] = vs * view[1]
|
|
674
674
|
Quat.tmpMat3[8] = vs * view[2]
|
|
@@ -682,7 +682,7 @@ export class Quat extends Float32Array {
|
|
|
682
682
|
* @param {Quat} out the receiving vector, defaults to this
|
|
683
683
|
* @returns {Quat} out
|
|
684
684
|
*/
|
|
685
|
-
normalize(out =
|
|
685
|
+
normalize(out = glmaths.ALWAYS_COPY ? new Quat() : this): Quat {
|
|
686
686
|
const x = this[0], y = this[1], z = this[2], w = this[3]
|
|
687
687
|
let len = x * x + y * y + z * z + w * w
|
|
688
688
|
if (len > 0) {
|
|
@@ -708,7 +708,7 @@ export class Quat extends Float32Array {
|
|
|
708
708
|
const s = Vec3.cross(f, up).normalize()
|
|
709
709
|
const u = Vec3.cross(s, f)
|
|
710
710
|
const m = new Mat3()
|
|
711
|
-
const vs =
|
|
711
|
+
const vs = glmaths.LEFT_HANDED ? 1 : -1
|
|
712
712
|
m[0] = s[0]; m[1] = u[0]; m[2] = vs * f[0]
|
|
713
713
|
m[3] = s[1]; m[4] = u[1]; m[5] = vs * f[1]
|
|
714
714
|
m[6] = s[2]; m[7] = u[2]; m[8] = vs * f[2]
|
package/src/quat2.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import glmaths from '.'
|
|
2
2
|
import { equals } from './internalUtils'
|
|
3
3
|
import { Vec3 } from './vec3'
|
|
4
4
|
import { Quat } from './quat'
|
|
@@ -167,7 +167,7 @@ export class Quat2 extends Float32Array {
|
|
|
167
167
|
* @returns {Quat2} out
|
|
168
168
|
*/
|
|
169
169
|
// @ts-ignore
|
|
170
|
-
multiply = (b: Quat2, out =
|
|
170
|
+
multiply = (b: Quat2, out = glmaths.ALWAYS_COPY ? new Quat2() : this): Quat2 => {
|
|
171
171
|
const ax0 = this[0], ay0 = this[1], az0 = this[2], aw0 = this[3]
|
|
172
172
|
const bx1 = b[4], by1 = b[5], bz1 = b[6], bw1 = b[7]
|
|
173
173
|
const ax1 = this[4], ay1 = this[5], az1 = this[6], aw1 = this[7]
|
|
@@ -196,7 +196,7 @@ export class Quat2 extends Float32Array {
|
|
|
196
196
|
* @param {Quat2} out the receiving dual quaternion, defaults to this
|
|
197
197
|
* @returns {Quat2} out
|
|
198
198
|
*/
|
|
199
|
-
translate(v: Vec3, out =
|
|
199
|
+
translate(v: Vec3, out = glmaths.ALWAYS_COPY ? new Quat2() : this): Quat2 {
|
|
200
200
|
const ax1 = this[0], ay1 = this[1], az1 = this[2], aw1 = this[3]
|
|
201
201
|
const bx1 = v[0] * 0.5, by1 = v[1] * 0.5, bz1 = v[2] * 0.5
|
|
202
202
|
const ax2 = this[4], ay2 = this[5], az2 = this[6], aw2 = this[7]
|
|
@@ -214,7 +214,7 @@ export class Quat2 extends Float32Array {
|
|
|
214
214
|
* @param {Quat2} out the receiving dual quaternion, defaults to this
|
|
215
215
|
* @returns {Quat2} out
|
|
216
216
|
*/
|
|
217
|
-
conjugate(out =
|
|
217
|
+
conjugate(out = glmaths.ALWAYS_COPY ? new Quat2() : this): Quat2 {
|
|
218
218
|
out[0] = -this[0]; out[1] = -this[1]; out[2] = -this[2]; out[3] = this[3]
|
|
219
219
|
out[4] = -this[4]; out[5] = -this[5]; out[6] = -this[6]; out[7] = this[7]
|
|
220
220
|
return out
|
|
@@ -226,7 +226,7 @@ export class Quat2 extends Float32Array {
|
|
|
226
226
|
* @param {Quat2} out the receiving dual quaternion, defaults to this
|
|
227
227
|
* @returns {Quat2} out
|
|
228
228
|
*/
|
|
229
|
-
invert(out =
|
|
229
|
+
invert(out = glmaths.ALWAYS_COPY ? new Quat2() : this): Quat2 {
|
|
230
230
|
const sqlen = this.squaredLength()
|
|
231
231
|
out[0] = -this[0] / sqlen; out[1] = -this[1] / sqlen
|
|
232
232
|
out[2] = -this[2] / sqlen; out[3] = this[3] / sqlen
|
|
@@ -260,7 +260,7 @@ export class Quat2 extends Float32Array {
|
|
|
260
260
|
* @param {Quat2} out the receiving dual quaternion, defaults to this
|
|
261
261
|
* @returns {Quat2} out
|
|
262
262
|
*/
|
|
263
|
-
normalize(out =
|
|
263
|
+
normalize(out = glmaths.ALWAYS_COPY ? new Quat2() : this): Quat2 {
|
|
264
264
|
let magnitude = this.squaredLength()
|
|
265
265
|
if (magnitude > 0) {
|
|
266
266
|
magnitude = Math.sqrt(magnitude)
|
|
@@ -318,7 +318,7 @@ export class Quat2 extends Float32Array {
|
|
|
318
318
|
* @param {Quat2} out the receiving dual quaternion, defaults to this
|
|
319
319
|
* @returns {Quat2} out
|
|
320
320
|
*/
|
|
321
|
-
plus(b: Quat2, out =
|
|
321
|
+
plus(b: Quat2, out = glmaths.ALWAYS_COPY ? new Quat2() : this): Quat2 {
|
|
322
322
|
out[0] = this[0] + b[0]; out[1] = this[1] + b[1]
|
|
323
323
|
out[2] = this[2] + b[2]; out[3] = this[3] + b[3]
|
|
324
324
|
out[4] = this[4] + b[4]; out[5] = this[5] + b[5]
|
|
@@ -333,7 +333,7 @@ export class Quat2 extends Float32Array {
|
|
|
333
333
|
* @param {Quat2} out the receiving dual quaternion, defaults to this
|
|
334
334
|
* @returns {Quat2} out
|
|
335
335
|
*/
|
|
336
|
-
scale(s: number, out =
|
|
336
|
+
scale(s: number, out = glmaths.ALWAYS_COPY ? new Quat2() : this): Quat2 {
|
|
337
337
|
out[0] = this[0] * s; out[1] = this[1] * s
|
|
338
338
|
out[2] = this[2] * s; out[3] = this[3] * s
|
|
339
339
|
out[4] = this[4] * s; out[5] = this[5] * s
|
package/src/vec2.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import glmaths from '.'
|
|
2
2
|
import { equals, defineSwizzles } from './internalUtils'
|
|
3
3
|
import { Vec3 } from './vec3'
|
|
4
4
|
import { Vec4 } from './vec4'
|
|
@@ -45,7 +45,7 @@ export class Vec2 extends Float32Array {
|
|
|
45
45
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
46
46
|
* @returns {Vec2} out
|
|
47
47
|
*/
|
|
48
|
-
plus(b: Vec2 | number, out =
|
|
48
|
+
plus(b: Vec2 | number, out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
49
49
|
if (typeof b === 'number') {
|
|
50
50
|
out[0] = this[0] + b
|
|
51
51
|
out[1] = this[1] + b
|
|
@@ -63,7 +63,7 @@ export class Vec2 extends Float32Array {
|
|
|
63
63
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
64
64
|
* @returns {Vec2} out
|
|
65
65
|
*/
|
|
66
|
-
minus(b: Vec2 | number, out =
|
|
66
|
+
minus(b: Vec2 | number, out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
67
67
|
if (typeof b === 'number') {
|
|
68
68
|
out[0] = this[0] - b
|
|
69
69
|
out[1] = this[1] - b
|
|
@@ -81,7 +81,7 @@ export class Vec2 extends Float32Array {
|
|
|
81
81
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
82
82
|
* @returns {Vec2} out
|
|
83
83
|
*/
|
|
84
|
-
mult(b: Vec2 | number, out =
|
|
84
|
+
mult(b: Vec2 | number, out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
85
85
|
if (typeof b === 'number') {
|
|
86
86
|
out[0] = this[0] * b
|
|
87
87
|
out[1] = this[1] * b
|
|
@@ -99,7 +99,7 @@ export class Vec2 extends Float32Array {
|
|
|
99
99
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
100
100
|
* @returns {Vec2} out
|
|
101
101
|
*/
|
|
102
|
-
div(b: Vec2 | number, out =
|
|
102
|
+
div(b: Vec2 | number, out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
103
103
|
if (typeof b === 'number') {
|
|
104
104
|
out[0] = this[0] / b
|
|
105
105
|
out[1] = this[1] / b
|
|
@@ -117,7 +117,7 @@ export class Vec2 extends Float32Array {
|
|
|
117
117
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
118
118
|
* @returns {Vec2} out
|
|
119
119
|
*/
|
|
120
|
-
invDiv(a: Vec2 | number, out =
|
|
120
|
+
invDiv(a: Vec2 | number, out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
121
121
|
if (typeof a === 'number') {
|
|
122
122
|
out[0] = a / this[0]
|
|
123
123
|
out[1] = a / this[1]
|
|
@@ -135,7 +135,7 @@ export class Vec2 extends Float32Array {
|
|
|
135
135
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
136
136
|
* @returns {Vec2} out
|
|
137
137
|
*/
|
|
138
|
-
rem(b: Vec2 | number, out =
|
|
138
|
+
rem(b: Vec2 | number, out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
139
139
|
if (typeof b === 'number') {
|
|
140
140
|
out[0] = this[0] % b
|
|
141
141
|
out[1] = this[1] % b
|
|
@@ -152,12 +152,12 @@ export class Vec2 extends Float32Array {
|
|
|
152
152
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
153
153
|
* @returns {Vec2} out
|
|
154
154
|
*/
|
|
155
|
-
negate(out =
|
|
155
|
+
negate(out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
156
156
|
out[0] = -this[0]
|
|
157
157
|
out[1] = -this[1]
|
|
158
158
|
return out
|
|
159
159
|
}
|
|
160
|
-
unaryPlus(out =
|
|
160
|
+
unaryPlus(out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
161
161
|
if (out != this) {
|
|
162
162
|
out[0] = this[0]
|
|
163
163
|
out[1] = this[1]
|
|
@@ -170,7 +170,7 @@ export class Vec2 extends Float32Array {
|
|
|
170
170
|
*
|
|
171
171
|
* @returns {Vec2} this
|
|
172
172
|
*/
|
|
173
|
-
normalize(out =
|
|
173
|
+
normalize(out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
174
174
|
const x = this[0], y = this[1]
|
|
175
175
|
let len = x * x + y * y
|
|
176
176
|
if (len > 0) {
|
|
@@ -230,7 +230,7 @@ export class Vec2 extends Float32Array {
|
|
|
230
230
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
231
231
|
* @returns {Vec2} out
|
|
232
232
|
*/
|
|
233
|
-
floor(out =
|
|
233
|
+
floor(out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
234
234
|
out[0] = Math.floor(this[0])
|
|
235
235
|
out[1] = Math.floor(this[1])
|
|
236
236
|
return out
|
|
@@ -241,7 +241,7 @@ export class Vec2 extends Float32Array {
|
|
|
241
241
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
242
242
|
* @returns {Vec2} out
|
|
243
243
|
*/
|
|
244
|
-
round(out =
|
|
244
|
+
round(out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
245
245
|
out[0] = Math.round(this[0])
|
|
246
246
|
out[1] = Math.round(this[1])
|
|
247
247
|
return out
|
|
@@ -253,7 +253,7 @@ export class Vec2 extends Float32Array {
|
|
|
253
253
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
254
254
|
* @returns {Vec2} out
|
|
255
255
|
*/
|
|
256
|
-
ceil(out =
|
|
256
|
+
ceil(out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
257
257
|
out[0] = Math.ceil(this[0])
|
|
258
258
|
out[1] = Math.ceil(this[1])
|
|
259
259
|
return out
|
|
@@ -265,7 +265,7 @@ export class Vec2 extends Float32Array {
|
|
|
265
265
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
266
266
|
* @returns {Vec2} out
|
|
267
267
|
*/
|
|
268
|
-
inverse(out =
|
|
268
|
+
inverse(out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
269
269
|
out[0] = 1.0 / this[0]
|
|
270
270
|
out[1] = 1.0 / this[1]
|
|
271
271
|
return out
|
|
@@ -286,7 +286,7 @@ export class Vec2 extends Float32Array {
|
|
|
286
286
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
287
287
|
* @returns {Vec2} out
|
|
288
288
|
*/
|
|
289
|
-
rotate(rad = 0, origin: Vec2 = Vec2.ZERO, out =
|
|
289
|
+
rotate(rad = 0, origin: Vec2 = Vec2.ZERO, out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
290
290
|
const p0 = this[0] - origin[0]
|
|
291
291
|
const p1 = this[1] - origin[1]
|
|
292
292
|
const sinC = Math.sin(rad)
|
|
@@ -312,7 +312,7 @@ export class Vec2 extends Float32Array {
|
|
|
312
312
|
* @returns {Vec2} a new random Vec2
|
|
313
313
|
*/
|
|
314
314
|
static random(scale = 1.0, out = new Vec2()) {
|
|
315
|
-
const angleR =
|
|
315
|
+
const angleR = glmaths.RANDOM() * 2.0 * Math.PI
|
|
316
316
|
out[0] = Math.cos(angleR) * scale
|
|
317
317
|
out[1] = Math.sin(angleR) * scale
|
|
318
318
|
return out
|
|
@@ -515,7 +515,7 @@ export class Vec2 extends Float32Array {
|
|
|
515
515
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
516
516
|
* @returns {Vec2} out
|
|
517
517
|
*/
|
|
518
|
-
scaleAndAdd(b: Vec2, scale: number, out =
|
|
518
|
+
scaleAndAdd(b: Vec2, scale: number, out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
519
519
|
out[0] = this[0] + b[0] * scale
|
|
520
520
|
out[1] = this[1] + b[1] * scale
|
|
521
521
|
return out
|
|
@@ -527,7 +527,7 @@ export class Vec2 extends Float32Array {
|
|
|
527
527
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
528
528
|
* @returns {Vec2} out
|
|
529
529
|
*/
|
|
530
|
-
abs(out =
|
|
530
|
+
abs(out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
531
531
|
out[0] = Math.abs(this[0])
|
|
532
532
|
out[1] = Math.abs(this[1])
|
|
533
533
|
return out
|
|
@@ -539,7 +539,7 @@ export class Vec2 extends Float32Array {
|
|
|
539
539
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
540
540
|
* @returns {Vec2} out
|
|
541
541
|
*/
|
|
542
|
-
sign(out =
|
|
542
|
+
sign(out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
543
543
|
out[0] = this[0] > 0 ? 1 : this[0] < 0 ? -1 : 0
|
|
544
544
|
out[1] = this[1] > 0 ? 1 : this[1] < 0 ? -1 : 0
|
|
545
545
|
return out
|
|
@@ -551,7 +551,7 @@ export class Vec2 extends Float32Array {
|
|
|
551
551
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
552
552
|
* @returns {Vec2} out
|
|
553
553
|
*/
|
|
554
|
-
fract(out =
|
|
554
|
+
fract(out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
555
555
|
out[0] = this[0] - Math.floor(this[0])
|
|
556
556
|
out[1] = this[1] - Math.floor(this[1])
|
|
557
557
|
return out
|
|
@@ -565,7 +565,7 @@ export class Vec2 extends Float32Array {
|
|
|
565
565
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
566
566
|
* @returns {Vec2} out
|
|
567
567
|
*/
|
|
568
|
-
clamp(min: Vec2 | number, max: Vec2 | number, out =
|
|
568
|
+
clamp(min: Vec2 | number, max: Vec2 | number, out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
569
569
|
if (typeof min === 'number' && typeof max === 'number') {
|
|
570
570
|
out[0] = Math.min(Math.max(this[0], min), max)
|
|
571
571
|
out[1] = Math.min(Math.max(this[1], min), max)
|
|
@@ -586,7 +586,7 @@ export class Vec2 extends Float32Array {
|
|
|
586
586
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
587
587
|
* @returns {Vec2} out
|
|
588
588
|
*/
|
|
589
|
-
saturate(out =
|
|
589
|
+
saturate(out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
590
590
|
out[0] = Math.min(Math.max(this[0], 0), 1)
|
|
591
591
|
out[1] = Math.min(Math.max(this[1], 0), 1)
|
|
592
592
|
return out
|
|
@@ -600,7 +600,7 @@ export class Vec2 extends Float32Array {
|
|
|
600
600
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
601
601
|
* @returns {Vec2} out
|
|
602
602
|
*/
|
|
603
|
-
mix(b: Vec2, t: Vec2 | number, out =
|
|
603
|
+
mix(b: Vec2, t: Vec2 | number, out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
604
604
|
if (typeof t === 'number') {
|
|
605
605
|
out[0] = this[0] + (b[0] - this[0]) * t
|
|
606
606
|
out[1] = this[1] + (b[1] - this[1]) * t
|
|
@@ -618,7 +618,7 @@ export class Vec2 extends Float32Array {
|
|
|
618
618
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
619
619
|
* @returns {Vec2} out
|
|
620
620
|
*/
|
|
621
|
-
step(edge: Vec2 | number, out =
|
|
621
|
+
step(edge: Vec2 | number, out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
622
622
|
if (typeof edge === 'number') {
|
|
623
623
|
out[0] = this[0] < edge ? 0 : 1
|
|
624
624
|
out[1] = this[1] < edge ? 0 : 1
|
|
@@ -637,7 +637,7 @@ export class Vec2 extends Float32Array {
|
|
|
637
637
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
638
638
|
* @returns {Vec2} out
|
|
639
639
|
*/
|
|
640
|
-
smoothstep(edge0: Vec2 | number, edge1: Vec2 | number, out =
|
|
640
|
+
smoothstep(edge0: Vec2 | number, edge1: Vec2 | number, out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
641
641
|
const e0x = typeof edge0 === 'number' ? edge0 : edge0[0]
|
|
642
642
|
const e0y = typeof edge0 === 'number' ? edge0 : edge0[1]
|
|
643
643
|
const e1x = typeof edge1 === 'number' ? edge1 : edge1[0]
|
|
@@ -656,7 +656,7 @@ export class Vec2 extends Float32Array {
|
|
|
656
656
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
657
657
|
* @returns {Vec2} out
|
|
658
658
|
*/
|
|
659
|
-
transformMat2(m: Mat2, out =
|
|
659
|
+
transformMat2(m: Mat2, out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
660
660
|
const x = this[0], y = this[1]
|
|
661
661
|
out[0] = m[0] * x + m[2] * y
|
|
662
662
|
out[1] = m[1] * x + m[3] * y
|
|
@@ -670,7 +670,7 @@ export class Vec2 extends Float32Array {
|
|
|
670
670
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
671
671
|
* @returns {Vec2} out
|
|
672
672
|
*/
|
|
673
|
-
transformMat2x3(m: Mat2x3, out =
|
|
673
|
+
transformMat2x3(m: Mat2x3, out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
674
674
|
const x = this[0], y = this[1]
|
|
675
675
|
out[0] = m[0] * x + m[2] * y + m[4]
|
|
676
676
|
out[1] = m[1] * x + m[3] * y + m[5]
|
|
@@ -684,7 +684,7 @@ export class Vec2 extends Float32Array {
|
|
|
684
684
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
685
685
|
* @returns {Vec2} out
|
|
686
686
|
*/
|
|
687
|
-
transformMat3(m: Mat3, out =
|
|
687
|
+
transformMat3(m: Mat3, out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
688
688
|
const x = this[0], y = this[1]
|
|
689
689
|
out[0] = m[0] * x + m[3] * y + m[6]
|
|
690
690
|
out[1] = m[1] * x + m[4] * y + m[7]
|
|
@@ -698,7 +698,7 @@ export class Vec2 extends Float32Array {
|
|
|
698
698
|
* @param {Vec2} out the receiving vector, defaults to this
|
|
699
699
|
* @returns {Vec2} out
|
|
700
700
|
*/
|
|
701
|
-
transformMat4(m: Mat4, out =
|
|
701
|
+
transformMat4(m: Mat4, out = glmaths.ALWAYS_COPY ? new Vec2() : this) {
|
|
702
702
|
const x = this[0], y = this[1]
|
|
703
703
|
out[0] = m[0] * x + m[4] * y + m[12]
|
|
704
704
|
out[1] = m[1] * x + m[5] * y + m[13]
|