@math.gl/culling 4.1.0 → 4.2.0-alpha.5

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.
Files changed (54) hide show
  1. package/LICENSE +51 -0
  2. package/README.md +8 -1
  3. package/dist/index.cjs +660 -83
  4. package/dist/index.cjs.map +3 -4
  5. package/dist/index.d.ts +12 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +6 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +1 -1
  10. package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -1
  11. package/dist/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
  12. package/dist/lib/plane.d.ts +9 -0
  13. package/dist/lib/plane.d.ts.map +1 -1
  14. package/dist/lib/plane.js +22 -1
  15. package/dist/lib/plane.js.map +1 -1
  16. package/dist/lib/ray.d.ts +13 -0
  17. package/dist/lib/ray.d.ts.map +1 -0
  18. package/dist/lib/ray.js +28 -0
  19. package/dist/lib/ray.js.map +1 -0
  20. package/dist/lib/shapes/box-shape.d.ts +19 -0
  21. package/dist/lib/shapes/box-shape.d.ts.map +1 -0
  22. package/dist/lib/shapes/box-shape.js +69 -0
  23. package/dist/lib/shapes/box-shape.js.map +1 -0
  24. package/dist/lib/shapes/capsule-shape.d.ts +23 -0
  25. package/dist/lib/shapes/capsule-shape.d.ts.map +1 -0
  26. package/dist/lib/shapes/capsule-shape.js +151 -0
  27. package/dist/lib/shapes/capsule-shape.js.map +1 -0
  28. package/dist/lib/shapes/cylinder-shape.d.ts +22 -0
  29. package/dist/lib/shapes/cylinder-shape.d.ts.map +1 -0
  30. package/dist/lib/shapes/cylinder-shape.js +99 -0
  31. package/dist/lib/shapes/cylinder-shape.js.map +1 -0
  32. package/dist/lib/shapes/implicit-shape.d.ts +55 -0
  33. package/dist/lib/shapes/implicit-shape.d.ts.map +1 -0
  34. package/dist/lib/shapes/implicit-shape.js +143 -0
  35. package/dist/lib/shapes/implicit-shape.js.map +1 -0
  36. package/dist/lib/shapes/plane-shape.d.ts +26 -0
  37. package/dist/lib/shapes/plane-shape.d.ts.map +1 -0
  38. package/dist/lib/shapes/plane-shape.js +72 -0
  39. package/dist/lib/shapes/plane-shape.js.map +1 -0
  40. package/dist/lib/shapes/sphere-shape.d.ts +18 -0
  41. package/dist/lib/shapes/sphere-shape.d.ts.map +1 -0
  42. package/dist/lib/shapes/sphere-shape.js +43 -0
  43. package/dist/lib/shapes/sphere-shape.js.map +1 -0
  44. package/package.json +4 -4
  45. package/src/index.ts +13 -0
  46. package/src/lib/bounding-volumes/oriented-bounding-box.ts +2 -1
  47. package/src/lib/plane.ts +28 -1
  48. package/src/lib/ray.ts +31 -0
  49. package/src/lib/shapes/box-shape.ts +78 -0
  50. package/src/lib/shapes/capsule-shape.ts +232 -0
  51. package/src/lib/shapes/cylinder-shape.ts +133 -0
  52. package/src/lib/shapes/implicit-shape.ts +209 -0
  53. package/src/lib/shapes/plane-shape.ts +78 -0
  54. package/src/lib/shapes/sphere-shape.ts +60 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ray.js","sourceRoot":"","sources":["../../src/lib/ray.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,8CAA8C;AAC9C,oCAAoC;AAEpC,sEAAsE;AACtE,4FAA4F;AAE5F,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AAEtC,kGAAkG;AAClG,MAAM,OAAO,GAAG;IAId;;;;;OAKG;IACH,YAAY,MAAgB,EAAE,SAAmB;QAC/C,IAAI,MAAM;YAAE,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;;YAC/B,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAE5B,IAAI,SAAS;YAAE,SAAS,GAAG,SAAS,CAAC,KAAK,EAAE,CAAC,SAAS,EAAE,CAAC;;YACpD,SAAS,GAAG,IAAI,OAAO,EAAE,CAAC;QAE/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,19 @@
