@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
package/dist/aabb.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Aabb, AabbLike, BoundingSphereLike, Matrix4Like, Vector3Like } from '@flighthq/types';
|
|
2
|
+
export declare function cloneAabb(source: Readonly<AabbLike>): Aabb;
|
|
3
|
+
/**
|
|
4
|
+
* Copies the min and max corners of an axis-aligned bounding box.
|
|
5
|
+
*
|
|
6
|
+
* Safe when `out` aliases `source`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function copyAabb(out: AabbLike, source: Readonly<AabbLike>): void;
|
|
9
|
+
/**
|
|
10
|
+
* Creates an axis-aligned bounding box from explicit min/max corner components. With no
|
|
11
|
+
* arguments the box is empty (min = +Infinity, max = -Infinity) so the first point expanded
|
|
12
|
+
* into it sets both corners.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createAabb(minX?: number, minY?: number, minZ?: number, maxX?: number, maxY?: number, maxZ?: number): Aabb;
|
|
15
|
+
/**
|
|
16
|
+
* Grows an axis-aligned bounding box to include a point, writing the result to `out`. When
|
|
17
|
+
* `aabb` is empty (min > max) the first point sets both corners exactly.
|
|
18
|
+
*
|
|
19
|
+
* Safe when `out` aliases `aabb`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function expandAabbByPoint(out: AabbLike, aabb: Readonly<AabbLike>, point: Readonly<Vector3Like>): void;
|
|
22
|
+
/**
|
|
23
|
+
* Grows an axis-aligned bounding box to include a bounding sphere. The sphere is expanded to
|
|
24
|
+
* its AABB first, then unioned with the existing box.
|
|
25
|
+
*
|
|
26
|
+
* Safe when `out` aliases `aabb`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function expandAabbBySphere(out: AabbLike, aabb: Readonly<AabbLike>, sphere: Readonly<BoundingSphereLike>): void;
|
|
29
|
+
/**
|
|
30
|
+
* Writes the center point of an axis-aligned bounding box (the midpoint of its corners).
|
|
31
|
+
*/
|
|
32
|
+
export declare function getAabbCenter(out: Vector3Like, aabb: Readonly<AabbLike>): void;
|
|
33
|
+
/**
|
|
34
|
+
* Returns whether a point lies inside (or on the boundary of) an axis-aligned bounding box.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getAabbContainsPoint(aabb: Readonly<AabbLike>, point: Readonly<Vector3Like>): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Writes the half-extents (half the size along each axis) of an axis-aligned bounding box.
|
|
39
|
+
*/
|
|
40
|
+
export declare function getAabbExtents(out: Vector3Like, aabb: Readonly<AabbLike>): void;
|
|
41
|
+
/**
|
|
42
|
+
* Writes the full size (extent along each axis) of an axis-aligned bounding box.
|
|
43
|
+
*/
|
|
44
|
+
export declare function getAabbSize(out: Vector3Like, aabb: Readonly<AabbLike>): void;
|
|
45
|
+
/**
|
|
46
|
+
* Writes the point on (or inside) an axis-aligned bounding box closest to `point` — each
|
|
47
|
+
* coordinate is clamped to the box's range on that axis. When `point` is already inside the box
|
|
48
|
+
* the result equals `point`. An empty box (min > max) clamps to the inverted range and yields a
|
|
49
|
+
* degenerate result; callers should guard empties.
|
|
50
|
+
*
|
|
51
|
+
* Safe when `out` aliases `point`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getClosestPointOnAabb(out: Vector3Like, aabb: Readonly<AabbLike>, point: Readonly<Vector3Like>): void;
|
|
54
|
+
/**
|
|
55
|
+
* Writes the intersection (overlap region) of two axis-aligned bounding boxes to `out`.
|
|
56
|
+
* If the boxes do not overlap, `out` is set to an empty box (min > max).
|
|
57
|
+
*
|
|
58
|
+
* Reads all inputs into locals before writing, so it is safe when `out` aliases `a` or `b`.
|
|
59
|
+
*/
|
|
60
|
+
export declare function intersectAabb(out: AabbLike, a: Readonly<AabbLike>, b: Readonly<AabbLike>): void;
|
|
61
|
+
/**
|
|
62
|
+
* Returns whether two axis-aligned bounding boxes overlap (share any interior or surface point).
|
|
63
|
+
*/
|
|
64
|
+
export declare function isAabbIntersectingAabb(a: Readonly<AabbLike>, b: Readonly<AabbLike>): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Sets the min and max corners of an axis-aligned bounding box from explicit components.
|
|
67
|
+
*/
|
|
68
|
+
export declare function setAabb(out: AabbLike, minX: number, minY: number, minZ: number, maxX: number, maxY: number, maxZ: number): void;
|
|
69
|
+
/**
|
|
70
|
+
* Computes the tight axis-aligned bounding box of a set of points. An empty list yields an
|
|
71
|
+
* empty box (min = +Infinity, max = -Infinity).
|
|
72
|
+
*/
|
|
73
|
+
export declare function setAabbFromPoints(out: AabbLike, points: Readonly<readonly Readonly<Vector3Like>[]>): void;
|
|
74
|
+
/**
|
|
75
|
+
* Transforms an axis-aligned bounding box by a Matrix4 and writes the tight AABB of the
|
|
76
|
+
* transformed box. Uses the center/extent absolute-value method so the result stays
|
|
77
|
+
* axis-aligned in the destination space.
|
|
78
|
+
*
|
|
79
|
+
* Reads all of `aabb` into locals before writing, so it is safe when `out` aliases `aabb`.
|
|
80
|
+
*/
|
|
81
|
+
export declare function transformAabbByMatrix4(out: AabbLike, aabb: Readonly<AabbLike>, m: Readonly<Matrix4Like>): void;
|
|
82
|
+
/**
|
|
83
|
+
* Writes the union of two axis-aligned bounding boxes — the smallest box enclosing both.
|
|
84
|
+
*
|
|
85
|
+
* Reads both inputs into locals before writing, so it is safe when `out` aliases `a` or `b`.
|
|
86
|
+
*/
|
|
87
|
+
export declare function unionAabb(out: AabbLike, a: Readonly<AabbLike>, b: Readonly<AabbLike>): void;
|
|
88
|
+
//# sourceMappingURL=aabb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aabb.d.ts","sourceRoot":"","sources":["../src/aabb.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,kBAAkB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAIpG,wBAAgB,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,GAAG,IAAI,CAE1D;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,GAAG,IAAI,CAOxE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,IAAI,CAAC,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,MAAM,GACZ,IAAI,CAYN;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAU7G;AAED;;;;;GAKG;AACH,wBAAgB,kBA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,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,IAAI,CAON;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,SAAS,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,GAAG,IAAI,CAwBzG;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAgC9G;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,GAAG,IAAI,CAoB3F"}
|
package/dist/aabb.js
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { createEntity } from '@flighthq/entity';
|
|
2
|
+
import { createVector3 } from './vector3';
|
|
3
|
+
export function cloneAabb(source) {
|
|
4
|
+
return createAabb(source.min.x, source.min.y, source.min.z, source.max.x, source.max.y, source.max.z);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Copies the min and max corners of an axis-aligned bounding box.
|
|
8
|
+
*
|
|
9
|
+
* Safe when `out` aliases `source`.
|
|
10
|
+
*/
|
|
11
|
+
export function copyAabb(out, source) {
|
|
12
|
+
out.min.x = source.min.x;
|
|
13
|
+
out.min.y = source.min.y;
|
|
14
|
+
out.min.z = source.min.z;
|
|
15
|
+
out.max.x = source.max.x;
|
|
16
|
+
out.max.y = source.max.y;
|
|
17
|
+
out.max.z = source.max.z;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates an axis-aligned bounding box from explicit min/max corner components. With no
|
|
21
|
+
* arguments the box is empty (min = +Infinity, max = -Infinity) so the first point expanded
|
|
22
|
+
* into it sets both corners.
|
|
23
|
+
*/
|
|
24
|
+
export function createAabb(minX, minY, minZ, maxX, maxY, maxZ) {
|
|
25
|
+
const min = createVector3(minX ?? Number.POSITIVE_INFINITY, minY ?? Number.POSITIVE_INFINITY, minZ ?? Number.POSITIVE_INFINITY);
|
|
26
|
+
const max = createVector3(maxX ?? Number.NEGATIVE_INFINITY, maxY ?? Number.NEGATIVE_INFINITY, maxZ ?? Number.NEGATIVE_INFINITY);
|
|
27
|
+
return createEntity({ max: max, min: min });
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Grows an axis-aligned bounding box to include a point, writing the result to `out`. When
|
|
31
|
+
* `aabb` is empty (min > max) the first point sets both corners exactly.
|
|
32
|
+
*
|
|
33
|
+
* Safe when `out` aliases `aabb`.
|
|
34
|
+
*/
|
|
35
|
+
export function expandAabbByPoint(out, aabb, point) {
|
|
36
|
+
const px = point.x, py = point.y, pz = point.z;
|
|
37
|
+
out.min.x = Math.min(aabb.min.x, px);
|
|
38
|
+
out.min.y = Math.min(aabb.min.y, py);
|
|
39
|
+
out.min.z = Math.min(aabb.min.z, pz);
|
|
40
|
+
out.max.x = Math.max(aabb.max.x, px);
|
|
41
|
+
out.max.y = Math.max(aabb.max.y, py);
|
|
42
|
+
out.max.z = Math.max(aabb.max.z, pz);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Grows an axis-aligned bounding box to include a bounding sphere. The sphere is expanded to
|
|
46
|
+
* its AABB first, then unioned with the existing box.
|
|
47
|
+
*
|
|
48
|
+
* Safe when `out` aliases `aabb`.
|
|
49
|
+
*/
|
|
50
|
+
export function expandAabbBySphere(out, aabb, sphere) {
|
|
51
|
+
if (sphere.radius < 0) {
|
|
52
|
+
// empty sphere — no expansion
|
|
53
|
+
out.min.x = aabb.min.x;
|
|
54
|
+
out.min.y = aabb.min.y;
|
|
55
|
+
out.min.z = aabb.min.z;
|
|
56
|
+
out.max.x = aabb.max.x;
|
|
57
|
+
out.max.y = aabb.max.y;
|
|
58
|
+
out.max.z = aabb.max.z;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const cx = sphere.center.x, cy = sphere.center.y, cz = sphere.center.z, r = sphere.radius;
|
|
62
|
+
out.min.x = Math.min(aabb.min.x, cx - r);
|
|
63
|
+
out.min.y = Math.min(aabb.min.y, cy - r);
|
|
64
|
+
out.min.z = Math.min(aabb.min.z, cz - r);
|
|
65
|
+
out.max.x = Math.max(aabb.max.x, cx + r);
|
|
66
|
+
out.max.y = Math.max(aabb.max.y, cy + r);
|
|
67
|
+
out.max.z = Math.max(aabb.max.z, cz + r);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Writes the center point of an axis-aligned bounding box (the midpoint of its corners).
|
|
71
|
+
*/
|
|
72
|
+
export function getAabbCenter(out, aabb) {
|
|
73
|
+
out.x = (aabb.min.x + aabb.max.x) * 0.5;
|
|
74
|
+
out.y = (aabb.min.y + aabb.max.y) * 0.5;
|
|
75
|
+
out.z = (aabb.min.z + aabb.max.z) * 0.5;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns whether a point lies inside (or on the boundary of) an axis-aligned bounding box.
|
|
79
|
+
*/
|
|
80
|
+
export function getAabbContainsPoint(aabb, point) {
|
|
81
|
+
return (point.x >= aabb.min.x &&
|
|
82
|
+
point.x <= aabb.max.x &&
|
|
83
|
+
point.y >= aabb.min.y &&
|
|
84
|
+
point.y <= aabb.max.y &&
|
|
85
|
+
point.z >= aabb.min.z &&
|
|
86
|
+
point.z <= aabb.max.z);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Writes the half-extents (half the size along each axis) of an axis-aligned bounding box.
|
|
90
|
+
*/
|
|
91
|
+
export function getAabbExtents(out, aabb) {
|
|
92
|
+
out.x = (aabb.max.x - aabb.min.x) * 0.5;
|
|
93
|
+
out.y = (aabb.max.y - aabb.min.y) * 0.5;
|
|
94
|
+
out.z = (aabb.max.z - aabb.min.z) * 0.5;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Writes the full size (extent along each axis) of an axis-aligned bounding box.
|
|
98
|
+
*/
|
|
99
|
+
export function getAabbSize(out, aabb) {
|
|
100
|
+
out.x = aabb.max.x - aabb.min.x;
|
|
101
|
+
out.y = aabb.max.y - aabb.min.y;
|
|
102
|
+
out.z = aabb.max.z - aabb.min.z;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Writes the point on (or inside) an axis-aligned bounding box closest to `point` — each
|
|
106
|
+
* coordinate is clamped to the box's range on that axis. When `point` is already inside the box
|
|
107
|
+
* the result equals `point`. An empty box (min > max) clamps to the inverted range and yields a
|
|
108
|
+
* degenerate result; callers should guard empties.
|
|
109
|
+
*
|
|
110
|
+
* Safe when `out` aliases `point`.
|
|
111
|
+
*/
|
|
112
|
+
export function getClosestPointOnAabb(out, aabb, point) {
|
|
113
|
+
const px = point.x, py = point.y, pz = point.z;
|
|
114
|
+
out.x = Math.min(Math.max(px, aabb.min.x), aabb.max.x);
|
|
115
|
+
out.y = Math.min(Math.max(py, aabb.min.y), aabb.max.y);
|
|
116
|
+
out.z = Math.min(Math.max(pz, aabb.min.z), aabb.max.z);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Writes the intersection (overlap region) of two axis-aligned bounding boxes to `out`.
|
|
120
|
+
* If the boxes do not overlap, `out` is set to an empty box (min > max).
|
|
121
|
+
*
|
|
122
|
+
* Reads all inputs into locals before writing, so it is safe when `out` aliases `a` or `b`.
|
|
123
|
+
*/
|
|
124
|
+
export function intersectAabb(out, a, b) {
|
|
125
|
+
const aMinX = a.min.x, aMinY = a.min.y, aMinZ = a.min.z;
|
|
126
|
+
const aMaxX = a.max.x, aMaxY = a.max.y, aMaxZ = a.max.z;
|
|
127
|
+
const bMinX = b.min.x, bMinY = b.min.y, bMinZ = b.min.z;
|
|
128
|
+
const bMaxX = b.max.x, bMaxY = b.max.y, bMaxZ = b.max.z;
|
|
129
|
+
out.min.x = Math.max(aMinX, bMinX);
|
|
130
|
+
out.min.y = Math.max(aMinY, bMinY);
|
|
131
|
+
out.min.z = Math.max(aMinZ, bMinZ);
|
|
132
|
+
out.max.x = Math.min(aMaxX, bMaxX);
|
|
133
|
+
out.max.y = Math.min(aMaxY, bMaxY);
|
|
134
|
+
out.max.z = Math.min(aMaxZ, bMaxZ);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Returns whether two axis-aligned bounding boxes overlap (share any interior or surface point).
|
|
138
|
+
*/
|
|
139
|
+
export function isAabbIntersectingAabb(a, b) {
|
|
140
|
+
return (a.min.x <= b.max.x &&
|
|
141
|
+
a.max.x >= b.min.x &&
|
|
142
|
+
a.min.y <= b.max.y &&
|
|
143
|
+
a.max.y >= b.min.y &&
|
|
144
|
+
a.min.z <= b.max.z &&
|
|
145
|
+
a.max.z >= b.min.z);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Sets the min and max corners of an axis-aligned bounding box from explicit components.
|
|
149
|
+
*/
|
|
150
|
+
export function setAabb(out, minX, minY, minZ, maxX, maxY, maxZ) {
|
|
151
|
+
out.min.x = minX;
|
|
152
|
+
out.min.y = minY;
|
|
153
|
+
out.min.z = minZ;
|
|
154
|
+
out.max.x = maxX;
|
|
155
|
+
out.max.y = maxY;
|
|
156
|
+
out.max.z = maxZ;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Computes the tight axis-aligned bounding box of a set of points. An empty list yields an
|
|
160
|
+
* empty box (min = +Infinity, max = -Infinity).
|
|
161
|
+
*/
|
|
162
|
+
export function setAabbFromPoints(out, points) {
|
|
163
|
+
let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, minZ = Number.POSITIVE_INFINITY;
|
|
164
|
+
let maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY, maxZ = Number.NEGATIVE_INFINITY;
|
|
165
|
+
for (let i = 0; i < points.length; i++) {
|
|
166
|
+
const p = points[i];
|
|
167
|
+
if (p.x < minX)
|
|
168
|
+
minX = p.x;
|
|
169
|
+
if (p.y < minY)
|
|
170
|
+
minY = p.y;
|
|
171
|
+
if (p.z < minZ)
|
|
172
|
+
minZ = p.z;
|
|
173
|
+
if (p.x > maxX)
|
|
174
|
+
maxX = p.x;
|
|
175
|
+
if (p.y > maxY)
|
|
176
|
+
maxY = p.y;
|
|
177
|
+
if (p.z > maxZ)
|
|
178
|
+
maxZ = p.z;
|
|
179
|
+
}
|
|
180
|
+
out.min.x = minX;
|
|
181
|
+
out.min.y = minY;
|
|
182
|
+
out.min.z = minZ;
|
|
183
|
+
out.max.x = maxX;
|
|
184
|
+
out.max.y = maxY;
|
|
185
|
+
out.max.z = maxZ;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Transforms an axis-aligned bounding box by a Matrix4 and writes the tight AABB of the
|
|
189
|
+
* transformed box. Uses the center/extent absolute-value method so the result stays
|
|
190
|
+
* axis-aligned in the destination space.
|
|
191
|
+
*
|
|
192
|
+
* Reads all of `aabb` into locals before writing, so it is safe when `out` aliases `aabb`.
|
|
193
|
+
*/
|
|
194
|
+
export function transformAabbByMatrix4(out, aabb, m) {
|
|
195
|
+
const minX = aabb.min.x, minY = aabb.min.y, minZ = aabb.min.z;
|
|
196
|
+
const maxX = aabb.max.x, maxY = aabb.max.y, maxZ = aabb.max.z;
|
|
197
|
+
const cx = (minX + maxX) * 0.5, cy = (minY + maxY) * 0.5, cz = (minZ + maxZ) * 0.5;
|
|
198
|
+
const ex = (maxX - minX) * 0.5, ey = (maxY - minY) * 0.5, ez = (maxZ - minZ) * 0.5;
|
|
199
|
+
const _m = m.m;
|
|
200
|
+
// Transformed center (column-major Matrix4, includes translation).
|
|
201
|
+
const tcx = _m[0] * cx + _m[4] * cy + _m[8] * cz + _m[12];
|
|
202
|
+
const tcy = _m[1] * cx + _m[5] * cy + _m[9] * cz + _m[13];
|
|
203
|
+
const tcz = _m[2] * cx + _m[6] * cy + _m[10] * cz + _m[14];
|
|
204
|
+
// Transformed extent via |M| · extent (absolute values of the linear part).
|
|
205
|
+
const tex = Math.abs(_m[0]) * ex + Math.abs(_m[4]) * ey + Math.abs(_m[8]) * ez;
|
|
206
|
+
const tey = Math.abs(_m[1]) * ex + Math.abs(_m[5]) * ey + Math.abs(_m[9]) * ez;
|
|
207
|
+
const tez = Math.abs(_m[2]) * ex + Math.abs(_m[6]) * ey + Math.abs(_m[10]) * ez;
|
|
208
|
+
out.min.x = tcx - tex;
|
|
209
|
+
out.min.y = tcy - tey;
|
|
210
|
+
out.min.z = tcz - tez;
|
|
211
|
+
out.max.x = tcx + tex;
|
|
212
|
+
out.max.y = tcy + tey;
|
|
213
|
+
out.max.z = tcz + tez;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Writes the union of two axis-aligned bounding boxes — the smallest box enclosing both.
|
|
217
|
+
*
|
|
218
|
+
* Reads both inputs into locals before writing, so it is safe when `out` aliases `a` or `b`.
|
|
219
|
+
*/
|
|
220
|
+
export function unionAabb(out, a, b) {
|
|
221
|
+
const aMinX = a.min.x, aMinY = a.min.y, aMinZ = a.min.z, aMaxX = a.max.x, aMaxY = a.max.y, aMaxZ = a.max.z;
|
|
222
|
+
const bMinX = b.min.x, bMinY = b.min.y, bMinZ = b.min.z, bMaxX = b.max.x, bMaxY = b.max.y, bMaxZ = b.max.z;
|
|
223
|
+
out.min.x = Math.min(aMinX, bMinX);
|
|
224
|
+
out.min.y = Math.min(aMinY, bMinY);
|
|
225
|
+
out.min.z = Math.min(aMinZ, bMinZ);
|
|
226
|
+
out.max.x = Math.max(aMaxX, bMaxX);
|
|
227
|
+
out.max.y = Math.max(aMaxY, bMaxY);
|
|
228
|
+
out.max.z = Math.max(aMaxZ, bMaxZ);
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=aabb.js.map
|
package/dist/aabb.js.map
ADDED
|
@@ -0,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C,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { AabbLike, BoundingSphere, BoundingSphereLike, Matrix4Like, Vector3Like } from '@flighthq/types';
|
|
2
|
+
export declare function cloneBoundingSphere(source: Readonly<BoundingSphereLike>): BoundingSphere;
|
|
3
|
+
/**
|
|
4
|
+
* Copies the center and radius of a bounding sphere.
|
|
5
|
+
*
|
|
6
|
+
* Safe when `out` aliases `source`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function copyBoundingSphere(out: BoundingSphereLike, source: Readonly<BoundingSphereLike>): void;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a bounding sphere from an explicit center and radius. With no arguments the sphere
|
|
11
|
+
* is empty (center at the origin, radius -1).
|
|
12
|
+
*/
|
|
13
|
+
export declare function createBoundingSphere(centerX?: number, centerY?: number, centerZ?: number, radius?: number): BoundingSphere;
|
|
14
|
+
/**
|
|
15
|
+
* Returns whether a point lies inside (or on the surface of) a bounding sphere. An empty
|
|
16
|
+
* sphere (negative radius) contains no points.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getBoundingSphereContainsPoint(sphere: Readonly<BoundingSphereLike>, point: Readonly<Vector3Like>): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Writes the point on the surface of a bounding sphere closest to `point`: the point projected
|
|
21
|
+
* onto the sphere along the ray from the center. When `point` lies at the center (no defined
|
|
22
|
+
* direction) the sphere center offset by `radius` along +X is written as a stable fallback. An
|
|
23
|
+
* empty sphere (negative radius) writes the sphere center.
|
|
24
|
+
*
|
|
25
|
+
* Reads `point` and the sphere into locals before writing, so it is safe when `out` aliases
|
|
26
|
+
* `point`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getClosestPointOnBoundingSphere(out: Vector3Like, sphere: Readonly<BoundingSphereLike>, point: Readonly<Vector3Like>): void;
|
|
29
|
+
/**
|
|
30
|
+
* Returns whether two bounding spheres overlap (share any interior or surface point).
|
|
31
|
+
* An empty sphere (negative radius) does not intersect anything.
|
|
32
|
+
*/
|
|
33
|
+
export declare function isBoundingSphereIntersectingBoundingSphere(a: Readonly<BoundingSphereLike>, b: Readonly<BoundingSphereLike>): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Writes the smallest sphere that encloses both `a` and `b`. An empty sphere (negative radius)
|
|
36
|
+
* is treated as having no volume; merging an empty sphere with a non-empty sphere returns the
|
|
37
|
+
* non-empty sphere.
|
|
38
|
+
*
|
|
39
|
+
* Reads all inputs before writing, so it is safe when `out` aliases `a` or `b`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function mergeBoundingSphere(out: BoundingSphereLike, a: Readonly<BoundingSphereLike>, b: Readonly<BoundingSphereLike>): void;
|
|
42
|
+
/**
|
|
43
|
+
* Sets the center and radius of a bounding sphere.
|
|
44
|
+
*/
|
|
45
|
+
export declare function setBoundingSphere(out: BoundingSphereLike, centerX: number, centerY: number, centerZ: number, radius: number): void;
|
|
46
|
+
/**
|
|
47
|
+
* Writes the bounding sphere that tightly encloses an axis-aligned bounding box: its center
|
|
48
|
+
* is the box center and its radius reaches the box corners. An empty box (min > max) yields
|
|
49
|
+
* an empty sphere (negative radius).
|
|
50
|
+
*
|
|
51
|
+
* Reads `aabb` into locals before writing, so it is safe even if `out` shares vector storage.
|
|
52
|
+
*/
|
|
53
|
+
export declare function setBoundingSphereFromAabb(out: BoundingSphereLike, aabb: Readonly<AabbLike>): void;
|
|
54
|
+
/**
|
|
55
|
+
* Transforms a bounding sphere by a Matrix4: its center is transformed as a point and its
|
|
56
|
+
* radius is scaled by the largest axis scale of the matrix's linear part, so the result still
|
|
57
|
+
* encloses the transformed sphere under non-uniform scale.
|
|
58
|
+
*
|
|
59
|
+
* Reads `sphere` into locals before writing, so it is safe when `out` aliases `sphere`.
|
|
60
|
+
*/
|
|
61
|
+
export declare function transformBoundingSphereByMatrix4(out: BoundingSphereLike, sphere: Readonly<BoundingSphereLike>, m: Readonly<Matrix4Like>): void;
|
|
62
|
+
//# sourceMappingURL=boundingSphere.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundingSphere.d.ts","sourceRoot":"","sources":["../src/boundingSphere.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,kBAAkB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI9G,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GAAG,cAAc,CAExF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,kBAAkB,EAAE,MAAM,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GAAG,IAAI,CAKtG;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,GACd,cAAc,CAGhB;AAED;;;GAGG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EACpC,KAAK,EAAE,QAAQ,CAAC,WAAW,CAAC,GAC3B,OAAO,CAMT;AAED;;;;;;;;GAQG;AACH,wBAAgB,+BAA+B,CAC7C,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EACpC,KAAK,EAAE,QAAQ,CAAC,WAAW,CAAC,GAC3B,IAAI,CAyBN;AAED;;;GAGG;AACH,wBAAgB,0CAA0C,CACxD,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EAC/B,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GAC9B,OAAO,CAQT;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,kBAAkB,EACvB,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EAC/B,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GAC9B,IAAI,CAuDN;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,kBAAkB,EACvB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,IAAI,CAKN;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,kBAAkB,EAAE,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,GAAG,IAAI,CA2BjG;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAC9C,GAAG,EAAE,kBAAkB,EACvB,MAAM,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EACpC,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GACvB,IAAI,CAoBN"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { createEntity } from '@flighthq/entity';
|
|
2
|
+
import { createVector3 } from './vector3';
|
|
3
|
+
export function cloneBoundingSphere(source) {
|
|
4
|
+
return createBoundingSphere(source.center.x, source.center.y, source.center.z, source.radius);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Copies the center and radius of a bounding sphere.
|
|
8
|
+
*
|
|
9
|
+
* Safe when `out` aliases `source`.
|
|
10
|
+
*/
|
|
11
|
+
export function copyBoundingSphere(out, source) {
|
|
12
|
+
out.center.x = source.center.x;
|
|
13
|
+
out.center.y = source.center.y;
|
|
14
|
+
out.center.z = source.center.z;
|
|
15
|
+
out.radius = source.radius;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a bounding sphere from an explicit center and radius. With no arguments the sphere
|
|
19
|
+
* is empty (center at the origin, radius -1).
|
|
20
|
+
*/
|
|
21
|
+
export function createBoundingSphere(centerX, centerY, centerZ, radius) {
|
|
22
|
+
const center = createVector3(centerX ?? 0, centerY ?? 0, centerZ ?? 0);
|
|
23
|
+
return createEntity({ center: center, radius: radius ?? -1 });
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns whether a point lies inside (or on the surface of) a bounding sphere. An empty
|
|
27
|
+
* sphere (negative radius) contains no points.
|
|
28
|
+
*/
|
|
29
|
+
export function getBoundingSphereContainsPoint(sphere, point) {
|
|
30
|
+
if (sphere.radius < 0)
|
|
31
|
+
return false;
|
|
32
|
+
const dx = point.x - sphere.center.x;
|
|
33
|
+
const dy = point.y - sphere.center.y;
|
|
34
|
+
const dz = point.z - sphere.center.z;
|
|
35
|
+
return dx * dx + dy * dy + dz * dz <= sphere.radius * sphere.radius;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Writes the point on the surface of a bounding sphere closest to `point`: the point projected
|
|
39
|
+
* onto the sphere along the ray from the center. When `point` lies at the center (no defined
|
|
40
|
+
* direction) the sphere center offset by `radius` along +X is written as a stable fallback. An
|
|
41
|
+
* empty sphere (negative radius) writes the sphere center.
|
|
42
|
+
*
|
|
43
|
+
* Reads `point` and the sphere into locals before writing, so it is safe when `out` aliases
|
|
44
|
+
* `point`.
|
|
45
|
+
*/
|
|
46
|
+
export function getClosestPointOnBoundingSphere(out, sphere, point) {
|
|
47
|
+
const cx = sphere.center.x, cy = sphere.center.y, cz = sphere.center.z, r = sphere.radius;
|
|
48
|
+
if (r < 0) {
|
|
49
|
+
out.x = cx;
|
|
50
|
+
out.y = cy;
|
|
51
|
+
out.z = cz;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const dx = point.x - cx, dy = point.y - cy, dz = point.z - cz;
|
|
55
|
+
const dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
56
|
+
if (dist === 0) {
|
|
57
|
+
out.x = cx + r;
|
|
58
|
+
out.y = cy;
|
|
59
|
+
out.z = cz;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const scale = r / dist;
|
|
63
|
+
out.x = cx + dx * scale;
|
|
64
|
+
out.y = cy + dy * scale;
|
|
65
|
+
out.z = cz + dz * scale;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Returns whether two bounding spheres overlap (share any interior or surface point).
|
|
69
|
+
* An empty sphere (negative radius) does not intersect anything.
|
|
70
|
+
*/
|
|
71
|
+
export function isBoundingSphereIntersectingBoundingSphere(a, b) {
|
|
72
|
+
if (a.radius < 0 || b.radius < 0)
|
|
73
|
+
return false;
|
|
74
|
+
const dx = a.center.x - b.center.x;
|
|
75
|
+
const dy = a.center.y - b.center.y;
|
|
76
|
+
const dz = a.center.z - b.center.z;
|
|
77
|
+
const distSq = dx * dx + dy * dy + dz * dz;
|
|
78
|
+
const sumR = a.radius + b.radius;
|
|
79
|
+
return distSq <= sumR * sumR;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Writes the smallest sphere that encloses both `a` and `b`. An empty sphere (negative radius)
|
|
83
|
+
* is treated as having no volume; merging an empty sphere with a non-empty sphere returns the
|
|
84
|
+
* non-empty sphere.
|
|
85
|
+
*
|
|
86
|
+
* Reads all inputs before writing, so it is safe when `out` aliases `a` or `b`.
|
|
87
|
+
*/
|
|
88
|
+
export function mergeBoundingSphere(out, a, b) {
|
|
89
|
+
// Handle empty spheres
|
|
90
|
+
if (a.radius < 0) {
|
|
91
|
+
out.center.x = b.center.x;
|
|
92
|
+
out.center.y = b.center.y;
|
|
93
|
+
out.center.z = b.center.z;
|
|
94
|
+
out.radius = b.radius;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (b.radius < 0) {
|
|
98
|
+
out.center.x = a.center.x;
|
|
99
|
+
out.center.y = a.center.y;
|
|
100
|
+
out.center.z = a.center.z;
|
|
101
|
+
out.radius = a.radius;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const acx = a.center.x, acy = a.center.y, acz = a.center.z, ar = a.radius;
|
|
105
|
+
const bcx = b.center.x, bcy = b.center.y, bcz = b.center.z, br = b.radius;
|
|
106
|
+
const dx = bcx - acx, dy = bcy - acy, dz = bcz - acz;
|
|
107
|
+
const dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
108
|
+
// One sphere completely contains the other
|
|
109
|
+
if (dist + br <= ar) {
|
|
110
|
+
out.center.x = acx;
|
|
111
|
+
out.center.y = acy;
|
|
112
|
+
out.center.z = acz;
|
|
113
|
+
out.radius = ar;
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (dist + ar <= br) {
|
|
117
|
+
out.center.x = bcx;
|
|
118
|
+
out.center.y = bcy;
|
|
119
|
+
out.center.z = bcz;
|
|
120
|
+
out.radius = br;
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
// General case: new radius = (dist + ar + br) / 2
|
|
124
|
+
const newRadius = (dist + ar + br) * 0.5;
|
|
125
|
+
// New center is along the line from a to b, offset by (newRadius - ar)
|
|
126
|
+
const t = dist !== 0 ? (newRadius - ar) / dist : 0;
|
|
127
|
+
out.center.x = acx + dx * t;
|
|
128
|
+
out.center.y = acy + dy * t;
|
|
129
|
+
out.center.z = acz + dz * t;
|
|
130
|
+
out.radius = newRadius;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Sets the center and radius of a bounding sphere.
|
|
134
|
+
*/
|
|
135
|
+
export function setBoundingSphere(out, centerX, centerY, centerZ, radius) {
|
|
136
|
+
out.center.x = centerX;
|
|
137
|
+
out.center.y = centerY;
|
|
138
|
+
out.center.z = centerZ;
|
|
139
|
+
out.radius = radius;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Writes the bounding sphere that tightly encloses an axis-aligned bounding box: its center
|
|
143
|
+
* is the box center and its radius reaches the box corners. An empty box (min > max) yields
|
|
144
|
+
* an empty sphere (negative radius).
|
|
145
|
+
*
|
|
146
|
+
* Reads `aabb` into locals before writing, so it is safe even if `out` shares vector storage.
|
|
147
|
+
*/
|
|
148
|
+
export function setBoundingSphereFromAabb(out, aabb) {
|
|
149
|
+
const minX = aabb.min.x, minY = aabb.min.y, minZ = aabb.min.z;
|
|
150
|
+
const maxX = aabb.max.x, maxY = aabb.max.y, maxZ = aabb.max.z;
|
|
151
|
+
if (minX > maxX || minY > maxY || minZ > maxZ) {
|
|
152
|
+
out.center.x = 0;
|
|
153
|
+
out.center.y = 0;
|
|
154
|
+
out.center.z = 0;
|
|
155
|
+
out.radius = -1;
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const cx = (minX + maxX) * 0.5, cy = (minY + maxY) * 0.5, cz = (minZ + maxZ) * 0.5;
|
|
159
|
+
const ex = (maxX - minX) * 0.5, ey = (maxY - minY) * 0.5, ez = (maxZ - minZ) * 0.5;
|
|
160
|
+
out.center.x = cx;
|
|
161
|
+
out.center.y = cy;
|
|
162
|
+
out.center.z = cz;
|
|
163
|
+
out.radius = Math.sqrt(ex * ex + ey * ey + ez * ez);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Transforms a bounding sphere by a Matrix4: its center is transformed as a point and its
|
|
167
|
+
* radius is scaled by the largest axis scale of the matrix's linear part, so the result still
|
|
168
|
+
* encloses the transformed sphere under non-uniform scale.
|
|
169
|
+
*
|
|
170
|
+
* Reads `sphere` into locals before writing, so it is safe when `out` aliases `sphere`.
|
|
171
|
+
*/
|
|
172
|
+
export function transformBoundingSphereByMatrix4(out, sphere, m) {
|
|
173
|
+
const cx = sphere.center.x, cy = sphere.center.y, cz = sphere.center.z;
|
|
174
|
+
const radius = sphere.radius;
|
|
175
|
+
const _m = m.m;
|
|
176
|
+
const tcx = _m[0] * cx + _m[4] * cy + _m[8] * cz + _m[12];
|
|
177
|
+
const tcy = _m[1] * cx + _m[5] * cy + _m[9] * cz + _m[13];
|
|
178
|
+
const tcz = _m[2] * cx + _m[6] * cy + _m[10] * cz + _m[14];
|
|
179
|
+
const sx = Math.sqrt(_m[0] * _m[0] + _m[1] * _m[1] + _m[2] * _m[2]);
|
|
180
|
+
const sy = Math.sqrt(_m[4] * _m[4] + _m[5] * _m[5] + _m[6] * _m[6]);
|
|
181
|
+
const sz = Math.sqrt(_m[8] * _m[8] + _m[9] * _m[9] + _m[10] * _m[10]);
|
|
182
|
+
const maxScale = Math.max(sx, sy, sz);
|
|
183
|
+
out.center.x = tcx;
|
|
184
|
+
out.center.y = tcy;
|
|
185
|
+
out.center.z = tcz;
|
|
186
|
+
out.radius = radius < 0 ? radius : radius * maxScale;
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=boundingSphere.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundingSphere.js","sourceRoot":"","sources":["../src/boundingSphere.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,UAAU,mBAAmB,CAAC,MAAoC;IACtE,OAAO,oBAAoB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AAChG,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAuB,EAAE,MAAoC;IAC9F,GAAG,CAAC,MAAM,CAAC,CAAC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C,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACpE,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACtE,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAEtC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,GAAG,CAAC;IACnB,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,GAAG,CAAC;IACnB,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,GAAG,CAAC;IACnB,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG,QAAQ,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { BoundingSphereLike, Capsule, CapsuleLike, Ray3DLike, Vector3Like } from '@flighthq/types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a capsule from a start point, end point, and radius. A negative radius conventionally
|
|
4
|
+
* marks an empty capsule.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createCapsule(startX: number, startY: number, startZ: number, endX: number, endY: number, endZ: number, radius: number): Capsule;
|
|
7
|
+
/**
|
|
8
|
+
* Writes the point on the capsule surface (or axis) closest to `point`. Projects `point` onto
|
|
9
|
+
* the capsule axis segment, clamps the parameter to [0, 1], then offsets by `radius` toward
|
|
10
|
+
* `point`. When `point` lies on the axis the stable fallback is the axis point itself offset
|
|
11
|
+
* along +X.
|
|
12
|
+
*
|
|
13
|
+
* Safe when `out` aliases `point` (reads all inputs before writing).
|
|
14
|
+
*/
|
|
15
|
+
export declare function getClosestPointOnCapsule(out: Vector3Like, capsule: Readonly<CapsuleLike>, point: Readonly<Vector3Like>): void;
|
|
16
|
+
/**
|
|
17
|
+
* Tests whether a ray intersects a capsule. Combines an infinite-cylinder slab test (clamped to
|
|
18
|
+
* the capsule axis segment) with hemispherical cap tests at start and end.
|
|
19
|
+
*
|
|
20
|
+
* Returns the entry parameter `t` (>= 0) on hit, or `-1` on miss. A ray starting inside the
|
|
21
|
+
* capsule returns `t = 0`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function intersectRay3DCapsule(ray: Readonly<Ray3DLike>, capsule: Readonly<CapsuleLike>): number;
|
|
24
|
+
/**
|
|
25
|
+
* Returns whether two capsules overlap (their inflated axis-segments share any point).
|
|
26
|
+
* An empty capsule (negative radius) does not intersect anything.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isCapsuleIntersectingCapsule(a: Readonly<CapsuleLike>, b: Readonly<CapsuleLike>): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Returns whether a capsule overlaps a bounding sphere. An empty capsule (negative radius) or
|
|
31
|
+
* empty sphere (negative radius) does not intersect anything.
|
|
32
|
+
*/
|
|
33
|
+
export declare function isCapsuleIntersectingSphere(capsule: Readonly<CapsuleLike>, sphere: Readonly<BoundingSphereLike>): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Sets all fields of a capsule in place.
|
|
36
|
+
*/
|
|
37
|
+
export declare function setCapsule(out: CapsuleLike, startX: number, startY: number, startZ: number, endX: number, endY: number, endZ: number, radius: number): void;
|
|
38
|
+
//# sourceMappingURL=capsule.d.ts.map
|