@codexo/exojs-physics 0.19.1 → 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
package/README.md CHANGED
@@ -1,79 +1,14 @@
1
1
  # @codexo/exojs-physics
2
2
 
3
- A TypeScript 2D rigid-body runtime for ExoJS: bodies, colliders, joints, sensors, contact policy, spatial queries, and scene-node binding.
3
+ Since ExoJS v0.20, import from @codexo/exojs/physics. This package is a compatibility shim for the 0.20 line; no independent feature development.
4
4
 
5
- Use it for simulated motion and collision response. Core's geometric queries are sufficient for simpler hit tests and overlaps. This package contributes no application extension descriptor: construct a `PhysicsWorld` and give it a scene or another explicit owner.
5
+ Every export of this package is the very binding its Core entry exports, so code that still imports `@codexo/exojs-physics` shares one engine instance with code that already imports `@codexo/exojs/physics`. The package contains no implementation of its own and depends on nothing but its `@codexo/exojs` peer.
6
6
 
7
- ## Install
7
+ | Import | Replace with | Forwards |
8
+ | --- | --- | --- |
9
+ | `@codexo/exojs-physics` | `@codexo/exojs/physics` | everything |
10
+ | `@codexo/exojs-physics/debug` | `@codexo/exojs/debug` | `PhysicsDebugDraw`, `PhysicsDebugDrawOptions` |
8
11
 
9
- ```sh
10
- npm install --save-exact @codexo/exojs @codexo/exojs-physics
11
- ```
12
+ ## Migrating
12
13
 