1
+ import { ImplicitShapeBase, type ImplicitShape, type LocalRayIntersection } from "./implicit-shape.js";
2
+ export type BoxShapeProps = {
3
+ size?: readonly [number, number, number];
4
+ matrix?: readonly number[];
5
+ };
6
+ /** Analytic glTF box shape. */
7
+ export declare class BoxShape extends ImplicitShapeBase {
8
+ readonly type: "box";
9
+ readonly size: readonly [number, number, number];
10
+ private readonly halfSize;
11
+ constructor(props?: BoxShapeProps);
12
+ clone(): BoxShape;
13
+ equals(shape: ImplicitShape): boolean;
14
+ containsLocalPoint(point: readonly number[]): boolean;
15
+ distanceToLocalPoint(point: readonly number[]): number;
16
+ supportLocal(direction: readonly number[]): readonly number[];
17
+ intersectLocalRay(origin: readonly number[], direction: readonly number[]): LocalRayIntersection | undefined;
18
+ }
19
+ //# sourceMappingURL=box-shape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box-shape.d.ts","sourceRoot":"","sources":["../../../src/lib/shapes/box-shape.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,iBAAiB,EAAE,KAAK,aAAa,EAAE,KAAK,oBAAoB,EAAC,4BAAyB;AAIlG,MAAM,MAAM,aAAa,GAAG;IAAC,IAAI,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAC,CAAC;AAEnG,+BAA+B;AAC/B,qBAAa,QAAS,SAAQ,iBAAiB;IAC7C,QAAQ,CAAC,IAAI,EAAG,KAAK,CAAU;IAC/B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoC;gBAEjD,KAAK,GAAE,aAAkB;IAQrC,KAAK,IAAI,QAAQ;IAGR,MAAM,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO;IAO9C,kBAAkB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO;IAGrD,oBAAoB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAGtD,YAAY,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE;IAG7D,iBAAiB,CACf,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,oBAAoB,GAAG,SAAS;CA+BpC"}
@@ -0,0 +1,69 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { ImplicitShapeBase } from "./implicit-shape.js";
5
+ const EPSILON = 1e-6;
6
+ /** Analytic glTF box shape. */
7
+ export class BoxShape extends ImplicitShapeBase {
8
+ constructor(props = {}) {
9
+ super(props.matrix);
10
+ this.type = 'box';
11
+ this.size = props.size ? [...props.size] : [1, 1, 1];
12
+ if (this.size.some(value => !Number.isFinite(value) || value <= 0))
13
+ throw new Error('Box size values must be greater than zero');
14
+ this.halfSize = [this.size[0] / 2, this.size[1] / 2, this.size[2] / 2];
15
+ }
16
+ clone() {
17
+ return new BoxShape({ size: this.size, matrix: this.matrix });
18
+ }
19
+ equals(shape) {
20
+ return (shape instanceof BoxShape &&
21
+ super.equals(shape) &&
22
+ this.size.every((value, i) => value === shape.size[i]));
23
+ }
24
+ containsLocalPoint(point) {
25
+ return point.every((value, i) => Math.abs(value) <= this.halfSize[i] + EPSILON);
26
+ }
27
+ distanceToLocalPoint(point) {
28
+ return Math.hypot(...point.map((value, i) => Math.max(0, Math.abs(value) - this.halfSize[i])));
29
+ }
30
+ supportLocal(direction) {
31
+ return direction.map((value, i) => (value < 0 ? -this.halfSize[i] : this.halfSize[i]));
32
+ }
33
+ intersectLocalRay(origin, direction) {
34
+ let near = -Infinity;
35
+ let far = Infinity;
36
+ let nearAxis = 0;
37
+ let farAxis = 0;
38
+ for (let axis = 0; axis < 3; axis++) {
39
+ if (Math.abs(direction[axis]) < 1e-15) {
40
+ if (Math.abs(origin[axis]) > this.halfSize[axis])
41
+ return undefined;
42
+ continue;
43
+ }
44
+ let t1 = (-this.halfSize[axis] - origin[axis]) / direction[axis];
45
+ let t2 = (this.halfSize[axis] - origin[axis]) / direction[axis];
46
+ if (t1 > t2)
47
+ [t1, t2] = [t2, t1];
48
+ if (t1 > near) {
49
+ near = t1;
50
+ nearAxis = axis;
51
+ }
52
+ if (t2 < far) {
53
+ far = t2;
54
+ farAxis = axis;
55
+ }
56
+ if (near > far)
57
+ return undefined;
58
+ }
59
+ const distance = near >= 0 ? near : far;
60
+ if (distance < 0 || !Number.isFinite(distance))
61
+ return undefined;
62
+ const axis = near >= 0 ? nearAxis : farAxis;
63
+ const pointCoordinate = origin[axis] + distance * direction[axis];
64
+ const normal = [0, 0, 0];
65
+ normal[axis] = pointCoordinate < 0 ? -1 : 1;
66
+ return { distance, normal };
67
+ }
68
+ }
69
+ //# sourceMappingURL=box-shape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box-shape.js","sourceRoot":"","sources":["../../../src/lib/shapes/box-shape.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,iBAAiB,EAAgD,4BAAyB;AAElG,MAAM,OAAO,GAAG,IAAI,CAAC;AAIrB,+BAA+B;AAC/B,MAAM,OAAO,QAAS,SAAQ,iBAAiB;IAK7C,YAAY,QAAuB,EAAE;QACnC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QALb,SAAI,GAAG,KAAc,CAAC;QAM7B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CA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EAAE;gBAAE,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;YACjC,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC;gBACd,IAAI,GAAG,EAAE,CAAC;gBACV,QAAQ,GAAG,IAAI,CAAC;YAClB,CAAC;YACD,IAAI,EAAE,GAAG,GAAG,EAAE,CAAC;gBACb,GAAG,GAAG,EAAE,CAAC;gBACT,OAAO,GAAG,IAAI,CAAC;YACjB,CAAC;YACD,IAAI,IAAI,GAAG,GAAG;gBAAE,OAAO,SAAS,CAAC;QACnC,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;QACxC,IAAI,QAAQ,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAAE,OAAO,SAAS,CAAC;QACjE,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;QAC5C,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;QAClE,MAAM,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACzB,MAAM,CAAC,IAAI,CAAC,GAAG,eAAe,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5C,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC;IAC5B,CAAC;CACF"}
@@ -0,0 +1,23 @@
1
+ import { ImplicitShapeBase, type ImplicitShape, type LocalRayIntersection } from "./implicit-shape.js";
2
+ export type CapsuleShapeProps = {
3
+ height?: number;
4
+ radiusBottom?: number;
5
+ radiusTop?: number;
6
+ matrix?: readonly number[];
7
+ };
8
+ /** Analytic glTF capsule: the convex hull of two spheres on the Y axis. */
9
+ export declare class CapsuleShape extends ImplicitShapeBase {
10
+ readonly type: "capsule";
11
+ readonly height: number;
12
+ readonly radiusBottom: number;
13
+ readonly radiusTop: number;
14
+ constructor(props?: CapsuleShapeProps);
15
+ clone(): CapsuleShape;
16
+ equals(shape: ImplicitShape): boolean;
17
+ containsLocalPoint(point: readonly number[]): boolean;
18
+ distanceToLocalPoint(point: readonly number[]): number;
19
+ supportLocal(direction: readonly number[]): readonly number[];
20
+ intersectLocalRay(origin: readonly number[], direction: readonly number[]): LocalRayIntersection | undefined;
21
+ private getProfile;
22
+ }
23
+ //# sourceMappingURL=capsule-shape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capsule-shape.d.ts","sourceRoot":"","sources":["../../../src/lib/shapes/capsule-shape.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,iBAAiB,EAEjB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAC1B,4BAAyB;AAI1B,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF,2EAA2E;AAC3E,qBAAa,YAAa,SAAQ,iBAAiB;IACjD,QAAQ,CAAC,IAAI,EAAG,SAAS,CAAU;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,KAAK,GAAE,iBAAsB;IAazC,KAAK,IAAI,YAAY;IAQZ,MAAM,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO;IAS9C,kBAAkB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO;IAgBrD,oBAAoB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAqCtD,YAAY,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE;IAe7D,iBAAiB,CACf,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,oBAAoB,GAAG,SAAS;IAwCnC,OAAO,CAAC,UAAU;CA4BnB"}
@@ -0,0 +1,151 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { closestDistanceToCircleArc2D, closestDistanceToSegment2D, ImplicitShapeBase, solveQuadratic } from "./implicit-shape.js";
5
+ const EPSILON = 1e-6;
6
+ /** Analytic glTF capsule: the convex hull of two spheres on the Y axis. */
7
+ export class CapsuleShape extends ImplicitShapeBase {
8
+ constructor(props = {}) {
9
+ super(props.matrix);
10
+ this.type = 'capsule';
11
+ this.height = props.height ?? 1;
12
+ this.radiusBottom = props.radiusBottom ?? 0.5;
13
+ this.radiusTop = props.radiusTop ?? 0.5;
14
+ if (!Number.isFinite(this.height) || this.height <= 0)
15
+ throw new Error('Capsule height must be greater than zero');
16
+ if (![this.radiusBottom, this.radiusTop].every(value => Number.isFinite(value) && value >= 0))
17
+ throw new Error('Capsule radii must be non-negative');
18
+ if (this.radiusBottom === 0 && this.radiusTop === 0)
19
+ throw new Error('At least one capsule radius must be greater than zero');
20
+ }
21
+ clone() {
22
+ return new CapsuleShape({
23
+ height: this.height,
24
+ radiusBottom: this.radiusBottom,
25
+ radiusTop: this.radiusTop,
26
+ matrix: this.matrix
27
+ });
28
+ }
29
+ equals(shape) {
30
+ return (shape instanceof CapsuleShape &&
31
+ super.equals(shape) &&
32
+ this.height === shape.height &&
33
+ this.radiusBottom === shape.radiusBottom &&
34
+ this.radiusTop === shape.radiusTop);
35
+ }
36
+ containsLocalPoint(point) {
37
+ const profile = this.getProfile();
38
+ const radial = Math.hypot(point[0], point[2]);
39
+ if (profile.sphere)
40
+ return (Math.hypot(radial, point[1] - profile.sphere.center) <= profile.sphere.radius + EPSILON);
41
+ if (point[1] < profile.bottom.y)
42
+ return Math.hypot(radial, point[1] + this.height / 2) <= this.radiusBottom + EPSILON;
43
+ if (point[1] > profile.top.y)
44
+ return Math.hypot(radial, point[1] - this.height / 2) <= this.radiusTop + EPSILON;
45
+ const t = (point[1] - profile.bottom.y) / (profile.top.y - profile.bottom.y);
46
+ return (radial <= profile.bottom.radius + (profile.top.radius - profile.bottom.radius) * t + EPSILON);
47
+ }
48
+ distanceToLocalPoint(point) {
49
+ if (this.containsLocalPoint(point))
50
+ return 0;
51
+ const profile = this.getProfile();
52
+ const radial = Math.hypot(point[0], point[2]);
53
+ if (profile.sphere)
54
+ return Math.max(0, Math.hypot(radial, point[1] - profile.sphere.center) - profile.sphere.radius);
55
+ const delta = this.radiusTop - this.radiusBottom;
56
+ const sideNormalY = -delta / this.height;
57
+ const bottomArc = closestDistanceToCircleArc2D(radial, point[1], -this.height / 2, this.radiusBottom, -1, sideNormalY);
58
+ const topArc = closestDistanceToCircleArc2D(radial, point[1], this.height / 2, this.radiusTop, sideNormalY, 1);
59
+ const side = closestDistanceToSegment2D(radial, point[1], profile.bottom.radius, profile.bottom.y, profile.top.radius, profile.top.y);
60
+ return Math.min(bottomArc, topArc, side);
61
+ }
62
+ supportLocal(direction) {
63
+ const length = Math.hypot(...direction);
64
+ const unit = length ? direction.map(value => value / length) : [1, 0, 0];
65
+ const bottom = [
66
+ unit[0] * this.radiusBottom,
67
+ -this.height / 2 + unit[1] * this.radiusBottom,
68
+ unit[2] * this.radiusBottom
69
+ ];
70
+ const top = [
71
+ unit[0] * this.radiusTop,
72
+ this.height / 2 + unit[1] * this.radiusTop,
73
+ unit[2] * this.radiusTop
74
+ ];
75
+ return dot(top, direction) >= dot(bottom, direction) ? top : bottom;
76
+ }
77
+ intersectLocalRay(origin, direction) {
78
+ const profile = this.getProfile();
79
+ if (profile.sphere)
80
+ return intersectSphere(origin, direction, profile.sphere.center, profile.sphere.radius);
81
+ const candidates = [];
82
+ const slope = (profile.top.radius - profile.bottom.radius) / (profile.top.y - profile.bottom.y);
83
+ const intercept = profile.bottom.radius - slope * profile.bottom.y;
84
+ const radialAtOrigin = intercept + slope * origin[1];
85
+ const radialAlongRay = slope * direction[1];
86
+ for (const distance of solveQuadratic(direction[0] ** 2 + direction[2] ** 2 - radialAlongRay ** 2, 2 * (origin[0] * direction[0] + origin[2] * direction[2] - radialAtOrigin * radialAlongRay), origin[0] ** 2 + origin[2] ** 2 - radialAtOrigin ** 2)) {
87
+ const y = origin[1] + distance * direction[1];
88
+ if (distance >= 0 && y >= profile.bottom.y - EPSILON && y <= profile.top.y + EPSILON) {
89
+ const x = origin[0] + distance * direction[0];
90
+ const z = origin[2] + distance * direction[2];
91
+ const radial = Math.hypot(x, z) || 1;
92
+ const normal = [x / radial, -slope, z / radial];
93
+ const length = Math.hypot(...normal);
94
+ candidates.push({ distance, normal: normal.map(value => value / length) });
95
+ }
96
+ }
97
+ for (const bottomHit of intersectSphereRoots(origin, direction, -this.height / 2, this.radiusBottom)) {
98
+ const y = origin[1] + bottomHit.distance * direction[1];
99
+ if (y <= profile.bottom.y + EPSILON)
100
+ candidates.push(bottomHit);
101
+ }
102
+ for (const topHit of intersectSphereRoots(origin, direction, this.height / 2, this.radiusTop)) {
103
+ const y = origin[1] + topHit.distance * direction[1];
104
+ if (y >= profile.top.y - EPSILON)
105
+ candidates.push(topHit);
106
+ }
107
+ return candidates.sort((a, b) => a.distance - b.distance)[0];
108
+ }
109
+ getProfile() {
110
+ const delta = this.radiusTop - this.radiusBottom;
111
+ if (Math.abs(delta) >= this.height) {
112
+ const topWins = this.radiusTop >= this.radiusBottom;
113
+ return {
114
+ sphere: {
115
+ center: topWins ? this.height / 2 : -this.height / 2,
116
+ radius: topWins ? this.radiusTop : this.radiusBottom
117
+ },
118
+ bottom: { radius: 0, y: 0 },
119
+ top: { radius: 0, y: 0 }
120
+ };
121
+ }
122
+ const sinSlope = delta / this.height;
123
+ const radialNormal = Math.sqrt(1 - sinSlope * sinSlope);
124
+ const normalY = -sinSlope;
125
+ return {
126
+ bottom: {
127
+ radius: this.radiusBottom * radialNormal,
128
+ y: -this.height / 2 + this.radiusBottom * normalY
129
+ },
130
+ top: { radius: this.radiusTop * radialNormal, y: this.height / 2 + this.radiusTop * normalY }
131
+ };
132
+ }
133
+ }
134
+ function intersectSphere(origin, direction, centerY, radius) {
135
+ return intersectSphereRoots(origin, direction, centerY, radius)[0];
136
+ }
137
+ function intersectSphereRoots(origin, direction, centerY, radius) {
138
+ if (radius === 0)
139
+ return [];
140
+ const relative = [origin[0], origin[1] - centerY, origin[2]];
141
+ return solveQuadratic(dot(direction, direction), 2 * dot(relative, direction), dot(relative, relative) - radius * radius)
142
+ .filter(distance => distance >= 0)
143
+ .map(distance => ({
144
+ distance,
145
+ normal: relative.map((value, i) => (value + distance * direction[i]) / radius)
146
+ }));
147
+ }
148
+ function dot(a, b) {
149
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
150
+ }
151
+ //# sourceMappingURL=capsule-shape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capsule-shape.js","sourceRoot":"","sources":["../../../src/lib/shapes/capsule-shape.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,iBAAiB,EACjB,cAAc,EAGf,4BAAyB;AAE1B,MAAM,OAAO,GAAG,IAAI,CAAC;AASrB,2EAA2E;AAC3E,MAAM,OAAO,YAAa,SAAQ,iBAAiB;IAMjD,YAAY,QAA2B,EAAE;QACvC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QANb,SAAI,GAAG,SAAkB,CAAC;QAOjC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,IAAI,G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,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { ImplicitShapeBase, type ImplicitShape, type LocalRayIntersection } from "./implicit-shape.js";
2
+ export type CylinderShapeProps = {
3
+ height?: number;
4
+ radiusBottom?: number;
5
+ radiusTop?: number;
6
+ matrix?: readonly number[];
7
+ };
8
+ /** Analytic closed, Y-aligned glTF cylinder shape, including tapered cylinders. */
9
+ export declare class CylinderShape extends ImplicitShapeBase {
10
+ readonly type: "cylinder";
11
+ readonly height: number;
12
+ readonly radiusBottom: number;
13
+ readonly radiusTop: number;
14
+ constructor(props?: CylinderShapeProps);
15
+ clone(): CylinderShape;
16
+ equals(shape: ImplicitShape): boolean;
17
+ containsLocalPoint(point: readonly number[]): boolean;
18
+ distanceToLocalPoint(point: readonly number[]): number;
19
+ supportLocal(direction: readonly number[]): readonly number[];
20
+ intersectLocalRay(origin: readonly number[], direction: readonly number[]): LocalRayIntersection | undefined;
21
+ }
22
+ //# sourceMappingURL=cylinder-shape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cylinder-shape.d.ts","sourceRoot":"","sources":["../../../src/lib/shapes/cylinder-shape.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,iBAAiB,EAEjB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAC1B,4BAAyB;AAI1B,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF,mFAAmF;AACnF,qBAAa,aAAc,SAAQ,iBAAiB;IAClD,QAAQ,CAAC,IAAI,EAAG,UAAU,CAAU;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,KAAK,GAAE,kBAAuB;IAa1C,KAAK,IAAI,aAAa;IAQb,MAAM,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO;IAS9C,kBAAkB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO;IAOrD,oBAAoB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAgBtD,YAAY,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE;IAW7D,iBAAiB,CACf,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,oBAAoB,GAAG,SAAS;CAqCpC"}
@@ -0,0 +1,99 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { closestDistanceToSegment2D, ImplicitShapeBase, solveQuadratic } from "./implicit-shape.js";
5
+ const EPSILON = 1e-6;
6
+ /** Analytic closed, Y-aligned glTF cylinder shape, including tapered cylinders. */
7
+ export class CylinderShape extends ImplicitShapeBase {
8
+ constructor(props = {}) {
9
+ super(props.matrix);
10
+ this.type = 'cylinder';
11
+ this.height = props.height ?? 2;
12
+ this.radiusBottom = props.radiusBottom ?? 0.5;
13
+ this.radiusTop = props.radiusTop ?? 0.5;
14
+ if (!Number.isFinite(this.height) || this.height <= 0)
15
+ throw new Error('Cylinder height must be greater than zero');
16
+ if (![this.radiusBottom, this.radiusTop].every(value => Number.isFinite(value) && value >= 0))
17
+ throw new Error('Cylinder radii must be non-negative');
18
+ if (this.radiusBottom === 0 && this.radiusTop === 0)
19
+ throw new Error('At least one cylinder radius must be greater than zero');
20
+ }
21
+ clone() {
22
+ return new CylinderShape({
23
+ height: this.height,
24
+ radiusBottom: this.radiusBottom,
25
+ radiusTop: this.radiusTop,
26
+ matrix: this.matrix
27
+ });
28
+ }
29
+ equals(shape) {
30
+ return (shape instanceof CylinderShape &&
31
+ super.equals(shape) &&
32
+ this.height === shape.height &&
33
+ this.radiusBottom === shape.radiusBottom &&
34
+ this.radiusTop === shape.radiusTop);
35
+ }
36
+ containsLocalPoint(point) {
37
+ const half = this.height / 2;
38
+ if (point[1] < -half - EPSILON || point[1] > half + EPSILON)
39
+ return false;
40
+ const t = (point[1] + half) / this.height;
41
+ const radius = this.radiusBottom + (this.radiusTop - this.radiusBottom) * t;
42
+ return Math.hypot(point[0], point[2]) <= radius + EPSILON;
43
+ }
44
+ distanceToLocalPoint(point) {
45
+ if (this.containsLocalPoint(point))
46
+ return 0;
47
+ const radial = Math.hypot(point[0], point[2]);
48
+ const half = this.height / 2;
49
+ const side = closestDistanceToSegment2D(radial, point[1], this.radiusBottom, -half, this.radiusTop, half);
50
+ const bottom = closestDistanceToSegment2D(radial, point[1], 0, -half, this.radiusBottom, -half);
51
+ const top = closestDistanceToSegment2D(radial, point[1], 0, half, this.radiusTop, half);
52
+ return Math.min(side, bottom, top);
53
+ }
54
+ supportLocal(direction) {
55
+ const radialLength = Math.hypot(direction[0], direction[2]);
56
+ const x = radialLength ? direction[0] / radialLength : 1;
57
+ const z = radialLength ? direction[2] / radialLength : 0;
58
+ const half = this.height / 2;
59
+ const bottomValue = radialLength * this.radiusBottom - direction[1] * half;
60
+ const topValue = radialLength * this.radiusTop + direction[1] * half;
61
+ return topValue >= bottomValue
62
+ ? [x * this.radiusTop, half, z * this.radiusTop]
63
+ : [x * this.radiusBottom, -half, z * this.radiusBottom];
64
+ }
65
+ intersectLocalRay(origin, direction) {
66
+ const half = this.height / 2;
67
+ const slope = (this.radiusTop - this.radiusBottom) / this.height;
68
+ const intercept = (this.radiusTop + this.radiusBottom) / 2;
69
+ const radialAtOrigin = intercept + slope * origin[1];
70
+ const radialAlongRay = slope * direction[1];
71
+ const candidates = [];
72
+ const roots = solveQuadratic(direction[0] ** 2 + direction[2] ** 2 - radialAlongRay ** 2, 2 * (origin[0] * direction[0] + origin[2] * direction[2] - radialAtOrigin * radialAlongRay), origin[0] ** 2 + origin[2] ** 2 - radialAtOrigin ** 2);
73
+ for (const distance of roots) {
74
+ const y = origin[1] + distance * direction[1];
75
+ if (distance >= 0 && y >= -half - EPSILON && y <= half + EPSILON) {
76
+ const x = origin[0] + distance * direction[0];
77
+ const z = origin[2] + distance * direction[2];
78
+ const radial = Math.hypot(x, z) || 1;
79
+ const normal = [x / radial, -slope, z / radial];
80
+ const length = Math.hypot(...normal);
81
+ candidates.push({ distance, normal: normal.map(value => value / length) });
82
+ }
83
+ }
84
+ if (Math.abs(direction[1]) > 1e-15) {
85
+ for (const [y, radius, normalY] of [
86
+ [-half, this.radiusBottom, -1],
87
+ [half, this.radiusTop, 1]
88
+ ]) {
89
+ const distance = (y - origin[1]) / direction[1];
90
+ const x = origin[0] + distance * direction[0];
91
+ const z = origin[2] + distance * direction[2];
92
+ if (distance >= 0 && Math.hypot(x, z) <= radius + EPSILON)
93
+ candidates.push({ distance, normal: [0, normalY, 0] });
94
+ }
95
+ }
96
+ return candidates.sort((a, b) => a.distance - b.distance)[0];
97
+ }
98
+ }
99
+ //# sourceMappingURL=cylinder-shape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cylinder-shape.js","sourceRoot":"","sources":["../../../src/lib/shapes/cylinder-shape.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EACL,0BAA0B,EAC1B,iBAAiB,EACjB,cAAc,EAGf,4BAAyB;AAE1B,MAAM,OAAO,GAAG,IAAI,CAAC;AASrB,mFAAmF;AACnF,MAAM,OAAO,aAAc,SAAQ,iBAAiB;IAMlD,YAAY,QAA4B,EAAE;QACxC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QANb,SAAI,GAAG,UAAmB,CAAC;QAOlC,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AQ,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,EAAC,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QACD,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,CAAC;CACF"}
@@ -0,0 +1,55 @@
1
+ import { Matrix4, Vector3 } from '@math.gl/core';
2
+ import { AxisAlignedBoundingBox } from "../bounding-volumes/axis-aligned-bounding-box.js";
3
+ import { BoundingSphere } from "../bounding-volumes/bounding-sphere.js";
4
+ import type { BoundingVolume } from "../bounding-volumes/bounding-volume.js";
5
+ import type { Plane } from "../plane.js";
6
+ import type { Ray } from "../ray.js";
7
+ export type RayIntersection = {
8
+ distance: number;
9
+ point: Vector3;
10
+ normal: Vector3;
11
+ entering: boolean;
12
+ };
13
+ export interface ImplicitShape extends BoundingVolume {
14
+ readonly type: 'box' | 'capsule' | 'cylinder' | 'plane' | 'sphere';
15
+ readonly matrix: Matrix4;
16
+ clone(): ImplicitShape;
17
+ equals(shape: ImplicitShape): boolean;
18
+ containsPoint(point: readonly number[]): boolean;
19
+ intersectRay(ray: Ray): RayIntersection | undefined;
20
+ getAxisAlignedBoundingBox(): AxisAlignedBoundingBox | undefined;
21
+ getBoundingSphere(): BoundingSphere | undefined;
22
+ }
23
+ export type LocalRayIntersection = {
24
+ distance: number;
25
+ normal: readonly number[];
26
+ };
27
+ /** Shared affine transform, support mapping and query implementation for finite convex shapes. */
28
+ export declare abstract class ImplicitShapeBase implements ImplicitShape {
29
+ abstract readonly type: ImplicitShape['type'];
30
+ readonly matrix: Matrix4;
31
+ protected inverseMatrix: Matrix4;
32
+ constructor(matrix?: readonly number[]);
33
+ abstract clone(): ImplicitShapeBase;
34
+ abstract containsLocalPoint(point: readonly number[]): boolean;
35
+ abstract distanceToLocalPoint(point: readonly number[]): number;
36
+ abstract supportLocal(direction: readonly number[]): readonly number[];
37
+ abstract intersectLocalRay(origin: readonly number[], direction: readonly number[]): LocalRayIntersection | undefined;
38
+ equals(shape: ImplicitShape): boolean;
39
+ transform(transform: readonly number[]): this;
40
+ containsPoint(point: readonly number[]): boolean;
41
+ distanceSquaredTo(point: readonly number[]): number;
42
+ /** Exact for rigid/uniform transforms; conservative estimate for non-uniform scale or shear. */
43
+ distanceTo(point: readonly number[]): number;
44
+ intersectPlane(plane: Plane): number;
45
+ intersectRay(ray: Ray): RayIntersection | undefined;
46
+ getAxisAlignedBoundingBox(): AxisAlignedBoundingBox | undefined;
47
+ getBoundingSphere(): BoundingSphere | undefined;
48
+ protected getSupportPoint(worldDirection: readonly number[]): Vector3;
49
+ }
50
+ export declare function validateAffineMatrix(matrix: readonly number[]): void;
51
+ export declare function solveQuadratic(a: number, b: number, c: number): number[];
52
+ export declare function closestDistanceToSegment2D(px: number, py: number, ax: number, ay: number, bx: number, by: number): number;
53
+ /** Distance in the radial/Y half-plane to a spherical profile arc selected by normal Y range. */
54
+ export declare function closestDistanceToCircleArc2D(px: number, py: number, centerY: number, radius: number, minimumNormalY: number, maximumNormalY: number): number;
55
+ //# sourceMappingURL=implicit-shape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"implicit-shape.d.ts","sourceRoot":"","sources":["../../../src/lib/shapes/implicit-shape.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,OAAO,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAC,sBAAsB,EAAC,yDAAsD;AACrF,OAAO,EAAC,cAAc,EAAC,+CAA4C;AACnE,OAAO,KAAK,EAAC,cAAc,EAAC,+CAA4C;AACxE,OAAO,KAAK,EAAC,KAAK,EAAC,oBAAiB;AACpC,OAAO,KAAK,EAAC,GAAG,EAAC,kBAAe;AAEhC,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,KA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