@codexo/exojs-physics 0.19.0 → 0.20.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.
Files changed (207) hide show
  1. package/README.md +8 -73
  2. package/{dist/esm/debug/index.d.ts → debug.d.ts} +1 -2
  3. package/debug.js +1 -0
  4. package/index.d.ts +1 -0
  5. package/index.js +1 -0
  6. package/package.json +17 -23
  7. package/dist/esm/Aabb.d.ts +0 -10
  8. package/dist/esm/Aabb.d.ts.map +0 -1
  9. package/dist/esm/Aabb.js +0 -16
  10. package/dist/esm/Aabb.js.map +0 -1
  11. package/dist/esm/Collider.d.ts +0 -107
  12. package/dist/esm/Collider.d.ts.map +0 -1
  13. package/dist/esm/Collider.js +0 -284
  14. package/dist/esm/Collider.js.map +0 -1
  15. package/dist/esm/ContactGraph.d.ts +0 -154
  16. package/dist/esm/ContactGraph.d.ts.map +0 -1
  17. package/dist/esm/ContactGraph.js +0 -383
  18. package/dist/esm/ContactGraph.js.map +0 -1
  19. package/dist/esm/ContactModifier.d.ts +0 -62
  20. package/dist/esm/ContactModifier.d.ts.map +0 -1
  21. package/dist/esm/ContactModifier.js +0 -49
  22. package/dist/esm/ContactModifier.js.map +0 -1
  23. package/dist/esm/PhysicsBody.d.ts +0 -186
  24. package/dist/esm/PhysicsBody.d.ts.map +0 -1
  25. package/dist/esm/PhysicsBody.js +0 -526
  26. package/dist/esm/PhysicsBody.js.map +0 -1
  27. package/dist/esm/PhysicsBodyComponent.d.ts +0 -45
  28. package/dist/esm/PhysicsBodyComponent.d.ts.map +0 -1
  29. package/dist/esm/PhysicsBodyComponent.js +0 -77
  30. package/dist/esm/PhysicsBodyComponent.js.map +0 -1
  31. package/dist/esm/PhysicsWorld.d.ts +0 -567
  32. package/dist/esm/PhysicsWorld.d.ts.map +0 -1
  33. package/dist/esm/PhysicsWorld.js +0 -1096
  34. package/dist/esm/PhysicsWorld.js.map +0 -1
  35. package/dist/esm/TimeStepper.d.ts +0 -40
  36. package/dist/esm/TimeStepper.d.ts.map +0 -1
  37. package/dist/esm/TimeStepper.js +0 -59
  38. package/dist/esm/TimeStepper.js.map +0 -1
  39. package/dist/esm/backend/NativePhysicsBackend.d.ts +0 -28
  40. package/dist/esm/backend/NativePhysicsBackend.d.ts.map +0 -1
  41. package/dist/esm/backend/NativePhysicsBackend.js +0 -52
  42. package/dist/esm/backend/NativePhysicsBackend.js.map +0 -1
  43. package/dist/esm/backend/PhysicsBackend.d.ts +0 -38
  44. package/dist/esm/backend/PhysicsBackend.d.ts.map +0 -1
  45. package/dist/esm/binding/BindingRegistry.d.ts +0 -48
  46. package/dist/esm/binding/BindingRegistry.d.ts.map +0 -1
  47. package/dist/esm/binding/BindingRegistry.js +0 -81
  48. package/dist/esm/binding/BindingRegistry.js.map +0 -1
  49. package/dist/esm/binding/PhysicsBinding.d.ts +0 -37
  50. package/dist/esm/binding/PhysicsBinding.d.ts.map +0 -1
  51. package/dist/esm/binding/PhysicsBinding.js +0 -54
  52. package/dist/esm/binding/PhysicsBinding.js.map +0 -1
  53. package/dist/esm/binding/nodeWorldTransform.d.ts +0 -18
  54. package/dist/esm/binding/nodeWorldTransform.d.ts.map +0 -1
  55. package/dist/esm/binding/nodeWorldTransform.js +0 -41
  56. package/dist/esm/binding/nodeWorldTransform.js.map +0 -1
  57. package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts +0 -84
  58. package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts.map +0 -1
  59. package/dist/esm/broadphase/AabbTreeBroadPhase.js +0 -183
  60. package/dist/esm/broadphase/AabbTreeBroadPhase.js.map +0 -1
  61. package/dist/esm/broadphase/BroadPhase.d.ts +0 -25
  62. package/dist/esm/broadphase/BroadPhase.d.ts.map +0 -1
  63. package/dist/esm/broadphase/index.d.ts +0 -3
  64. package/dist/esm/broadphase/index.d.ts.map +0 -1
  65. package/dist/esm/collision/CollisionProxy.d.ts +0 -15
  66. package/dist/esm/collision/CollisionProxy.d.ts.map +0 -1
  67. package/dist/esm/collision/Manifold.d.ts +0 -34
  68. package/dist/esm/collision/Manifold.d.ts.map +0 -1
  69. package/dist/esm/collision/Manifold.js +0 -37
  70. package/dist/esm/collision/Manifold.js.map +0 -1
  71. package/dist/esm/collision/chainAdjacency.d.ts +0 -2
  72. package/dist/esm/collision/chainAdjacency.d.ts.map +0 -1
  73. package/dist/esm/collision/chainAdjacency.js +0 -44
  74. package/dist/esm/collision/chainAdjacency.js.map +0 -1
  75. package/dist/esm/collision/dispatch.d.ts +0 -35
  76. package/dist/esm/collision/dispatch.d.ts.map +0 -1
  77. package/dist/esm/collision/dispatch.js +0 -58
  78. package/dist/esm/collision/dispatch.js.map +0 -1
  79. package/dist/esm/collision/index.d.ts +0 -5
  80. package/dist/esm/collision/index.d.ts.map +0 -1
  81. package/dist/esm/collision/narrowphase.d.ts +0 -17
  82. package/dist/esm/collision/narrowphase.d.ts.map +0 -1
  83. package/dist/esm/collision/narrowphase.js +0 -555
  84. package/dist/esm/collision/narrowphase.js.map +0 -1
  85. package/dist/esm/collision/segments.d.ts +0 -19
  86. package/dist/esm/collision/segments.d.ts.map +0 -1
  87. package/dist/esm/collision/segments.js +0 -36
  88. package/dist/esm/collision/segments.js.map +0 -1
  89. package/dist/esm/collision/sweep.d.ts +0 -35
  90. package/dist/esm/collision/sweep.d.ts.map +0 -1
  91. package/dist/esm/collision/sweep.js +0 -437
  92. package/dist/esm/collision/sweep.js.map +0 -1
  93. package/dist/esm/debug/PhysicsDebugDraw.d.ts +0 -72
  94. package/dist/esm/debug/PhysicsDebugDraw.d.ts.map +0 -1
  95. package/dist/esm/debug/PhysicsDebugDraw.js +0 -239
  96. package/dist/esm/debug/PhysicsDebugDraw.js.map +0 -1
  97. package/dist/esm/debug/index.d.ts.map +0 -1
  98. package/dist/esm/debug/index.js +0 -3
  99. package/dist/esm/events.d.ts +0 -36
  100. package/dist/esm/events.d.ts.map +0 -1
  101. package/dist/esm/index.d.ts +0 -2
  102. package/dist/esm/index.d.ts.map +0 -1
  103. package/dist/esm/index.js +0 -25
  104. package/dist/esm/joints/DistanceJoint.d.ts +0 -70
  105. package/dist/esm/joints/DistanceJoint.d.ts.map +0 -1
  106. package/dist/esm/joints/DistanceJoint.js +0 -167
  107. package/dist/esm/joints/DistanceJoint.js.map +0 -1
  108. package/dist/esm/joints/Joint.d.ts +0 -76
  109. package/dist/esm/joints/Joint.d.ts.map +0 -1
  110. package/dist/esm/joints/Joint.js +0 -62
  111. package/dist/esm/joints/Joint.js.map +0 -1
  112. package/dist/esm/joints/MouseJoint.d.ts +0 -55
  113. package/dist/esm/joints/MouseJoint.d.ts.map +0 -1
  114. package/dist/esm/joints/MouseJoint.js +0 -139
  115. package/dist/esm/joints/MouseJoint.js.map +0 -1
  116. package/dist/esm/joints/PrismaticJoint.d.ts +0 -84
  117. package/dist/esm/joints/PrismaticJoint.d.ts.map +0 -1
  118. package/dist/esm/joints/PrismaticJoint.js +0 -218
  119. package/dist/esm/joints/PrismaticJoint.js.map +0 -1
  120. package/dist/esm/joints/RevoluteJoint.d.ts +0 -77
  121. package/dist/esm/joints/RevoluteJoint.d.ts.map +0 -1
  122. package/dist/esm/joints/RevoluteJoint.js +0 -204
  123. package/dist/esm/joints/RevoluteJoint.js.map +0 -1
  124. package/dist/esm/joints/WeldJoint.d.ts +0 -60
  125. package/dist/esm/joints/WeldJoint.d.ts.map +0 -1
  126. package/dist/esm/joints/WeldJoint.js +0 -166
  127. package/dist/esm/joints/WeldJoint.js.map +0 -1
  128. package/dist/esm/joints/WheelJoint.d.ts +0 -91
  129. package/dist/esm/joints/WheelJoint.d.ts.map +0 -1
  130. package/dist/esm/joints/WheelJoint.js +0 -235
  131. package/dist/esm/joints/WheelJoint.js.map +0 -1
  132. package/dist/esm/math.d.ts +0 -29
  133. package/dist/esm/math.d.ts.map +0 -1
  134. package/dist/esm/math.js +0 -60
  135. package/dist/esm/math.js.map +0 -1
  136. package/dist/esm/physicsBuildInfo.d.ts +0 -16
  137. package/dist/esm/physicsBuildInfo.d.ts.map +0 -1
  138. package/dist/esm/physicsBuildInfo.js +0 -10
  139. package/dist/esm/physicsBuildInfo.js.map +0 -1
  140. package/dist/esm/public.d.ts +0 -34
  141. package/dist/esm/public.d.ts.map +0 -1
  142. package/dist/esm/query/QueryEngine.d.ts +0 -95
  143. package/dist/esm/query/QueryEngine.d.ts.map +0 -1
  144. package/dist/esm/query/QueryEngine.js +0 -512
  145. package/dist/esm/query/QueryEngine.js.map +0 -1
  146. package/dist/esm/query/SpatialIndex.d.ts +0 -34
  147. package/dist/esm/query/SpatialIndex.d.ts.map +0 -1
  148. package/dist/esm/shapes/AnyShape.d.ts +0 -14
  149. package/dist/esm/shapes/AnyShape.d.ts.map +0 -1
  150. package/dist/esm/shapes/BoxShape.d.ts +0 -12
  151. package/dist/esm/shapes/BoxShape.d.ts.map +0 -1
  152. package/dist/esm/shapes/BoxShape.js +0 -41
  153. package/dist/esm/shapes/BoxShape.js.map +0 -1
  154. package/dist/esm/shapes/CapsuleShape.d.ts +0 -30
  155. package/dist/esm/shapes/CapsuleShape.d.ts.map +0 -1
  156. package/dist/esm/shapes/CapsuleShape.js +0 -88
  157. package/dist/esm/shapes/CapsuleShape.js.map +0 -1
  158. package/dist/esm/shapes/ChainEdgeShape.d.ts +0 -2
  159. package/dist/esm/shapes/ChainEdgeShape.d.ts.map +0 -1
  160. package/dist/esm/shapes/ChainEdgeShape.js +0 -66
  161. package/dist/esm/shapes/ChainEdgeShape.js.map +0 -1
  162. package/dist/esm/shapes/ChainShape.d.ts +0 -46
  163. package/dist/esm/shapes/ChainShape.d.ts.map +0 -1
  164. package/dist/esm/shapes/ChainShape.js +0 -85
  165. package/dist/esm/shapes/ChainShape.js.map +0 -1
  166. package/dist/esm/shapes/CircleShape.d.ts +0 -14
  167. package/dist/esm/shapes/CircleShape.d.ts.map +0 -1
  168. package/dist/esm/shapes/CircleShape.js +0 -31
  169. package/dist/esm/shapes/CircleShape.js.map +0 -1
  170. package/dist/esm/shapes/PolygonShape.d.ts +0 -24
  171. package/dist/esm/shapes/PolygonShape.d.ts.map +0 -1
  172. package/dist/esm/shapes/PolygonShape.js +0 -153
  173. package/dist/esm/shapes/PolygonShape.js.map +0 -1
  174. package/dist/esm/shapes/SegmentShape.d.ts +0 -31
  175. package/dist/esm/shapes/SegmentShape.d.ts.map +0 -1
  176. package/dist/esm/shapes/SegmentShape.js +0 -62
  177. package/dist/esm/shapes/SegmentShape.js.map +0 -1
  178. package/dist/esm/shapes/Shape.d.ts +0 -37
  179. package/dist/esm/shapes/Shape.d.ts.map +0 -1
  180. package/dist/esm/shapes/Shape.js +0 -15
  181. package/dist/esm/shapes/Shape.js.map +0 -1
  182. package/dist/esm/shapes/convexParts.d.ts +0 -21
  183. package/dist/esm/shapes/convexParts.d.ts.map +0 -1
  184. package/dist/esm/shapes/convexParts.js +0 -26
  185. package/dist/esm/shapes/convexParts.js.map +0 -1
  186. package/dist/esm/shapes/decompose.d.ts +0 -2
  187. package/dist/esm/shapes/decompose.d.ts.map +0 -1
  188. package/dist/esm/shapes/decompose.js +0 -272
  189. package/dist/esm/shapes/decompose.js.map +0 -1
  190. package/dist/esm/shapes/index.d.ts +0 -9
  191. package/dist/esm/shapes/index.d.ts.map +0 -1
  192. package/dist/esm/solver/ContactSolver.d.ts +0 -94
  193. package/dist/esm/solver/ContactSolver.d.ts.map +0 -1
  194. package/dist/esm/solver/ContactSolver.js +0 -457
  195. package/dist/esm/solver/ContactSolver.js.map +0 -1
  196. package/dist/esm/solver/tolerances.d.ts +0 -2
  197. package/dist/esm/solver/tolerances.d.ts.map +0 -1
  198. package/dist/esm/solver/tolerances.js +0 -36
  199. package/dist/esm/solver/tolerances.js.map +0 -1
  200. package/dist/esm/sort.d.ts +0 -2
  201. package/dist/esm/sort.d.ts.map +0 -1
  202. package/dist/esm/sort.js +0 -44
  203. package/dist/esm/sort.js.map +0 -1
  204. package/dist/esm/types.d.ts +0 -35
  205. package/dist/esm/types.d.ts.map +0 -1
  206. package/dist/esm/types.js +0 -26
  207. package/dist/esm/types.js.map +0 -1
