@flighthq/geometry 0.1.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/dist/aabb.d.ts +88 -0
- package/dist/aabb.d.ts.map +1 -0
- package/dist/aabb.js +230 -0
- package/dist/aabb.js.map +1 -0
- package/dist/boundingSphere.d.ts +62 -0
- package/dist/boundingSphere.d.ts.map +1 -0
- package/dist/boundingSphere.js +188 -0
- package/dist/boundingSphere.js.map +1 -0
- package/dist/capsule.d.ts +38 -0
- package/dist/capsule.d.ts.map +1 -0
- package/dist/capsule.js +215 -0
- package/dist/capsule.js.map +1 -0
- package/dist/frustum.d.ts +49 -0
- package/dist/frustum.d.ts.map +1 -0
- package/dist/frustum.js +149 -0
- package/dist/frustum.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/matrix.d.ts +152 -0
- package/dist/matrix.d.ts.map +1 -0
- package/dist/matrix.js +488 -0
- package/dist/matrix.js.map +1 -0
- package/dist/matrix3.d.ts +63 -0
- package/dist/matrix3.d.ts.map +1 -0
- package/dist/matrix3.js +408 -0
- package/dist/matrix3.js.map +1 -0
- package/dist/matrix3Pool.d.ts +6 -0
- package/dist/matrix3Pool.d.ts.map +1 -0
- package/dist/matrix3Pool.js +26 -0
- package/dist/matrix3Pool.js.map +1 -0
- package/dist/matrix4.d.ts +238 -0
- package/dist/matrix4.d.ts.map +1 -0
- package/dist/matrix4.js +931 -0
- package/dist/matrix4.js.map +1 -0
- package/dist/matrix4Pool.d.ts +6 -0
- package/dist/matrix4Pool.d.ts.map +1 -0
- package/dist/matrix4Pool.js +26 -0
- package/dist/matrix4Pool.js.map +1 -0
- package/dist/matrixPool.d.ts +6 -0
- package/dist/matrixPool.d.ts.map +1 -0
- package/dist/matrixPool.js +26 -0
- package/dist/matrixPool.js.map +1 -0
- package/dist/obb.d.ts +44 -0
- package/dist/obb.d.ts.map +1 -0
- package/dist/obb.js +248 -0
- package/dist/obb.js.map +1 -0
- package/dist/plane.d.ts +66 -0
- package/dist/plane.d.ts.map +1 -0
- package/dist/plane.js +140 -0
- package/dist/plane.js.map +1 -0
- package/dist/quaternion.d.ts +128 -0
- package/dist/quaternion.d.ts.map +1 -0
- package/dist/quaternion.js +508 -0
- package/dist/quaternion.js.map +1 -0
- package/dist/quaternionPool.d.ts +6 -0
- package/dist/quaternionPool.d.ts.map +1 -0
- package/dist/quaternionPool.js +29 -0
- package/dist/quaternionPool.js.map +1 -0
- package/dist/ray3d.d.ts +69 -0
- package/dist/ray3d.d.ts.map +1 -0
- package/dist/ray3d.js +264 -0
- package/dist/ray3d.js.map +1 -0
- package/dist/rectangle.d.ts +56 -0
- package/dist/rectangle.d.ts.map +1 -0
- package/dist/rectangle.js +235 -0
- package/dist/rectangle.js.map +1 -0
- package/dist/rectanglePool.d.ts +6 -0
- package/dist/rectanglePool.d.ts.map +1 -0
- package/dist/rectanglePool.js +29 -0
- package/dist/rectanglePool.js.map +1 -0
- package/dist/typedarray.d.ts +4 -0
- package/dist/typedarray.d.ts.map +1 -0
- package/dist/typedarray.js +25 -0
- package/dist/typedarray.js.map +1 -0
- package/dist/vector2.d.ts +130 -0
- package/dist/vector2.d.ts.map +1 -0
- package/dist/vector2.js +250 -0
- package/dist/vector2.js.map +1 -0
- package/dist/vector2Pool.d.ts +6 -0
- package/dist/vector2Pool.d.ts.map +1 -0
- package/dist/vector2Pool.js +20 -0
- package/dist/vector2Pool.js.map +1 -0
- package/dist/vector3.d.ts +220 -0
- package/dist/vector3.d.ts.map +1 -0
- package/dist/vector3.js +380 -0
- package/dist/vector3.js.map +1 -0
- package/dist/vector3Pool.d.ts +6 -0
- package/dist/vector3Pool.d.ts.map +1 -0
- package/dist/vector3Pool.js +28 -0
- package/dist/vector3Pool.js.map +1 -0
- package/dist/vector4.d.ts +180 -0
- package/dist/vector4.d.ts.map +1 -0
- package/dist/vector4.js +333 -0
- package/dist/vector4.js.map +1 -0
- package/dist/vector4Pool.d.ts +6 -0
- package/dist/vector4Pool.d.ts.map +1 -0
- package/dist/vector4Pool.js +29 -0
- package/dist/vector4Pool.js.map +1 -0
- package/package.json +38 -0
- package/src/aabb.test.ts +341 -0
- package/src/boundingSphere.test.ts +247 -0
- package/src/capsule.test.ts +157 -0
- package/src/frustum.test.ts +160 -0
- package/src/matrix.test.ts +1111 -0
- package/src/matrix3.test.ts +752 -0
- package/src/matrix3Pool.test.ts +73 -0
- package/src/matrix4.test.ts +1627 -0
- package/src/matrix4Pool.test.ts +71 -0
- package/src/matrixPool.test.ts +69 -0
- package/src/obb.test.ts +183 -0
- package/src/plane.test.ts +225 -0
- package/src/quaternion.test.ts +531 -0
- package/src/quaternionPool.test.ts +64 -0
- package/src/ray3d.test.ts +297 -0
- package/src/rectangle.test.ts +982 -0
- package/src/rectanglePool.test.ts +71 -0
- package/src/typedarray.test.ts +118 -0
- package/src/vector2.test.ts +958 -0
- package/src/vector2Pool.test.ts +65 -0
- package/src/vector3.test.ts +749 -0
- package/src/vector3Pool.test.ts +68 -0
- package/src/vector4.test.ts +660 -0
- package/src/vector4Pool.test.ts +71 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Rectangle } from '@flighthq/types';
|
|
2
|
+
|
|
3
|
+
import { acquireEmptyRectangle, acquireRectangle, clearRectanglePool, releaseRectangle } from './rectanglePool';
|
|
4
|
+
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
clearRectanglePool();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
describe('acquireEmptyRectangle', () => {
|
|
10
|
+
it('returns a rectangle with all properties set to 0', () => {
|
|
11
|
+
const r = acquireEmptyRectangle();
|
|
12
|
+
expect(r.x).toBe(0);
|
|
13
|
+
expect(r.y).toBe(0);
|
|
14
|
+
expect(r.width).toBe(0);
|
|
15
|
+
expect(r.height).toBe(0);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('resets a released rectangle to empty', () => {
|
|
19
|
+
const r1 = acquireRectangle();
|
|
20
|
+
r1.x = 5;
|
|
21
|
+
r1.y = 10;
|
|
22
|
+
r1.width = 50;
|
|
23
|
+
r1.height = 100;
|
|
24
|
+
releaseRectangle(r1);
|
|
25
|
+
const r2 = acquireEmptyRectangle();
|
|
26
|
+
expect(r2).toBe(r1);
|
|
27
|
+
expect(r2.x).toBe(0);
|
|
28
|
+
expect(r2.y).toBe(0);
|
|
29
|
+
expect(r2.width).toBe(0);
|
|
30
|
+
expect(r2.height).toBe(0);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('acquireRectangle', () => {
|
|
35
|
+
it('returns a new Rectangle when pool is empty', () => {
|
|
36
|
+
const r: Rectangle = acquireRectangle();
|
|
37
|
+
expect(r).not.toBeNull();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('reuses released rectangles', () => {
|
|
41
|
+
const r1 = acquireRectangle();
|
|
42
|
+
releaseRectangle(r1);
|
|
43
|
+
const r2 = acquireRectangle();
|
|
44
|
+
expect(r2).toBe(r1);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('reuses released rectangles in last-in-first-out order', () => {
|
|
48
|
+
const r1 = acquireRectangle();
|
|
49
|
+
const r2 = acquireRectangle();
|
|
50
|
+
releaseRectangle(r1);
|
|
51
|
+
releaseRectangle(r2);
|
|
52
|
+
expect(acquireRectangle()).toBe(r2);
|
|
53
|
+
expect(acquireRectangle()).toBe(r1);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('clearRectanglePool', () => {
|
|
58
|
+
it('empties the pool so the next get allocates fresh', () => {
|
|
59
|
+
const r = acquireRectangle();
|
|
60
|
+
releaseRectangle(r);
|
|
61
|
+
clearRectanglePool();
|
|
62
|
+
const r2 = acquireRectangle();
|
|
63
|
+
expect(r2).not.toBe(r);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('releaseRectangle', () => {
|
|
68
|
+
it('handles null safely', () => {
|
|
69
|
+
expect(() => releaseRectangle(null as unknown as Rectangle)).not.toThrow();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { reserveFloat32Array, reserveInt16Array, reserveUint16Array } from './typedarray';
|
|
2
|
+
|
|
3
|
+
describe('reserveFloat32Array', () => {
|
|
4
|
+
it('returns the same array if the capacity is equal', () => {
|
|
5
|
+
const array = new Float32Array(100);
|
|
6
|
+
const out = reserveFloat32Array(array, 100);
|
|
7
|
+
expect(out).toStrictEqual(array);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('returns the same array if the capacity is less than existing length', () => {
|
|
11
|
+
const array = new Float32Array(100);
|
|
12
|
+
const out = reserveFloat32Array(array, 10);
|
|
13
|
+
expect(out).toStrictEqual(array);
|
|
14
|
+
expect(out.length).toBe(100);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('allocates a new array if the capacity is larger', () => {
|
|
18
|
+
const array = new Float32Array(100);
|
|
19
|
+
const out = reserveFloat32Array(array, 1000);
|
|
20
|
+
expect(out).not.toStrictEqual(array);
|
|
21
|
+
expect(out.length).toBe(1000);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('leaves extended capacity zero-filled', () => {
|
|
25
|
+
const array = new Float32Array([1, 2]);
|
|
26
|
+
const out = reserveFloat32Array(array, 4);
|
|
27
|
+
expect(Array.from(out)).toEqual([1, 2, 0, 0]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('copies the existing array values if it allocates', () => {
|
|
31
|
+
const array = new Float32Array(10);
|
|
32
|
+
for (let i = 0; i < 10; i++) {
|
|
33
|
+
array[i] = i;
|
|
34
|
+
}
|
|
35
|
+
const out = reserveFloat32Array(array, 100);
|
|
36
|
+
for (let i = 0; i < 10; i++) {
|
|
37
|
+
expect(out[i]).toBe(array[i]);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('reserveInt16Array', () => {
|
|
43
|
+
it('returns the same array if the capacity is equal', () => {
|
|
44
|
+
const array = new Int16Array(100);
|
|
45
|
+
const out = reserveInt16Array(array, 100);
|
|
46
|
+
expect(out).toStrictEqual(array);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('returns the same array if the capacity is less than existing length', () => {
|
|
50
|
+
const array = new Int16Array(100);
|
|
51
|
+
const out = reserveInt16Array(array, 10);
|
|
52
|
+
expect(out).toStrictEqual(array);
|
|
53
|
+
expect(out.length).toBe(100);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('allocates a new array if the capacity is larger', () => {
|
|
57
|
+
const array = new Int16Array(100);
|
|
58
|
+
const out = reserveInt16Array(array, 1000);
|
|
59
|
+
expect(out).not.toStrictEqual(array);
|
|
60
|
+
expect(out.length).toBe(1000);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('leaves extended capacity zero-filled', () => {
|
|
64
|
+
const array = new Int16Array([1, 2]);
|
|
65
|
+
const out = reserveInt16Array(array, 4);
|
|
66
|
+
expect(Array.from(out)).toEqual([1, 2, 0, 0]);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('copies the existing array values if it allocates', () => {
|
|
70
|
+
const array = new Int16Array(10);
|
|
71
|
+
for (let i = 0; i < 10; i++) {
|
|
72
|
+
array[i] = i;
|
|
73
|
+
}
|
|
74
|
+
const out = reserveInt16Array(array, 100);
|
|
75
|
+
for (let i = 0; i < 10; i++) {
|
|
76
|
+
expect(out[i]).toBe(array[i]);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('reserveUint16Array', () => {
|
|
82
|
+
it('returns the same array if the capacity is equal', () => {
|
|
83
|
+
const array = new Uint16Array(100);
|
|
84
|
+
const out = reserveUint16Array(array, 100);
|
|
85
|
+
expect(out).toStrictEqual(array);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('returns the same array if the capacity is less than existing length', () => {
|
|
89
|
+
const array = new Uint16Array(100);
|
|
90
|
+
const out = reserveUint16Array(array, 10);
|
|
91
|
+
expect(out).toStrictEqual(array);
|
|
92
|
+
expect(out.length).toBe(100);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('allocates a new array if the capacity is larger', () => {
|
|
96
|
+
const array = new Uint16Array(100);
|
|
97
|
+
const out = reserveUint16Array(array, 1000);
|
|
98
|
+
expect(out).not.toStrictEqual(array);
|
|
99
|
+
expect(out.length).toBe(1000);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('leaves extended capacity zero-filled', () => {
|
|
103
|
+
const array = new Uint16Array([1, 2]);
|
|
104
|
+
const out = reserveUint16Array(array, 4);
|
|
105
|
+
expect(Array.from(out)).toEqual([1, 2, 0, 0]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('copies the existing array values if it allocates', () => {
|
|
109
|
+
const array = new Uint16Array(10);
|
|
110
|
+
for (let i = 0; i < 10; i++) {
|
|
111
|
+
array[i] = i;
|
|
112
|
+
}
|
|
113
|
+
const out = reserveUint16Array(array, 100);
|
|
114
|
+
for (let i = 0; i < 10; i++) {
|
|
115
|
+
expect(out[i]).toBe(array[i]);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
});
|