13
- Core is a peer dependency. Keep the packages on a compatible release line.
14
-
15
- ## Start a scene-owned world
16
-
17
- ```ts
18
- import { Scene, SystemOrder } from '@codexo/exojs';
19
- import { BoxShape, Collider, PhysicsBody, PhysicsWorld } from '@codexo/exojs-physics';
20
-
21
- export class GameScene extends Scene {
22
- override init(): void {
23
- const world = new PhysicsWorld({ gravity: { x: 0, y: 980 } });
24
-
25
- this.systems.add(world, { order: SystemOrder.Physics });
26
- world.add(
27
- new PhysicsBody({
28
- type: 'static',
29
- position: { x: 400, y: 560 },
30
- colliders: [new Collider({ shape: new BoxShape(700, 32) })],
31
- }),
32
- );
33
- world.add(
34
- new PhysicsBody({
35
- type: 'dynamic',
36
- position: { x: 400, y: 100 },
37
- colliders: [new Collider({ shape: new BoxShape(40, 40) })],
38
- }),
39
- );
40
- }
41
- }
42
- ```
43
-
44
- The scene registry drives and destroys this world. The snippet creates simulation only; bodies do not draw themselves. Use `world.attach(node, definition)` or `world.bind(body, node)` to connect visible nodes, and render them from the scene's `draw` hook. The [Physics guide](https://exoridus.github.io/ExoJS/en/guide/physics/physics-basics/) supplies a complete, asset-free falling-box application.
45
-
46
- ## Bodies owned by nodes
47
-
48
- `PhysicsBodyComponent` gives a node a body that follows the node's lifecycle: it joins the world while the node is active in a scene, leaves it with its state kept when the component is disabled, the node is removed or reparented, or its scene is retained, and is destroyed with the node.
49
-
50
- ```ts
51
- import { Graphics } from '@codexo/exojs';
52
- import { CircleShape, PhysicsBodyComponent, PhysicsWorld } from '@codexo/exojs-physics';
53
-
54
- const world = new PhysicsWorld({ gravity: { x: 0, y: 980 } });
55
- const ball = new Graphics();
56
- const physics = ball.addComponent(new PhysicsBodyComponent(world, { colliders: [{ shape: new CircleShape(12) }] }));
57
-
58
- physics.body.applyImpulse(0, -300);
59
- ```
60
-
61
- Component-managed bodies do not support joints yet. `world.remove(body)` takes any body out of the simulation without destroying it; `world.add(body)` puts it back.
62
-
63
- ## Important boundaries
64
-
65
- Choose one stepping clock. A world registered in `scene.systems` is stepped by the host; do not also call `step()`. An independently hosted world can use `step(frameDeltaSeconds)` and its own accumulator.
66
-
67
- Physics angles use radians and clockwise-positive screen rotation. Scene-node rotation uses degrees with the opposite screen sign; the built-in binding performs the conversion. Interpolation affects bound-node presentation, not the number of collision steps.
68
-
69
- Continuous collision covers supported translational shape casts, not unrestricted rotational sweeping. Boundary-only geometry is not a solid dynamic mass. Fixed timesteps do not promise cross-build or cross-machine lockstep determinism, and performance depends on the actual contacts, shapes, and workload.
70
-
71
- For tilemap collision, use [`@codexo/exojs-tilemap-physics`](https://github.com/Exoridus/ExoJS/tree/next/packages/exojs-tilemap-physics). For diagnostic drawing, use the package's `@codexo/exojs-physics/debug` entry point.
72
-
73
- ## Documentation
74
-
75
- [Physics guide](https://exoridus.github.io/ExoJS/en/guide/physics/physics-basics/) · [Joints and contact behavior](https://exoridus.github.io/ExoJS/en/guide/physics/joints-and-dynamics/) · [PhysicsWorld API](https://exoridus.github.io/ExoJS/en/api/physics-world/) · [Drag and Throw playground](https://exoridus.github.io/ExoJS/en/playground/?example=physics/sprite-follows-body)
76
-
77
- ## License
78
-
79
- MIT © Codexo
14
+ Change each import to the Core entry in the table, then remove this package with `npm uninstall @codexo/exojs-physics`. `@codexo/exojs` already contains the module; there is nothing else to install. The migration guide on the ExoJS site lists every renamed import.
@@ -1,2 +1 @@
1
- export { PhysicsDebugDraw, type PhysicsDebugDrawOptions } from './PhysicsDebugDraw';
2
- //# sourceMappingURL=index.d.ts.map
1
+ export { PhysicsDebugDraw, type PhysicsDebugDrawOptions } from '@codexo/exojs/debug';
package/debug.js ADDED
@@ -0,0 +1 @@
1
+ export { PhysicsDebugDraw } from '@codexo/exojs/debug';
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from '@codexo/exojs/physics';
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from '@codexo/exojs/physics';
package/package.json CHANGED
@@ -1,51 +1,45 @@
1
1
  {
2
2
  "name": "@codexo/exojs-physics",
3
- "version": "0.19.1",
4
- "description": "Native 2D collision, query and sensor runtime for ExoJS.",
3
+ "version": "0.20.0",
4
+ "description": "Compatibility shim that forwards to @codexo/exojs/physics. Since ExoJS v0.20, import from @codexo/exojs/physics.",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/Exoridus/ExoJS.git",
8
- "directory": "packages/exojs-physics"
8
+ "directory": "packages/legacy/exojs-physics"
9
9
  },
10
10
  "type": "module",
11
11
  "sideEffects": false,
12
- "main": "./dist/esm/index.js",
13
- "module": "./dist/esm/index.js",
14
- "types": "./dist/esm/index.d.ts",
12
+ "main": "./index.js",
13
+ "types": "./index.d.ts",
15
14
  "exports": {
16
15
  ".": {
17
- "types": "./dist/esm/index.d.ts",
18
- "import": "./dist/esm/index.js",
19
- "default": "./dist/esm/index.js"
16
+ "types": "./index.d.ts",
17
+ "import": "./index.js",
18
+ "default": "./index.js"
20
19
  },
21
20
  "./debug": {
22
- "types": "./dist/esm/debug/index.d.ts",
23
- "import": "./dist/esm/debug/index.js",
24
- "default": "./dist/esm/debug/index.js"
21
+ "types": "./debug.d.ts",
22
+ "import": "./debug.js",
23
+ "default": "./debug.js"
25
24
  },
26
25
  "./package.json": "./package.json"
27
26
  },
28
27
  "files": [
29
- "dist/esm/",
28
+ "index.js",
29
+ "index.d.ts",
30
+ "debug.js",
31
+ "debug.d.ts",
30
32
  "README.md",
31
33
  "LICENSE"
32
34
  ],
33
35
  "peerDependencies": {
34
- "@codexo/exojs": "0.19.x"
36
+ "@codexo/exojs": "0.20.x"
35
37
  },
36
38
  "devDependencies": {
37
- "@codexo/exojs-config": "0.0.0",
38
- "@codexo/exojs": "0.19.1"
39
+ "@codexo/exojs": "0.20.0"
39
40
  },
40
41
  "license": "MIT",
41
42
  "publishConfig": {
42
43
  "access": "public"
43
- },
44
- "scripts": {
45
- "build": "tsx ../../scripts/build-extension.ts",
46
- "build:dev": "tsx ../../scripts/build-extension.ts --dev",
47
- "typecheck": "exo-tsc --noEmit && exo-tsc --noEmit -p tsconfig.test.json",
48
- "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
49
- "test": "vitest run --root ../.. --project=exojs-physics"
50
44
  }
51
45
  }
@@ -1,10 +0,0 @@
1
- import type { AabbLike } from '@codexo/exojs';
2
- /** Create a zero-extent AABB at the origin. */
3
- export declare const createAabb: () => AabbLike;
4
- /** `true` when two AABBs overlap (touching edges count as overlapping). */
5
- export declare const aabbOverlap: (a: AabbLike, b: AabbLike) => boolean;
6
- /** `true` when `(x, y)` lies inside (or on the edge of) `aabb`. */
7
- export declare const aabbContainsPoint: (aabb: AabbLike, x: number, y: number) => boolean;
8
- /** Grow `aabb` outward by `margin` on every side, in place. */
9
- export declare const expandAabb: (aabb: AabbLike, margin: number) => AabbLike;
10
- //# sourceMappingURL=Aabb.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Aabb.d.ts","sourceRoot":"","sources":["../../src/Aabb.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,+CAA+C;AAC/C,eAAO,MAAM,UAAU,QAAO,QAAoD,CAAC;AAEnF,2EAA2E;AAC3E,eAAO,MAAM,WAAW,MAAO,QAAQ,KAAK,QAAQ,KAAG,OAAuF,CAAC;AAE/I,mEAAmE;AACnE,eAAO,MAAM,iBAAiB,SAAU,QAAQ,KAAK,MAAM,KAAK,MAAM,KAAG,OAA+E,CAAC;AAEzJ,+DAA+D;AAC/D,eAAO,MAAM,UAAU,SAAU,QAAQ,UAAU,MAAM,KAAG,QAO3D,CAAC"}
package/dist/esm/Aabb.js DELETED
@@ -1,16 +0,0 @@
1
- //#region src/Aabb.ts
2
- /** Create a zero-extent AABB at the origin. */
3
- const createAabb = () => ({
4
- minX: 0,
5
- minY: 0,
6
- maxX: 0,
7
- maxY: 0
8
- });
9
- /** `true` when two AABBs overlap (touching edges count as overlapping). */
10
- const aabbOverlap = (a, b) => a.minX <= b.maxX && a.maxX >= b.minX && a.minY <= b.maxY && a.maxY >= b.minY;
11
- /** `true` when `(x, y)` lies inside (or on the edge of) `aabb`. */
12
- const aabbContainsPoint = (aabb, x, y) => x >= aabb.minX && x <= aabb.maxX && y >= aabb.minY && y <= aabb.maxY;
13
-
14
- //#endregion
15
- export { aabbContainsPoint, aabbOverlap, createAabb };
16
- //# sourceMappingURL=Aabb.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Aabb.js","names":[],"sources":["../../src/Aabb.ts"],"sourcesContent":["// Axis-aligned bounding box helpers for the broad phase and AABB queries. The\n// box itself is core's structural `AabbLike` (min/max extents, not centre +\n// half-extent) - the broad-phase tree and the overlap tests read the edges\n// directly, and sharing one contract keeps colliders, spatial trees and query\n// bounds interchangeable across package boundaries.\n\nimport type { AabbLike } from '@codexo/exojs';\n\n/** Create a zero-extent AABB at the origin. */\nexport const createAabb = (): AabbLike => ({ minX: 0, minY: 0, maxX: 0, maxY: 0 });\n\n/** `true` when two AABBs overlap (touching edges count as overlapping). */\nexport const aabbOverlap = (a: AabbLike, b: AabbLike): boolean => a.minX <= b.maxX && a.maxX >= b.minX && a.minY <= b.maxY && a.maxY >= b.minY;\n\n/** `true` when `(x, y)` lies inside (or on the edge of) `aabb`. */\nexport const aabbContainsPoint = (aabb: AabbLike, x: number, y: number): boolean => x >= aabb.minX && x <= aabb.maxX && y >= aabb.minY && y <= aabb.maxY;\n\n/** Grow `aabb` outward by `margin` on every side, in place. */\nexport const expandAabb = (aabb: AabbLike, margin: number): AabbLike => {\n aabb.minX -= margin;\n aabb.minY -= margin;\n aabb.maxX += margin;\n aabb.maxY += margin;\n\n return aabb;\n};\n"],"mappings":";;AASA,MAAa,oBAA8B;CAAE,MAAM;CAAG,MAAM;CAAG,MAAM;CAAG,MAAM;AAAE;;AAGhF,MAAa,eAAe,GAAa,MAAyB,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE;;AAG1I,MAAa,qBAAqB,MAAgB,GAAW,MAAuB,KAAK,KAAK,QAAQ,KAAK,KAAK,QAAQ,KAAK,KAAK,QAAQ,KAAK,KAAK"}
@@ -1,107 +0,0 @@
1
- import type { AabbLike, PointLike } from '@codexo/exojs';
2
- import type { Transform } from './math';
3
- import type { PhysicsBody } from './PhysicsBody';
4
- import type { AnyShape } from './shapes/AnyShape';
5
- import type { CollisionFilter } from './types';
6
- /** Construction options for a collider. */
7
- export interface ColliderOptions {
8
- /** The collision geometry. */
9
- shape: AnyShape;
10
- /** Density (mass per px²) for the owning body's mass; ignored for static/kinematic. Default `1`. */
11
- density?: number;
12
- /** Coulomb friction coefficient (used by the solver once dynamics ship). Default `0.2`. */
13
- friction?: number;
14
- /** Restitution / bounciness in `[0, 1]` (used by the solver once dynamics ship). Default `0`. */
15
- restitution?: number;
16
- /** When `true`, generates overlap events but no contact response. Default `false`. */
17
- isSensor?: boolean;
18
- /** Category/mask/group filter; partials merge over the defaults. */
19
- filter?: Partial<CollisionFilter>;
20
- /** Body-local offset of the shape origin. Default `(0, 0)`. */
21
- offset?: Readonly<PointLike>;
22
- /** Body-local rotation of the shape in radians (compound colliders). Default `0`. */
23
- rotation?: number;
24
- }
25
- /**
26
- * Geometry attached to a {@link PhysicsBody}: a {@link Shape} plus a body-local
27
- * offset/rotation, material (friction/restitution/density) and a collision
28
- * filter. A body may own several colliders (compound). The collider also caches
29
- * its world-space geometry - refreshed by {@link synchronize} - which the broad
30
- * phase, narrow phase and queries read directly.
31
- *
32
- * Material fields and the filter are mutable; the shape and local placement are
33
- * immutable (rebuild the collider to change geometry).
34
- */
35
- export declare class Collider {
36
- /** Stable id, assigned when the owning body joins a world (`-1` until then). */
37
- readonly shape: AnyShape;
38
- readonly offsetX: number;
39
- readonly offsetY: number;
40
- readonly localRotation: number;
41
- density: number;
42
- friction: number;
43
- restitution: number;
44
- isSensor: boolean;
45
- readonly filter: CollisionFilter;
46
- private _id;
47
- private _body;
48
- private readonly _chainEdges;
49
- private _chainParent;
50
- private readonly _localTransform;
51
- private readonly _worldTransform;
52
- private readonly _aabb;
53
- private readonly _worldCenter;
54
- private readonly _syncScratch;
55
- private readonly _worldVertices;
56
- private readonly _worldNormals;
57
- private _destroyed;
58
- constructor(options: ColliderOptions);
59
- /** Stable id, assigned when the owning body joins a world via `world.add()`; `-1` until then. */
60
- get id(): number;
61
- /**
62
- * The body this collider belongs to. `null` until the collider has been added
63
- * to a body that has joined a world (free-standing colliders have no body yet).
64
- */
65
- get body(): PhysicsBody;
66
- /** The collider's world AABB (valid after the latest {@link synchronize}). */
67
- get aabb(): Readonly<AabbLike>;
68
- /** The collider's world transform (offset/rotation composed with the body's). */
69
- get worldTransform(): Readonly<Transform>;
70
- /** The collider's body-local transform (offset + local rotation). */
71
- get localTransform(): Readonly<Transform>;
72
- /** World-space circle centre (only meaningful for circle shapes). */
73
- get worldCenter(): Readonly<PointLike>;
74
- /** World-space polygon vertices `[x0, y0, ...]` (only meaningful for polygon shapes). */
75
- get worldVertices(): readonly number[];
76
- /** World-space polygon outward normals `[x0, y0, ...]` (only meaningful for polygon shapes). */
77
- get worldNormals(): readonly number[];
78
- /** `true` after the owning world has destroyed this collider. */
79
- get destroyed(): boolean;
80
- /**
81
- * Recompute the cached world geometry from the body's transform. Called by the
82
- * body on `setTransform`, on collider creation, and by the world before each
83
- * detection pass.
84
- */
85
- synchronize(bodyTransform: Transform): void;
86
- /**
87
- * A chain's world geometry is its edge proxies': each of them shares the
88
- * chain's local placement and syncs its own two endpoints, and the chain's own
89
- * AABB is their union. Nothing is transformed twice, and no proxy is rebuilt.
90
- */
91
- private _synchronizeChain;
92
- /** A circle is its transformed centre; the local vertex buffers stay unused. */
93
- private _synchronizeCircle;
94
- /**
95
- * Transform a local vertex/normal ring into the world buffers and take the
96
- * AABB while doing it. `radius` inflates the box for a rounded outline (a
97
- * capsule's spine); it is `0` for a plain polygon.
98
- */
99
- private _synchronizePolygon;
100
- /**
101
- * Fan a chain out into one proxy per edge. Each proxy carries the chain's own
102
- * local placement, so it needs no transform of its own, and its shape carries
103
- * the adjacency that keeps a body from snagging at a shared vertex.
104
- */
105
- private _buildChainEdges;
106
- }
107
- //# sourceMappingURL=Collider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Collider.d.ts","sourceRoot":"","sources":["../../src/Collider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAGzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAA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,CAAC,QAAQ,CAAC,YAAY,CAA6B;IAC1D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAW;IAC1C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAW;IAEzC,OAAO,CAAC,UAAU,CAAS;IAqB3B,YAAmB,OAAO,EAAE,eAAe,EAuB1C;IAED,iGAAiG;IACjG,IAAW,EAAE,IAAI,MAAM,CAEtB;IAED;;;OAGG;IACH,IAAW,IAAI,IAAI,WAAW,CAM7B;IAED,8EAA8E;IAC9E,IAAW,IAAI,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAEpC;IAED,iFAAiF;IACjF,IAAW,cAAc,IAAI,QAAQ,CAAC,SAAS,CAAC,CAE/C;IAED,qEAAqE;IACrE,IAAW,cAAc,IAAI,QAAQ,CAAC,SAAS,CAAC,CAE/C;IAED,qEAAqE;IACrE,IAAW,WAAW,IAAI,QAAQ,CAAC,SAAS,CAAC,CAE5C;IAED,yFAAyF;IACzF,IAAW,aAAa,IAAI,SAAS,MAAM,EAAE,CAE5C;IAED,gGAAgG;IAChG,IAAW,YAAY,IAAI,SAAS,MAAM,EAAE,CAE3C;IAmBD,iEAAiE;IACjE,IAAW,SAAS,IAAI,OAAO,CAE9B;IAED;;;;OAIG;IACI,WAAW,CAAC,aAAa,EAAE,SAAS,GAAG,IAAI,CAwBjD;IAED;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAwBzB,gFAAgF;IAChF,OAAO,CAAC,kBAAkB;IAS1B;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAgD3B;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;CA+BzB"}
@@ -1,284 +0,0 @@
1
- import { createAabb } from "./Aabb.js";
2
- import { applyRotation, applyTransform, composeTransforms, createTransform } from "./math.js";
3
- import { resolveFilter } from "./types.js";
4
-
5
- //#region src/Collider.ts
6
- /** Number of world-space vertices a shape kind caches on its collider. */
7
- const worldVertexCount = (shape) => {
8
- switch (shape.type) {
9
- case "polygon": return shape.count;
10
- case "capsule":
11
- case "segment": return 2;
12
- case "circle":
13
- case "chain": return 0;
14
- }
15
- };
16
- /**
17
- * Geometry attached to a {@link PhysicsBody}: a {@link Shape} plus a body-local
18
- * offset/rotation, material (friction/restitution/density) and a collision
19
- * filter. A body may own several colliders (compound). The collider also caches
20
- * its world-space geometry - refreshed by {@link synchronize} - which the broad
21
- * phase, narrow phase and queries read directly.
22
- *
23
- * Material fields and the filter are mutable; the shape and local placement are
24
- * immutable (rebuild the collider to change geometry).
25
- */
26
- var Collider = class Collider {
27
- /** Stable id, assigned when the owning body joins a world (`-1` until then). */
28
- shape;
29
- offsetX;
30
- offsetY;
31
- localRotation;
32
- density;
33
- friction;
34
- restitution;
35
- isSensor;
36
- filter;
37
- _id = -1;
38
- _body = null;
39
- _chainEdges;
40
- _chainParent = null;
41
- _localTransform;
42
- _worldTransform = createTransform();
43
- _aabb = createAabb();
44
- _worldCenter = {
45
- x: 0,
46
- y: 0
47
- };
48
- _syncScratch = {
49
- x: 0,
50
- y: 0
51
- };
52
- _worldVertices;
53
- _worldNormals;
54
- _destroyed = false;
55
- /**
56
- * @internal - proxy id in the physics world's broad-phase spatial tree; `-1`
57
- * when not inserted. Like `PhysicsBody._islandIndex`/`_sleepTime`, this is a
58
- * single-owner slot: exactly ONE `AabbTreeBroadPhase` may track this collider
59
- * at a time (in production, the world's own broad phase for the collider's
60
- * whole lifetime). A second broad phase over the same collider would clobber
61
- * this value and corrupt the first's tree - never do that.
62
- */
63
- _treeProxy = -1;
64
- /**
65
- * @internal - whether {@link aabb} has changed since the owning broad phase
66
- * last looked at it. Set by every write to the AABB ({@link synchronize} is
67
- * the only one) and cleared when the broad phase has taken the new box, so a
68
- * resting collider costs nothing to re-sync. Single-owner like
69
- * {@link _treeProxy}, and for the same reason.
70
- */
71
- _treeDirty = true;
72
- constructor(options) {
73
- const density = options.density ?? 1;
74
- if (!Number.isFinite(density) || density < 0) throw new RangeError(`Collider: density must be a non-negative finite number, received ${density}.`);
75
- this.shape = options.shape;
76
- this.offsetX = options.offset?.x ?? 0;
77
- this.offsetY = options.offset?.y ?? 0;
78
- this.localRotation = options.rotation ?? 0;
79
- this.density = density;
80
- this.friction = options.friction ?? .2;
81
- this.restitution = options.restitution ?? 0;
82
- this.isSensor = options.isSensor ?? false;
83
- this.filter = resolveFilter(options.filter);
84
- this._localTransform = createTransform(this.offsetX, this.offsetY, this.localRotation);
85
- const vertexCount = worldVertexCount(this.shape);
86
- this._worldVertices = new Array(vertexCount * 2).fill(0);
87
- this._worldNormals = new Array(vertexCount * 2).fill(0);
88
- this._chainEdges = this.shape.type === "chain" ? this._buildChainEdges(this.shape) : null;
89
- }
90
- /** Stable id, assigned when the owning body joins a world via `world.add()`; `-1` until then. */
91
- get id() {
92
- return this._id;
93
- }
94
- /**
95
- * The body this collider belongs to. `null` until the collider has been added
96
- * to a body that has joined a world (free-standing colliders have no body yet).
97
- */
98
- get body() {
99
- if (this._body === null) throw new Error("Collider: this collider has not been attached to a body in a world yet.");
100
- return this._body;
101
- }
102
- /** The collider's world AABB (valid after the latest {@link synchronize}). */
103
- get aabb() {
104
- return this._aabb;
105
- }
106
- /** The collider's world transform (offset/rotation composed with the body's). */
107
- get worldTransform() {
108
- return this._worldTransform;
109
- }
110
- /** The collider's body-local transform (offset + local rotation). */
111
- get localTransform() {
112
- return this._localTransform;
113
- }
114
- /** World-space circle centre (only meaningful for circle shapes). */
115
- get worldCenter() {
116
- return this._worldCenter;
117
- }
118
- /** World-space polygon vertices `[x0, y0, ...]` (only meaningful for polygon shapes). */
119
- get worldVertices() {
120
- return this._worldVertices;
121
- }
122
- /** World-space polygon outward normals `[x0, y0, ...]` (only meaningful for polygon shapes). */
123
- get worldNormals() {
124
- return this._worldNormals;
125
- }
126
- /**
127
- * @internal - the engine-owned edge proxies a chain collider fans out into,
128
- * one per chain edge; `null` for every other shape. They are what the broad
129
- * phase, the narrow phase and the solver see, so a chain contact reuses the
130
- * one-manifold-per-pair model unchanged. They are never part of
131
- * `body.colliders`, `world.colliders` or any query result - the authored
132
- * collider is the public identity of every contact they produce.
133
- */
134
- get chainEdges() {
135
- return this._chainEdges;
136
- }
137
- /** @internal - the authored chain collider this edge proxy belongs to; `null` for an authored collider. */
138
- get chainParent() {
139
- return this._chainParent;
140
- }
141
- /** `true` after the owning world has destroyed this collider. */
142
- get destroyed() {
143
- return this._destroyed;
144
- }
145
- /**
146
- * Recompute the cached world geometry from the body's transform. Called by the
147
- * body on `setTransform`, on collider creation, and by the world before each
148
- * detection pass.
149
- */
150
- synchronize(bodyTransform) {
151
- const world = composeTransforms(bodyTransform, this._localTransform, this._worldTransform);
152
- this._treeDirty = true;
153
- switch (this.shape.type) {
154
- case "circle":
155
- this._synchronizeCircle(world, this.shape.radius);
156
- break;
157
- case "capsule":
158
- this._synchronizePolygon(world, this.shape.vertices, this.shape.normals, 2, this.shape.radius);
159
- break;
160
- case "segment":
161
- this._synchronizePolygon(world, this.shape.vertices, this.shape.normals, 2, 0);
162
- break;
163
- case "polygon":
164
- this._synchronizePolygon(world, this.shape.vertices, this.shape.normals, this.shape.count, 0);
165
- break;
166
- case "chain": this._synchronizeChain(bodyTransform);
167
- }
168
- }
169
- /**
170
- * A chain's world geometry is its edge proxies': each of them shares the
171
- * chain's local placement and syncs its own two endpoints, and the chain's own
172
- * AABB is their union. Nothing is transformed twice, and no proxy is rebuilt.
173
- */
174
- _synchronizeChain(bodyTransform) {
175
- const edges = this._chainEdges;
176
- let minX = Infinity;
177
- let minY = Infinity;
178
- let maxX = -Infinity;
179
- let maxY = -Infinity;
180
- for (const edge of edges) {
181
- edge.synchronize(bodyTransform);
182
- const aabb = edge.aabb;
183
- minX = aabb.minX < minX ? aabb.minX : minX;
184
- minY = aabb.minY < minY ? aabb.minY : minY;
185
- maxX = aabb.maxX > maxX ? aabb.maxX : maxX;
186
- maxY = aabb.maxY > maxY ? aabb.maxY : maxY;
187
- }
188
- this._aabb.minX = minX;
189
- this._aabb.minY = minY;
190
- this._aabb.maxX = maxX;
191
- this._aabb.maxY = maxY;
192
- }
193
- /** A circle is its transformed centre; the local vertex buffers stay unused. */
194
- _synchronizeCircle(world, radius) {
195
- this._worldCenter.x = world.x;
196
- this._worldCenter.y = world.y;
197
- this._aabb.minX = world.x - radius;
198
- this._aabb.minY = world.y - radius;
199
- this._aabb.maxX = world.x + radius;
200
- this._aabb.maxY = world.y + radius;
201
- }
202
- /**
203
- * Transform a local vertex/normal ring into the world buffers and take the
204
- * AABB while doing it. `radius` inflates the box for a rounded outline (a
205
- * capsule's spine); it is `0` for a plain polygon.
206
- */
207
- _synchronizePolygon(world, local, normals, count, radius) {
208
- const out = this._syncScratch;
209
- let minX = Infinity;
210
- let minY = Infinity;
211
- let maxX = -Infinity;
212
- let maxY = -Infinity;
213
- for (let i = 0; i < count; i++) {
214
- applyTransform(world, local[i * 2], local[i * 2 + 1], out);
215
- this._worldVertices[i * 2] = out.x;
216
- this._worldVertices[i * 2 + 1] = out.y;
217
- minX = out.x < minX ? out.x : minX;
218
- minY = out.y < minY ? out.y : minY;
219
- maxX = out.x > maxX ? out.x : maxX;
220
- maxY = out.y > maxY ? out.y : maxY;
221
- applyRotation(world, normals[i * 2], normals[i * 2 + 1], out);
222
- this._worldNormals[i * 2] = out.x;
223
- this._worldNormals[i * 2 + 1] = out.y;
224
- }
225
- this._aabb.minX = minX - radius;
226
- this._aabb.minY = minY - radius;
227
- this._aabb.maxX = maxX + radius;
228
- this._aabb.maxY = maxY + radius;
229
- }
230
- /** @internal - bind this collider to its body and id (called when the body joins a world). */
231
- _attach(body, id) {
232
- this._body = body;
233
- this._id = id;
234
- }
235
- /**
236
- * @internal - forget the ids this collider and its chain edges held in the
237
- * world they left. The body link stays: the collider still belongs to its
238
- * body, which may join a world again.
239
- */
240
- _detachFromWorld() {
241
- this._id = -1;
242
- if (this._chainEdges !== null) for (const edge of this._chainEdges) edge._id = -1;
243
- }
244
- /**
245
- * Fan a chain out into one proxy per edge. Each proxy carries the chain's own
246
- * local placement, so it needs no transform of its own, and its shape carries
247
- * the adjacency that keeps a body from snagging at a shared vertex.
248
- */
249
- _buildChainEdges(chain) {
250
- const edges = [];
251
- for (const edgeShape of chain.edges) {
252
- const edge = new Collider({
253
- shape: edgeShape,
254
- offset: {
255
- x: this.offsetX,
256
- y: this.offsetY
257
- },
258
- rotation: this.localRotation,
259
- density: 0
260
- });
261
- edge._chainParent = this;
262
- edges.push(edge);
263
- }
264
- return edges;
265
- }
266
- /** @internal - mark destroyed (called by the world). */
267
- _markDestroyed() {
268
- this._destroyed = true;
269
- if (this._chainEdges !== null) for (const edge of this._chainEdges) edge._destroyed = true;
270
- }
271
- };
272
- /**
273
- * The authored collider a contact, query hit or sweep target belongs to: the
274
- * collider itself, or the chain it is an engine-owned edge proxy of. Every
275
- * public identity - events, query results, the contact modifier - goes through
276
- * this, so a solver-side partition never reaches a caller.
277
- *
278
- * @internal
279
- */
280
- const authoredCollider = (collider) => collider.chainParent ?? collider;
281
-
282
- //#endregion
283
- export { Collider, authoredCollider };
284
- //# sourceMappingURL=Collider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Collider.js","names":[],"sources":["../../src/Collider.ts"],"sourcesContent":["import type { AabbLike, PointLike } from '@codexo/exojs';\n\nimport { createAabb } from './Aabb';\nimport type { Transform } from './math';\nimport { applyRotation, applyTransform, composeTransforms, createTransform } from './math';\nimport type { PhysicsBody } from './PhysicsBody';\nimport type { AnyShape } from './shapes/AnyShape';\nimport type { ChainShape } from './shapes/ChainShape';\nimport type { CollisionFilter } from './types';\nimport { resolveFilter } from './types';\n\n/** Number of world-space vertices a shape kind caches on its collider. */\nconst worldVertexCount = (shape: AnyShape): number => {\n switch (shape.type) {\n case 'polygon':\n return shape.count;\n case 'capsule':\n case 'segment':\n // Two endpoints. Both are a two-vertex ring, with and without a radius.\n return 2;\n case 'circle':\n case 'chain':\n // A chain caches nothing of its own: its geometry lives on the per-edge\n // child proxies, and its AABB is the union of theirs.\n return 0;\n }\n};\n\n/** Construction options for a collider. */\nexport interface ColliderOptions {\n /** The collision geometry. */\n shape: AnyShape;\n /** Density (mass per px²) for the owning body's mass; ignored for static/kinematic. Default `1`. */\n density?: number;\n /** Coulomb friction coefficient (used by the solver once dynamics ship). Default `0.2`. */\n friction?: number;\n /** Restitution / bounciness in `[0, 1]` (used by the solver once dynamics ship). Default `0`. */\n restitution?: number;\n /** When `true`, generates overlap events but no contact response. Default `false`. */\n isSensor?: boolean;\n /** Category/mask/group filter; partials merge over the defaults. */\n filter?: Partial<CollisionFilter>;\n /** Body-local offset of the shape origin. Default `(0, 0)`. */\n offset?: Readonly<PointLike>;\n /** Body-local rotation of the shape in radians (compound colliders). Default `0`. */\n rotation?: number;\n}\n\n/**\n * Geometry attached to a {@link PhysicsBody}: a {@link Shape} plus a body-local\n * offset/rotation, material (friction/restitution/density) and a collision\n * filter. A body may own several colliders (compound). The collider also caches\n * its world-space geometry - refreshed by {@link synchronize} - which the broad\n * phase, narrow phase and queries read directly.\n *\n * Material fields and the filter are mutable; the shape and local placement are\n * immutable (rebuild the collider to change geometry).\n */\nexport class Collider {\n /** Stable id, assigned when the owning body joins a world (`-1` until then). */\n public readonly shape: AnyShape;\n public readonly offsetX: number;\n public readonly offsetY: number;\n public readonly localRotation: number;\n\n public density: number;\n public friction: number;\n public restitution: number;\n public isSensor: boolean;\n public readonly filter: CollisionFilter;\n\n private _id = -1;\n private _body: PhysicsBody | null = null;\n private readonly _chainEdges: readonly Collider[] | null;\n private _chainParent: Collider | null = null;\n private readonly _localTransform: Transform;\n private readonly _worldTransform: Transform = createTransform();\n private readonly _aabb: AabbLike = createAabb();\n private readonly _worldCenter: PointLike = { x: 0, y: 0 };\n // Reused per-vertex scratch for synchronize()'s polygon transform loop so a\n // collider sync allocates nothing. Instance-private: never held across the\n // call, never aliased between colliders.\n private readonly _syncScratch: PointLike = { x: 0, y: 0 };\n private readonly _worldVertices: number[];\n private readonly _worldNormals: number[];\n\n private _destroyed = false;\n\n /**\n * @internal - proxy id in the physics world's broad-phase spatial tree; `-1`\n * when not inserted. Like `PhysicsBody._islandIndex`/`_sleepTime`, this is a\n * single-owner slot: exactly ONE `AabbTreeBroadPhase` may track this collider\n * at a time (in production, the world's own broad phase for the collider's\n * whole lifetime). A second broad phase over the same collider would clobber\n * this value and corrupt the first's tree - never do that.\n */\n public _treeProxy = -1;\n\n /**\n * @internal - whether {@link aabb} has changed since the owning broad phase\n * last looked at it. Set by every write to the AABB ({@link synchronize} is\n * the only one) and cleared when the broad phase has taken the new box, so a\n * resting collider costs nothing to re-sync. Single-owner like\n * {@link _treeProxy}, and for the same reason.\n */\n public _treeDirty = true;\n\n public constructor(options: ColliderOptions) {\n const density = options.density ?? 1;\n\n if (!Number.isFinite(density) || density < 0) {\n throw new RangeError(`Collider: density must be a non-negative finite number, received ${density}.`);\n }\n\n this.shape = options.shape;\n this.offsetX = options.offset?.x ?? 0;\n this.offsetY = options.offset?.y ?? 0;\n this.localRotation = options.rotation ?? 0;\n this.density = density;\n this.friction = options.friction ?? 0.2;\n this.restitution = options.restitution ?? 0;\n this.isSensor = options.isSensor ?? false;\n this.filter = resolveFilter(options.filter);\n this._localTransform = createTransform(this.offsetX, this.offsetY, this.localRotation);\n\n const vertexCount = worldVertexCount(this.shape);\n\n this._worldVertices = new Array<number>(vertexCount * 2).fill(0);\n this._worldNormals = new Array<number>(vertexCount * 2).fill(0);\n this._chainEdges = this.shape.type === 'chain' ? this._buildChainEdges(this.shape) : null;\n }\n\n /** Stable id, assigned when the owning body joins a world via `world.add()`; `-1` until then. */\n public get id(): number {\n return this._id;\n }\n\n /**\n * The body this collider belongs to. `null` until the collider has been added\n * to a body that has joined a world (free-standing colliders have no body yet).\n */\n public get body(): PhysicsBody {\n if (this._body === null) {\n throw new Error('Collider: this collider has not been attached to a body in a world yet.');\n }\n\n return this._body;\n }\n\n /** The collider's world AABB (valid after the latest {@link synchronize}). */\n public get aabb(): Readonly<AabbLike> {\n return this._aabb;\n }\n\n /** The collider's world transform (offset/rotation composed with the body's). */\n public get worldTransform(): Readonly<Transform> {\n return this._worldTransform;\n }\n\n /** The collider's body-local transform (offset + local rotation). */\n public get localTransform(): Readonly<Transform> {\n return this._localTransform;\n }\n\n /** World-space circle centre (only meaningful for circle shapes). */\n public get worldCenter(): Readonly<PointLike> {\n return this._worldCenter;\n }\n\n /** World-space polygon vertices `[x0, y0, ...]` (only meaningful for polygon shapes). */\n public get worldVertices(): readonly number[] {\n return this._worldVertices;\n }\n\n /** World-space polygon outward normals `[x0, y0, ...]` (only meaningful for polygon shapes). */\n public get worldNormals(): readonly number[] {\n return this._worldNormals;\n }\n\n /**\n * @internal - the engine-owned edge proxies a chain collider fans out into,\n * one per chain edge; `null` for every other shape. They are what the broad\n * phase, the narrow phase and the solver see, so a chain contact reuses the\n * one-manifold-per-pair model unchanged. They are never part of\n * `body.colliders`, `world.colliders` or any query result - the authored\n * collider is the public identity of every contact they produce.\n */\n public get chainEdges(): readonly Collider[] | null {\n return this._chainEdges;\n }\n\n /** @internal - the authored chain collider this edge proxy belongs to; `null` for an authored collider. */\n public get chainParent(): Collider | null {\n return this._chainParent;\n }\n\n /** `true` after the owning world has destroyed this collider. */\n public get destroyed(): boolean {\n return this._destroyed;\n }\n\n /**\n * Recompute the cached world geometry from the body's transform. Called by the\n * body on `setTransform`, on collider creation, and by the world before each\n * detection pass.\n */\n public synchronize(bodyTransform: Transform): void {\n const world = composeTransforms(bodyTransform, this._localTransform, this._worldTransform);\n\n this._treeDirty = true;\n\n switch (this.shape.type) {\n case 'circle':\n this._synchronizeCircle(world, this.shape.radius);\n break;\n case 'capsule':\n // A capsule is a two-vertex ring plus a radius, so it rides the polygon\n // path and only the AABB inflation differs.\n this._synchronizePolygon(world, this.shape.vertices, this.shape.normals, 2, this.shape.radius);\n break;\n case 'segment':\n this._synchronizePolygon(world, this.shape.vertices, this.shape.normals, 2, 0);\n break;\n case 'polygon':\n this._synchronizePolygon(world, this.shape.vertices, this.shape.normals, this.shape.count, 0);\n break;\n case 'chain':\n this._synchronizeChain(bodyTransform);\n break;\n }\n }\n\n /**\n * A chain's world geometry is its edge proxies': each of them shares the\n * chain's local placement and syncs its own two endpoints, and the chain's own\n * AABB is their union. Nothing is transformed twice, and no proxy is rebuilt.\n */\n private _synchronizeChain(bodyTransform: Transform): void {\n const edges = this._chainEdges!;\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for (const edge of edges) {\n edge.synchronize(bodyTransform);\n\n const aabb = edge.aabb;\n\n minX = aabb.minX < minX ? aabb.minX : minX;\n minY = aabb.minY < minY ? aabb.minY : minY;\n maxX = aabb.maxX > maxX ? aabb.maxX : maxX;\n maxY = aabb.maxY > maxY ? aabb.maxY : maxY;\n }\n\n this._aabb.minX = minX;\n this._aabb.minY = minY;\n this._aabb.maxX = maxX;\n this._aabb.maxY = maxY;\n }\n\n /** A circle is its transformed centre; the local vertex buffers stay unused. */\n private _synchronizeCircle(world: Transform, radius: number): void {\n this._worldCenter.x = world.x;\n this._worldCenter.y = world.y;\n this._aabb.minX = world.x - radius;\n this._aabb.minY = world.y - radius;\n this._aabb.maxX = world.x + radius;\n this._aabb.maxY = world.y + radius;\n }\n\n /**\n * Transform a local vertex/normal ring into the world buffers and take the\n * AABB while doing it. `radius` inflates the box for a rounded outline (a\n * capsule's spine); it is `0` for a plain polygon.\n */\n private _synchronizePolygon(world: Transform, local: readonly number[], normals: readonly number[], count: number, radius: number): void {\n const out = this._syncScratch;\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for (let i = 0; i < count; i++) {\n applyTransform(world, local[i * 2]!, local[i * 2 + 1]!, out);\n this._worldVertices[i * 2] = out.x;\n this._worldVertices[i * 2 + 1] = out.y;\n minX = out.x < minX ? out.x : minX;\n minY = out.y < minY ? out.y : minY;\n maxX = out.x > maxX ? out.x : maxX;\n maxY = out.y > maxY ? out.y : maxY;\n\n applyRotation(world, normals[i * 2]!, normals[i * 2 + 1]!, out);\n this._worldNormals[i * 2] = out.x;\n this._worldNormals[i * 2 + 1] = out.y;\n }\n\n this._aabb.minX = minX - radius;\n this._aabb.minY = minY - radius;\n this._aabb.maxX = maxX + radius;\n this._aabb.maxY = maxY + radius;\n }\n\n /** @internal - bind this collider to its body and id (called when the body joins a world). */\n public _attach(body: PhysicsBody, id: number): void {\n this._body = body;\n this._id = id;\n }\n\n /**\n * @internal - forget the ids this collider and its chain edges held in the\n * world they left. The body link stays: the collider still belongs to its\n * body, which may join a world again.\n */\n public _detachFromWorld(): void {\n this._id = -1;\n\n if (this._chainEdges !== null) {\n for (const edge of this._chainEdges) {\n edge._id = -1;\n }\n }\n }\n\n /**\n * Fan a chain out into one proxy per edge. Each proxy carries the chain's own\n * local placement, so it needs no transform of its own, and its shape carries\n * the adjacency that keeps a body from snagging at a shared vertex.\n */\n private _buildChainEdges(chain: ChainShape): readonly Collider[] {\n const edges: Collider[] = [];\n\n for (const edgeShape of chain.edges) {\n const edge = new Collider({\n shape: edgeShape,\n offset: { x: this.offsetX, y: this.offsetY },\n rotation: this.localRotation,\n // Material, filter and sensor flag stay mutable on the authored collider\n // and are read from there per pass, so copying them here would only add a\n // second, staler source of truth.\n density: 0,\n });\n\n edge._chainParent = this;\n edges.push(edge);\n }\n\n return edges;\n }\n\n /** @internal - mark destroyed (called by the world). */\n public _markDestroyed(): void {\n this._destroyed = true;\n\n if (this._chainEdges !== null) {\n for (const edge of this._chainEdges) {\n edge._destroyed = true;\n }\n }\n }\n}\n\n/**\n * The authored collider a contact, query hit or sweep target belongs to: the\n * collider itself, or the chain it is an engine-owned edge proxy of. Every\n * public identity - events, query results, the contact modifier - goes through\n * this, so a solver-side partition never reaches a caller.\n *\n * @internal\n */\nexport const authoredCollider = (collider: Collider): Collider => collider.chainParent ?? collider;\n"],"mappings":";;;;;;AAYA,MAAM,oBAAoB,UAA4B;CACpD,QAAQ,MAAM,MAAd;EACE,KAAK,WACH,OAAO,MAAM;EACf,KAAK;EACL,KAAK,WAEH,OAAO;EACT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