@@ -1,41 +0,0 @@
1
- import { PolygonShape } from "./PolygonShape.js";
2
-
3
- //#region src/shapes/BoxShape.ts
4
- /**
5
- * Axis-aligned box of `width × height` centred on the collider's local origin -
6
- * a convenience over {@link PolygonShape}. The result is a regular polygon, so
7
- * it participates in the polygon narrow phase like any other convex shape.
8
- */
9
- var BoxShape = class extends PolygonShape {
10
- width;
11
- height;
12
- constructor(width, height) {
13
- if (!Number.isFinite(width) || width <= 0 || !Number.isFinite(height) || height <= 0) throw new RangeError(`BoxShape: width and height must be positive finite numbers, received ${width} × ${height}.`);
14
- const hw = width / 2;
15
- const hh = height / 2;
16
- super([
17
- {
18
- x: -hw,
19
- y: -hh
20
- },
21
- {
22
- x: hw,
23
- y: -hh
24
- },
25
- {
26
- x: hw,
27
- y: hh
28
- },
29
- {
30
- x: -hw,
31
- y: hh
32
- }
33
- ]);
34
- this.width = width;
35
- this.height = height;
36
- }
37
- };
38
-
39
- //#endregion
40
- export { BoxShape };
41
- //# sourceMappingURL=BoxShape.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BoxShape.js","names":[],"sources":["../../../src/shapes/BoxShape.ts"],"sourcesContent":["import { PolygonShape } from './PolygonShape';\n\n/**\n * Axis-aligned box of `width × height` centred on the collider's local origin -\n * a convenience over {@link PolygonShape}. The result is a regular polygon, so\n * it participates in the polygon narrow phase like any other convex shape.\n */\nexport class BoxShape extends PolygonShape {\n public readonly width: number;\n public readonly height: number;\n\n public constructor(width: number, height: number) {\n if (!Number.isFinite(width) || width <= 0 || !Number.isFinite(height) || height <= 0) {\n throw new RangeError(`BoxShape: width and height must be positive finite numbers, received ${width} × ${height}.`);\n }\n\n const hw = width / 2;\n const hh = height / 2;\n\n super([\n { x: -hw, y: -hh },\n { x: hw, y: -hh },\n { x: hw, y: hh },\n { x: -hw, y: hh },\n ]);\n\n this.width = width;\n this.height = height;\n }\n}\n"],"mappings":";;;;;;;;AAOA,IAAa,WAAb,cAA8B,aAAa;CACzC,AAAgB;CAChB,AAAgB;CAEhB,AAAO,YAAY,OAAe,QAAgB;EAChD,IAAI,CAAC,OAAO,SAAS,KAAK,KAAK,SAAS,KAAK,CAAC,OAAO,SAAS,MAAM,KAAK,UAAU,GACjF,MAAM,IAAI,WAAW,wEAAwE,MAAM,KAAK,OAAO,EAAE;EAGnH,MAAM,KAAK,QAAQ;EACnB,MAAM,KAAK,SAAS;EAEpB,MAAM;GACJ;IAAE,GAAG,CAAC;IAAI,GAAG,CAAC;GAAG;GACjB;IAAE,GAAG;IAAI,GAAG,CAAC;GAAG;GAChB;IAAE,GAAG;IAAI,GAAG;GAAG;GACf;IAAE,GAAG,CAAC;IAAI,GAAG;GAAG;EAClB,CAAC;EAED,KAAK,QAAQ;EACb,KAAK,SAAS;CAChB;AACF"}
@@ -1,30 +0,0 @@
1
- import type { ShapeMassProperties } from './Shape';
2
- import { Shape } from './Shape';
3
- /**
4
- * A capsule: the set of points within `radius` of the segment between two
5
- * local-space endpoints. Exact geometry, never a polygon approximation - the
6
- * mass model and the narrow phase both work on the spine and the radius, so
7
- * nothing about a capsule depends on a tessellation constant.
8
- *
9
- * The spine is given as two points rather than a centre, a half-height and an
10
- * angle: every consumer needs the two endpoints, and the collider already
11
- * carries a local rotation, so an angle on the shape would be a second and
12
- * redundant orientation.
13
- *
14
- * A zero-length spine is rejected rather than quietly becoming a circle - use
15
- * {@link CircleShape} to say that.
16
- */
17
- export declare class CapsuleShape extends Shape {
18
- readonly type: 'capsule';
19
- /** Local spine endpoints, flattened - the same layout a polygon uses. */
20
- readonly vertices: readonly number[];
21
- /** Outward unit normals of the two spine sides, flattened. */
22
- readonly normals: readonly number[];
23
- readonly radius: number;
24
- /** Spine length; the capsule is `length + 2 × radius` long overall. */
25
- readonly length: number;
26
- readonly boundingRadius: number;
27
- readonly massProperties: ShapeMassProperties;
28
- constructor(x0: number, y0: number, x1: number, y1: number, radius: number);
29
- }
30
- //# sourceMappingURL=CapsuleShape.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CapsuleShape.d.ts","sourceRoot":"","sources":["../../../src/shapes/CapsuleShape.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAKhC;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,SAAgB,IAAI,EAAG,SAAS,CAAU;IAE1C,yEAAyE;IACzE,SAAgB,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAE5C,8DAA8D;IAC9D,SAAgB,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAE3C,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,uEAAuE;IACvE,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,SAAgB,cAAc,EAAE,MAAM,CAAC;IACvC,SAAgB,cAAc,EAAE,mBAAmB,CAAC;IAEpD,YAAmB,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAiChF;CACF"}
@@ -1,88 +0,0 @@
1
- import { Shape } from "./Shape.js";
2
-
3
- //#region src/shapes/CapsuleShape.ts
4
- /** Spines shorter than this (px) have no well-defined orientation. */
5
- const minimumLength = .001;
6
- /**
7
- * A capsule: the set of points within `radius` of the segment between two
8
- * local-space endpoints. Exact geometry, never a polygon approximation - the
9
- * mass model and the narrow phase both work on the spine and the radius, so
10
- * nothing about a capsule depends on a tessellation constant.
11
- *
12
- * The spine is given as two points rather than a centre, a half-height and an
13
- * angle: every consumer needs the two endpoints, and the collider already
14
- * carries a local rotation, so an angle on the shape would be a second and
15
- * redundant orientation.
16
- *
17
- * A zero-length spine is rejected rather than quietly becoming a circle - use
18
- * {@link CircleShape} to say that.
19
- */
20
- var CapsuleShape = class extends Shape {
21
- type = "capsule";
22
- /** Local spine endpoints, flattened - the same layout a polygon uses. */
23
- vertices;
24
- /** Outward unit normals of the two spine sides, flattened. */
25
- normals;
26
- radius;
27
- /** Spine length; the capsule is `length + 2 × radius` long overall. */
28
- length;
29
- boundingRadius;
30
- massProperties;
31
- constructor(x0, y0, x1, y1, radius) {
32
- super();
33
- if (!Number.isFinite(x0) || !Number.isFinite(y0) || !Number.isFinite(x1) || !Number.isFinite(y1)) throw new RangeError(`CapsuleShape: spine endpoints must be finite, received (${x0}, ${y0}) and (${x1}, ${y1}).`);
34
- if (!Number.isFinite(radius) || radius <= 0) throw new RangeError(`CapsuleShape: radius must be a positive finite number, received ${radius}.`);
35
- const ex = x1 - x0;
36
- const ey = y1 - y0;
37
- const length = Math.hypot(ex, ey);
38
- if (length < minimumLength) throw new RangeError(`CapsuleShape: the spine is degenerate (length ${length}); use CircleShape for a round collider.`);
39
- const nx = ey / length;
40
- const ny = -ex / length;
41
- this.radius = radius;
42
- this.length = length;
43
- this.vertices = Object.freeze([
44
- x0,
45
- y0,
46
- x1,
47
- y1
48
- ]);
49
- this.normals = Object.freeze([
50
- nx,
51
- ny,
52
- -nx,
53
- -ny
54
- ]);
55
- this.boundingRadius = Math.max(Math.hypot(x0, y0), Math.hypot(x1, y1)) + radius;
56
- this.massProperties = Object.freeze(capsuleMassProperties(x0, y0, x1, y1, length, radius));
57
- Object.freeze(this);
58
- }
59
- };
60
- /**
61
- * Exact area-based mass properties: a `2r × L` rectangle plus the two end
62
- * caps, which together are a full disc of radius `r` displaced to the ends.
63
- *
64
- * The second moment about the centroid is the sum of
65
- * - the rectangle's polar moment `A·((2r)² + L²)/12`, and
66
- * - the two caps', each shifted from its own centroid to the capsule centre by
67
- * the parallel-axis theorem. A half-disc's polar moment about the centre of
68
- * its flat edge is `π r⁴/4`, and its centroid sits `4r/(3π)` from that edge.
69
- *
70
- * At `L → 0` the cap terms alone give `π r⁴/2`, the disc value {@link CircleShape}
71
- * computes - which is the check that pins the constants.
72
- */
73
- const capsuleMassProperties = (x0, y0, x1, y1, length, radius) => {
74
- const rectangleArea = 2 * radius * length;
75
- const capArea = Math.PI * radius * radius;
76
- const rectangleInertia = rectangleArea * (4 * radius * radius + length * length) / 12;
77
- const capInertia = Math.PI * radius ** 4 / 2 + Math.PI * radius * radius * length * length / 4 + 4 * radius ** 3 * length / 3;
78
- return {
79
- area: rectangleArea + capArea,
80
- centroidX: (x0 + x1) / 2,
81
- centroidY: (y0 + y1) / 2,
82
- unitInertia: rectangleInertia + capInertia
83
- };
84
- };
85
-
86
- //#endregion
87
- export { CapsuleShape };
88
- //# sourceMappingURL=CapsuleShape.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CapsuleShape.js","names":[],"sources":["../../../src/shapes/CapsuleShape.ts"],"sourcesContent":["import type { ShapeMassProperties } from './Shape';\nimport { Shape } from './Shape';\n\n/** Spines shorter than this (px) have no well-defined orientation. */\nconst minimumLength = 1e-3;\n\n/**\n * A capsule: the set of points within `radius` of the segment between two\n * local-space endpoints. Exact geometry, never a polygon approximation - the\n * mass model and the narrow phase both work on the spine and the radius, so\n * nothing about a capsule depends on a tessellation constant.\n *\n * The spine is given as two points rather than a centre, a half-height and an\n * angle: every consumer needs the two endpoints, and the collider already\n * carries a local rotation, so an angle on the shape would be a second and\n * redundant orientation.\n *\n * A zero-length spine is rejected rather than quietly becoming a circle - use\n * {@link CircleShape} to say that.\n */\nexport class CapsuleShape extends Shape {\n public readonly type = 'capsule' as const;\n\n /** Local spine endpoints, flattened - the same layout a polygon uses. */\n public readonly vertices: readonly number[];\n\n /** Outward unit normals of the two spine sides, flattened. */\n public readonly normals: readonly number[];\n\n public readonly radius: number;\n\n /** Spine length; the capsule is `length + 2 × radius` long overall. */\n public readonly length: number;\n\n public readonly boundingRadius: number;\n public readonly massProperties: ShapeMassProperties;\n\n public constructor(x0: number, y0: number, x1: number, y1: number, radius: number) {\n super();\n\n if (!Number.isFinite(x0) || !Number.isFinite(y0) || !Number.isFinite(x1) || !Number.isFinite(y1)) {\n throw new RangeError(`CapsuleShape: spine endpoints must be finite, received (${x0}, ${y0}) and (${x1}, ${y1}).`);\n }\n\n if (!Number.isFinite(radius) || radius <= 0) {\n throw new RangeError(`CapsuleShape: radius must be a positive finite number, received ${radius}.`);\n }\n\n const ex = x1 - x0;\n const ey = y1 - y0;\n const length = Math.hypot(ex, ey);\n\n if (length < minimumLength) {\n throw new RangeError(`CapsuleShape: the spine is degenerate (length ${length}); use CircleShape for a round collider.`);\n }\n\n // Same convention as PolygonShape: for the counter-clockwise edge i → i+1 the\n // outward normal is (eY, -eX). A two-vertex ring has two opposite edges, so\n // the second normal is the negation of the first.\n const nx = ey / length;\n const ny = -ex / length;\n\n this.radius = radius;\n this.length = length;\n this.vertices = Object.freeze([x0, y0, x1, y1]);\n this.normals = Object.freeze([nx, ny, -nx, -ny]);\n this.boundingRadius = Math.max(Math.hypot(x0, y0), Math.hypot(x1, y1)) + radius;\n this.massProperties = Object.freeze(capsuleMassProperties(x0, y0, x1, y1, length, radius));\n\n Object.freeze(this);\n }\n}\n\n/**\n * Exact area-based mass properties: a `2r × L` rectangle plus the two end\n * caps, which together are a full disc of radius `r` displaced to the ends.\n *\n * The second moment about the centroid is the sum of\n * - the rectangle's polar moment `A·((2r)² + L²)/12`, and\n * - the two caps', each shifted from its own centroid to the capsule centre by\n * the parallel-axis theorem. A half-disc's polar moment about the centre of\n * its flat edge is `π r⁴/4`, and its centroid sits `4r/(3π)` from that edge.\n *\n * At `L → 0` the cap terms alone give `π r⁴/2`, the disc value {@link CircleShape}\n * computes - which is the check that pins the constants.\n */\nconst capsuleMassProperties = (x0: number, y0: number, x1: number, y1: number, length: number, radius: number): ShapeMassProperties => {\n const rectangleArea = 2 * radius * length;\n const capArea = Math.PI * radius * radius;\n const rectangleInertia = (rectangleArea * (4 * radius * radius + length * length)) / 12;\n const capInertia = (Math.PI * radius ** 4) / 2 + (Math.PI * radius * radius * length * length) / 4 + (4 * radius ** 3 * length) / 3;\n\n return {\n area: rectangleArea + capArea,\n // Both the rectangle and the cap pair are symmetric about the spine midpoint.\n centroidX: (x0 + x1) / 2,\n centroidY: (y0 + y1) / 2,\n unitInertia: rectangleInertia + capInertia,\n };\n};\n"],"mappings":";;;;AAIA,MAAM,gBAAgB;;;;;;;;;;;;;;;AAgBtB,IAAa,eAAb,cAAkC,MAAM;CACtC,AAAgB,OAAO;;CAGvB,AAAgB;;CAGhB,AAAgB;CAEhB,AAAgB;;CAGhB,AAAgB;CAEhB,AAAgB;CAChB,AAAgB;CAEhB,AAAO,YAAY,IAAY,IAAY,IAAY,IAAY,QAAgB;EACjF,MAAM;EAEN,IAAI,CAAC,OAAO,SAAS,EAAE,KAAK,CAAC,OAAO,SAAS,EAAE,KAAK,CAAC,OAAO,SAAS,EAAE,KAAK,CAAC,OAAO,SAAS,EAAE,GAC7F,MAAM,IAAI,WAAW,2DAA2D,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,GAAG,GAAG;EAGlH,IAAI,CAAC,OAAO,SAAS,MAAM,KAAK,UAAU,GACxC,MAAM,IAAI,WAAW,mEAAmE,OAAO,EAAE;EAGnG,MAAM,KAAK,KAAK;EAChB,MAAM,KAAK,KAAK;EAChB,MAAM,SAAS,KAAK,MAAM,IAAI,EAAE;EAEhC,IAAI,SAAS,eACX,MAAM,IAAI,WAAW,iDAAiD,OAAO,yCAAyC;EAMxH,MAAM,KAAK,KAAK;EAChB,MAAM,KAAK,CAAC,KAAK;EAEjB,KAAK,SAAS;EACd,KAAK,SAAS;EACd,KAAK,WAAW,OAAO,OAAO;GAAC;GAAI;GAAI;GAAI;EAAE,CAAC;EAC9C,KAAK,UAAU,OAAO,OAAO;GAAC;GAAI;GAAI,CAAC;GAAI,CAAC;EAAE,CAAC;EAC/C,KAAK,iBAAiB,KAAK,IAAI,KAAK,MAAM,IAAI,EAAE,GAAG,KAAK,MAAM,IAAI,EAAE,CAAC,IAAI;EACzE,KAAK,iBAAiB,OAAO,OAAO,sBAAsB,IAAI,IAAI,IAAI,IAAI,QAAQ,MAAM,CAAC;EAEzF,OAAO,OAAO,IAAI;CACpB;AACF;;;;;;;;;;;;;;AAeA,MAAM,yBAAyB,IAAY,IAAY,IAAY,IAAY,QAAgB,WAAwC;CACrI,MAAM,gBAAgB,IAAI,SAAS;CACnC,MAAM,UAAU,KAAK,KAAK,SAAS;CACnC,MAAM,mBAAoB,iBAAiB,IAAI,SAAS,SAAS,SAAS,UAAW;CACrF,MAAM,aAAc,KAAK,KAAK,UAAU,IAAK,IAAK,KAAK,KAAK,SAAS,SAAS,SAAS,SAAU,IAAK,IAAI,UAAU,IAAI,SAAU;CAElI,OAAO;EACL,MAAM,gBAAgB;EAEtB,YAAY,KAAK,MAAM;EACvB,YAAY,KAAK,MAAM;EACvB,aAAa,mBAAmB;CAClC;AACF"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=ChainEdgeShape.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ChainEdgeShape.d.ts","sourceRoot":"","sources":["../../../src/shapes/ChainEdgeShape.ts"],"names":[],"mappings":""}
@@ -1,66 +0,0 @@
1
- import { SegmentShape } from "./SegmentShape.js";
2
-
3
- //#region src/shapes/ChainEdgeShape.ts
4
- /**
5
- * One edge of a {@link ChainShape}, the geometry the solver actually sees. Built
6
- * and owned by the engine when a chain collider is created; never authored, and
7
- * never part of the public collider set.
8
- *
9
- * It is a segment plus the adjacency of the chain it came from. The adjacency is
10
- * stored as the rotation from this edge's outward normal to a neighbour's, which
11
- * is invariant under the collider's world transform - so the narrow phase can
12
- * compare a world-space contact normal against the neighbouring edges without
13
- * knowing the transform and without caching a second set of world normals.
14
- *
15
- * @internal
16
- */
17
- var ChainEdgeShape = class extends SegmentShape {
18
- /** Index of this edge within the owning chain. */
19
- index;
20
- /** `false` at the free end of an open chain, where a body may pass around the edge. */
21
- hasPrevious;
22
- hasNext;
23
- /** Rotation (cos, sin) taking this edge's outward normal onto the previous edge's. */
24
- previousCos;
25
- previousSin;
26
- /** Rotation (cos, sin) taking this edge's outward normal onto the next edge's. */
27
- nextCos;
28
- nextSin;
29
- constructor(chain, index) {
30
- const count = chain.count;
31
- const v = chain.vertices;
32
- const start = index;
33
- const end = (index + 1) % count;
34
- super(v[start * 2], v[start * 2 + 1], v[end * 2], v[end * 2 + 1]);
35
- const hasPrevious = chain.closed || index > 0;
36
- const hasNext = chain.closed || index < chain.edgeCount - 1;
37
- const nx = this.normals[0];
38
- const ny = this.normals[1];
39
- this.index = index;
40
- this.hasPrevious = hasPrevious;
41
- this.hasNext = hasNext;
42
- const previous = hasPrevious ? edgeNormal(v, count, (index - 1 + count) % count) : null;
43
- const next = hasNext ? edgeNormal(v, count, (index + 1) % count) : null;
44
- this.previousCos = previous ? nx * previous.x + ny * previous.y : 1;
45
- this.previousSin = previous ? nx * previous.y - ny * previous.x : 0;
46
- this.nextCos = next ? nx * next.x + ny * next.y : 1;
47
- this.nextSin = next ? nx * next.y - ny * next.x : 0;
48
- Object.freeze(this);
49
- }
50
- };
51
- /** Outward unit normal of chain edge `index`, in the chain's local space. */
52
- const edgeNormal = (vertices, count, index) => {
53
- const start = index;
54
- const end = (index + 1) % count;
55
- const ex = vertices[end * 2] - vertices[start * 2];
56
- const ey = vertices[end * 2 + 1] - vertices[start * 2 + 1];
57
- const length = Math.hypot(ex, ey);
58
- return {
59
- x: ey / length,
60
- y: -ex / length
61
- };
62
- };
63
-
64
- //#endregion
65
- export { ChainEdgeShape };
66
- //# sourceMappingURL=ChainEdgeShape.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ChainEdgeShape.js","names":[],"sources":["../../../src/shapes/ChainEdgeShape.ts"],"sourcesContent":["import type { ChainShape } from './ChainShape';\nimport { SegmentShape } from './SegmentShape';\n\n/**\n * One edge of a {@link ChainShape}, the geometry the solver actually sees. Built\n * and owned by the engine when a chain collider is created; never authored, and\n * never part of the public collider set.\n *\n * It is a segment plus the adjacency of the chain it came from. The adjacency is\n * stored as the rotation from this edge's outward normal to a neighbour's, which\n * is invariant under the collider's world transform - so the narrow phase can\n * compare a world-space contact normal against the neighbouring edges without\n * knowing the transform and without caching a second set of world normals.\n *\n * @internal\n */\nexport class ChainEdgeShape extends SegmentShape {\n /** Index of this edge within the owning chain. */\n public readonly index: number;\n\n /** `false` at the free end of an open chain, where a body may pass around the edge. */\n public readonly hasPrevious: boolean;\n public readonly hasNext: boolean;\n\n /** Rotation (cos, sin) taking this edge's outward normal onto the previous edge's. */\n public readonly previousCos: number;\n public readonly previousSin: number;\n\n /** Rotation (cos, sin) taking this edge's outward normal onto the next edge's. */\n public readonly nextCos: number;\n public readonly nextSin: number;\n\n public constructor(chain: ChainShape, index: number) {\n const count = chain.count;\n const v = chain.vertices;\n const start = index;\n const end = (index + 1) % count;\n\n super(v[start * 2]!, v[start * 2 + 1]!, v[end * 2]!, v[end * 2 + 1]!);\n\n const hasPrevious = chain.closed || index > 0;\n const hasNext = chain.closed || index < chain.edgeCount - 1;\n const nx = this.normals[0]!;\n const ny = this.normals[1]!;\n\n this.index = index;\n this.hasPrevious = hasPrevious;\n this.hasNext = hasNext;\n\n const previous = hasPrevious ? edgeNormal(v, count, (index - 1 + count) % count) : null;\n const next = hasNext ? edgeNormal(v, count, (index + 1) % count) : null;\n\n this.previousCos = previous ? nx * previous.x + ny * previous.y : 1;\n this.previousSin = previous ? nx * previous.y - ny * previous.x : 0;\n this.nextCos = next ? nx * next.x + ny * next.y : 1;\n this.nextSin = next ? nx * next.y - ny * next.x : 0;\n\n Object.freeze(this);\n }\n}\n\n/** Outward unit normal of chain edge `index`, in the chain's local space. */\nconst edgeNormal = (vertices: readonly number[], count: number, index: number): { x: number; y: number } => {\n const start = index;\n const end = (index + 1) % count;\n const ex = vertices[end * 2]! - vertices[start * 2]!;\n const ey = vertices[end * 2 + 1]! - vertices[start * 2 + 1]!;\n const length = Math.hypot(ex, ey);\n\n return { x: ey / length, y: -ex / length };\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,IAAa,iBAAb,cAAoC,aAAa;;CAE/C,AAAgB;;CAGhB,AAAgB;CAChB,AAAgB;;CAGhB,AAAgB;CAChB,AAAgB;;CAGhB,AAAgB;CAChB,AAAgB;CAEhB,AAAO,YAAY,OAAmB,OAAe;EACnD,MAAM,QAAQ,MAAM;EACpB,MAAM,IAAI,MAAM;EAChB,MAAM,QAAQ;EACd,MAAM,OAAO,QAAQ,KAAK;EAE1B,MAAM,EAAE,QAAQ,IAAK,EAAE,QAAQ,IAAI,IAAK,EAAE,MAAM,IAAK,EAAE,MAAM,IAAI,EAAG;EAEpE,MAAM,cAAc,MAAM,UAAU,QAAQ;EAC5C,MAAM,UAAU,MAAM,UAAU,QAAQ,MAAM,YAAY;EAC1D,MAAM,KAAK,KAAK,QAAQ;EACxB,MAAM,KAAK,KAAK,QAAQ;EAExB,KAAK,QAAQ;EACb,KAAK,cAAc;EACnB,KAAK,UAAU;EAEf,MAAM,WAAW,cAAc,WAAW,GAAG,QAAQ,QAAQ,IAAI,SAAS,KAAK,IAAI;EACnF,MAAM,OAAO,UAAU,WAAW,GAAG,QAAQ,QAAQ,KAAK,KAAK,IAAI;EAEnE,KAAK,cAAc,WAAW,KAAK,SAAS,IAAI,KAAK,SAAS,IAAI;EAClE,KAAK,cAAc,WAAW,KAAK,SAAS,IAAI,KAAK,SAAS,IAAI;EAClE,KAAK,UAAU,OAAO,KAAK,KAAK,IAAI,KAAK,KAAK,IAAI;EAClD,KAAK,UAAU,OAAO,KAAK,KAAK,IAAI,KAAK,KAAK,IAAI;EAElD,OAAO,OAAO,IAAI;CACpB;AACF;;AAGA,MAAM,cAAc,UAA6B,OAAe,UAA4C;CAC1G,MAAM,QAAQ;CACd,MAAM,OAAO,QAAQ,KAAK;CAC1B,MAAM,KAAK,SAAS,MAAM,KAAM,SAAS,QAAQ;CACjD,MAAM,KAAK,SAAS,MAAM,IAAI,KAAM,SAAS,QAAQ,IAAI;CACzD,MAAM,SAAS,KAAK,MAAM,IAAI,EAAE;CAEhC,OAAO;EAAE,GAAG,KAAK;EAAQ,GAAG,CAAC,KAAK;CAAO;AAC3C"}
@@ -1,46 +0,0 @@
1
- import type { PointLike } from '@codexo/exojs';
2
- import { Shape } from './Shape';
3
- /** Construction options for a {@link ChainShape}. */
4
- export interface ChainShapeOptions {
5
- /** When `true`, the last vertex connects back to the first. Default `false`. */
6
- closed?: boolean;
7
- }
8
- /**
9
- * A connected boundary through a run of local-space vertices: level outlines,
10
- * terrain, the ground of a side-scroller. Open (a polyline) or closed (a loop).
11
- *
12
- * A chain is not an array of {@link SegmentShape}s. At a shared vertex two
13
- * independent segments carry two different normals, so a body sliding across the
14
- * seam can snag, be launched, or receive a normal pointing into the surface. A
15
- * chain owns the adjacency between its edges and uses it to suppress exactly
16
- * those contacts, which is why the adjacency belongs to the engine rather than
17
- * to the caller.
18
- *
19
- * Unlike a segment, a chain is **one-sided**: each edge collides only from the
20
- * side its outward normal points to. Winding therefore decides which side is
21
- * solid, following the polygon convention - a counter-clockwise run is solid on
22
- * the outside (an island), a clockwise run is solid on the inside (a container).
23
- * Bodies on the hollow side pass through.
24
- *
25
- * It has no interior, so {@link Shape.massProperties} is `null` and a `dynamic`
26
- * body needs at least one mass-bearing collider alongside it. A `static` or
27
- * `kinematic` body carries a chain on its own.
28
- *
29
- * Collinear vertices are kept. A straight run is authoring data, and dropping it
30
- * would move the adjacency of the neighbouring edges.
31
- */
32
- export declare class ChainShape extends Shape {
33
- readonly type: 'chain';
34
- /** Local-space vertices, flattened, after welding coincident input. */
35
- readonly vertices: readonly number[];
36
- /** Number of vertices in {@link vertices}. */
37
- readonly count: number;
38
- /** Number of edges: `count` when {@link closed}, `count - 1` otherwise. */
39
- readonly edgeCount: number;
40
- readonly closed: boolean;
41
- readonly boundingRadius: number;
42
- /** Always `null`: a boundary has no interior and therefore no mass. */
43
- readonly massProperties: null;
44
- constructor(vertices: ReadonlyArray<Readonly<PointLike>>, options?: ChainShapeOptions);
45
- }
46
- //# sourceMappingURL=ChainShape.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ChainShape.d.ts","sourceRoot":"","sources":["../../../src/shapes/ChainShape.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAKhC,qDAAqD;AACrD,MAAM,WAAW,iBAAiB;IAChC,gFAAgF;IAChF,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,SAAgB,IAAI,EAAG,OAAO,CAAU;IAExC,uEAAuE;IACvE,SAAgB,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAE5C,8CAA8C;IAC9C,SAAgB,KAAK,EAAE,MAAM,CAAC;IAE9B,2EAA2E;IAC3E,SAAgB,SAAS,EAAE,MAAM,CAAC;IAElC,SAAgB,MAAM,EAAE,OAAO,CAAC;IAChC,SAAgB,cAAc,EAAE,MAAM,CAAC;IAEvC,uEAAuE;IACvE,SAAgB,cAAc,OAAQ;IAQtC,YAAmB,QAAQ,EAAE,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,GAAE,iBAAsB,EA8D/F;CACF"}
@@ -1,85 +0,0 @@
1
- import { Shape } from "./Shape.js";
2
- import { ChainEdgeShape } from "./ChainEdgeShape.js";
3
-
4
- //#region src/shapes/ChainShape.ts
5
- /** Vertices closer than this (px) are welded into one. */
6
- const weldEpsilon = 1e-4;
7
- /**
8
- * A connected boundary through a run of local-space vertices: level outlines,
9
- * terrain, the ground of a side-scroller. Open (a polyline) or closed (a loop).
10
- *
11
- * A chain is not an array of {@link SegmentShape}s. At a shared vertex two
12
- * independent segments carry two different normals, so a body sliding across the
13
- * seam can snag, be launched, or receive a normal pointing into the surface. A
14
- * chain owns the adjacency between its edges and uses it to suppress exactly
15
- * those contacts, which is why the adjacency belongs to the engine rather than
16
- * to the caller.
17
- *
18
- * Unlike a segment, a chain is **one-sided**: each edge collides only from the
19
- * side its outward normal points to. Winding therefore decides which side is
20
- * solid, following the polygon convention - a counter-clockwise run is solid on
21
- * the outside (an island), a clockwise run is solid on the inside (a container).
22
- * Bodies on the hollow side pass through.
23
- *
24
- * It has no interior, so {@link Shape.massProperties} is `null` and a `dynamic`
25
- * body needs at least one mass-bearing collider alongside it. A `static` or
26
- * `kinematic` body carries a chain on its own.
27
- *
28
- * Collinear vertices are kept. A straight run is authoring data, and dropping it
29
- * would move the adjacency of the neighbouring edges.
30
- */
31
- var ChainShape = class extends Shape {
32
- type = "chain";
33
- /** Local-space vertices, flattened, after welding coincident input. */
34
- vertices;
35
- /** Number of vertices in {@link vertices}. */
36
- count;
37
- /** Number of edges: `count` when {@link closed}, `count - 1` otherwise. */
38
- edgeCount;
39
- closed;
40
- boundingRadius;
41
- /** Always `null`: a boundary has no interior and therefore no mass. */
42
- massProperties = null;
43
- /**
44
- * @internal - the per-edge geometry the solver works on, built once with the
45
- * chain. Immutable and shared by every collider carrying this shape.
46
- */
47
- edges;
48
- constructor(vertices, options = {}) {
49
- super();
50
- const closed = options.closed ?? false;
51
- const points = [];
52
- for (const vertex of vertices) {
53
- if (!Number.isFinite(vertex.x) || !Number.isFinite(vertex.y)) throw new RangeError(`ChainShape: vertex has a non-finite component (${vertex.x}, ${vertex.y}).`);
54
- const px = points[points.length - 2];
55
- const py = points[points.length - 1];
56
- if (px !== void 0 && py !== void 0 && Math.hypot(vertex.x - px, vertex.y - py) < weldEpsilon) continue;
57
- points.push(vertex.x, vertex.y);
58
- }
59
- if (closed && points.length >= 4) {
60
- const firstX = points[0];
61
- const firstY = points[1];
62
- const lastX = points[points.length - 2];
63
- const lastY = points[points.length - 1];
64
- if (Math.hypot(lastX - firstX, lastY - firstY) < weldEpsilon) points.length -= 2;
65
- }
66
- const count = points.length / 2;
67
- const minimum = closed ? 3 : 2;
68
- if (count < minimum) throw new RangeError(`ChainShape: ${closed ? "a closed chain" : "a chain"} needs at least ${minimum} distinct vertices, received ${count}.`);
69
- let boundingRadius = 0;
70
- for (let i = 0; i < count; i++) boundingRadius = Math.max(boundingRadius, Math.hypot(points[i * 2], points[i * 2 + 1]));
71
- this.vertices = Object.freeze(points);
72
- this.count = count;
73
- this.edgeCount = closed ? count : count - 1;
74
- this.closed = closed;
75
- this.boundingRadius = boundingRadius;
76
- const edges = [];
77
- for (let i = 0; i < this.edgeCount; i++) edges.push(new ChainEdgeShape(this, i));
78
- this.edges = Object.freeze(edges);
79
- Object.freeze(this);
80
- }
81
- };
82
-
83
- //#endregion
84
- export { ChainShape };
85
- //# sourceMappingURL=ChainShape.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ChainShape.js","names":[],"sources":["../../../src/shapes/ChainShape.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\n\nimport { ChainEdgeShape } from './ChainEdgeShape';\nimport { Shape } from './Shape';\n\n/** Vertices closer than this (px) are welded into one. */\nconst weldEpsilon = 1e-4;\n\n/** Construction options for a {@link ChainShape}. */\nexport interface ChainShapeOptions {\n /** When `true`, the last vertex connects back to the first. Default `false`. */\n closed?: boolean;\n}\n\n/**\n * A connected boundary through a run of local-space vertices: level outlines,\n * terrain, the ground of a side-scroller. Open (a polyline) or closed (a loop).\n *\n * A chain is not an array of {@link SegmentShape}s. At a shared vertex two\n * independent segments carry two different normals, so a body sliding across the\n * seam can snag, be launched, or receive a normal pointing into the surface. A\n * chain owns the adjacency between its edges and uses it to suppress exactly\n * those contacts, which is why the adjacency belongs to the engine rather than\n * to the caller.\n *\n * Unlike a segment, a chain is **one-sided**: each edge collides only from the\n * side its outward normal points to. Winding therefore decides which side is\n * solid, following the polygon convention - a counter-clockwise run is solid on\n * the outside (an island), a clockwise run is solid on the inside (a container).\n * Bodies on the hollow side pass through.\n *\n * It has no interior, so {@link Shape.massProperties} is `null` and a `dynamic`\n * body needs at least one mass-bearing collider alongside it. A `static` or\n * `kinematic` body carries a chain on its own.\n *\n * Collinear vertices are kept. A straight run is authoring data, and dropping it\n * would move the adjacency of the neighbouring edges.\n */\nexport class ChainShape extends Shape {\n public readonly type = 'chain' as const;\n\n /** Local-space vertices, flattened, after welding coincident input. */\n public readonly vertices: readonly number[];\n\n /** Number of vertices in {@link vertices}. */\n public readonly count: number;\n\n /** Number of edges: `count` when {@link closed}, `count - 1` otherwise. */\n public readonly edgeCount: number;\n\n public readonly closed: boolean;\n public readonly boundingRadius: number;\n\n /** Always `null`: a boundary has no interior and therefore no mass. */\n public readonly massProperties = null;\n\n /**\n * @internal - the per-edge geometry the solver works on, built once with the\n * chain. Immutable and shared by every collider carrying this shape.\n */\n public readonly edges: readonly ChainEdgeShape[];\n\n public constructor(vertices: ReadonlyArray<Readonly<PointLike>>, options: ChainShapeOptions = {}) {\n super();\n\n const closed = options.closed ?? false;\n const points: number[] = [];\n\n for (const vertex of vertices) {\n if (!Number.isFinite(vertex.x) || !Number.isFinite(vertex.y)) {\n throw new RangeError(`ChainShape: vertex has a non-finite component (${vertex.x}, ${vertex.y}).`);\n }\n\n const px = points[points.length - 2];\n const py = points[points.length - 1];\n\n if (px !== undefined && py !== undefined && Math.hypot(vertex.x - px, vertex.y - py) < weldEpsilon) {\n continue;\n }\n\n points.push(vertex.x, vertex.y);\n }\n\n if (closed && points.length >= 4) {\n const firstX = points[0]!;\n const firstY = points[1]!;\n const lastX = points[points.length - 2]!;\n const lastY = points[points.length - 1]!;\n\n // A caller repeating the first vertex to \"close\" the loop is expressing the\n // same intent as `closed: true`; keeping it would produce a zero-length edge.\n if (Math.hypot(lastX - firstX, lastY - firstY) < weldEpsilon) {\n points.length -= 2;\n }\n }\n\n const count = points.length / 2;\n const minimum = closed ? 3 : 2;\n\n if (count < minimum) {\n throw new RangeError(`ChainShape: ${closed ? 'a closed chain' : 'a chain'} needs at least ${minimum} distinct vertices, received ${count}.`);\n }\n\n let boundingRadius = 0;\n\n for (let i = 0; i < count; i++) {\n boundingRadius = Math.max(boundingRadius, Math.hypot(points[i * 2]!, points[i * 2 + 1]!));\n }\n\n this.vertices = Object.freeze(points);\n this.count = count;\n this.edgeCount = closed ? count : count - 1;\n this.closed = closed;\n this.boundingRadius = boundingRadius;\n\n const edges: ChainEdgeShape[] = [];\n\n for (let i = 0; i < this.edgeCount; i++) {\n edges.push(new ChainEdgeShape(this, i));\n }\n\n this.edges = Object.freeze(edges);\n\n Object.freeze(this);\n }\n}\n"],"mappings":";;;;;AAMA,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;AAgCpB,IAAa,aAAb,cAAgC,MAAM;CACpC,AAAgB,OAAO;;CAGvB,AAAgB;;CAGhB,AAAgB;;CAGhB,AAAgB;CAEhB,AAAgB;CAChB,AAAgB;;CAGhB,AAAgB,iBAAiB;;;;;CAMjC,AAAgB;CAEhB,AAAO,YAAY,UAA8C,UAA6B,CAAC,GAAG;EAChG,MAAM;EAEN,MAAM,SAAS,QAAQ,UAAU;EACjC,MAAM,SAAmB,CAAC;EAE1B,KAAK,MAAM,UAAU,UAAU;GAC7B,IAAI,CAAC,OAAO,SAAS,OAAO,CAAC,KAAK,CAAC,OAAO,SAAS,OAAO,CAAC,GACzD,MAAM,IAAI,WAAW,kDAAkD,OAAO,EAAE,IAAI,OAAO,EAAE,GAAG;GAGlG,MAAM,KAAK,OAAO,OAAO,SAAS;GAClC,MAAM,KAAK,OAAO,OAAO,SAAS;GAElC,IAAI,OAAO,UAAa,OAAO,UAAa,KAAK,MAAM,OAAO,IAAI,IAAI,OAAO,IAAI,EAAE,IAAI,aACrF;GAGF,OAAO,KAAK,OAAO,GAAG,OAAO,CAAC;EAChC;EAEA,IAAI,UAAU,OAAO,UAAU,GAAG;GAChC,MAAM,SAAS,OAAO;GACtB,MAAM,SAAS,OAAO;GACtB,MAAM,QAAQ,OAAO,OAAO,SAAS;GACrC,MAAM,QAAQ,OAAO,OAAO,SAAS;GAIrC,IAAI,KAAK,MAAM,QAAQ,QAAQ,QAAQ,MAAM,IAAI,aAC/C,OAAO,UAAU;EAErB;EAEA,MAAM,QAAQ,OAAO,SAAS;EAC9B,MAAM,UAAU,SAAS,IAAI;EAE7B,IAAI,QAAQ,SACV,MAAM,IAAI,WAAW,eAAe,SAAS,mBAAmB,UAAU,kBAAkB,QAAQ,+BAA+B,MAAM,EAAE;EAG7I,IAAI,iBAAiB;EAErB,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KACzB,iBAAiB,KAAK,IAAI,gBAAgB,KAAK,MAAM,OAAO,IAAI,IAAK,OAAO,IAAI,IAAI,EAAG,CAAC;EAG1F,KAAK,WAAW,OAAO,OAAO,MAAM;EACpC,KAAK,QAAQ;EACb,KAAK,YAAY,SAAS,QAAQ,QAAQ;EAC1C,KAAK,SAAS;EACd,KAAK,iBAAiB;EAEtB,MAAM,QAA0B,CAAC;EAEjC,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,WAAW,KAClC,MAAM,KAAK,IAAI,eAAe,MAAM,CAAC,CAAC;EAGxC,KAAK,QAAQ,OAAO,OAAO,KAAK;EAEhC,OAAO,OAAO,IAAI;CACpB;AACF"}
@@ -1,14 +0,0 @@
1
- import type { ShapeMassProperties } from './Shape';
2
- import { Shape } from './Shape';
3
- /**
4
- * A circle of the given `radius` centred on the collider's local origin.
5
- * The cheapest shape for both broad- and narrow-phase.
6
- */
7
- export declare class CircleShape extends Shape {
8
- readonly type: 'circle';
9
- readonly radius: number;
10
- readonly boundingRadius: number;
11
- readonly massProperties: ShapeMassProperties;
12
- constructor(radius: number);
13
- }
14
- //# sourceMappingURL=CircleShape.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CircleShape.d.ts","sourceRoot":"","sources":["../../../src/shapes/CircleShape.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;;GAGG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,SAAgB,IAAI,EAAG,QAAQ,CAAU;IACzC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,cAAc,EAAE,MAAM,CAAC;IACvC,SAAgB,cAAc,EAAE,mBAAmB,CAAC;IAEpD,YAAmB,MAAM,EAAE,MAAM,EAoBhC;CACF"}
@@ -1,31 +0,0 @@
1
- import { Shape } from "./Shape.js";
2
-
3
- //#region src/shapes/CircleShape.ts
4
- /**
5
- * A circle of the given `radius` centred on the collider's local origin.
6
- * The cheapest shape for both broad- and narrow-phase.
7
- */
8
- var CircleShape = class extends Shape {
9
- type = "circle";
10
- radius;
11
- boundingRadius;
12
- massProperties;
13
- constructor(radius) {
14
- super();
15
- if (!Number.isFinite(radius) || radius <= 0) throw new RangeError(`CircleShape: radius must be a positive finite number, received ${radius}.`);
16
- const area = Math.PI * radius * radius;
17
- this.radius = radius;
18
- this.boundingRadius = radius;
19
- this.massProperties = Object.freeze({
20
- area,
21
- centroidX: 0,
22
- centroidY: 0,
23
- unitInertia: .5 * area * radius * radius
24
- });
25
- Object.freeze(this);
26
- }
27
- };
28
-
29
- //#endregion
30
- export { CircleShape };
31
- //# sourceMappingURL=CircleShape.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CircleShape.js","names":[],"sources":["../../../src/shapes/CircleShape.ts"],"sourcesContent":["import type { ShapeMassProperties } from './Shape';\nimport { Shape } from './Shape';\n\n/**\n * A circle of the given `radius` centred on the collider's local origin.\n * The cheapest shape for both broad- and narrow-phase.\n */\nexport class CircleShape extends Shape {\n public readonly type = 'circle' as const;\n public readonly radius: number;\n public readonly boundingRadius: number;\n public readonly massProperties: ShapeMassProperties;\n\n public constructor(radius: number) {\n super();\n\n if (!Number.isFinite(radius) || radius <= 0) {\n throw new RangeError(`CircleShape: radius must be a positive finite number, received ${radius}.`);\n }\n\n const area = Math.PI * radius * radius;\n\n this.radius = radius;\n this.boundingRadius = radius;\n this.massProperties = Object.freeze({\n area,\n centroidX: 0,\n centroidY: 0,\n // Second moment of area of a disc about its centre: ∫ r² dA = (π/2) R⁴.\n unitInertia: 0.5 * area * radius * radius,\n });\n\n Object.freeze(this);\n }\n}\n"],"mappings":";;;;;;;AAOA,IAAa,cAAb,cAAiC,MAAM;CACrC,AAAgB,OAAO;CACvB,AAAgB;CAChB,AAAgB;CAChB,AAAgB;CAEhB,AAAO,YAAY,QAAgB;EACjC,MAAM;EAEN,IAAI,CAAC,OAAO,SAAS,MAAM,KAAK,UAAU,GACxC,MAAM,IAAI,WAAW,kEAAkE,OAAO,EAAE;EAGlG,MAAM,OAAO,KAAK,KAAK,SAAS;EAEhC,KAAK,SAAS;EACd,KAAK,iBAAiB;EACtB,KAAK,iBAAiB,OAAO,OAAO;GAClC;GACA,WAAW;GACX,WAAW;GAEX,aAAa,KAAM,OAAO,SAAS;EACrC,CAAC;EAED,OAAO,OAAO,IAAI;CACpB;AACF"}
@@ -1,24 +0,0 @@
1
- import type { PointLike } from '@codexo/exojs';
2
- import type { ShapeMassProperties } from './Shape';
3
- import { Shape } from './Shape';
4
- /**
5
- * A convex polygon defined by ≥3 local-space vertices. Input vertices may be
6
- * given in either winding; they are canonicalised to counter-clockwise and the
7
- * outward edge normals are precomputed. Construction throws on any non-convex,
8
- * degenerate, or under-specified input - there is no silent repair.
9
- *
10
- * Vertices and normals are exposed as flat `[x0, y0, x1, y1, ...]` arrays to keep
11
- * the narrow phase allocation-free; both are frozen.
12
- */
13
- export declare class PolygonShape extends Shape {
14
- readonly type: 'polygon';
15
- /** Local-space vertices, CCW, flattened. */
16
- readonly vertices: readonly number[];
17
- /** Outward unit edge normals (edge `i` spans vertex `i → i+1`), flattened. */
18
- readonly normals: readonly number[];
19
- readonly count: number;
20
- readonly boundingRadius: number;
21
- readonly massProperties: ShapeMassProperties;
22
- constructor(vertices: ReadonlyArray<Readonly<PointLike>>);
23
- }
24
- //# sourceMappingURL=PolygonShape.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PolygonShape.d.ts","sourceRoot":"","sources":["../../../src/shapes/PolygonShape.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAKhC;;;;;;;;GAQG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,SAAgB,IAAI,EAAG,SAAS,CAAU;IAE1C,4CAA4C;IAC5C,SAAgB,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAE5C,8EAA8E;IAC9E,SAAgB,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAE3C,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B,SAAgB,cAAc,EAAE,MAAM,CAAC;IACvC,SAAgB,cAAc,EAAE,mBAAmB,CAAC;IAEpD,YAAmB,QAAQ,EAAE,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAwF9D;CACF"}