@flighthq/geometry 0.5.1-next.973.788d3d7 → 0.6.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 +2 -2
- package/dist/.tsbuildinfo.contract +1 -0
- package/dist/.tsbuildinfo.runtime +1 -0
- package/dist/aabb.d.ts +2 -1
- package/dist/aabb.d.ts.map +1 -1
- package/dist/aabb.js +3 -3
- package/dist/aabb.js.map +1 -1
- package/dist/boundingSphere.d.ts +2 -1
- package/dist/boundingSphere.d.ts.map +1 -1
- package/dist/boundingSphere.js +3 -3
- package/dist/boundingSphere.js.map +1 -1
- package/dist/capsule.d.ts +2 -1
- package/dist/capsule.d.ts.map +1 -1
- package/dist/capsule.js +2 -2
- package/dist/capsule.js.map +1 -1
- package/dist/contract.d.ts +2 -44
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.geometry-types.d.ts +2 -0
- package/dist/contract.geometry-types.d.ts.map +1 -0
- package/dist/contract.geometry-types.js +4 -0
- package/dist/contract.geometry-types.js.map +1 -0
- package/dist/contract.js +2 -44
- package/dist/contract.js.map +1 -1
- package/dist/enableGeometryPoolGuards.d.ts +10 -1
- package/dist/enableGeometryPoolGuards.d.ts.map +1 -1
- package/dist/enableGeometryPoolGuards.js +56 -23
- package/dist/enableGeometryPoolGuards.js.map +1 -1
- package/dist/frustum.d.ts +2 -1
- package/dist/frustum.d.ts.map +1 -1
- package/dist/frustum.js +3 -3
- package/dist/frustum.js.map +1 -1
- package/dist/geometryPoolGuards.d.ts +3 -3
- package/dist/geometryPoolGuards.d.ts.map +1 -1
- package/dist/geometryPoolGuards.js +3 -0
- package/dist/geometryPoolGuards.js.map +1 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -1
- package/dist/index.js.map +1 -1
- package/dist/matrix.d.ts +3 -1
- package/dist/matrix.d.ts.map +1 -1
- package/dist/matrix.js +3 -2
- package/dist/matrix.js.map +1 -1
- package/dist/matrix3.d.ts +6 -4
- package/dist/matrix3.d.ts.map +1 -1
- package/dist/matrix3.js +13 -27
- package/dist/matrix3.js.map +1 -1
- package/dist/matrix3Pool.d.ts +1 -1
- package/dist/matrix3Pool.d.ts.map +1 -1
- package/dist/matrix3Pool.js +4 -4
- package/dist/matrix3Pool.js.map +1 -1
- package/dist/matrix4.d.ts +5 -3
- package/dist/matrix4.d.ts.map +1 -1
- package/dist/matrix4.js +12 -40
- package/dist/matrix4.js.map +1 -1
- package/dist/matrix4Pool.d.ts +1 -1
- package/dist/matrix4Pool.d.ts.map +1 -1
- package/dist/matrix4Pool.js +4 -4
- package/dist/matrix4Pool.js.map +1 -1
- package/dist/matrixPool.d.ts +1 -1
- package/dist/matrixPool.d.ts.map +1 -1
- package/dist/matrixPool.js +4 -4
- package/dist/matrixPool.js.map +1 -1
- package/dist/obb.d.ts +2 -1
- package/dist/obb.d.ts.map +1 -1
- package/dist/obb.js +2 -2
- package/dist/obb.js.map +1 -1
- package/dist/plane.d.ts +2 -1
- package/dist/plane.d.ts.map +1 -1
- package/dist/plane.js +2 -2
- package/dist/plane.js.map +1 -1
- package/dist/quaternion.d.ts +2 -1
- package/dist/quaternion.d.ts.map +1 -1
- package/dist/quaternion.js +2 -2
- package/dist/quaternion.js.map +1 -1
- package/dist/quaternionPool.d.ts +1 -1
- package/dist/quaternionPool.d.ts.map +1 -1
- package/dist/quaternionPool.js +4 -4
- package/dist/quaternionPool.js.map +1 -1
- package/dist/ray3d.d.ts +2 -1
- package/dist/ray3d.d.ts.map +1 -1
- package/dist/ray3d.js +3 -3
- package/dist/ray3d.js.map +1 -1
- package/dist/rectangle.d.ts +2 -1
- package/dist/rectangle.d.ts.map +1 -1
- package/dist/rectangle.js +2 -2
- package/dist/rectangle.js.map +1 -1
- package/dist/rectanglePool.d.ts +1 -1
- package/dist/rectanglePool.d.ts.map +1 -1
- package/dist/rectanglePool.js +4 -4
- package/dist/rectanglePool.js.map +1 -1
- package/dist/runtime.d.ts +29 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +29 -0
- package/dist/runtime.js.map +1 -0
- package/dist/transform2d.d.ts +2 -1
- package/dist/transform2d.d.ts.map +1 -1
- package/dist/transform2d.js +2 -2
- package/dist/transform2d.js.map +1 -1
- package/dist/transform3d.d.ts +2 -1
- package/dist/transform3d.d.ts.map +1 -1
- package/dist/transform3d.js +5 -5
- package/dist/transform3d.js.map +1 -1
- package/dist/types.d.ts +145 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/vector2.d.ts +2 -1
- package/dist/vector2.d.ts.map +1 -1
- package/dist/vector2.js +2 -2
- package/dist/vector2.js.map +1 -1
- package/dist/vector2Pool.d.ts +1 -1
- package/dist/vector2Pool.d.ts.map +1 -1
- package/dist/vector2Pool.js +4 -4
- package/dist/vector2Pool.js.map +1 -1
- package/dist/vector3.d.ts +2 -1
- package/dist/vector3.d.ts.map +1 -1
- package/dist/vector3.js +2 -2
- package/dist/vector3.js.map +1 -1
- package/dist/vector3Pool.d.ts +1 -1
- package/dist/vector3Pool.d.ts.map +1 -1
- package/dist/vector3Pool.js +4 -4
- package/dist/vector3Pool.js.map +1 -1
- package/dist/vector4.d.ts +2 -1
- package/dist/vector4.d.ts.map +1 -1
- package/dist/vector4.js +2 -2
- package/dist/vector4.js.map +1 -1
- package/dist/vector4Pool.d.ts +1 -1
- package/dist/vector4Pool.d.ts.map +1 -1
- package/dist/vector4Pool.js +4 -4
- package/dist/vector4Pool.js.map +1 -1
- package/package.json +7 -6
- package/src/aabb.test.ts +3 -2
- package/src/boundingSphere.test.ts +4 -3
- package/src/capsule.test.ts +1 -1
- package/src/enableGeometryPoolGuards.test.ts +31 -24
- package/src/frustum.test.ts +5 -4
- package/src/geometryPoolGuards.test.ts +14 -1
- package/src/matrix.test.ts +2 -2
- package/src/matrix3.test.ts +59 -63
- package/src/matrix3Pool.test.ts +2 -2
- package/src/matrix4.test.ts +42 -51
- package/src/matrix4Pool.test.ts +2 -2
- package/src/matrixPool.test.ts +2 -2
- package/src/obb.test.ts +7 -5
- package/src/plane.test.ts +1 -1
- package/src/quaternion.test.ts +2 -2
- package/src/ray3d.test.ts +8 -8
- package/src/rectangle.test.ts +2 -2
- package/src/rectanglePool.test.ts +2 -2
- package/src/transform2d.test.ts +2 -2
- package/src/transform3d.test.ts +4 -4
- package/src/typedarray.test.ts +1 -1
- package/src/vector2.test.ts +2 -2
- package/src/vector2Pool.test.ts +2 -2
- package/src/vector3.test.ts +2 -2
- package/src/vector3Pool.test.ts +2 -2
- package/src/vector4.test.ts +2 -2
- package/src/vector4Pool.test.ts +2 -2
package/src/matrix3.test.ts
CHANGED
|
@@ -7,7 +7,9 @@ import {
|
|
|
7
7
|
copyMatrix3RowToVector3,
|
|
8
8
|
createMatrix,
|
|
9
9
|
createMatrix3,
|
|
10
|
+
createMatrix3FromValues,
|
|
10
11
|
createMatrix4,
|
|
12
|
+
createMatrix4FromValues,
|
|
11
13
|
createVector3,
|
|
12
14
|
equalsMatrix3,
|
|
13
15
|
getMatrix3Determinant,
|
|
@@ -28,9 +30,9 @@ import {
|
|
|
28
30
|
transposeMatrix3,
|
|
29
31
|
writeMatrix3ToFloat32Array,
|
|
30
32
|
} from '@flighthq/geometry/contract';
|
|
31
|
-
import type { Matrix3 } from '@flighthq/types/contract';
|
|
32
33
|
|
|
33
|
-
import { initializeMatrix3 } from './matrix3';
|
|
34
|
+
import { initializeMatrix3 } from './matrix3.ts';
|
|
35
|
+
import type { Matrix3 } from './types.ts';
|
|
34
36
|
|
|
35
37
|
// Matrix3 storage is column-major: element (row r, column c) lives at m[3 * c + r], matching
|
|
36
38
|
// Matrix4 and the GL/GLSL/WGSL uniform ABI. A matrix-like {m} built from a raw Float32Array below
|
|
@@ -39,7 +41,7 @@ import { initializeMatrix3 } from './matrix3';
|
|
|
39
41
|
|
|
40
42
|
describe('cloneMatrix3', () => {
|
|
41
43
|
it('should clone the matrix correctly', () => {
|
|
42
|
-
const m1 =
|
|
44
|
+
const m1 = createMatrix3FromValues(2, 3, 4, 5, 6, 7, 8, 9, 10);
|
|
43
45
|
const m2 = cloneMatrix3(m1);
|
|
44
46
|
expect(getMatrix3Element(m2, 0, 0)).toBe(2);
|
|
45
47
|
expect(getMatrix3Element(m2, 0, 1)).toBe(3);
|
|
@@ -76,7 +78,7 @@ describe('cloneMatrix3', () => {
|
|
|
76
78
|
|
|
77
79
|
describe('copyMatrix3', () => {
|
|
78
80
|
it('should copy matrix values from another matrix', () => {
|
|
79
|
-
const m1 =
|
|
81
|
+
const m1 = createMatrix3FromValues(2, 3, 4, 5, 6, 7, 8, 9, 10);
|
|
80
82
|
const m2 = createMatrix3();
|
|
81
83
|
copyMatrix3(m2, m1);
|
|
82
84
|
expect(getMatrix3Element(m2, 0, 0)).toBe(2);
|
|
@@ -91,7 +93,7 @@ describe('copyMatrix3', () => {
|
|
|
91
93
|
});
|
|
92
94
|
|
|
93
95
|
it('supports out === source', () => {
|
|
94
|
-
const matrix =
|
|
96
|
+
const matrix = createMatrix3FromValues(2, 3, 4, 5, 6, 7, 8, 9, 10);
|
|
95
97
|
copyMatrix3(matrix, matrix);
|
|
96
98
|
expect(Array.from(matrix.m)).toEqual([2, 5, 8, 3, 6, 9, 4, 7, 10]);
|
|
97
99
|
});
|
|
@@ -135,7 +137,7 @@ describe('copyMatrix3ColumnFromVector3', () => {
|
|
|
135
137
|
|
|
136
138
|
describe('copyMatrix3ColumnToVector3', () => {
|
|
137
139
|
it('should copy column to a Vector3 from a Matrix3', () => {
|
|
138
|
-
const m =
|
|
140
|
+
const m = createMatrix3FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
|
139
141
|
const v = createVector3();
|
|
140
142
|
copyMatrix3ColumnToVector3(v, 0, m); // column 0
|
|
141
143
|
expect(v.x).toBe(1);
|
|
@@ -144,7 +146,7 @@ describe('copyMatrix3ColumnToVector3', () => {
|
|
|
144
146
|
});
|
|
145
147
|
|
|
146
148
|
it('should copy column 1 into Vector3', () => {
|
|
147
|
-
const m =
|
|
149
|
+
const m = createMatrix3FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
|
148
150
|
const v = createVector3();
|
|
149
151
|
copyMatrix3ColumnToVector3(v, 1, m);
|
|
150
152
|
expect(v.x).toBe(2);
|
|
@@ -153,7 +155,7 @@ describe('copyMatrix3ColumnToVector3', () => {
|
|
|
153
155
|
});
|
|
154
156
|
|
|
155
157
|
it('should copy column 2 into Vector3', () => {
|
|
156
|
-
const m =
|
|
158
|
+
const m = createMatrix3FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
|
157
159
|
const v = createVector3();
|
|
158
160
|
copyMatrix3ColumnToVector3(v, 2, m);
|
|
159
161
|
expect(v.x).toBe(3);
|
|
@@ -217,7 +219,7 @@ describe('copyMatrix3RowFromVector3', () => {
|
|
|
217
219
|
|
|
218
220
|
describe('copyMatrix3RowToVector3', () => {
|
|
219
221
|
it('should copy row to a Vector3 from a Matrix3', () => {
|
|
220
|
-
const m =
|
|
222
|
+
const m = createMatrix3FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
|
221
223
|
const v = createVector3();
|
|
222
224
|
copyMatrix3RowToVector3(v, 0, m); // row 0
|
|
223
225
|
expect(v.x).toBe(1); // m.a
|
|
@@ -226,7 +228,7 @@ describe('copyMatrix3RowToVector3', () => {
|
|
|
226
228
|
});
|
|
227
229
|
|
|
228
230
|
it('should copy row 1 (b, d, ty)', () => {
|
|
229
|
-
const m =
|
|
231
|
+
const m = createMatrix3FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
|
230
232
|
const v = createVector3();
|
|
231
233
|
copyMatrix3RowToVector3(v, 1, m);
|
|
232
234
|
expect(v.x).toBe(4);
|
|
@@ -262,8 +264,15 @@ describe('copyMatrix3RowToVector3', () => {
|
|
|
262
264
|
});
|
|
263
265
|
|
|
264
266
|
describe('createMatrix3', () => {
|
|
265
|
-
it('
|
|
266
|
-
const m = createMatrix3(
|
|
267
|
+
it('initializes to identity', () => {
|
|
268
|
+
const m = createMatrix3();
|
|
269
|
+
expect(Array.from(m.m)).toEqual([1, 0, 0, 0, 1, 0, 0, 0, 1]);
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
describe('createMatrix3FromValues', () => {
|
|
274
|
+
it('initializes matrix with provided values', () => {
|
|
275
|
+
const m = createMatrix3FromValues(2, 3, 4, 5, 6, 7, 8, 9, 10);
|
|
267
276
|
expect(getMatrix3Element(m, 0, 0)).toBe(2);
|
|
268
277
|
expect(getMatrix3Element(m, 0, 1)).toBe(3);
|
|
269
278
|
expect(getMatrix3Element(m, 0, 2)).toBe(4);
|
|
@@ -276,22 +285,9 @@ describe('createMatrix3', () => {
|
|
|
276
285
|
});
|
|
277
286
|
|
|
278
287
|
it('stores its (row, column) arguments column-major', () => {
|
|
279
|
-
const m =
|
|
288
|
+
const m = createMatrix3FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
|
280
289
|
expect(Array.from(m.m)).toEqual([1, 4, 7, 2, 5, 8, 3, 6, 9]);
|
|
281
290
|
});
|
|
282
|
-
|
|
283
|
-
it('should default to identity matrix when no values are provided', () => {
|
|
284
|
-
const m = createMatrix3();
|
|
285
|
-
expect(getMatrix3Element(m, 0, 0)).toBe(1);
|
|
286
|
-
expect(getMatrix3Element(m, 0, 1)).toBe(0);
|
|
287
|
-
expect(getMatrix3Element(m, 0, 2)).toBe(0);
|
|
288
|
-
expect(getMatrix3Element(m, 1, 0)).toBe(0);
|
|
289
|
-
expect(getMatrix3Element(m, 1, 1)).toBe(1);
|
|
290
|
-
expect(getMatrix3Element(m, 1, 2)).toBe(0);
|
|
291
|
-
expect(getMatrix3Element(m, 2, 0)).toBe(0);
|
|
292
|
-
expect(getMatrix3Element(m, 2, 1)).toBe(0);
|
|
293
|
-
expect(getMatrix3Element(m, 2, 2)).toBe(1);
|
|
294
|
-
});
|
|
295
291
|
});
|
|
296
292
|
|
|
297
293
|
describe('equalsMatrix3', () => {
|
|
@@ -325,7 +321,7 @@ describe('equalsMatrix3', () => {
|
|
|
325
321
|
});
|
|
326
322
|
|
|
327
323
|
it('should return true if one object is matrix-like and one is not', () => {
|
|
328
|
-
const mat1 =
|
|
324
|
+
const mat1 = createMatrix3FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
|
329
325
|
// Column-major storage of the same matrix.
|
|
330
326
|
const mat2 = { m: new Float32Array([1, 4, 7, 2, 5, 8, 3, 6, 9]) };
|
|
331
327
|
expect(equalsMatrix3(mat1, mat2)).toBe(true);
|
|
@@ -345,18 +341,18 @@ describe('getMatrix3Determinant', () => {
|
|
|
345
341
|
|
|
346
342
|
it('returns 0 for a singular matrix', () => {
|
|
347
343
|
// Two identical rows → determinant = 0.
|
|
348
|
-
expect(getMatrix3Determinant(
|
|
344
|
+
expect(getMatrix3Determinant(createMatrix3FromValues(1, 2, 3, 1, 2, 3, 4, 5, 6))).toBeCloseTo(0, 6);
|
|
349
345
|
});
|
|
350
346
|
|
|
351
347
|
it('returns a negative value when a row is negated (sign flip)', () => {
|
|
352
348
|
// Negate one row flips sign of det. Identity det = 1, negate row 0 → -1.
|
|
353
|
-
expect(getMatrix3Determinant(
|
|
349
|
+
expect(getMatrix3Determinant(createMatrix3FromValues(-1, 0, 0, 0, 1, 0, 0, 0, 1))).toBeCloseTo(-1, 6);
|
|
354
350
|
});
|
|
355
351
|
});
|
|
356
352
|
|
|
357
353
|
describe('getMatrix3Element', () => {
|
|
358
354
|
it('returns the element at the given row and column', () => {
|
|
359
|
-
const m =
|
|
355
|
+
const m = createMatrix3FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
|
360
356
|
expect(getMatrix3Element(m, 0, 0)).toBe(1);
|
|
361
357
|
expect(getMatrix3Element(m, 0, 1)).toBe(2);
|
|
362
358
|
expect(getMatrix3Element(m, 0, 2)).toBe(3);
|
|
@@ -374,7 +370,7 @@ describe('initializeMatrix3', () => {
|
|
|
374
370
|
describe('inverseMatrix3', () => {
|
|
375
371
|
it('should invert the matrix correctly', () => {
|
|
376
372
|
// A scale of 2 with translation of (5, 3): rows [2,0,5],[0,2,3],[0,0,1].
|
|
377
|
-
const m =
|
|
373
|
+
const m = createMatrix3FromValues(2, 0, 5, 0, 2, 3, 0, 0, 1);
|
|
378
374
|
|
|
379
375
|
const out = createMatrix3();
|
|
380
376
|
inverseMatrix3(out, m);
|
|
@@ -389,8 +385,8 @@ describe('inverseMatrix3', () => {
|
|
|
389
385
|
});
|
|
390
386
|
|
|
391
387
|
it('should not depend on initial out matrix values', () => {
|
|
392
|
-
const source =
|
|
393
|
-
const out =
|
|
388
|
+
const source = createMatrix3FromValues(2, 1, 5, 3, 4, 6, 0, 0, 1);
|
|
389
|
+
const out = createMatrix3FromValues(9, 9, 9, 9, 9, 9, 0, 0, 1);
|
|
394
390
|
|
|
395
391
|
inverseMatrix3(out, source);
|
|
396
392
|
|
|
@@ -417,7 +413,7 @@ describe('inverseMatrix3', () => {
|
|
|
417
413
|
});
|
|
418
414
|
|
|
419
415
|
it('supports out === source for affine matrices', () => {
|
|
420
|
-
const matrix =
|
|
416
|
+
const matrix = createMatrix3FromValues(2, 1, 5, 3, 4, 6, 0, 0, 1);
|
|
421
417
|
const expected = createMatrix3();
|
|
422
418
|
inverseMatrix3(expected, matrix);
|
|
423
419
|
|
|
@@ -427,7 +423,7 @@ describe('inverseMatrix3', () => {
|
|
|
427
423
|
});
|
|
428
424
|
|
|
429
425
|
it('supports out === source for non-affine matrices', () => {
|
|
430
|
-
const matrix =
|
|
426
|
+
const matrix = createMatrix3FromValues(1, 2, 3, 0, 1, 4, 5, 6, 0);
|
|
431
427
|
const expected = createMatrix3();
|
|
432
428
|
inverseMatrix3(expected, matrix);
|
|
433
429
|
|
|
@@ -437,13 +433,13 @@ describe('inverseMatrix3', () => {
|
|
|
437
433
|
});
|
|
438
434
|
|
|
439
435
|
it('returns true on success', () => {
|
|
440
|
-
const m =
|
|
436
|
+
const m = createMatrix3FromValues(2, 0, 5, 0, 2, 3, 0, 0, 1);
|
|
441
437
|
const out = createMatrix3();
|
|
442
438
|
expect(inverseMatrix3(out, m)).toBe(true);
|
|
443
439
|
});
|
|
444
440
|
|
|
445
441
|
it('returns false and fills NaN for a singular affine matrix', () => {
|
|
446
|
-
const m =
|
|
442
|
+
const m = createMatrix3FromValues(0, 0, 5, 0, 0, 3, 0, 0, 1); // zero linear part -> det 0
|
|
447
443
|
const out = createMatrix3();
|
|
448
444
|
expect(inverseMatrix3(out, m)).toBe(false);
|
|
449
445
|
expect(out.m[0]).toBeNaN();
|
|
@@ -451,14 +447,14 @@ describe('inverseMatrix3', () => {
|
|
|
451
447
|
});
|
|
452
448
|
|
|
453
449
|
it('returns false and fills NaN for a singular non-affine matrix', () => {
|
|
454
|
-
const m =
|
|
450
|
+
const m = createMatrix3FromValues(1, 2, 3, 2, 4, 6, 1, 1, 1); // rows 0,1 linearly dependent -> det 0
|
|
455
451
|
const out = createMatrix3();
|
|
456
452
|
expect(inverseMatrix3(out, m)).toBe(false);
|
|
457
453
|
expect(out.m[0]).toBeNaN();
|
|
458
454
|
});
|
|
459
455
|
|
|
460
456
|
it('returns false for a singular matrix with out === source', () => {
|
|
461
|
-
const m =
|
|
457
|
+
const m = createMatrix3FromValues(0, 0, 5, 0, 0, 3, 0, 0, 1);
|
|
462
458
|
expect(inverseMatrix3(m, m)).toBe(false);
|
|
463
459
|
expect(m.m[0]).toBeNaN();
|
|
464
460
|
});
|
|
@@ -471,21 +467,21 @@ describe('isAffineMatrix3', () => {
|
|
|
471
467
|
});
|
|
472
468
|
|
|
473
469
|
it('returns false when last row is not (0, 0, 1)', () => {
|
|
474
|
-
const m =
|
|
470
|
+
const m = createMatrix3FromValues(1, 0, 0, 0, 1, 0, 1, 0, 1);
|
|
475
471
|
expect(isAffineMatrix3(m)).toBe(false);
|
|
476
472
|
});
|
|
477
473
|
|
|
478
474
|
it('returns true for a matrix with translation', () => {
|
|
479
|
-
const m =
|
|
475
|
+
const m = createMatrix3FromValues(1, 0, 5, 0, 1, 10, 0, 0, 1);
|
|
480
476
|
expect(isAffineMatrix3(m)).toBe(true);
|
|
481
477
|
});
|
|
482
478
|
});
|
|
483
479
|
|
|
484
480
|
describe('multiplyMatrix3', () => {
|
|
485
481
|
it('multiplies a non-affine matrix into distinct and aliased outputs', () => {
|
|
486
|
-
const a =
|
|
487
|
-
const b =
|
|
488
|
-
const expected =
|
|
482
|
+
const a = createMatrix3FromValues(1, 2, 3, 4, 5, 6, 7, 8, 10);
|
|
483
|
+
const b = createMatrix3FromValues(2, 0, 1, 1, 3, 0, 0, 2, 4);
|
|
484
|
+
const expected = createMatrix3FromValues(4, 12, 13, 13, 27, 28, 22, 44, 47);
|
|
489
485
|
const out = createMatrix3();
|
|
490
486
|
multiplyMatrix3(out, a, b);
|
|
491
487
|
expect(equalsMatrix3(out, expected)).toBe(true);
|
|
@@ -495,8 +491,8 @@ describe('multiplyMatrix3', () => {
|
|
|
495
491
|
});
|
|
496
492
|
|
|
497
493
|
it('should support out === a', () => {
|
|
498
|
-
const a =
|
|
499
|
-
const b =
|
|
494
|
+
const a = createMatrix3FromValues(2, 3, 4, 5, 7, 8, 0, 0, 1);
|
|
495
|
+
const b = createMatrix3FromValues(11, 13, 17, 19, 23, 29, 0, 0, 1);
|
|
500
496
|
const expected = createMatrix3();
|
|
501
497
|
multiplyMatrix3(expected, a, b);
|
|
502
498
|
|
|
@@ -505,8 +501,8 @@ describe('multiplyMatrix3', () => {
|
|
|
505
501
|
});
|
|
506
502
|
|
|
507
503
|
it('should support out === b', () => {
|
|
508
|
-
const a =
|
|
509
|
-
const b =
|
|
504
|
+
const a = createMatrix3FromValues(2, 3, 4, 5, 7, 8, 0, 0, 1);
|
|
505
|
+
const b = createMatrix3FromValues(11, 13, 17, 19, 23, 29, 0, 0, 1);
|
|
510
506
|
const expected = createMatrix3();
|
|
511
507
|
multiplyMatrix3(expected, a, b);
|
|
512
508
|
|
|
@@ -516,7 +512,7 @@ describe('multiplyMatrix3', () => {
|
|
|
516
512
|
|
|
517
513
|
it('should multiply identity correctly', () => {
|
|
518
514
|
const a = createMatrix3();
|
|
519
|
-
const b =
|
|
515
|
+
const b = createMatrix3FromValues(2, 3, 4, 5, 6, 7, 0, 0, 1);
|
|
520
516
|
const out = createMatrix3();
|
|
521
517
|
multiplyMatrix3(out, a, b);
|
|
522
518
|
expect(equalsMatrix3(out, b)).toBe(true);
|
|
@@ -524,8 +520,8 @@ describe('multiplyMatrix3', () => {
|
|
|
524
520
|
|
|
525
521
|
it('composes an affine scale then translate (row/column semantics)', () => {
|
|
526
522
|
// a = scale(2,2), b = translate(5,5). a * b applies b then a to a column vector.
|
|
527
|
-
const a =
|
|
528
|
-
const b =
|
|
523
|
+
const a = createMatrix3FromValues(2, 0, 0, 0, 2, 0, 0, 0, 1);
|
|
524
|
+
const b = createMatrix3FromValues(1, 0, 5, 0, 1, 5, 0, 0, 1);
|
|
529
525
|
multiplyMatrix3(a, a, b);
|
|
530
526
|
expect(getMatrix3Element(a, 0, 2)).toBe(10);
|
|
531
527
|
expect(getMatrix3Element(a, 1, 2)).toBe(10);
|
|
@@ -543,7 +539,7 @@ describe('multiplyMatrix3', () => {
|
|
|
543
539
|
|
|
544
540
|
describe('rotateMatrix3', () => {
|
|
545
541
|
it('should rotate the matrix correctly', () => {
|
|
546
|
-
const m =
|
|
542
|
+
const m = createMatrix3FromValues(1, 0, 0, 0, 1, 0, 0, 0, 1);
|
|
547
543
|
const out = createMatrix3();
|
|
548
544
|
rotateMatrix3(out, m, Math.PI / 2); // 90 degrees
|
|
549
545
|
// Rotation (0,1)-plane: (0,0)=0, (0,1)=-1, (1,0)=1, (1,1)=0.
|
|
@@ -567,7 +563,7 @@ describe('rotateMatrix3', () => {
|
|
|
567
563
|
});
|
|
568
564
|
|
|
569
565
|
it('supports out === source', () => {
|
|
570
|
-
const matrix =
|
|
566
|
+
const matrix = createMatrix3FromValues(2, 3, 4, 5, 7, 8, 11, 13, 17);
|
|
571
567
|
const expected = createMatrix3();
|
|
572
568
|
rotateMatrix3(expected, matrix, Math.PI / 2);
|
|
573
569
|
|
|
@@ -594,7 +590,7 @@ describe('scaleMatrix3', () => {
|
|
|
594
590
|
});
|
|
595
591
|
|
|
596
592
|
it('supports out === source', () => {
|
|
597
|
-
const matrix =
|
|
593
|
+
const matrix = createMatrix3FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
|
598
594
|
scaleMatrix3(matrix, matrix, 2, 3);
|
|
599
595
|
expect(Array.from(matrix.m)).toEqual([2, 8, 14, 6, 15, 24, 3, 6, 9]);
|
|
600
596
|
});
|
|
@@ -744,7 +740,7 @@ describe('setMatrix3FromMatrix4', () => {
|
|
|
744
740
|
|
|
745
741
|
describe('setMatrix3Identity', () => {
|
|
746
742
|
it('resets a matrix to the identity', () => {
|
|
747
|
-
const m =
|
|
743
|
+
const m = createMatrix3FromValues(2, 3, 4, 5, 6, 7, 8, 9, 10);
|
|
748
744
|
setMatrix3Identity(m);
|
|
749
745
|
expect(getMatrix3Element(m, 0, 0)).toBe(1);
|
|
750
746
|
expect(getMatrix3Element(m, 1, 1)).toBe(1);
|
|
@@ -757,7 +753,7 @@ describe('setMatrix3Identity', () => {
|
|
|
757
753
|
describe('setMatrix3NormalFromMatrix4', () => {
|
|
758
754
|
it('equals the rotation basis for an orthonormal matrix', () => {
|
|
759
755
|
// A 90-degree rotation about z (column-major Matrix4): +x -> +y.
|
|
760
|
-
const m4 =
|
|
756
|
+
const m4 = createMatrix4FromValues(0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
|
761
757
|
const out = createMatrix3();
|
|
762
758
|
setMatrix3NormalFromMatrix4(out, m4);
|
|
763
759
|
// For a pure rotation, normal matrix == rotation R (+x -> +y): (0,0)=0,(0,1)=-1,(1,0)=1,(1,1)=0.
|
|
@@ -771,7 +767,7 @@ describe('setMatrix3NormalFromMatrix4', () => {
|
|
|
771
767
|
it('uploads column-major so a GL upload needs no transpose', () => {
|
|
772
768
|
// The whole point of the migration: the normal matrix' storage matches uniformMatrix3fv(false).
|
|
773
769
|
// 90-degree rotation about z, column-major storage: R = [[0,-1,0],[1,0,0],[0,0,1]] -> [0,1,0,-1,0,0,0,0,1].
|
|
774
|
-
const m4 =
|
|
770
|
+
const m4 = createMatrix4FromValues(0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
|
775
771
|
const out = createMatrix3();
|
|
776
772
|
setMatrix3NormalFromMatrix4(out, m4);
|
|
777
773
|
expect(out.m[0]).toBeCloseTo(0, 5);
|
|
@@ -782,7 +778,7 @@ describe('setMatrix3NormalFromMatrix4', () => {
|
|
|
782
778
|
|
|
783
779
|
it('keeps a normal perpendicular under non-uniform scale', () => {
|
|
784
780
|
// Scale x by 2, y by 1: a surface normal (1,1,0) on a plane should stay perpendicular.
|
|
785
|
-
const m4 =
|
|
781
|
+
const m4 = createMatrix4FromValues(2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
|
786
782
|
const normalMatrix = createMatrix3();
|
|
787
783
|
setMatrix3NormalFromMatrix4(normalMatrix, m4);
|
|
788
784
|
// Inverse-transpose of diag(2,1,1) = diag(0.5,1,1).
|
|
@@ -810,7 +806,7 @@ describe('translateMatrix3', () => {
|
|
|
810
806
|
});
|
|
811
807
|
|
|
812
808
|
it('supports out === source', () => {
|
|
813
|
-
const matrix =
|
|
809
|
+
const matrix = createMatrix3FromValues(1, 2, 3, 4, 5, 6, 0, 0, 1);
|
|
814
810
|
translateMatrix3(matrix, matrix, 2, 3);
|
|
815
811
|
expect(Array.from(matrix.m)).toEqual([1, 4, 0, 2, 5, 0, 11, 29, 1]);
|
|
816
812
|
});
|
|
@@ -818,7 +814,7 @@ describe('translateMatrix3', () => {
|
|
|
818
814
|
|
|
819
815
|
describe('transposeMatrix3', () => {
|
|
820
816
|
it('swaps rows and columns', () => {
|
|
821
|
-
const m =
|
|
817
|
+
const m = createMatrix3FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
|
822
818
|
const out = createMatrix3();
|
|
823
819
|
transposeMatrix3(out, m);
|
|
824
820
|
// Transpose of rows [1,2,3],[4,5,6],[7,8,9] is rows [1,4,7],[2,5,8],[3,6,9];
|
|
@@ -829,7 +825,7 @@ describe('transposeMatrix3', () => {
|
|
|
829
825
|
});
|
|
830
826
|
|
|
831
827
|
it('supports out === source', () => {
|
|
832
|
-
const m =
|
|
828
|
+
const m = createMatrix3FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
|
833
829
|
transposeMatrix3(m, m);
|
|
834
830
|
expect(Array.from(m.m)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
835
831
|
});
|
|
@@ -843,7 +839,7 @@ describe('transposeMatrix3', () => {
|
|
|
843
839
|
});
|
|
844
840
|
describe('writeMatrix3ToFloat32Array', () => {
|
|
845
841
|
it('writes 9 values starting at the given offset', () => {
|
|
846
|
-
const m =
|
|
842
|
+
const m = createMatrix3FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
|
847
843
|
const data = new Float32Array(10);
|
|
848
844
|
writeMatrix3ToFloat32Array(data, 1, m);
|
|
849
845
|
// Column-major storage of the matrix, written verbatim.
|
|
@@ -851,7 +847,7 @@ describe('writeMatrix3ToFloat32Array', () => {
|
|
|
851
847
|
});
|
|
852
848
|
|
|
853
849
|
it('round-trips through setMatrix3FromFloat32Array', () => {
|
|
854
|
-
const m =
|
|
850
|
+
const m = createMatrix3FromValues(9, 8, 7, 6, 5, 4, 3, 2, 1);
|
|
855
851
|
const data = new Float32Array(9);
|
|
856
852
|
writeMatrix3ToFloat32Array(data, 0, m);
|
|
857
853
|
const m2 = createMatrix3();
|
package/src/matrix3Pool.test.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { attachEntityBinding, getEntityBinding } from '@flighthq/entity/contract';
|
|
2
2
|
import { getMatrix3Element } from '@flighthq/geometry/contract';
|
|
3
|
-
import type { Matrix3 } from '@flighthq/types/contract';
|
|
4
3
|
|
|
5
|
-
import { acquireIdentityMatrix3, acquireMatrix3, clearMatrix3Pool, releaseMatrix3 } from './matrix3Pool';
|
|
4
|
+
import { acquireIdentityMatrix3, acquireMatrix3, clearMatrix3Pool, releaseMatrix3 } from './matrix3Pool.ts';
|
|
5
|
+
import type { Matrix3 } from './types.ts';
|
|
6
6
|
|
|
7
7
|
beforeEach(() => {
|
|
8
8
|
clearMatrix3Pool();
|
package/src/matrix4.test.ts
CHANGED
|
@@ -12,8 +12,10 @@ import {
|
|
|
12
12
|
copyMatrix4RowToVector4,
|
|
13
13
|
createMatrix,
|
|
14
14
|
createMatrix3,
|
|
15
|
+
createMatrix3FromValues,
|
|
15
16
|
createMatrix4,
|
|
16
17
|
createMatrix4From2D,
|
|
18
|
+
createMatrix4FromValues,
|
|
17
19
|
createOrthographicMatrix4,
|
|
18
20
|
createPerspectiveMatrix4,
|
|
19
21
|
createQuaternion,
|
|
@@ -56,9 +58,9 @@ import {
|
|
|
56
58
|
transposeMatrix4,
|
|
57
59
|
writeMatrix4ToFloat32Array,
|
|
58
60
|
} from '@flighthq/geometry/contract';
|
|
59
|
-
import type { Matrix, Matrix4 } from '@flighthq/types/contract';
|
|
60
61
|
|
|
61
|
-
import { initializeMatrix4 } from './matrix4';
|
|
62
|
+
import { initializeMatrix4 } from './matrix4.ts';
|
|
63
|
+
import type { Matrix, Matrix4 } from './types.ts';
|
|
62
64
|
|
|
63
65
|
const X_AXIS = { x: 1, y: 0, z: 0, w: 0 };
|
|
64
66
|
const Y_AXIS = { x: 0, y: 1, z: 0, w: 0 };
|
|
@@ -287,7 +289,7 @@ describe('appendTranslationMatrix4', () => {
|
|
|
287
289
|
it('copies the whole source matrix when out is a distinct object', () => {
|
|
288
290
|
const source = discriminatingMatrix4();
|
|
289
291
|
const before = Array.from(source.m);
|
|
290
|
-
const out =
|
|
292
|
+
const out = createMatrix4FromValues(9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9);
|
|
291
293
|
const aliased = cloneMatrix4(source);
|
|
292
294
|
|
|
293
295
|
appendTranslationMatrix4(out, source, 1, 2, 3);
|
|
@@ -308,7 +310,7 @@ describe('cloneMatrix4', () => {
|
|
|
308
310
|
});
|
|
309
311
|
|
|
310
312
|
it('copies all values from the source matrix', () => {
|
|
311
|
-
const source =
|
|
313
|
+
const source = createMatrix4FromValues(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53);
|
|
312
314
|
|
|
313
315
|
const clone = cloneMatrix4(source);
|
|
314
316
|
|
|
@@ -368,7 +370,7 @@ describe('composeMatrix4', () => {
|
|
|
368
370
|
|
|
369
371
|
describe('copyMatrix4', () => {
|
|
370
372
|
it('copies all values from source into out', () => {
|
|
371
|
-
const source =
|
|
373
|
+
const source = createMatrix4FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
|
|
372
374
|
|
|
373
375
|
const out = createMatrix4();
|
|
374
376
|
copyMatrix4(out, source);
|
|
@@ -434,7 +436,7 @@ describe('copyMatrix4ColumnFromVector4', () => {
|
|
|
434
436
|
// column catches a row/column transposition or a stray write that a single-index check misses.
|
|
435
437
|
it('writes column c into elements 4c..4c+3 for every column', () => {
|
|
436
438
|
for (let column = 0; column < 4; column++) {
|
|
437
|
-
const m =
|
|
439
|
+
const m = createMatrix4FromValues(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
438
440
|
|
|
439
441
|
copyMatrix4ColumnFromVector4(m, column, { x: 1, y: 2, z: 3, w: 4 });
|
|
440
442
|
|
|
@@ -450,7 +452,7 @@ describe('copyMatrix4ColumnFromVector4', () => {
|
|
|
450
452
|
|
|
451
453
|
describe('copyMatrix4ColumnToVector4', () => {
|
|
452
454
|
it('copies values from column 1 into a vector', () => {
|
|
453
|
-
const m =
|
|
455
|
+
const m = createMatrix4FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
|
|
454
456
|
|
|
455
457
|
const out = { x: 0, y: 0, z: 0, w: 0 };
|
|
456
458
|
|
|
@@ -473,7 +475,7 @@ describe('copyMatrix4ColumnToVector4', () => {
|
|
|
473
475
|
});
|
|
474
476
|
|
|
475
477
|
it('reads column c from elements 4c..4c+3 for every column', () => {
|
|
476
|
-
const m =
|
|
478
|
+
const m = createMatrix4FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
|
|
477
479
|
|
|
478
480
|
for (let column = 0; column < 4; column++) {
|
|
479
481
|
const out = { x: 0, y: 0, z: 0, w: 0 };
|
|
@@ -527,7 +529,7 @@ describe('copyMatrix4RowFromVector4', () => {
|
|
|
527
529
|
// column write in column-major storage.
|
|
528
530
|
it('writes row r with a stride of four for every row', () => {
|
|
529
531
|
for (let row = 0; row < 4; row++) {
|
|
530
|
-
const m =
|
|
532
|
+
const m = createMatrix4FromValues(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
531
533
|
|
|
532
534
|
copyMatrix4RowFromVector4(m, row, { x: 1, y: 2, z: 3, w: 4 });
|
|
533
535
|
|
|
@@ -543,7 +545,7 @@ describe('copyMatrix4RowFromVector4', () => {
|
|
|
543
545
|
|
|
544
546
|
describe('copyMatrix4RowToVector4', () => {
|
|
545
547
|
it('copies values from row 2 into a vector', () => {
|
|
546
|
-
const m =
|
|
548
|
+
const m = createMatrix4FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
|
|
547
549
|
|
|
548
550
|
const out = { x: 0, y: 0, z: 0, w: 0 };
|
|
549
551
|
|
|
@@ -566,7 +568,7 @@ describe('copyMatrix4RowToVector4', () => {
|
|
|
566
568
|
});
|
|
567
569
|
|
|
568
570
|
it('reads row r with a stride of four for every row', () => {
|
|
569
|
-
const m =
|
|
571
|
+
const m = createMatrix4FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
|
|
570
572
|
|
|
571
573
|
for (let row = 0; row < 4; row++) {
|
|
572
574
|
const out = { x: 0, y: 0, z: 0, w: 0 };
|
|
@@ -591,34 +593,6 @@ describe('createMatrix4', () => {
|
|
|
591
593
|
expect(m.m).toBeInstanceOf(Float32Array);
|
|
592
594
|
expect(m.m.length).toBe(16);
|
|
593
595
|
});
|
|
594
|
-
|
|
595
|
-
it('overrides only the provided constructor values', () => {
|
|
596
|
-
const m = createMatrix4(
|
|
597
|
-
2, // m00
|
|
598
|
-
undefined,
|
|
599
|
-
undefined,
|
|
600
|
-
undefined,
|
|
601
|
-
undefined,
|
|
602
|
-
3, // m11
|
|
603
|
-
);
|
|
604
|
-
|
|
605
|
-
expect(Array.from(m.m)).toEqual([2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
606
|
-
});
|
|
607
|
-
|
|
608
|
-
it('maps constructor arguments to correct column-major indices', () => {
|
|
609
|
-
const m = createMatrix4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
|
|
610
|
-
|
|
611
|
-
expect(Array.from(m.m)).toEqual([
|
|
612
|
-
// column 0
|
|
613
|
-
1, 2, 3, 4,
|
|
614
|
-
// column 1
|
|
615
|
-
5, 6, 7, 8,
|
|
616
|
-
// column 2
|
|
617
|
-
9, 10, 11, 12,
|
|
618
|
-
// column 3
|
|
619
|
-
13, 14, 15, 16,
|
|
620
|
-
]);
|
|
621
|
-
});
|
|
622
596
|
});
|
|
623
597
|
|
|
624
598
|
describe('createMatrix4From2D', () => {
|
|
@@ -644,6 +618,23 @@ describe('createMatrix4From2D', () => {
|
|
|
644
618
|
});
|
|
645
619
|
});
|
|
646
620
|
|
|
621
|
+
describe('createMatrix4FromValues', () => {
|
|
622
|
+
it('maps constructor arguments to correct column-major indices', () => {
|
|
623
|
+
const m = createMatrix4FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
|
|
624
|
+
|
|
625
|
+
expect(Array.from(m.m)).toEqual([
|
|
626
|
+
// column 0
|
|
627
|
+
1, 2, 3, 4,
|
|
628
|
+
// column 1
|
|
629
|
+
5, 6, 7, 8,
|
|
630
|
+
// column 2
|
|
631
|
+
9, 10, 11, 12,
|
|
632
|
+
// column 3
|
|
633
|
+
13, 14, 15, 16,
|
|
634
|
+
]);
|
|
635
|
+
});
|
|
636
|
+
});
|
|
637
|
+
|
|
647
638
|
describe('createOrthographicMatrix4', () => {
|
|
648
639
|
it('returns a Matrix4 equivalent to setOrtho', () => {
|
|
649
640
|
const m1 = createOrthographicMatrix4(-1, 1, -1, 1, 0.1, 100);
|
|
@@ -780,9 +771,9 @@ describe('equalsMatrix4', () => {
|
|
|
780
771
|
});
|
|
781
772
|
|
|
782
773
|
it('returns true for two matrices with identical values', () => {
|
|
783
|
-
const a =
|
|
774
|
+
const a = createMatrix4FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
|
|
784
775
|
|
|
785
|
-
const b =
|
|
776
|
+
const b = createMatrix4FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
|
|
786
777
|
|
|
787
778
|
expect(equalsMatrix4(a, b)).toBe(true);
|
|
788
779
|
});
|
|
@@ -806,7 +797,7 @@ describe('getMatrix4Determinant', () => {
|
|
|
806
797
|
|
|
807
798
|
describe('getMatrix4Element', () => {
|
|
808
799
|
it('returns the element at the given row and column', () => {
|
|
809
|
-
const m =
|
|
800
|
+
const m = createMatrix4FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
|
|
810
801
|
expect(getMatrix4Element(m, 0, 0)).toBe(1);
|
|
811
802
|
expect(getMatrix4Element(m, 1, 0)).toBe(2);
|
|
812
803
|
expect(getMatrix4Element(m, 0, 1)).toBe(5);
|
|
@@ -1154,8 +1145,8 @@ describe('multiplyMatrix4', () => {
|
|
|
1154
1145
|
});
|
|
1155
1146
|
|
|
1156
1147
|
it('supports out === a', () => {
|
|
1157
|
-
const a =
|
|
1158
|
-
const b =
|
|
1148
|
+
const a = createMatrix4FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
|
|
1149
|
+
const b = createMatrix4FromValues(17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79);
|
|
1159
1150
|
const expected = createMatrix4();
|
|
1160
1151
|
multiplyMatrix4(expected, a, b);
|
|
1161
1152
|
|
|
@@ -1164,8 +1155,8 @@ describe('multiplyMatrix4', () => {
|
|
|
1164
1155
|
});
|
|
1165
1156
|
|
|
1166
1157
|
it('supports out === b', () => {
|
|
1167
|
-
const a =
|
|
1168
|
-
const b =
|
|
1158
|
+
const a = createMatrix4FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
|
|
1159
|
+
const b = createMatrix4FromValues(17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79);
|
|
1169
1160
|
const expected = createMatrix4();
|
|
1170
1161
|
multiplyMatrix4(expected, a, b);
|
|
1171
1162
|
|
|
@@ -1581,7 +1572,7 @@ describe('setMatrix4', () => {
|
|
|
1581
1572
|
});
|
|
1582
1573
|
|
|
1583
1574
|
it('overwrites existing matrix values completely', () => {
|
|
1584
|
-
const m =
|
|
1575
|
+
const m = createMatrix4FromValues(99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99);
|
|
1585
1576
|
|
|
1586
1577
|
setMatrix4(m, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
|
1587
1578
|
|
|
@@ -1738,7 +1729,7 @@ describe('setMatrix4FromMatrix3', () => {
|
|
|
1738
1729
|
|
|
1739
1730
|
it('should handle scaling and translation', () => {
|
|
1740
1731
|
// scale(2,3), translate(5,10)
|
|
1741
|
-
const mat3 =
|
|
1732
|
+
const mat3 = createMatrix3FromValues(2, 0, 5, 0, 3, 10, 0, 0, 1);
|
|
1742
1733
|
|
|
1743
1734
|
const mat = createMatrix4();
|
|
1744
1735
|
setMatrix4FromMatrix3(mat, mat3);
|
|
@@ -1767,7 +1758,7 @@ describe('setMatrix4FromMatrix3', () => {
|
|
|
1767
1758
|
|
|
1768
1759
|
describe('setMatrix4FromQuaternion', () => {
|
|
1769
1760
|
it('identity quaternion writes the identity matrix', () => {
|
|
1770
|
-
const m =
|
|
1761
|
+
const m = createMatrix4FromValues(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2);
|
|
1771
1762
|
setMatrix4FromQuaternion(m, createQuaternion());
|
|
1772
1763
|
expect(Array.from(m.m)).toEqual([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
1773
1764
|
});
|
|
@@ -1787,7 +1778,7 @@ describe('setMatrix4FromQuaternion', () => {
|
|
|
1787
1778
|
|
|
1788
1779
|
describe('setMatrix4Identity', () => {
|
|
1789
1780
|
it('resets a matrix to identity', () => {
|
|
1790
|
-
const m =
|
|
1781
|
+
const m = createMatrix4FromValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
|
|
1791
1782
|
|
|
1792
1783
|
setMatrix4Identity(m);
|
|
1793
1784
|
|
|
@@ -1964,7 +1955,7 @@ describe('translateMatrix4', () => {
|
|
|
1964
1955
|
it('copies the whole source matrix when out is a distinct object', () => {
|
|
1965
1956
|
const source = createMatrix4();
|
|
1966
1957
|
setMatrix4(source, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 7, 8, 9, 1);
|
|
1967
|
-
const out =
|
|
1958
|
+
const out = createMatrix4FromValues(9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9);
|
|
1968
1959
|
const aliased = cloneMatrix4(source);
|
|
1969
1960
|
|
|
1970
1961
|
translateMatrix4(out, source, 1, 2, 3);
|
package/src/matrix4Pool.test.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { attachEntityBinding, getEntityBinding } from '@flighthq/entity/contract';
|
|
2
2
|
import { getMatrix4Element } from '@flighthq/geometry/contract';
|
|
3
|
-
import type { Matrix4 } from '@flighthq/types/contract';
|
|
4
3
|
|
|
5
|
-
import { acquireIdentityMatrix4, acquireMatrix4, clearMatrix4Pool, releaseMatrix4 } from './matrix4Pool';
|
|
4
|
+
import { acquireIdentityMatrix4, acquireMatrix4, clearMatrix4Pool, releaseMatrix4 } from './matrix4Pool.ts';
|
|
5
|
+
import type { Matrix4 } from './types.ts';
|
|
6
6
|
|
|
7
7
|
beforeEach(() => {
|
|
8
8
|
clearMatrix4Pool();
|