@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,457 +0,0 @@
1
- import { contactSlop } from "./tolerances.js";
2
-
3
- //#region src/solver/ContactSolver.ts
4
- /**
5
- * Cap on the soft-constraint push-out velocity (px/s). Bounds how fast the bias
6
- * resolves deep penetration so a large overlap cannot fling bodies apart.
7
- *
8
- * The Box2D-v3 analogue is `contactSpeed = 3·lengthUnit`, i.e. 3 m/s in SI. The
9
- * conversion to pixels is the whole content of this constant: 2D games in this
10
- * engine's envelope put a metre at roughly 20-100 px (equivalently, the gravity
11
- * range the solver is tuned for, a few hundred to a few thousand px/s²), so the
12
- * same physical speed is 60-300 px/s. The low end of that band is taken - it is
13
- * already past the point where a settling scene stops fighting the cap, and
14
- * anything higher only widens the speed at which a deep overlap may be undone.
15
- *
16
- * A single-digit cap is enough for one body resting on a floor and badly short
17
- * everywhere else: a gravity-driven pile rearranges faster than such a push-out
18
- * can work, so overlap accumulates instead of resolving, the pile settles
19
- * several px deep with far more touching pairs than its geometry has, and the
20
- * permanently unresolved contacts keep every island awake.
21
- */
22
- const maxBiasVelocity = 60;
23
- /** Reject the 2-point block solve when the contact matrix is worse-conditioned than this (fall back to sequential). */
24
- const maxConditionNumber = 1e3;
25
- /**
26
- * Per-contact velocity constraint (1-2 points), computed once per **frame** in
27
- * {@link ContactSolver.prepare} and reused across all sub-steps and passes.
28
- * Pooled and reused across frames, so a steady-state step constructs no
29
- * constraint of its own. It is not allocation-free in the wider sense: a double
30
- * handed to a function the optimiser declines to inline is boxed on the heap for
31
- * the duration of that call, which is why the hot paths below apply their
32
- * results in place instead of through helpers.
33
- */
34
- var ContactConstraint = class {
35
- record;
36
- bodyA;
37
- bodyB;
38
- nx = 0;
39
- ny = 0;
40
- tx = 0;
41
- ty = 0;
42
- friction = 0;
43
- restitution = 0;
44
- pointCount = 0;
45
- biasRate = 0;
46
- massScale = 1;
47
- impulseScale = 0;
48
- rAx = [0, 0];
49
- rAy = [0, 0];
50
- rBx = [0, 0];
51
- rBy = [0, 0];
52
- rotAx = [0, 0];
53
- rotAy = [0, 0];
54
- rotBx = [0, 0];
55
- rotBy = [0, 0];
56
- normalMass = [0, 0];
57
- tangentMass = [0, 0];
58
- /** Contact separation at frame start (= −penetration; negative when overlapping). */
59
- baseSeparation = [0, 0];
60
- /** Relative normal velocity at frame start (the impact speed the restitution pass keys off). */
61
- relativeVelocity = [0, 0];
62
- /** Push-out target normal velocity for the current pass (set per pass from the live separation). */
63
- velocityBias = [0, 0];
64
- /**
65
- * Whether the point's push-out target was clamped to `maxBiasVelocity` this
66
- * pass. A clamped target is no longer the spring response the soft scaling
67
- * models, so the single-point solve drops that scaling while it holds.
68
- */
69
- biasClamped = [false, false];
70
- block = false;
71
- k11 = 0;
72
- k12 = 0;
73
- k22 = 0;
74
- invK11 = 0;
75
- invK12 = 0;
76
- invK22 = 0;
77
- };
78
- /**
79
- * Native warm-started **TGS-Soft** contact solver (Box2D-v3 "soft step"). Driven
80
- * by {@link PhysicsWorld} as a sub-stepping loop: detection runs once per frame,
81
- * then {@link prepare} builds the per-contact constraints (effective masses,
82
- * frame-start separation + impact velocity, soft factors, and a 2×2 block matrix
83
- * for two-point manifolds) **once**, and each sub-step runs
84
- * {@link warmStart} → {@link solveVelocities}(useBias=true) → integrate positions
85
- * → {@link solveVelocities}(useBias=false) relax. A final {@link applyRestitution}
86
- * pass adds bounce above the threshold.
87
- *
88
- * The position constraint is folded into the velocity solve as a **soft bias**
89
- * (a damped-spring push-out whose stiffness is decoupled from the iteration
90
- * count), recomputed each pass from the live per-body delta position/rotation -
91
- * so there is no separate NGS geometric pass. The contact anchors are rotated by
92
- * the live sub-step rotation each pass, so a tilting stack's restoring torque is
93
- * computed against its current orientation (without this the tilt grows instead
94
- * of being corrected). Two-point manifolds still solve the normal impulses **as a
95
- * 2×2 block LCP** (Box2D-style), which propagates stack loads far better than
96
- * solving the points sequentially; the block path carries the soft push-out as
97
- * its velocity target (hard mass scale), while single-point contacts use the full
98
- * soft mass/impulse scaling for as long as their push-out target stays inside
99
- * the cap, and the hard scale once it is clamped. Accumulated impulses are
100
- * written back to each {@link ContactRecord} for warm-starting the next frame.
101
- *
102
- * Internal to {@link NativePhysicsBackend}; not part of the public surface.
103
- */
104
- var ContactSolver = class {
105
- _constraints = [];
106
- _count = 0;
107
- /**
108
- * Build the per-contact constraints for this frame from the touching solid
109
- * contacts. `h` is the sub-step duration (`fixedDelta / subStepCount`); the
110
- * soft factors are derived from it together with `contactHertz`/`dampingRatio`.
111
- * Runs once per frame (detection is not repeated per sub-step).
112
- */
113
- prepare(contacts, h, contactHertz, dampingRatio) {
114
- this._count = 0;
115
- const omega = 2 * Math.PI * contactHertz;
116
- const a1 = 2 * dampingRatio + h * omega;
117
- const a2 = h * omega * a1;
118
- const a3 = 1 / (1 + a2);
119
- const biasRate = contactHertz > 0 ? omega / a1 : 0;
120
- const massScale = contactHertz > 0 ? a2 * a3 : 1;
121
- const impulseScale = contactHertz > 0 ? a3 : 0;
122
- for (const contact of contacts) {
123
- const manifold = contact.manifold;
124
- const pointCount = manifold.pointCount;
125
- if (pointCount === 0 || !contact.enabled) continue;
126
- const bodyA = contact.a.body;
127
- const bodyB = contact.b.body;
128
- if (bodyA.isSleeping || bodyB.isSleeping) continue;
129
- const constraint = this._acquire();
130
- const nx = manifold.normalX;
131
- const ny = manifold.normalY;
132
- const tx = -ny;
133
- const ty = nx;
134
- constraint.record = contact;
135
- constraint.bodyA = bodyA;
136
- constraint.bodyB = bodyB;
137
- constraint.nx = nx;
138
- constraint.ny = ny;
139
- constraint.tx = tx;
140
- constraint.ty = ty;
141
- constraint.friction = contact.friction;
142
- constraint.restitution = contact.restitution;
143
- constraint.pointCount = pointCount;
144
- constraint.block = false;
145
- constraint.biasRate = biasRate;
146
- constraint.massScale = massScale;
147
- constraint.impulseScale = impulseScale;
148
- const mA = bodyA.invMass;
149
- const mB = bodyB.invMass;
150
- const iA = bodyA.invInertia;
151
- const iB = bodyB.invInertia;
152
- const comAx = bodyA.worldCenterOfMassX;
153
- const comAy = bodyA.worldCenterOfMassY;
154
- const comBx = bodyB.worldCenterOfMassX;
155
- const comBy = bodyB.worldCenterOfMassY;
156
- for (let i = 0; i < pointCount; i++) {
157
- const point = i === 0 ? manifold.points[0] : manifold.points[1];
158
- const rAx = point.x - comAx;
159
- const rAy = point.y - comAy;
160
- const rBx = point.x - comBx;
161
- const rBy = point.y - comBy;
162
- constraint.rAx[i] = rAx;
163
- constraint.rAy[i] = rAy;
164
- constraint.rBx[i] = rBx;
165
- constraint.rBy[i] = rBy;
166
- constraint.rotAx[i] = rAx;
167
- constraint.rotAy[i] = rAy;
168
- constraint.rotBx[i] = rBx;
169
- constraint.rotBy[i] = rBy;
170
- const rnA = rAx * ny - rAy * nx;
171
- const rnB = rBx * ny - rBy * nx;
172
- const kn = mA + mB + iA * rnA * rnA + iB * rnB * rnB;
173
- const rtA = rAx * ty - rAy * tx;
174
- const rtB = rBx * ty - rBy * tx;
175
- const kt = mA + mB + iA * rtA * rtA + iB * rtB * rtB;
176
- constraint.normalMass[i] = kn > 0 ? 1 / kn : 0;
177
- constraint.tangentMass[i] = kt > 0 ? 1 / kt : 0;
178
- constraint.baseSeparation[i] = -point.penetration;
179
- constraint.velocityBias[i] = 0;
180
- constraint.relativeVelocity[i] = normalVelocity(bodyA, bodyB, rAx, rAy, rBx, rBy, nx, ny);
181
- }
182
- if (pointCount === 2) {
183
- const rn1A = n(constraint.rAx, 0) * ny - n(constraint.rAy, 0) * nx;
184
- const rn1B = n(constraint.rBx, 0) * ny - n(constraint.rBy, 0) * nx;
185
- const rn2A = n(constraint.rAx, 1) * ny - n(constraint.rAy, 1) * nx;
186
- const rn2B = n(constraint.rBx, 1) * ny - n(constraint.rBy, 1) * nx;
187
- const k11 = mA + mB + iA * rn1A * rn1A + iB * rn1B * rn1B;
188
- const k22 = mA + mB + iA * rn2A * rn2A + iB * rn2B * rn2B;
189
- const k12 = mA + mB + iA * rn1A * rn2A + iB * rn1B * rn2B;
190
- const det = k11 * k22 - k12 * k12;
191
- if (det > 0 && k11 * k11 < maxConditionNumber * det) {
192
- const invDet = 1 / det;
193
- constraint.k11 = k11;
194
- constraint.k12 = k12;
195
- constraint.k22 = k22;
196
- constraint.invK11 = invDet * k22;
197
- constraint.invK12 = -invDet * k12;
198
- constraint.invK22 = invDet * k11;
199
- constraint.block = true;
200
- }
201
- }
202
- }
203
- }
204
- /** Re-apply the cached impulses from the previous frame (warm-starting); runs each sub-step. */
205
- warmStart() {
206
- for (let ci = 0; ci < this._count; ci++) {
207
- const constraint = this._at(ci);
208
- const bodyA = constraint.bodyA;
209
- const bodyB = constraint.bodyB;
210
- this._updateArms(constraint);
211
- for (let i = 0; i < constraint.pointCount; i++) {
212
- const normalImpulse = n(constraint.record.normalImpulse, i);
213
- const tangentImpulse = n(constraint.record.tangentImpulse, i);
214
- const jx = normalImpulse * constraint.nx + tangentImpulse * constraint.tx;
215
- const jy = normalImpulse * constraint.ny + tangentImpulse * constraint.ty;
216
- applyImpulse(bodyA, bodyB, n(constraint.rotAx, i), n(constraint.rotAy, i), n(constraint.rotBx, i), n(constraint.rotBy, i), jx, jy);
217
- }
218
- }
219
- }
220
- /**
221
- * One velocity pass over every contact: the normal constraint (block when
222
- * possible) then friction (Coulomb cone). With `useBias` the normal solve
223
- * carries the soft push-out bias (the main pass, recomputed from the live
224
- * separation); without it the relax pass drives the normal velocity to zero so
225
- * the bias velocity does not remain in the bodies as injected energy.
226
- */
227
- solveVelocities(useBias) {
228
- for (let ci = 0; ci < this._count; ci++) this._solveVelocityContact(this._at(ci), useBias);
229
- }
230
- /**
231
- * Restitution pass, run once after the sub-step loop. For each loaded point
232
- * whose frame-start impact speed exceeded the threshold, add the impulse that
233
- * brings the post-solve normal velocity to `−restitution·impactSpeed`. Kept
234
- * separate from the main solve so resting contacts (impact below threshold) do
235
- * not micro-bounce.
236
- */
237
- applyRestitution() {
238
- for (let ci = 0; ci < this._count; ci++) {
239
- const constraint = this._at(ci);
240
- if (constraint.restitution === 0) continue;
241
- const bodyA = constraint.bodyA;
242
- const bodyB = constraint.bodyB;
243
- const nx = constraint.nx;
244
- const ny = constraint.ny;
245
- this._updateArms(constraint);
246
- for (let i = 0; i < constraint.pointCount; i++) {
247
- const relativeVelocity = n(constraint.relativeVelocity, i);
248
- if (relativeVelocity > -1 || n(constraint.record.normalImpulse, i) <= 0) continue;
249
- const rAx = n(constraint.rotAx, i);
250
- const rAy = n(constraint.rotAy, i);
251
- const rBx = n(constraint.rotBx, i);
252
- const rBy = n(constraint.rotBy, i);
253
- const vn = normalVelocity(bodyA, bodyB, rAx, rAy, rBx, rBy, nx, ny);
254
- const oldNormal = n(constraint.record.normalImpulse, i);
255
- const newNormal = Math.max(0, oldNormal - n(constraint.normalMass, i) * (vn + constraint.restitution * relativeVelocity));
256
- const deltaNormal = newNormal - oldNormal;
257
- constraint.record.normalImpulse[i] = newNormal;
258
- applyImpulse(bodyA, bodyB, rAx, rAy, rBx, rBy, deltaNormal * nx, deltaNormal * ny);
259
- }
260
- }
261
- }
262
- /** Refresh the live (rotated) contact arms from each body's accumulated sub-step rotation. */
263
- _updateArms(constraint) {
264
- const cosA = constraint.bodyA._deltaCos;
265
- const sinA = constraint.bodyA._deltaSin;
266
- const cosB = constraint.bodyB._deltaCos;
267
- const sinB = constraint.bodyB._deltaSin;
268
- for (let i = 0; i < constraint.pointCount; i++) {
269
- const rAx = n(constraint.rAx, i);
270
- const rAy = n(constraint.rAy, i);
271
- const rBx = n(constraint.rBx, i);
272
- const rBy = n(constraint.rBy, i);
273
- constraint.rotAx[i] = rAx * cosA - rAy * sinA;
274
- constraint.rotAy[i] = rAx * sinA + rAy * cosA;
275
- constraint.rotBx[i] = rBx * cosB - rBy * sinB;
276
- constraint.rotBy[i] = rBx * sinB + rBy * cosB;
277
- }
278
- }
279
- _solveVelocityContact(constraint, useBias) {
280
- this._updateArms(constraint);
281
- for (let i = 0; i < constraint.pointCount; i++) {
282
- const excess = -currentSeparation(constraint, i) - contactSlop;
283
- const target = useBias && excess > 0 ? constraint.biasRate * excess : 0;
284
- constraint.velocityBias[i] = Math.min(target, maxBiasVelocity);
285
- constraint.biasClamped[i] = target > maxBiasVelocity;
286
- }
287
- if (constraint.block) this._solveNormalBlock(constraint);
288
- else this._solveNormalSequential(constraint, useBias);
289
- this._solveFriction(constraint);
290
- }
291
- /** Per-point friction: clamp the accumulated tangent impulse to the Coulomb cone `±μ·normalImpulse`. */
292
- _solveFriction(constraint) {
293
- const bodyA = constraint.bodyA;
294
- const bodyB = constraint.bodyB;
295
- for (let i = 0; i < constraint.pointCount; i++) {
296
- const rAx = n(constraint.rotAx, i);
297
- const rAy = n(constraint.rotAy, i);
298
- const rBx = n(constraint.rotBx, i);
299
- const rBy = n(constraint.rotBy, i);
300
- const vtX = bodyB.linearVelocityX - bodyB.angularVelocity * rBy - (bodyA.linearVelocityX - bodyA.angularVelocity * rAy);
301
- const vtY = bodyB.linearVelocityY + bodyB.angularVelocity * rBx - (bodyA.linearVelocityY + bodyA.angularVelocity * rAx);
302
- const vt = vtX * constraint.tx + vtY * constraint.ty;
303
- const maxFriction = constraint.friction * n(constraint.record.normalImpulse, i);
304
- const oldTangent = n(constraint.record.tangentImpulse, i);
305
- const newTangent = clamp(oldTangent - n(constraint.tangentMass, i) * vt, -maxFriction, maxFriction);
306
- const deltaTangent = newTangent - oldTangent;
307
- constraint.record.tangentImpulse[i] = newTangent;
308
- applyImpulse(bodyA, bodyB, rAx, rAy, rBx, rBy, deltaTangent * constraint.tx, deltaTangent * constraint.ty);
309
- }
310
- }
311
- /**
312
- * Single-point (or ill-conditioned) soft normal solve, accumulated and clamped
313
- * ≥ 0. The Box2D-v3 incremental form: with the soft bias active the impulse is
314
- * `−normalMass·massScale·(vn − bias) − impulseScale·accumulated`, which both
315
- * pushes out the penetration and bleeds a little stored impulse (the damped
316
- * spring). The relax pass passes `useBias=false`, collapsing it to the hard
317
- * `−normalMass·vn` (no bias, full mass, no impulse decay).
318
- *
319
- * A point whose push-out target was clamped to `maxBiasVelocity` is solved
320
- * with the hard scale as well: the soft scaling models a spring, and once the
321
- * target is capped the point would otherwise reach only a fraction of an
322
- * already limited push-out. That deficit grows with the load, so past the
323
- * acceleration at which the cap binds the contact would sink without bound
324
- * instead of settling into a slightly deeper limit cycle.
325
- */
326
- _solveNormalSequential(constraint, useBias) {
327
- const bodyA = constraint.bodyA;
328
- const bodyB = constraint.bodyB;
329
- const nx = constraint.nx;
330
- const ny = constraint.ny;
331
- for (let i = 0; i < constraint.pointCount; i++) {
332
- const rAx = n(constraint.rotAx, i);
333
- const rAy = n(constraint.rotAy, i);
334
- const rBx = n(constraint.rotBx, i);
335
- const rBy = n(constraint.rotBy, i);
336
- const vn = normalVelocity(bodyA, bodyB, rAx, rAy, rBx, rBy, nx, ny);
337
- const oldNormal = n(constraint.record.normalImpulse, i);
338
- const clamped = constraint.biasClamped[i] ?? false;
339
- const massScale = useBias && !clamped ? constraint.massScale : 1;
340
- const impulseScale = useBias && !clamped ? constraint.impulseScale : 0;
341
- const impulse = -n(constraint.normalMass, i) * massScale * (vn - n(constraint.velocityBias, i)) - impulseScale * oldNormal;
342
- const newNormal = Math.max(0, oldNormal + impulse);
343
- const deltaNormal = newNormal - oldNormal;
344
- constraint.record.normalImpulse[i] = newNormal;
345
- applyImpulse(bodyA, bodyB, rAx, rAy, rBx, rBy, deltaNormal * nx, deltaNormal * ny);
346
- }
347
- }
348
- /**
349
- * Two-point block normal solve (Box2D LCP): find both new normal impulses
350
- * `x ≥ 0` so the post-solve normal velocities equal the push-out targets
351
- * (`velocityBias`, zero in the relax pass) and are complementary, trying the
352
- * four corners (both active, one active, none). The block path carries the
353
- * soft push-out as its target but solves with a hard mass scale.
354
- */
355
- _solveNormalBlock(constraint) {
356
- const bodyA = constraint.bodyA;
357
- const bodyB = constraint.bodyB;
358
- const nx = constraint.nx;
359
- const ny = constraint.ny;
360
- const a1 = n(constraint.record.normalImpulse, 0);
361
- const a2 = n(constraint.record.normalImpulse, 1);
362
- const vn1 = normalVelocity(bodyA, bodyB, n(constraint.rotAx, 0), n(constraint.rotAy, 0), n(constraint.rotBx, 0), n(constraint.rotBy, 0), nx, ny);
363
- const vn2 = normalVelocity(bodyA, bodyB, n(constraint.rotAx, 1), n(constraint.rotAy, 1), n(constraint.rotBx, 1), n(constraint.rotBy, 1), nx, ny);
364
- const bx = vn1 - n(constraint.velocityBias, 0) - (constraint.k11 * a1 + constraint.k12 * a2);
365
- const by = vn2 - n(constraint.velocityBias, 1) - (constraint.k12 * a1 + constraint.k22 * a2);
366
- let x1 = -(constraint.invK11 * bx + constraint.invK12 * by);
367
- let x2 = -(constraint.invK12 * bx + constraint.invK22 * by);
368
- let solved = x1 >= 0 && x2 >= 0;
369
- if (!solved) {
370
- x1 = -n(constraint.normalMass, 0) * bx;
371
- x2 = 0;
372
- solved = x1 >= 0 && constraint.k12 * x1 + by >= 0;
373
- }
374
- if (!solved) {
375
- x1 = 0;
376
- x2 = -n(constraint.normalMass, 1) * by;
377
- solved = x2 >= 0 && constraint.k12 * x2 + bx >= 0;
378
- }
379
- if (!solved) {
380
- if (bx < 0 || by < 0) return;
381
- x1 = 0;
382
- x2 = 0;
383
- }
384
- const d1 = x1 - a1;
385
- const d2 = x2 - a2;
386
- const jx = (d1 + d2) * nx;
387
- const jy = (d1 + d2) * ny;
388
- const torqueA = (n(constraint.rotAx, 0) * ny - n(constraint.rotAy, 0) * nx) * d1 + (n(constraint.rotAx, 1) * ny - n(constraint.rotAy, 1) * nx) * d2;
389
- const torqueB = (n(constraint.rotBx, 0) * ny - n(constraint.rotBy, 0) * nx) * d1 + (n(constraint.rotBx, 1) * ny - n(constraint.rotBy, 1) * nx) * d2;
390
- bodyA.linearVelocityX -= jx * bodyA.invMass;
391
- bodyA.linearVelocityY -= jy * bodyA.invMass;
392
- bodyA.angularVelocity -= torqueA * bodyA.invInertia;
393
- bodyB.linearVelocityX += jx * bodyB.invMass;
394
- bodyB.linearVelocityY += jy * bodyB.invMass;
395
- bodyB.angularVelocity += torqueB * bodyB.invInertia;
396
- constraint.record.normalImpulse[0] = x1;
397
- constraint.record.normalImpulse[1] = x2;
398
- }
399
- _acquire() {
400
- if (this._count === this._constraints.length) this._constraints.push(new ContactConstraint());
401
- return this._at(this._count++);
402
- }
403
- /**
404
- * Pooled constraint at `ci`. Every caller indexes within `0..this._count-1`
405
- * and `_count` never exceeds the pool length, so the entry always exists; the
406
- * throw is unreachable and only discharges `noUncheckedIndexedAccess` without a
407
- * cast or non-null assertion.
408
- */
409
- _at(ci) {
410
- const constraint = this._constraints[ci];
411
- if (constraint === void 0) throw new RangeError(`ContactSolver: constraint pool index ${ci} out of range.`);
412
- return constraint;
413
- }
414
- };
415
- /**
416
- * Live contact separation at point `i`, recomputed from each body's accumulated
417
- * delta position plus the rotation-induced shift of the (rotated) anchor since
418
- * frame start, projected onto the normal. Negative when overlapping. This is what
419
- * folds the position constraint into the velocity solve without a separate
420
- * geometric pass or re-running detection per sub-step.
421
- */
422
- const currentSeparation = (constraint, i) => {
423
- const bodyA = constraint.bodyA;
424
- const bodyB = constraint.bodyB;
425
- const dispAx = bodyA._deltaPosX + n(constraint.rotAx, i) - n(constraint.rAx, i);
426
- const dispAy = bodyA._deltaPosY + n(constraint.rotAy, i) - n(constraint.rAy, i);
427
- const dispBx = bodyB._deltaPosX + n(constraint.rotBx, i) - n(constraint.rBx, i);
428
- const dispBy = bodyB._deltaPosY + n(constraint.rotBy, i) - n(constraint.rBy, i);
429
- return n(constraint.baseSeparation, i) + (dispBx - dispAx) * constraint.nx + (dispBy - dispAy) * constraint.ny;
430
- };
431
- /** Relative normal velocity at a contact point: `dot(vB + ωB×rB − vA − ωA×rA, n)`. */
432
- const normalVelocity = (bodyA, bodyB, rAx, rAy, rBx, rBy, nx, ny) => {
433
- const dvx = bodyB.linearVelocityX - bodyB.angularVelocity * rBy - (bodyA.linearVelocityX - bodyA.angularVelocity * rAy);
434
- const dvy = bodyB.linearVelocityY + bodyB.angularVelocity * rBx - (bodyA.linearVelocityY + bodyA.angularVelocity * rAx);
435
- return dvx * nx + dvy * ny;
436
- };
437
- /** Apply impulse `(jx, jy)` to B and its negation to A about their contact arms. */
438
- const applyImpulse = (bodyA, bodyB, rAx, rAy, rBx, rBy, jx, jy) => {
439
- bodyA.linearVelocityX -= jx * bodyA.invMass;
440
- bodyA.linearVelocityY -= jy * bodyA.invMass;
441
- bodyA.angularVelocity -= (rAx * jy - rAy * jx) * bodyA.invInertia;
442
- bodyB.linearVelocityX += jx * bodyB.invMass;
443
- bodyB.linearVelocityY += jy * bodyB.invMass;
444
- bodyB.angularVelocity += (rBx * jy - rBy * jx) * bodyB.invInertia;
445
- };
446
- const clamp = (value, low, high) => Math.min(Math.max(value, low), high);
447
- /**
448
- * In-bounds read of a fixed-size (length-2) per-point scratch array. Every
449
- * caller indexes within `0..pointCount-1` (pointCount ≤ 2), so the element
450
- * always exists; the `0` fallback only discharges `noUncheckedIndexedAccess`
451
- * for the unreachable case and keeps the `??` out of caller complexity.
452
- */
453
- const n = (arr, i) => arr[i] ?? 0;
454
-
455
- //#endregion
456
- export { ContactSolver };
457
- //# sourceMappingURL=ContactSolver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ContactSolver.js","names":[],"sources":["../../../src/solver/ContactSolver.ts"],"sourcesContent":["import type { ContactRecord } from '../ContactGraph';\nimport type { PhysicsBody } from '../PhysicsBody';\nimport { contactSlop } from './tolerances';\n\n/** Relative normal speed (px/s) below which a contact is treated as resting (no restitution). */\nconst restitutionThreshold = 1;\n/**\n * Cap on the soft-constraint push-out velocity (px/s). Bounds how fast the bias\n * resolves deep penetration so a large overlap cannot fling bodies apart.\n *\n * The Box2D-v3 analogue is `contactSpeed = 3·lengthUnit`, i.e. 3 m/s in SI. The\n * conversion to pixels is the whole content of this constant: 2D games in this\n * engine's envelope put a metre at roughly 20-100 px (equivalently, the gravity\n * range the solver is tuned for, a few hundred to a few thousand px/s²), so the\n * same physical speed is 60-300 px/s. The low end of that band is taken - it is\n * already past the point where a settling scene stops fighting the cap, and\n * anything higher only widens the speed at which a deep overlap may be undone.\n *\n * A single-digit cap is enough for one body resting on a floor and badly short\n * everywhere else: a gravity-driven pile rearranges faster than such a push-out\n * can work, so overlap accumulates instead of resolving, the pile settles\n * several px deep with far more touching pairs than its geometry has, and the\n * permanently unresolved contacts keep every island awake.\n */\nconst maxBiasVelocity = 60;\n/** Reject the 2-point block solve when the contact matrix is worse-conditioned than this (fall back to sequential). */\nconst maxConditionNumber = 1000;\n\n/**\n * Per-contact velocity constraint (1-2 points), computed once per **frame** in\n * {@link ContactSolver.prepare} and reused across all sub-steps and passes.\n * Pooled and reused across frames, so a steady-state step constructs no\n * constraint of its own. It is not allocation-free in the wider sense: a double\n * handed to a function the optimiser declines to inline is boxed on the heap for\n * the duration of that call, which is why the hot paths below apply their\n * results in place instead of through helpers.\n */\nclass ContactConstraint {\n public record!: ContactRecord;\n public bodyA!: PhysicsBody;\n public bodyB!: PhysicsBody;\n public nx = 0;\n public ny = 0;\n public tx = 0;\n public ty = 0;\n public friction = 0;\n public restitution = 0;\n public pointCount = 0;\n\n // Soft-constraint factors (Box2D-v3 \"soft step\"), derived once per frame from\n // contactHertz/dampingRatio and the sub-step `h`. Shared by both points.\n public biasRate = 0;\n public massScale = 1;\n public impulseScale = 0;\n\n // Per-point contact arms at frame start (relative to each body's centre of mass).\n public readonly rAx = [0, 0];\n public readonly rAy = [0, 0];\n public readonly rBx = [0, 0];\n public readonly rBy = [0, 0];\n // Per-point arms rotated by the live sub-step rotation (refreshed each pass by\n // {@link ContactSolver._updateArms}); the solve reads these so a rotating body's\n // contact torque tracks its current orientation.\n public readonly rotAx = [0, 0];\n public readonly rotAy = [0, 0];\n public readonly rotBx = [0, 0];\n public readonly rotBy = [0, 0];\n public readonly normalMass = [0, 0];\n public readonly tangentMass = [0, 0];\n /** Contact separation at frame start (= −penetration; negative when overlapping). */\n public readonly baseSeparation = [0, 0];\n /** Relative normal velocity at frame start (the impact speed the restitution pass keys off). */\n public readonly relativeVelocity = [0, 0];\n /** Push-out target normal velocity for the current pass (set per pass from the live separation). */\n public readonly velocityBias = [0, 0];\n /**\n * Whether the point's push-out target was clamped to `maxBiasVelocity` this\n * pass. A clamped target is no longer the spring response the soft scaling\n * models, so the single-point solve drops that scaling while it holds.\n */\n public readonly biasClamped = [false, false];\n\n // 2-point block: the contact matrix `K` and its inverse (set only when the\n // manifold has two points and `K` is well-conditioned; else sequential).\n public block = false;\n public k11 = 0;\n public k12 = 0;\n public k22 = 0;\n public invK11 = 0;\n public invK12 = 0;\n public invK22 = 0;\n}\n\n/**\n * Native warm-started **TGS-Soft** contact solver (Box2D-v3 \"soft step\"). Driven\n * by {@link PhysicsWorld} as a sub-stepping loop: detection runs once per frame,\n * then {@link prepare} builds the per-contact constraints (effective masses,\n * frame-start separation + impact velocity, soft factors, and a 2×2 block matrix\n * for two-point manifolds) **once**, and each sub-step runs\n * {@link warmStart} → {@link solveVelocities}(useBias=true) → integrate positions\n * → {@link solveVelocities}(useBias=false) relax. A final {@link applyRestitution}\n * pass adds bounce above the threshold.\n *\n * The position constraint is folded into the velocity solve as a **soft bias**\n * (a damped-spring push-out whose stiffness is decoupled from the iteration\n * count), recomputed each pass from the live per-body delta position/rotation -\n * so there is no separate NGS geometric pass. The contact anchors are rotated by\n * the live sub-step rotation each pass, so a tilting stack's restoring torque is\n * computed against its current orientation (without this the tilt grows instead\n * of being corrected). Two-point manifolds still solve the normal impulses **as a\n * 2×2 block LCP** (Box2D-style), which propagates stack loads far better than\n * solving the points sequentially; the block path carries the soft push-out as\n * its velocity target (hard mass scale), while single-point contacts use the full\n * soft mass/impulse scaling for as long as their push-out target stays inside\n * the cap, and the hard scale once it is clamped. Accumulated impulses are\n * written back to each {@link ContactRecord} for warm-starting the next frame.\n *\n * Internal to {@link NativePhysicsBackend}; not part of the public surface.\n */\nexport class ContactSolver {\n private readonly _constraints: ContactConstraint[] = [];\n private _count = 0;\n\n /**\n * Build the per-contact constraints for this frame from the touching solid\n * contacts. `h` is the sub-step duration (`fixedDelta / subStepCount`); the\n * soft factors are derived from it together with `contactHertz`/`dampingRatio`.\n * Runs once per frame (detection is not repeated per sub-step).\n */\n public prepare(contacts: readonly ContactRecord[], h: number, contactHertz: number, dampingRatio: number): void {\n this._count = 0;\n\n // Box2D-v3 soft-constraint factors from a damped spring (hertz, zeta) at the\n // sub-step `h`: omega = 2πf; a1 = 2ζ + hω; a2 = hω·a1; a3 = 1/(1+a2).\n const omega = 2 * Math.PI * contactHertz;\n const a1 = 2 * dampingRatio + h * omega;\n const a2 = h * omega * a1;\n const a3 = 1 / (1 + a2);\n const biasRate = contactHertz > 0 ? omega / a1 : 0;\n const massScale = contactHertz > 0 ? a2 * a3 : 1;\n const impulseScale = contactHertz > 0 ? a3 : 0;\n\n for (const contact of contacts) {\n const manifold = contact.manifold;\n const pointCount = manifold.pointCount;\n\n // A contact the world's `ContactModifier` disabled for this step stays\n // touching geometrically but applies no impulse.\n if (pointCount === 0 || !contact.enabled) {\n continue;\n }\n\n const bodyA = contact.a.body;\n const bodyB = contact.b.body;\n\n // Skip contacts where either body is asleep: a sleeping island's solid\n // contacts are all sleeping↔sleeping or sleeping↔static (both at rest), so\n // there is nothing to solve. A sleeping body touched by an awake one is\n // woken (island merge) before this runs, so it is never skipped wrongly.\n if (bodyA.isSleeping || bodyB.isSleeping) {\n continue;\n }\n\n const constraint = this._acquire();\n const nx = manifold.normalX;\n const ny = manifold.normalY;\n const tx = -ny;\n const ty = nx;\n\n constraint.record = contact;\n constraint.bodyA = bodyA;\n constraint.bodyB = bodyB;\n constraint.nx = nx;\n constraint.ny = ny;\n constraint.tx = tx;\n constraint.ty = ty;\n // Per-step values: derived from the two colliders each pass, then possibly\n // overridden by the world's `ContactModifier`.\n constraint.friction = contact.friction;\n constraint.restitution = contact.restitution;\n constraint.pointCount = pointCount;\n constraint.block = false;\n constraint.biasRate = biasRate;\n constraint.massScale = massScale;\n constraint.impulseScale = impulseScale;\n\n const mA = bodyA.invMass;\n const mB = bodyB.invMass;\n const iA = bodyA.invInertia;\n const iB = bodyB.invInertia;\n const comAx = bodyA.worldCenterOfMassX;\n const comAy = bodyA.worldCenterOfMassY;\n const comBx = bodyB.worldCenterOfMassX;\n const comBy = bodyB.worldCenterOfMassY;\n\n for (let i = 0; i < pointCount; i++) {\n // i in 0..pointCount-1 and pointCount ≤ 2, so the manifold point exists.\n const point = i === 0 ? manifold.points[0] : manifold.points[1];\n const rAx = point.x - comAx;\n const rAy = point.y - comAy;\n const rBx = point.x - comBx;\n const rBy = point.y - comBy;\n\n constraint.rAx[i] = rAx;\n constraint.rAy[i] = rAy;\n constraint.rBx[i] = rBx;\n constraint.rBy[i] = rBy;\n // Frame start: no accumulated rotation yet, so the live arms equal the base arms.\n constraint.rotAx[i] = rAx;\n constraint.rotAy[i] = rAy;\n constraint.rotBx[i] = rBx;\n constraint.rotBy[i] = rBy;\n\n const rnA = rAx * ny - rAy * nx;\n const rnB = rBx * ny - rBy * nx;\n const kn = mA + mB + iA * rnA * rnA + iB * rnB * rnB;\n const rtA = rAx * ty - rAy * tx;\n const rtB = rBx * ty - rBy * tx;\n const kt = mA + mB + iA * rtA * rtA + iB * rtB * rtB;\n\n constraint.normalMass[i] = kn > 0 ? 1 / kn : 0;\n constraint.tangentMass[i] = kt > 0 ? 1 / kt : 0;\n constraint.baseSeparation[i] = -point.penetration;\n constraint.velocityBias[i] = 0;\n\n // Frame-start relative normal velocity (the true impact speed, captured\n // before this frame's gravity since prepare runs ahead of the sub-step\n // loop) - keys the restitution pass so a resting contact does not\n // perpetually micro-bounce off the per-step gravity increment.\n constraint.relativeVelocity[i] = normalVelocity(bodyA, bodyB, rAx, rAy, rBx, rBy, nx, ny);\n }\n\n if (pointCount === 2) {\n const rn1A = n(constraint.rAx, 0) * ny - n(constraint.rAy, 0) * nx;\n const rn1B = n(constraint.rBx, 0) * ny - n(constraint.rBy, 0) * nx;\n const rn2A = n(constraint.rAx, 1) * ny - n(constraint.rAy, 1) * nx;\n const rn2B = n(constraint.rBx, 1) * ny - n(constraint.rBy, 1) * nx;\n const k11 = mA + mB + iA * rn1A * rn1A + iB * rn1B * rn1B;\n const k22 = mA + mB + iA * rn2A * rn2A + iB * rn2B * rn2B;\n const k12 = mA + mB + iA * rn1A * rn2A + iB * rn1B * rn2B;\n const det = k11 * k22 - k12 * k12;\n\n // Only block-solve when `K` is well-conditioned (parallel-ish contacts\n // produce a near-singular matrix → fall back to sequential).\n if (det > 0 && k11 * k11 < maxConditionNumber * det) {\n const invDet = 1 / det;\n\n constraint.k11 = k11;\n constraint.k12 = k12;\n constraint.k22 = k22;\n constraint.invK11 = invDet * k22;\n constraint.invK12 = -invDet * k12;\n constraint.invK22 = invDet * k11;\n constraint.block = true;\n }\n }\n }\n }\n\n /** Re-apply the cached impulses from the previous frame (warm-starting); runs each sub-step. */\n public warmStart(): void {\n for (let ci = 0; ci < this._count; ci++) {\n const constraint = this._at(ci);\n const bodyA = constraint.bodyA;\n const bodyB = constraint.bodyB;\n\n this._updateArms(constraint);\n\n for (let i = 0; i < constraint.pointCount; i++) {\n const normalImpulse = n(constraint.record.normalImpulse, i);\n const tangentImpulse = n(constraint.record.tangentImpulse, i);\n const jx = normalImpulse * constraint.nx + tangentImpulse * constraint.tx;\n const jy = normalImpulse * constraint.ny + tangentImpulse * constraint.ty;\n\n applyImpulse(bodyA, bodyB, n(constraint.rotAx, i), n(constraint.rotAy, i), n(constraint.rotBx, i), n(constraint.rotBy, i), jx, jy);\n }\n }\n }\n\n /**\n * One velocity pass over every contact: the normal constraint (block when\n * possible) then friction (Coulomb cone). With `useBias` the normal solve\n * carries the soft push-out bias (the main pass, recomputed from the live\n * separation); without it the relax pass drives the normal velocity to zero so\n * the bias velocity does not remain in the bodies as injected energy.\n */\n public solveVelocities(useBias: boolean): void {\n for (let ci = 0; ci < this._count; ci++) {\n this._solveVelocityContact(this._at(ci), useBias);\n }\n }\n\n /**\n * Restitution pass, run once after the sub-step loop. For each loaded point\n * whose frame-start impact speed exceeded the threshold, add the impulse that\n * brings the post-solve normal velocity to `−restitution·impactSpeed`. Kept\n * separate from the main solve so resting contacts (impact below threshold) do\n * not micro-bounce.\n */\n public applyRestitution(): void {\n for (let ci = 0; ci < this._count; ci++) {\n const constraint = this._at(ci);\n\n if (constraint.restitution === 0) {\n continue;\n }\n\n const bodyA = constraint.bodyA;\n const bodyB = constraint.bodyB;\n const nx = constraint.nx;\n const ny = constraint.ny;\n\n this._updateArms(constraint);\n\n for (let i = 0; i < constraint.pointCount; i++) {\n const relativeVelocity = n(constraint.relativeVelocity, i);\n\n // Only points that carried load (normalImpulse > 0) and were struck\n // above the resting threshold bounce.\n if (relativeVelocity > -restitutionThreshold || n(constraint.record.normalImpulse, i) <= 0) {\n continue;\n }\n\n const rAx = n(constraint.rotAx, i);\n const rAy = n(constraint.rotAy, i);\n const rBx = n(constraint.rotBx, i);\n const rBy = n(constraint.rotBy, i);\n const vn = normalVelocity(bodyA, bodyB, rAx, rAy, rBx, rBy, nx, ny);\n const oldNormal = n(constraint.record.normalImpulse, i);\n const newNormal = Math.max(0, oldNormal - n(constraint.normalMass, i) * (vn + constraint.restitution * relativeVelocity));\n const deltaNormal = newNormal - oldNormal;\n\n constraint.record.normalImpulse[i] = newNormal;\n applyImpulse(bodyA, bodyB, rAx, rAy, rBx, rBy, deltaNormal * nx, deltaNormal * ny);\n }\n }\n }\n\n /** Refresh the live (rotated) contact arms from each body's accumulated sub-step rotation. */\n private _updateArms(constraint: ContactConstraint): void {\n const cosA = constraint.bodyA._deltaCos;\n const sinA = constraint.bodyA._deltaSin;\n const cosB = constraint.bodyB._deltaCos;\n const sinB = constraint.bodyB._deltaSin;\n\n for (let i = 0; i < constraint.pointCount; i++) {\n const rAx = n(constraint.rAx, i);\n const rAy = n(constraint.rAy, i);\n const rBx = n(constraint.rBx, i);\n const rBy = n(constraint.rBy, i);\n\n constraint.rotAx[i] = rAx * cosA - rAy * sinA;\n constraint.rotAy[i] = rAx * sinA + rAy * cosA;\n constraint.rotBx[i] = rBx * cosB - rBy * sinB;\n constraint.rotBy[i] = rBx * sinB + rBy * cosB;\n }\n }\n\n private _solveVelocityContact(constraint: ContactConstraint, useBias: boolean): void {\n this._updateArms(constraint);\n\n // Recompute the per-point push-out target from the live separation (folds the\n // position constraint into the velocity solve as a soft bias). With useBias\n // off (relax pass) the target is zero - the plain hard normal solve.\n for (let i = 0; i < constraint.pointCount; i++) {\n // Push out only the penetration beyond the slop, capped - leaving the slop\n // keeps the contact overlapping so the narrow phase does not drop it.\n const excess = -currentSeparation(constraint, i) - contactSlop;\n const target = useBias && excess > 0 ? constraint.biasRate * excess : 0;\n\n constraint.velocityBias[i] = Math.min(target, maxBiasVelocity);\n constraint.biasClamped[i] = target > maxBiasVelocity;\n }\n\n // Normal before friction (Box2D-v3 order): friction's Coulomb cone clamps to\n // `μ·normalImpulse`, so it must see this pass's freshly-solved normal impulse -\n // solving friction first uses last pass's cone and lets stacks creep laterally.\n if (constraint.block) {\n this._solveNormalBlock(constraint);\n } else {\n this._solveNormalSequential(constraint, useBias);\n }\n\n this._solveFriction(constraint);\n }\n\n /** Per-point friction: clamp the accumulated tangent impulse to the Coulomb cone `±μ·normalImpulse`. */\n private _solveFriction(constraint: ContactConstraint): void {\n const bodyA = constraint.bodyA;\n const bodyB = constraint.bodyB;\n\n for (let i = 0; i < constraint.pointCount; i++) {\n const rAx = n(constraint.rotAx, i);\n const rAy = n(constraint.rotAy, i);\n const rBx = n(constraint.rotBx, i);\n const rBy = n(constraint.rotBy, i);\n const vtX = bodyB.linearVelocityX - bodyB.angularVelocity * rBy - (bodyA.linearVelocityX - bodyA.angularVelocity * rAy);\n const vtY = bodyB.linearVelocityY + bodyB.angularVelocity * rBx - (bodyA.linearVelocityY + bodyA.angularVelocity * rAx);\n const vt = vtX * constraint.tx + vtY * constraint.ty;\n const maxFriction = constraint.friction * n(constraint.record.normalImpulse, i);\n const oldTangent = n(constraint.record.tangentImpulse, i);\n const newTangent = clamp(oldTangent - n(constraint.tangentMass, i) * vt, -maxFriction, maxFriction);\n const deltaTangent = newTangent - oldTangent;\n\n constraint.record.tangentImpulse[i] = newTangent;\n applyImpulse(bodyA, bodyB, rAx, rAy, rBx, rBy, deltaTangent * constraint.tx, deltaTangent * constraint.ty);\n }\n }\n\n /**\n * Single-point (or ill-conditioned) soft normal solve, accumulated and clamped\n * ≥ 0. The Box2D-v3 incremental form: with the soft bias active the impulse is\n * `−normalMass·massScale·(vn − bias) − impulseScale·accumulated`, which both\n * pushes out the penetration and bleeds a little stored impulse (the damped\n * spring). The relax pass passes `useBias=false`, collapsing it to the hard\n * `−normalMass·vn` (no bias, full mass, no impulse decay).\n *\n * A point whose push-out target was clamped to `maxBiasVelocity` is solved\n * with the hard scale as well: the soft scaling models a spring, and once the\n * target is capped the point would otherwise reach only a fraction of an\n * already limited push-out. That deficit grows with the load, so past the\n * acceleration at which the cap binds the contact would sink without bound\n * instead of settling into a slightly deeper limit cycle.\n */\n private _solveNormalSequential(constraint: ContactConstraint, useBias: boolean): void {\n const bodyA = constraint.bodyA;\n const bodyB = constraint.bodyB;\n const nx = constraint.nx;\n const ny = constraint.ny;\n\n for (let i = 0; i < constraint.pointCount; i++) {\n const rAx = n(constraint.rotAx, i);\n const rAy = n(constraint.rotAy, i);\n const rBx = n(constraint.rotBx, i);\n const rBy = n(constraint.rotBy, i);\n const vn = normalVelocity(bodyA, bodyB, rAx, rAy, rBx, rBy, nx, ny);\n const oldNormal = n(constraint.record.normalImpulse, i);\n // A clamped push-out target is a fixed velocity goal, not a spring\n // response: scaling it down by `massScale` would leave the point short of\n // a target that is already capped, and the deficit is what removes the\n // fixpoint once the cap binds. Solve those points hard, as the two-point\n // block path always does.\n const clamped = constraint.biasClamped[i] ?? false;\n const massScale = useBias && !clamped ? constraint.massScale : 1;\n const impulseScale = useBias && !clamped ? constraint.impulseScale : 0;\n const impulse = -n(constraint.normalMass, i) * massScale * (vn - n(constraint.velocityBias, i)) - impulseScale * oldNormal;\n const newNormal = Math.max(0, oldNormal + impulse);\n const deltaNormal = newNormal - oldNormal;\n\n constraint.record.normalImpulse[i] = newNormal;\n applyImpulse(bodyA, bodyB, rAx, rAy, rBx, rBy, deltaNormal * nx, deltaNormal * ny);\n }\n }\n\n /**\n * Two-point block normal solve (Box2D LCP): find both new normal impulses\n * `x ≥ 0` so the post-solve normal velocities equal the push-out targets\n * (`velocityBias`, zero in the relax pass) and are complementary, trying the\n * four corners (both active, one active, none). The block path carries the\n * soft push-out as its target but solves with a hard mass scale.\n */\n private _solveNormalBlock(constraint: ContactConstraint): void {\n const bodyA = constraint.bodyA;\n const bodyB = constraint.bodyB;\n const nx = constraint.nx;\n const ny = constraint.ny;\n const a1 = n(constraint.record.normalImpulse, 0);\n const a2 = n(constraint.record.normalImpulse, 1);\n const vn1 = normalVelocity(bodyA, bodyB, n(constraint.rotAx, 0), n(constraint.rotAy, 0), n(constraint.rotBx, 0), n(constraint.rotBy, 0), nx, ny);\n const vn2 = normalVelocity(bodyA, bodyB, n(constraint.rotAx, 1), n(constraint.rotAy, 1), n(constraint.rotBx, 1), n(constraint.rotBy, 1), nx, ny);\n\n // Residual at the current impulse: b = (vn − bias) − K·a.\n const bx = vn1 - n(constraint.velocityBias, 0) - (constraint.k11 * a1 + constraint.k12 * a2);\n const by = vn2 - n(constraint.velocityBias, 1) - (constraint.k12 * a1 + constraint.k22 * a2);\n\n // Case 1 - both points active: x = −K⁻¹·b.\n let x1 = -(constraint.invK11 * bx + constraint.invK12 * by);\n let x2 = -(constraint.invK12 * bx + constraint.invK22 * by);\n let solved = x1 >= 0 && x2 >= 0;\n\n if (!solved) {\n // Case 2 - only point 1 active (x2 = 0).\n x1 = -n(constraint.normalMass, 0) * bx;\n x2 = 0;\n solved = x1 >= 0 && constraint.k12 * x1 + by >= 0;\n }\n\n if (!solved) {\n // Case 3 - only point 2 active (x1 = 0).\n x1 = 0;\n x2 = -n(constraint.normalMass, 1) * by;\n solved = x2 >= 0 && constraint.k12 * x2 + bx >= 0;\n }\n\n if (!solved) {\n // Case 4 - neither active (separating). Only valid when both residuals are\n // non-negative; otherwise no corner applies and the impulses stay put.\n if (bx < 0 || by < 0) {\n return;\n }\n\n x1 = 0;\n x2 = 0;\n }\n\n // Applied here rather than through a helper: the deltas are freshly computed\n // doubles, and passing them across a call the optimiser declines to inline\n // boxes each one on the heap for the duration of the call.\n const d1 = x1 - a1;\n const d2 = x2 - a2;\n const jx = (d1 + d2) * nx;\n const jy = (d1 + d2) * ny;\n const torqueA = (n(constraint.rotAx, 0) * ny - n(constraint.rotAy, 0) * nx) * d1 + (n(constraint.rotAx, 1) * ny - n(constraint.rotAy, 1) * nx) * d2;\n const torqueB = (n(constraint.rotBx, 0) * ny - n(constraint.rotBy, 0) * nx) * d1 + (n(constraint.rotBx, 1) * ny - n(constraint.rotBy, 1) * nx) * d2;\n\n bodyA.linearVelocityX -= jx * bodyA.invMass;\n bodyA.linearVelocityY -= jy * bodyA.invMass;\n bodyA.angularVelocity -= torqueA * bodyA.invInertia;\n bodyB.linearVelocityX += jx * bodyB.invMass;\n bodyB.linearVelocityY += jy * bodyB.invMass;\n bodyB.angularVelocity += torqueB * bodyB.invInertia;\n\n constraint.record.normalImpulse[0] = x1;\n constraint.record.normalImpulse[1] = x2;\n }\n\n private _acquire(): ContactConstraint {\n if (this._count === this._constraints.length) {\n this._constraints.push(new ContactConstraint());\n }\n\n return this._at(this._count++);\n }\n\n /**\n * Pooled constraint at `ci`. Every caller indexes within `0..this._count-1`\n * and `_count` never exceeds the pool length, so the entry always exists; the\n * throw is unreachable and only discharges `noUncheckedIndexedAccess` without a\n * cast or non-null assertion.\n */\n private _at(ci: number): ContactConstraint {\n const constraint = this._constraints[ci];\n\n if (constraint === undefined) {\n throw new RangeError(`ContactSolver: constraint pool index ${ci} out of range.`);\n }\n\n return constraint;\n }\n}\n\n/**\n * Live contact separation at point `i`, recomputed from each body's accumulated\n * delta position plus the rotation-induced shift of the (rotated) anchor since\n * frame start, projected onto the normal. Negative when overlapping. This is what\n * folds the position constraint into the velocity solve without a separate\n * geometric pass or re-running detection per sub-step.\n */\nconst currentSeparation = (constraint: ContactConstraint, i: number): number => {\n const bodyA = constraint.bodyA;\n const bodyB = constraint.bodyB;\n // Anchor displacement since frame start = linear delta + (rotated arm − base arm).\n const dispAx = bodyA._deltaPosX + n(constraint.rotAx, i) - n(constraint.rAx, i);\n const dispAy = bodyA._deltaPosY + n(constraint.rotAy, i) - n(constraint.rAy, i);\n const dispBx = bodyB._deltaPosX + n(constraint.rotBx, i) - n(constraint.rBx, i);\n const dispBy = bodyB._deltaPosY + n(constraint.rotBy, i) - n(constraint.rBy, i);\n\n return n(constraint.baseSeparation, i) + (dispBx - dispAx) * constraint.nx + (dispBy - dispAy) * constraint.ny;\n};\n\n/** Relative normal velocity at a contact point: `dot(vB + ωB×rB − vA − ωA×rA, n)`. */\nconst normalVelocity = (bodyA: PhysicsBody, bodyB: PhysicsBody, rAx: number, rAy: number, rBx: number, rBy: number, nx: number, ny: number): number => {\n const dvx = bodyB.linearVelocityX - bodyB.angularVelocity * rBy - (bodyA.linearVelocityX - bodyA.angularVelocity * rAy);\n const dvy = bodyB.linearVelocityY + bodyB.angularVelocity * rBx - (bodyA.linearVelocityY + bodyA.angularVelocity * rAx);\n\n return dvx * nx + dvy * ny;\n};\n\n/** Apply impulse `(jx, jy)` to B and its negation to A about their contact arms. */\nconst applyImpulse = (bodyA: PhysicsBody, bodyB: PhysicsBody, rAx: number, rAy: number, rBx: number, rBy: number, jx: number, jy: number): void => {\n bodyA.linearVelocityX -= jx * bodyA.invMass;\n bodyA.linearVelocityY -= jy * bodyA.invMass;\n bodyA.angularVelocity -= (rAx * jy - rAy * jx) * bodyA.invInertia;\n\n bodyB.linearVelocityX += jx * bodyB.invMass;\n bodyB.linearVelocityY += jy * bodyB.invMass;\n bodyB.angularVelocity += (rBx * jy - rBy * jx) * bodyB.invInertia;\n};\n\nconst clamp = (value: number, low: number, high: number): number => Math.min(Math.max(value, low), high);\n\n/**\n * In-bounds read of a fixed-size (length-2) per-point scratch array. Every\n * caller indexes within `0..pointCount-1` (pointCount ≤ 2), so the element\n * always exists; the `0` fallback only discharges `noUncheckedIndexedAccess`\n * for the unreachable case and keeps the `??` out of caller complexity.\n */\nconst n = (arr: readonly number[], i: number): number => arr[i] ?? 0;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,kBAAkB;;AAExB,MAAM,qBAAqB;;;;;;;;;;AAW3B,IAAM,oBAAN,MAAwB;CACtB,AAAO;CACP,AAAO;CACP,AAAO;CACP,AAAO,KAAK;CACZ,AAAO,KAAK;CACZ,AAAO,KAAK;CACZ,AAAO,KAAK;CACZ,AAAO,WAAW;CAClB,AAAO,cAAc;CACrB,AAAO,aAAa;CAIpB,AAAO,WAAW;CAClB,AAAO,YAAY;CACnB,AAAO,eAAe;CAGtB,AAAgB,MAAM,CAAC,GAAG,CAAC;CAC3B,AAAgB,MAAM,CAAC,GAAG,CAAC;CAC3B,AAAgB,MAAM,CAAC,GAAG,CAAC;CAC3B,AAAgB,MAAM,CAAC,GAAG,CAAC;CAI3B,AAAgB,QAAQ,CAAC,GAAG,CAAC;CAC7B,AAAgB,QAAQ,CAAC,GAAG,CAAC;CAC7B,AAAgB,QAAQ,CAAC,GAAG,CAAC;CAC7B,AAAgB,QAAQ,CAAC,GAAG,CAAC;CAC7B,AAAgB,aAAa,CAAC,GAAG,CAAC;CAClC,AAAgB,cAAc,CAAC,GAAG,CAAC;;CAEnC,AAAgB,iBAAiB,CAAC,GAAG,CAAC;;CAEtC,AAAgB,mBAAmB,CAAC,GAAG,CAAC;;CAExC,AAAgB,eAAe,CAAC,GAAG,CAAC;;;;;;CAMpC,AAAgB,cAAc,CAAC,OAAO,KAAK;CAI3C,AAAO,QAAQ;CACf,AAAO,MAAM;CACb,AAAO,MAAM;CACb,AAAO,MAAM;CACb,AAAO,SAAS;CAChB,AAAO,SAAS;CAChB,AAAO,SAAS;AAClB;;;;;;;;;;;;;;;;;;;;;;;;;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# sourceMappingURL=tolerances.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tolerances.d.ts","sourceRoot":"","sources":["../../../src/solver/tolerances.ts"],"names":[],"mappings":""}
@@ -1,36 +0,0 @@
1
- //#region src/solver/tolerances.ts
2
- /**
3
- * Penetration allowance (px) the soft bias leaves uncorrected. The narrow phase
4
- * only produces a manifold while the colliders overlap, so pushing penetration
5
- * fully to zero lets a resting contact wink out for a frame (free-fall, then
6
- * re-detect) - a periodic energy spike. Leaving a small slop keeps the contact
7
- * persistently overlapping and the warm-start cache alive.
8
- * @internal
9
- */
10
- const contactSlop = .25;
11
- /**
12
- * Penetration (px) below which a contact never blocks the sleep decision,
13
- * whatever the push-out is doing.
14
- *
15
- * The sleep gate has to consult penetration at all because the push-out moves
16
- * bodies through the solver's position bias, which the relax pass removes from
17
- * their velocity again: a body still climbing out of geometry looks motionless
18
- * to the velocity thresholds, and sleeping it would freeze it visibly embedded.
19
- * Both sides must read the same tolerance, or the sleep gate and the constraint
20
- * it is gating drift apart.
21
- *
22
- * The value is empirical, not derived: a face contact converges to exactly one
23
- * slop at any gravity, but a single-point contact rests one static spring
24
- * deflection deeper, and that offset grows with acceleration (0.28 px at
25
- * 1 000 px/s², 0.53 px at 10 000). Three slops clears that envelope for the
26
- * gravity range the engine is tuned for, so an ordinary resting contact is
27
- * settled by depth alone. Equilibria deeper than that - a loaded contact inside
28
- * a pile, or a lone contact at extreme acceleration - are decided on push-out
29
- * progress instead, against {@link sleepPushOutProgressSpeed}.
30
- * @internal
31
- */
32
- const sleepPenetrationTolerance = 3 * contactSlop;
33
-
34
- //#endregion
35
- export { contactSlop, sleepPenetrationTolerance };
36
- //# sourceMappingURL=tolerances.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tolerances.js","names":[],"sources":["../../../src/solver/tolerances.ts"],"sourcesContent":["/**\n * Penetration allowance (px) the soft bias leaves uncorrected. The narrow phase\n * only produces a manifold while the colliders overlap, so pushing penetration\n * fully to zero lets a resting contact wink out for a frame (free-fall, then\n * re-detect) - a periodic energy spike. Leaving a small slop keeps the contact\n * persistently overlapping and the warm-start cache alive.\n * @internal\n */\nexport const contactSlop = 0.25;\n\n/**\n * Penetration (px) below which a contact never blocks the sleep decision,\n * whatever the push-out is doing.\n *\n * The sleep gate has to consult penetration at all because the push-out moves\n * bodies through the solver's position bias, which the relax pass removes from\n * their velocity again: a body still climbing out of geometry looks motionless\n * to the velocity thresholds, and sleeping it would freeze it visibly embedded.\n * Both sides must read the same tolerance, or the sleep gate and the constraint\n * it is gating drift apart.\n *\n * The value is empirical, not derived: a face contact converges to exactly one\n * slop at any gravity, but a single-point contact rests one static spring\n * deflection deeper, and that offset grows with acceleration (0.28 px at\n * 1 000 px/s², 0.53 px at 10 000). Three slops clears that envelope for the\n * gravity range the engine is tuned for, so an ordinary resting contact is\n * settled by depth alone. Equilibria deeper than that - a loaded contact inside\n * a pile, or a lone contact at extreme acceleration - are decided on push-out\n * progress instead, against {@link sleepPushOutProgressSpeed}.\n * @internal\n */\nexport const sleepPenetrationTolerance = 3 * contactSlop;\n\n/**\n * Speed (px/s) at which an overlap deeper than {@link sleepPenetrationTolerance}\n * still counts as being worked off, so neither of its bodies may bank sleep\n * time. Below it the contact has reached the depth its own load holds it at, and\n * keeping the island awake would only re-solve a scene that has stopped moving.\n *\n * The threshold has to clear the jitter a settled scene's contacts carry while\n * staying well under the speed a genuinely converging contact shows: the soft\n * bias closes the excess beyond the slop at roughly `biasRate` per second\n * (about 9/s at the default 30 Hz over four sub-steps), so a contact converging\n * onto the tolerance is still closing at several px/s when it arrives there.\n * @internal\n */\nexport const sleepPushOutProgressSpeed = 1;\n"],"mappings":";;;;;;;;;AAQA,MAAa,cAAc;;;;;;;;;;;;;;;;;;;;;;AAuB3B,MAAa,4BAA4B,IAAI"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=sort.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../src/sort.ts"],"names":[],"mappings":""}
package/dist/esm/sort.js DELETED
@@ -1,44 +0,0 @@
1
- //#region src/sort.ts
2
- /**
3
- * In-place heap sort - deterministic, O(n log n) regardless of input order, and
4
- * allocation-free. `Array.prototype.sort` allocates an internal temp buffer in
5
- * V8's TimSort for arrays larger than ~10 elements; the broad-phase and contact
6
- * sorts run over ~1,000 elements every step, so that temp buffer is per-step
7
- * garbage. Heap sort sorts in place with only a constant number of locals.
8
- *
9
- * Heap sort is not stable, but every physics comparator (`byMinX`, `byPairId`,
10
- * `byRecordPair`, `byColliderPair`, `bySensorPair`) breaks ties on collider id,
11
- * so no two elements ever compare equal - the ordering is total and therefore
12
- * bit-identical to the `Array.prototype.sort` it replaces (replay
13
- * determinism). Do not use this with a comparator that can return 0 for distinct
14
- * elements; the result order would then differ from a stable sort.
15
- *
16
- * @internal
17
- */
18
- const sortInPlace = (array, compare) => {
19
- const n = array.length;
20
- for (let i = (n >> 1) - 1; i >= 0; i--) siftDown(array, i, n, compare);
21
- for (let end = n - 1; end > 0; end--) {
22
- const root = array[0];
23
- array[0] = array[end];
24
- array[end] = root;
25
- siftDown(array, 0, end, compare);
26
- }
27
- };
28
- const siftDown = (array, start, end, compare) => {
29
- let parent = start;
30
- for (;;) {
31
- let child = parent * 2 + 1;
32
- if (child >= end) break;
33
- if (child + 1 < end && compare(array[child], array[child + 1]) < 0) child++;
34
- if (compare(array[parent], array[child]) >= 0) break;
35
- const tmp = array[parent];
36
- array[parent] = array[child];
37
- array[child] = tmp;
38
- parent = child;
39
- }
40
- };
41
-
42
- //#endregion
43
- export { sortInPlace };
44
- //# sourceMappingURL=sort.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sort.js","names":[],"sources":["../../src/sort.ts"],"sourcesContent":["/**\n * In-place heap sort - deterministic, O(n log n) regardless of input order, and\n * allocation-free. `Array.prototype.sort` allocates an internal temp buffer in\n * V8's TimSort for arrays larger than ~10 elements; the broad-phase and contact\n * sorts run over ~1,000 elements every step, so that temp buffer is per-step\n * garbage. Heap sort sorts in place with only a constant number of locals.\n *\n * Heap sort is not stable, but every physics comparator (`byMinX`, `byPairId`,\n * `byRecordPair`, `byColliderPair`, `bySensorPair`) breaks ties on collider id,\n * so no two elements ever compare equal - the ordering is total and therefore\n * bit-identical to the `Array.prototype.sort` it replaces (replay\n * determinism). Do not use this with a comparator that can return 0 for distinct\n * elements; the result order would then differ from a stable sort.\n *\n * @internal\n */\nexport const sortInPlace = <T>(array: T[], compare: (a: T, b: T) => number): void => {\n const n = array.length;\n\n // Heapify: turn the array into a max-heap bottom-up.\n for (let i = (n >> 1) - 1; i >= 0; i--) {\n siftDown(array, i, n, compare);\n }\n\n // Repeatedly move the max (root) to the sorted tail, then restore the heap.\n for (let end = n - 1; end > 0; end--) {\n const root = array[0]!;\n array[0] = array[end]!;\n array[end] = root;\n siftDown(array, 0, end, compare);\n }\n};\n\nconst siftDown = <T>(array: T[], start: number, end: number, compare: (a: T, b: T) => number): void => {\n let parent = start;\n\n for (;;) {\n let child = parent * 2 + 1;\n\n if (child >= end) {\n break;\n }\n\n // Pick the larger of the two children.\n if (child + 1 < end && compare(array[child]!, array[child + 1]!) < 0) {\n child++;\n }\n\n // Parent already dominates the larger child - heap property restored.\n if (compare(array[parent]!, array[child]!) >= 0) {\n break;\n }\n\n const tmp = array[parent]!;\n array[parent] = array[child]!;\n array[child] = tmp;\n parent = child;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,MAAa,eAAkB,OAAY,YAA0C;CACnF,MAAM,IAAI,MAAM;CAGhB,KAAK,IAAI,KAAK,KAAK,KAAK,GAAG,KAAK,GAAG,KACjC,SAAS,OAAO,GAAG,GAAG,OAAO;CAI/B,KAAK,IAAI,MAAM,IAAI,GAAG,MAAM,GAAG,OAAO;EACpC,MAAM,OAAO,MAAM;EACnB,MAAM,KAAK,MAAM;EACjB,MAAM,OAAO;EACb,SAAS,OAAO,GAAG,KAAK,OAAO;CACjC;AACF;AAEA,MAAM,YAAe,OAAY,OAAe,KAAa,YAA0C;CACrG,IAAI,SAAS;CAEb,SAAS;EACP,IAAI,QAAQ,SAAS,IAAI;EAEzB,IAAI,SAAS,KACX;EAIF,IAAI,QAAQ,IAAI,OAAO,QAAQ,MAAM,QAAS,MAAM,QAAQ,EAAG,IAAI,GACjE;EAIF,IAAI,QAAQ,MAAM,SAAU,MAAM,MAAO,KAAK,GAC5C;EAGF,MAAM,MAAM,MAAM;EAClB,MAAM,UAAU,MAAM;EACtB,MAAM,SAAS;EACf,SAAS;CACX;AACF"}