@newkrok/nape-js 3.6.2 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1269,6 +1269,23 @@ declare class InteractionFilter {
1269
1269
  toString(): string;
1270
1270
  }
1271
1271
 
1272
+ /**
1273
+ * Result from a raycast query.
1274
+ *
1275
+ * Provides the contact normal, distance, inside-flag, and shape hit.
1276
+ * Instances are pooled — call `dispose()` when done to return to pool.
1277
+ */
1278
+ declare class RayResult {
1279
+ static __name__: string[];
1280
+ constructor();
1281
+ get normal(): Vec2;
1282
+ get distance(): number;
1283
+ get inner(): boolean;
1284
+ get shape(): Shape;
1285
+ dispose(): void;
1286
+ toString(): string;
1287
+ }
1288
+
1272
1289
  /**
1273
1290
  * Broadphase algorithm type for Space collision detection.
1274
1291
  *
@@ -1311,1281 +1328,1444 @@ declare class InteractionType {
1311
1328
  }
1312
1329
 
1313
1330
  /**
1314
- * The physics world. Add bodies, shapes, and constraints, then call `step()` each frame to advance the simulation.
1331
+ * Structural interface for all dynamically-generated Nape list classes
1332
+ * (BodyList, ShapeList, CompoundList, etc.).
1333
+ *
1334
+ * These classes are created at runtime by {@link createListClasses} and placed
1335
+ * in the `nape` namespace, so they cannot be imported directly. Use this
1336
+ * interface as the return type for Space / Body query methods.
1315
1337
  */
1316
- declare class Space {
1317
- /**
1318
- * @param gravity - Initial gravity vector (default (0, 0)).
1319
- * @param broadphase - Broadphase algorithm to use.
1320
- */
1321
- constructor(gravity?: Vec2, broadphase?: Broadphase);
1322
- /** Arbitrary user data attached to this Space. */
1338
+ interface TypedListLike<T> extends Iterable<T> {
1339
+ /** Number of elements in the list. */
1340
+ readonly length: number;
1341
+ /** Returns element at the given index. */
1342
+ at(index: number): T;
1343
+ /** Returns true if the list contains `obj`. */
1344
+ has(obj: T): boolean;
1345
+ /** Adds `obj` to the end of the list. Returns true if successful. */
1346
+ push(obj: T): boolean;
1347
+ /** Adds `obj` to the front of the list. Returns true if successful. */
1348
+ unshift(obj: T): boolean;
1349
+ /** Removes and returns the last element. */
1350
+ pop(): T;
1351
+ /** Removes and returns the first element. */
1352
+ shift(): T;
1353
+ /** Adds `obj` (anywhere). Returns true if successful. */
1354
+ add(obj: T): boolean;
1355
+ /** Removes `obj`. Returns true if it was present. */
1356
+ remove(obj: T): boolean;
1357
+ /** Removes all elements. */
1358
+ clear(): void;
1359
+ /** Returns true if the list has no elements. */
1360
+ empty(): boolean;
1361
+ /** Returns an iterator over the elements. */
1362
+ iterator(): Iterable<T>;
1363
+ /** Returns a shallow or deep copy of the list. */
1364
+ copy(deep?: boolean): TypedListLike<T>;
1365
+ /** Merge elements of `xs` into this list. */
1366
+ merge(xs: TypedListLike<T>): void;
1367
+ /** Apply `lambda` to every element. */
1368
+ foreach(lambda: (obj: T) => void): void;
1369
+ /** Returns a filtered copy. */
1370
+ filter(lambda: (obj: T) => boolean): TypedListLike<T>;
1371
+ /** Converts to a plain array. */
1372
+ toArray(): T[];
1373
+ }
1374
+
1375
+ /**
1376
+ * Arbiter type classification.
1377
+ *
1378
+ * - `COLLISION` — collision arbiter
1379
+ * - `SENSOR` — sensor arbiter
1380
+ * - `FLUID` — fluid arbiter
1381
+ *
1382
+ * Converted from nape-compiled.js lines 11653–11725.
1383
+ */
1384
+ declare class ArbiterType {
1385
+ static __name__: string[];
1386
+ constructor();
1387
+ static get COLLISION(): ArbiterType;
1388
+ static get SENSOR(): ArbiterType;
1389
+ static get FLUID(): ArbiterType;
1390
+ toString(): string;
1391
+ }
1392
+
1393
+ /**
1394
+ * Physical material properties applied to shapes.
1395
+ *
1396
+ * Controls elasticity (bounciness), friction coefficients, density, and
1397
+ * rolling friction. Internally wraps a ZPP_Material and is registered as
1398
+ * the public `nape.phys.Material` class in the compiled namespace.
1399
+ *
1400
+ * Converted from nape-compiled.js lines 38254–38573.
1401
+ */
1402
+ declare class Material {
1403
+ static __name__: string[];
1404
+ constructor(elasticity?: number, dynamicFriction?: number, staticFriction?: number, density?: number, rollingFriction?: number);
1405
+ get elasticity(): number;
1406
+ set elasticity(value: number);
1407
+ get dynamicFriction(): number;
1408
+ set dynamicFriction(value: number);
1409
+ get staticFriction(): number;
1410
+ set staticFriction(value: number);
1411
+ get density(): number;
1412
+ set density(value: number);
1413
+ get rollingFriction(): number;
1414
+ set rollingFriction(value: number);
1323
1415
  get userData(): Record<string, unknown>;
1416
+ copy(): Material;
1417
+ toString(): string;
1418
+ static wood(): Material;
1419
+ static steel(): Material;
1420
+ static ice(): Material;
1421
+ static rubber(): Material;
1422
+ static glass(): Material;
1423
+ static sand(): Material;
1424
+ }
1425
+
1426
+ /**
1427
+ * A convex polygon physics shape.
1428
+ */
1429
+ declare class Polygon extends Shape {
1430
+ static __name__: string[];
1431
+ static __super__: any;
1324
1432
  /**
1325
- * World gravity applied to all dynamic bodies each step. Live Vec2.
1326
- * @throws If set to null or a disposed Vec2.
1433
+ * Create a Polygon from a list of Vec2 vertices. Vertices must form a convex polygon
1434
+ * in counter-clockwise order.
1435
+ * @param localVerts - Vertices as `Array<Vec2>`, `Vec2List`, or `GeomPoly`.
1436
+ * @param material - Material to assign (uses default if omitted).
1437
+ * @param filter - InteractionFilter to assign (uses default if omitted).
1327
1438
  */
1328
- get gravity(): Vec2;
1329
- set gravity(value: Vec2);
1330
- /** The broadphase algorithm currently in use (SWEEP_AND_PRUNE or DYNAMIC_AABB_TREE). */
1331
- get broadphase(): Broadphase;
1332
- /** If true, contact points are sorted for determinism. Default: true. */
1333
- get sortContacts(): boolean;
1334
- set sortContacts(value: boolean);
1439
+ constructor(localVerts?: Vec2[] | any, material?: Material, filter?: InteractionFilter);
1335
1440
  /**
1336
- * Global angular drag coefficient applied to all bodies.
1337
- * @throws If set to NaN.
1441
+ * Create an axis-aligned rectangle at the given position.
1442
+ * @param x - Left edge x coordinate.
1443
+ * @param y - Top edge y coordinate.
1444
+ * @param width - Rectangle width.
1445
+ * @param height - Rectangle height.
1446
+ * @param weak - If true, returned Vec2s are marked weak and will be auto-disposed.
1447
+ * @returns Array of four Vec2 corner vertices.
1338
1448
  */
1339
- get worldAngularDrag(): number;
1340
- set worldAngularDrag(value: number);
1449
+ static rect(x: number, y: number, width: number, height: number, weak?: boolean): Vec2[];
1341
1450
  /**
1342
- * Global linear drag coefficient applied to all bodies.
1343
- * @throws If set to NaN.
1451
+ * Create an axis-aligned rectangular polygon centred at the origin.
1452
+ * @param width - Rectangle width.
1453
+ * @param height - Rectangle height (defaults to `width` for a square).
1454
+ * @param weak - If true, returned Vec2s are marked weak and will be auto-disposed.
1455
+ * @returns Array of four Vec2 corner vertices.
1344
1456
  */
1345
- get worldLinearDrag(): number;
1346
- set worldLinearDrag(value: number);
1347
- /** Read-only list of all Compound objects in this space. */
1348
- get compounds(): object;
1349
- /** Read-only list of all Body objects directly in this space. */
1350
- get bodies(): object;
1351
- /** Read-only list of bodies that are awake and actively simulated. */
1352
- get liveBodies(): object;
1353
- /** Read-only list of all Constraint objects in this space. */
1354
- get constraints(): object;
1355
- /** Read-only list of active (awake) constraints. */
1356
- get liveConstraints(): object;
1357
- /** The static world body that acts as an immovable anchor for constraints. */
1358
- get world(): Body;
1359
- /** Read-only list of all active collision/fluid arbiters. */
1360
- get arbiters(): object;
1361
- /** Read-only list of all event listeners registered to this space. */
1362
- get listeners(): object;
1363
- /** Number of `step()` calls made so far. */
1364
- get timeStamp(): number;
1365
- /** Cumulative time simulated (sum of all `deltaTime` values passed to `step()`). */
1366
- get elapsedTime(): number;
1457
+ static box(width: number, height?: number, weak?: boolean): Vec2[];
1367
1458
  /**
1368
- * Advance the simulation by `deltaTime` seconds.
1369
- * `velocityIterations` and `positionIterations` control solver accuracy (default 10 each).
1370
- * @param deltaTime - Time step in seconds; must be strictly positive and not NaN.
1371
- * @param velocityIterations - Number of velocity solver iterations (minimum 1).
1372
- * @param positionIterations - Number of position solver iterations (minimum 1).
1373
- * @throws If `deltaTime` is NaN, non-positive, or any iteration count is less than 1.
1459
+ * Create a regular polygon (or ellipse approximation) centred at the origin.
1460
+ * @param xRadius - Horizontal radius of the circumscribed ellipse.
1461
+ * @param yRadius - Vertical radius of the circumscribed ellipse.
1462
+ * @param edgeCount - Number of sides (must be >= 3).
1463
+ * @param angleOffset - Rotation offset in radians applied to all vertices (default 0).
1464
+ * @param weak - If true, returned Vec2s are marked weak and will be auto-disposed.
1465
+ * @returns Array of `edgeCount` Vec2 vertices.
1374
1466
  */
1375
- step(deltaTime: number, velocityIterations?: number, positionIterations?: number): void;
1467
+ static regular(xRadius: number, yRadius: number, edgeCount: number, angleOffset?: number, weak?: boolean): Vec2[];
1468
+ /** The list of local-space vertices defining this polygon's shape. */
1469
+ get localVerts(): any;
1470
+ /** World-space vertices of this polygon, updated each simulation step. */
1471
+ get worldVerts(): any;
1472
+ /** The list of edges derived from this polygon's vertices. */
1473
+ get edges(): any;
1376
1474
  /**
1377
- * Remove all bodies, constraints, and compounds from this space.
1378
- * @throws If called during a `step()`.
1475
+ * Validate the polygon geometry and return a string describing any issues, or
1476
+ * `"valid"` if the polygon is well-formed.
1477
+ * @returns A validation result string from the underlying ZPP_Polygon.
1379
1478
  */
1380
- clear(): void;
1479
+ validity(): any;
1480
+ }
1481
+
1482
+ /**
1483
+ * An edge of a polygon shape.
1484
+ *
1485
+ * Edges are read-only and managed by the polygon they belong to.
1486
+ * Cannot be instantiated directly — only obtained from Polygon.edges.
1487
+ *
1488
+ * Fully modernized — all getters access ZPP_Edge directly.
1489
+ */
1490
+ declare class Edge {
1491
+ static __name__: string[];
1492
+ constructor();
1493
+ /** Parent polygon. */
1494
+ get polygon(): Polygon;
1495
+ /** Local-space normal vector (immutable Vec2). */
1496
+ get localNormal(): Vec2;
1497
+ /** World-space normal vector (immutable Vec2). Requires polygon in a body. */
1498
+ get worldNormal(): Vec2;
1499
+ /** Edge length. */
1500
+ get length(): number;
1501
+ /** Local-space projection along the edge normal. */
1502
+ get localProjection(): number;
1503
+ /** World-space projection. Requires polygon in a body. */
1504
+ get worldProjection(): number;
1505
+ /** First local vertex of this edge. */
1506
+ get localVertex1(): Vec2;
1507
+ /** Second local vertex of this edge. */
1508
+ get localVertex2(): Vec2;
1509
+ /** First world vertex. Requires polygon in a body. */
1510
+ get worldVertex1(): Vec2;
1511
+ /** Second world vertex. Requires polygon in a body. */
1512
+ get worldVertex2(): Vec2;
1513
+ toString(): string;
1381
1514
  /**
1382
- * Call `lambda` for every body in the space, including those inside compounds.
1383
- * @param lambda - Callback invoked with each Body.
1384
- * @throws If `lambda` is null.
1515
+ * Wrap a ZPP_Vec2 vertex into its public Vec2 outer.
1516
+ * Mirrors the compiled vertex wrapping pattern.
1385
1517
  */
1386
- visitBodies(lambda: (body: Body) => void): void;
1518
+ private _wrapVert;
1519
+ }
1520
+
1521
+ /**
1522
+ * An arbiter representing a physical collision between two solid shapes.
1523
+ *
1524
+ * Provides access to contact points, collision normal, friction coefficients,
1525
+ * elasticity, and impulse data. Properties marked _mutable in pre-handler_ can
1526
+ * only be set within a {@link PreListener} handler.
1527
+ *
1528
+ * Obtain via {@link Arbiter.collisionArbiter} or by casting from a callback's
1529
+ * arbiter list.
1530
+ *
1531
+ * Fully modernized — uses extracted ZPP_ColArbiter directly.
1532
+ */
1533
+ declare class CollisionArbiter extends Arbiter {
1534
+ static __name__: string[];
1535
+ static __super__: typeof Arbiter;
1536
+ constructor();
1387
1537
  /**
1388
- * Call `lambda` for every constraint in the space, including those inside compounds.
1389
- * @param lambda - Callback invoked with each Constraint.
1390
- * @throws If `lambda` is null.
1538
+ * The list of active contact points between the two shapes.
1539
+ * Contains 1 or 2 {@link Contact} objects depending on the collision geometry.
1391
1540
  */
1392
- visitConstraints(lambda: (constraint: Constraint) => void): void;
1541
+ get contacts(): object;
1393
1542
  /**
1394
- * Call `lambda` for every compound in the space (recursively).
1395
- * @param lambda - Callback invoked with each Compound.
1396
- * @throws If `lambda` is null.
1543
+ * Collision normal vector pointing from `shape1` toward `shape2`.
1544
+ * Read-only; available after the arbiter is active.
1397
1545
  */
1398
- visitCompounds(lambda: (compound: Compound) => void): void;
1546
+ get normal(): Vec2;
1547
+ /** Sum of the radii of the two shapes at the collision point. */
1548
+ get radius(): number;
1549
+ /** Reference edge of shape1 (if polygon), or null. */
1550
+ get referenceEdge1(): Edge | null;
1551
+ /** Reference edge of shape2 (if polygon), or null. */
1552
+ get referenceEdge2(): Edge | null;
1399
1553
  /**
1400
- * Determine the type of interaction between two shapes (COLLISION, FLUID, SENSOR, or null if they don't interact).
1401
- * @param shape1 - The first shape; must belong to a Body.
1402
- * @param shape2 - The second shape; must belong to a Body.
1403
- * @returns The InteractionType, or null if the shapes would not interact.
1404
- * @throws If either shape is null or not attached to a Body.
1405
- */
1406
- interactionType(shape1: Shape, shape2: Shape): InteractionType | null;
1407
- /**
1408
- * Return all shapes whose geometry contains the given world-space point.
1409
- * @param point - The world-space point to test.
1410
- * @param filter - Optional interaction filter to restrict results.
1411
- * @param output - Optional existing ShapeList to accumulate results into.
1412
- * @returns A ShapeList of matching shapes.
1413
- * @throws If `point` is null or disposed.
1414
- */
1415
- shapesUnderPoint(point: Vec2, filter?: InteractionFilter | null, output?: object | null): object;
1416
- /**
1417
- * Return all bodies that have at least one shape containing the given world-space point.
1418
- * @param point - The world-space point to test.
1419
- * @param filter - Optional interaction filter to restrict results.
1420
- * @param output - Optional existing BodyList to accumulate results into.
1421
- * @returns A BodyList of matching bodies.
1422
- * @throws If `point` is null or disposed.
1423
- */
1424
- bodiesUnderPoint(point: Vec2, filter?: InteractionFilter | null, output?: object | null): object;
1425
- /**
1426
- * Return all shapes that overlap with the given AABB.
1427
- * @param aabb - The axis-aligned bounding box to test against.
1428
- * @param containment - If true, only shapes fully contained within the AABB are returned.
1429
- * @param strict - If true, exact shape geometry is tested; otherwise only AABBs are compared.
1430
- * @param filter - Optional interaction filter to restrict results.
1431
- * @param output - Optional existing ShapeList to accumulate results into.
1432
- * @returns A ShapeList of matching shapes.
1433
- * @throws If `aabb` is null or degenerate (zero width or height).
1434
- */
1435
- shapesInAABB(aabb: AABB, containment?: boolean, strict?: boolean, filter?: InteractionFilter | null, output?: object | null): object;
1436
- /**
1437
- * Return all bodies that have at least one shape overlapping the given AABB.
1438
- * @param aabb - The axis-aligned bounding box to test against.
1439
- * @param containment - If true, only shapes fully contained within the AABB count.
1440
- * @param strict - If true, exact shape geometry is tested; otherwise only AABBs are compared.
1441
- * @param filter - Optional interaction filter to restrict results.
1442
- * @param output - Optional existing BodyList to accumulate results into.
1443
- * @returns A BodyList of matching bodies.
1444
- * @throws If `aabb` is null or degenerate (zero width or height).
1445
- */
1446
- bodiesInAABB(aabb: AABB, containment?: boolean, strict?: boolean, filter?: InteractionFilter | null, output?: object | null): object;
1447
- /**
1448
- * Return all shapes that overlap with a circle defined by `position` and `radius`.
1449
- * @param position - World-space centre of the query circle.
1450
- * @param radius - Radius of the query circle; must be strictly positive and not NaN.
1451
- * @param containment - If true, only shapes fully contained within the circle are returned.
1452
- * @param filter - Optional interaction filter to restrict results.
1453
- * @param output - Optional existing ShapeList to accumulate results into.
1454
- * @returns A ShapeList of matching shapes.
1455
- * @throws If `position` is null/disposed, or `radius` is NaN or non-positive.
1554
+ * Coefficient of restitution (bounciness).
1555
+ *
1556
+ * Combined from the two shapes' `elasticity` values. Can be overridden
1557
+ * inside a pre-handler. Must be `>= 0`.
1558
+ *
1559
+ * _Mutable in pre-handler only._
1456
1560
  */
1457
- shapesInCircle(position: Vec2, radius: number, containment?: boolean, filter?: InteractionFilter | null, output?: object | null): object;
1561
+ get elasticity(): number;
1562
+ set elasticity(value: number);
1458
1563
  /**
1459
- * Return all bodies that have at least one shape overlapping a query circle.
1460
- * @param position - World-space centre of the query circle.
1461
- * @param radius - Radius of the query circle; must be strictly positive and not NaN.
1462
- * @param containment - If true, only shapes fully contained within the circle count.
1463
- * @param filter - Optional interaction filter to restrict results.
1464
- * @param output - Optional existing BodyList to accumulate results into.
1465
- * @returns A BodyList of matching bodies.
1466
- * @throws If `position` is null/disposed, or `radius` is NaN or non-positive.
1564
+ * Dynamic (kinetic) friction coefficient applied when the contact is sliding.
1565
+ * Combined from the two shapes' material values. _Mutable in pre-handler only._
1467
1566
  */
1468
- bodiesInCircle(position: Vec2, radius: number, containment?: boolean, filter?: InteractionFilter | null, output?: object | null): object;
1567
+ get dynamicFriction(): number;
1568
+ set dynamicFriction(value: number);
1469
1569
  /**
1470
- * Return all shapes in the space that overlap with `shape`.
1471
- * @param shape - The query shape; must be attached to a Body.
1472
- * @param containment - If true, only shapes fully contained within `shape` are returned.
1473
- * @param filter - Optional interaction filter to restrict results.
1474
- * @param output - Optional existing ShapeList to accumulate results into.
1475
- * @returns A ShapeList of overlapping shapes.
1476
- * @throws If `shape` is null, not attached to a Body, or is an invalid polygon.
1570
+ * Static friction coefficient applied when the contact is at rest.
1571
+ * Combined from the two shapes' material values. _Mutable in pre-handler only._
1477
1572
  */
1478
- shapesInShape(shape: Shape, containment?: boolean, filter?: InteractionFilter | null, output?: object | null): object;
1573
+ get staticFriction(): number;
1574
+ set staticFriction(value: number);
1479
1575
  /**
1480
- * Return all bodies in the space that have at least one shape overlapping `shape`.
1481
- * @param shape - The query shape; must be attached to a Body.
1482
- * @param containment - If true, only shapes fully contained within `shape` count.
1483
- * @param filter - Optional interaction filter to restrict results.
1484
- * @param output - Optional existing BodyList to accumulate results into.
1485
- * @returns A BodyList of overlapping bodies.
1486
- * @throws If `shape` is null, not attached to a Body, or is an invalid polygon.
1576
+ * Rolling friction coefficient resists rolling motion.
1577
+ * Combined from the two shapes' material values. _Mutable in pre-handler only._
1487
1578
  */
1488
- bodiesInShape(shape: Shape, containment?: boolean, filter?: InteractionFilter | null, output?: object | null): object;
1579
+ get rollingFriction(): number;
1580
+ set rollingFriction(value: number);
1581
+ /** Whether the first contact point lies on a polygon vertex (poly-circle only). */
1582
+ firstVertex(): boolean;
1583
+ /** Whether the second contact point lies on a polygon vertex (poly-circle only). */
1584
+ secondVertex(): boolean;
1489
1585
  /**
1490
- * Return all shapes in the space that overlap with any shape attached to `body`.
1491
- * Equivalent to calling `shapesInShape` for each of `body`'s shapes and merging results.
1492
- * @param body - The body whose shapes are used as the query region.
1493
- * @param filter - Optional interaction filter to restrict results.
1494
- * @param output - Optional existing ShapeList to accumulate results into.
1495
- * @returns A ShapeList of overlapping shapes.
1496
- * @throws If `body` is null.
1586
+ * Impulse applied in the normal (collision) direction, summed over all contacts.
1587
+ * @param body - One of the two bodies, or `null` for the combined value.
1588
+ * @param freshOnly - Only include new contact points. Default `false`.
1497
1589
  */
1498
- shapesInBody(body: Body, filter?: InteractionFilter | null, output?: object | null): object;
1590
+ normalImpulse(body?: Body | null, freshOnly?: boolean): Vec3;
1499
1591
  /**
1500
- * Return all bodies in the space that overlap with any shape attached to `body`.
1501
- * Equivalent to calling `bodiesInShape` for each of `body`'s shapes and merging results.
1502
- * @param body - The body whose shapes are used as the query region.
1503
- * @param filter - Optional interaction filter to restrict results.
1504
- * @param output - Optional existing BodyList to accumulate results into.
1505
- * @returns A BodyList of overlapping bodies.
1506
- * @throws If `body` is null.
1592
+ * Friction impulse applied in the tangent direction, summed over all contacts.
1593
+ * @param body - One of the two bodies, or `null` for the combined value.
1594
+ * @param freshOnly - Only include new contact points. Default `false`.
1507
1595
  */
1508
- bodiesInBody(body: Body, filter?: InteractionFilter | null, output?: object | null): object;
1596
+ tangentImpulse(body?: Body | null, freshOnly?: boolean): Vec3;
1597
+ /** Total impulse (normal + tangent + rolling) accumulated across all contacts. */
1598
+ totalImpulse(body?: Body | null, freshOnly?: boolean): Vec3;
1509
1599
  /**
1510
- * Sweep `shape` along its current velocity for `deltaTime` seconds and return the first hit.
1511
- * @param shape - The shape to sweep; must belong to a Body.
1512
- * @param deltaTime - Duration of the sweep; must be non-negative.
1513
- * @param liveSweep - If true, other body velocities are considered during the sweep.
1514
- * @param filter - Optional interaction filter to restrict results.
1515
- * @returns The first RayResult hit, or null if nothing was struck.
1516
- * @throws If `shape` is null, not attached to a Body, or `deltaTime` is negative/NaN.
1600
+ * Rolling impulse applied by this collision.
1601
+ * @param body - One of the two bodies, or `null` for the combined value.
1602
+ * @param freshOnly - Only include new contact points. Default `false`.
1517
1603
  */
1518
- convexCast(shape: Shape, deltaTime: number, liveSweep?: boolean, filter?: InteractionFilter | null): object | null;
1604
+ rollingImpulse(body?: Body | null, freshOnly?: boolean): number;
1605
+ }
1606
+
1607
+ /**
1608
+ * An arbiter representing a fluid interaction between a fluid shape and a body.
1609
+ *
1610
+ * Provides access to buoyancy and drag impulses, the overlap area, and the
1611
+ * centre of overlap. Properties marked _mutable in pre-handler_ can only be
1612
+ * set within a {@link PreListener} handler.
1613
+ *
1614
+ * Obtain via {@link Arbiter.fluidArbiter} or by casting from a callback arbiter.
1615
+ *
1616
+ * Fully modernized — uses extracted ZPP_FluidArbiter directly.
1617
+ */
1618
+ declare class FluidArbiter extends Arbiter {
1619
+ static __name__: string[];
1620
+ static __super__: typeof Arbiter;
1621
+ constructor();
1519
1622
  /**
1520
- * Sweep `shape` along its current velocity for `deltaTime` seconds and return all hits.
1521
- * @param shape - The shape to sweep; must belong to a Body.
1522
- * @param deltaTime - Duration of the sweep; must be non-negative.
1523
- * @param liveSweep - If true, other body velocities are considered during the sweep.
1524
- * @param filter - Optional interaction filter to restrict results.
1525
- * @param output - Optional existing RayResultList to accumulate results into.
1526
- * @returns A RayResultList of all hits encountered during the sweep.
1527
- * @throws If `shape` is null, not attached to a Body, or `deltaTime` is negative/NaN.
1623
+ * Centre of the overlap region between the fluid and the body shape.
1624
+ * _Mutable in pre-handler only._
1528
1625
  */
1529
- convexMultiCast(shape: Shape, deltaTime: number, liveSweep?: boolean, filter?: InteractionFilter | null, output?: object | null): object;
1626
+ get position(): Vec2;
1627
+ set position(value: Vec2);
1530
1628
  /**
1531
- * Cast a ray into the space and return the closest hit.
1532
- * @param ray - The ray to cast.
1533
- * @param inner - If true, shapes are tested from the inside as well (useful for concave queries).
1534
- * @param filter - Optional interaction filter to restrict results.
1535
- * @returns The closest RayResult, or null if nothing was hit.
1536
- * @throws If `ray` is null.
1629
+ * Area of the overlap region in pixels². Used to compute buoyancy force.
1630
+ * Must be strictly positive and finite.
1631
+ * _Mutable in pre-handler only._
1537
1632
  */
1538
- rayCast(ray: Ray, inner?: boolean, filter?: InteractionFilter | null): object | null;
1633
+ get overlap(): number;
1634
+ set overlap(value: number);
1539
1635
  /**
1540
- * Cast a ray into the space and return all hits.
1541
- * @param ray - The ray to cast.
1542
- * @param inner - If true, shapes are tested from the inside as well.
1543
- * @param filter - Optional interaction filter to restrict results.
1544
- * @param output - Optional existing RayResultList to accumulate results into.
1545
- * @returns A RayResultList of all shapes the ray intersected.
1546
- * @throws If `ray` is null.
1636
+ * Buoyancy impulse applied in the last step as `(fx, fy, torque)`.
1637
+ * @param body - One of the two bodies, or `null` for the combined value.
1547
1638
  */
1548
- rayMultiCast(ray: Ray, inner?: boolean, filter?: InteractionFilter | null, output?: object | null): object;
1639
+ buoyancyImpulse(body?: Body | null): Vec3;
1549
1640
  /**
1550
- * Returns a brief string summary of this space.
1551
- * @returns A string in the form `Space(bodies=N)`.
1641
+ * Linear and angular drag impulse applied in the last step as `(fx, fy, torque)`.
1642
+ * @param body - One of the two bodies, or `null` for the combined value.
1552
1643
  */
1553
- toString(): string;
1644
+ dragImpulse(body?: Body | null): Vec3;
1645
+ /** Total impulse (buoyancy + drag). */
1646
+ totalImpulse(body?: Body | null, _freshOnly?: boolean): Vec3;
1554
1647
  }
1555
1648
 
1556
1649
  /**
1557
- * Body type enumeration.
1650
+ * Return value for {@link PreListener} handlers — controls whether the interaction
1651
+ * is resolved this step and in future steps.
1558
1652
  *
1559
- * - `STATIC` immovable, infinite mass (walls, floors)
1560
- * - `DYNAMIC` fully simulated (default)
1561
- * - `KINEMATIC` — moves only via velocity, not affected by forces
1653
+ * - `ACCEPT` resolve the interaction (default if handler returns `null`)
1654
+ * - `IGNORE` suppress the interaction permanently until the next `BEGIN`
1655
+ * - `ACCEPT_ONCE` — accept this step only, then revert to the previous flag
1656
+ * - `IGNORE_ONCE` — ignore this step only, then revert to the previous flag
1562
1657
  *
1563
- * Converted from nape-compiled.js lines 24640–24705.
1658
+ * Use `IGNORE`/`ACCEPT` for stateful decisions (e.g., one-way platforms).
1659
+ * Use `*_ONCE` variants for single-step overrides.
1660
+ *
1661
+ * Converted from nape-compiled.js lines 2504–2591.
1564
1662
  */
1565
- declare class BodyType {
1663
+ declare class PreFlag {
1566
1664
  static __name__: string[];
1567
1665
  constructor();
1568
- static get STATIC(): BodyType;
1569
- static get DYNAMIC(): BodyType;
1570
- static get KINEMATIC(): BodyType;
1666
+ /** Accept and resolve the interaction normally. */
1667
+ static get ACCEPT(): PreFlag;
1668
+ /** Suppress the interaction permanently until the next `BEGIN` event. */
1669
+ static get IGNORE(): PreFlag;
1670
+ /** Accept this step only; revert to the previous flag next step. */
1671
+ static get ACCEPT_ONCE(): PreFlag;
1672
+ /** Ignore this step only; revert to the previous flag next step. */
1673
+ static get IGNORE_ONCE(): PreFlag;
1571
1674
  toString(): string;
1572
1675
  }
1573
1676
 
1574
1677
  /**
1575
- * Physical material properties applied to shapes.
1678
+ * Represents an active interaction between two shapes.
1576
1679
  *
1577
- * Controls elasticity (bounciness), friction coefficients, density, and
1578
- * rolling friction. Internally wraps a ZPP_Material and is registered as
1579
- * the public `nape.phys.Material` class in the compiled namespace.
1680
+ * Arbiters are created and pooled internally by the engine — they cannot be
1681
+ * instantiated directly. Access them via:
1682
+ * - `space.arbiters` all active arbiters in the simulation
1683
+ * - `body.arbiters` — arbiters involving a specific body
1684
+ * - `InteractionCallback.arbiters` — arbiters in an interaction callback
1685
+ * - `PreCallback.arbiter` — the arbiter in a pre-handler
1580
1686
  *
1581
- * Converted from nape-compiled.js lines 38254–38573.
1687
+ * Use {@link Arbiter.collisionArbiter} or {@link Arbiter.fluidArbiter} to cast
1688
+ * to a subtype for type-specific properties.
1689
+ *
1690
+ * **Warning:** do not hold references to `Arbiter` objects after the current
1691
+ * simulation step — they are pooled and may be reused.
1692
+ *
1693
+ * Fully modernized — uses extracted ZPP_Arbiter directly.
1582
1694
  */
1583
- declare class Material {
1695
+ declare class Arbiter {
1584
1696
  static __name__: string[];
1585
- constructor(elasticity?: number, dynamicFriction?: number, staticFriction?: number, density?: number, rollingFriction?: number);
1586
- get elasticity(): number;
1587
- set elasticity(value: number);
1588
- get dynamicFriction(): number;
1589
- set dynamicFriction(value: number);
1590
- get staticFriction(): number;
1591
- set staticFriction(value: number);
1592
- get density(): number;
1593
- set density(value: number);
1594
- get rollingFriction(): number;
1595
- set rollingFriction(value: number);
1596
- get userData(): Record<string, unknown>;
1597
- copy(): Material;
1598
- toString(): string;
1599
- static wood(): Material;
1600
- static steel(): Material;
1601
- static ice(): Material;
1602
- static rubber(): Material;
1603
- static glass(): Material;
1604
- static sand(): Material;
1697
+ constructor();
1698
+ /**
1699
+ * Whether both interacting bodies are currently sleeping.
1700
+ * Throws if the arbiter is not active.
1701
+ */
1702
+ get isSleeping(): boolean;
1703
+ /**
1704
+ * The interaction type of this arbiter.
1705
+ * @see {@link ArbiterType}
1706
+ */
1707
+ get type(): ArbiterType;
1708
+ /** Cast to CollisionArbiter if this is a collision, else null. */
1709
+ get collisionArbiter(): CollisionArbiter | null;
1710
+ /** Cast to FluidArbiter if this is a fluid interaction, else null. */
1711
+ get fluidArbiter(): FluidArbiter | null;
1712
+ /** First shape (lower id). */
1713
+ get shape1(): Shape;
1714
+ /** Second shape (higher id). */
1715
+ get shape2(): Shape;
1716
+ /** Body of shape1. */
1717
+ get body1(): Body;
1718
+ /** Body of shape2. */
1719
+ get body2(): Body;
1720
+ /** The pre-handler state of this arbiter. */
1721
+ get state(): PreFlag;
1722
+ /** Whether this is a collision arbiter. */
1723
+ isCollisionArbiter(): boolean;
1724
+ /** Whether this is a fluid arbiter. */
1725
+ isFluidArbiter(): boolean;
1726
+ /** Whether this is a sensor arbiter. */
1727
+ isSensorArbiter(): boolean;
1728
+ /**
1729
+ * Total impulse applied by this arbiter in the last step as `(fx, fy, torque)`.
1730
+ *
1731
+ * Pass a `body` to get the impulse applied specifically to that body.
1732
+ * Pass `freshOnly = true` to include only new contact points (not persistent ones).
1733
+ *
1734
+ * Overridden by {@link CollisionArbiter} and {@link FluidArbiter}.
1735
+ *
1736
+ * @param body - One of the two interacting bodies, or `null` for the combined impulse.
1737
+ * @param _freshOnly - When `true`, only count fresh (new) contacts. Default `false`.
1738
+ */
1739
+ totalImpulse(body?: Body | null, _freshOnly?: boolean): Vec3;
1740
+ toString(): string;
1605
1741
  }
1606
1742
 
1607
1743
  /**
1608
- * Fluid properties for shapes that act as fluid regions.
1744
+ * Enumeration of physics callback event types.
1609
1745
  *
1610
- * Controls density, viscosity, and per-fluid gravity override.
1611
- * Internally wraps a ZPP_FluidProperties and is registered as
1612
- * the public `nape.phys.FluidProperties` class in the compiled namespace.
1746
+ * Use these singletons to specify which phase of an interaction a listener
1747
+ * should respond to:
1613
1748
  *
1614
- * Converted from nape-compiled.js lines 37002–37511.
1749
+ * - `BEGIN` — fired once when two interactors first make contact
1750
+ * - `ONGOING` — fired every simulation step while the interaction persists
1751
+ * - `END` — fired once when two interactors separate
1752
+ * - `WAKE` — fired when a body or constraint wakes from sleep
1753
+ * - `SLEEP` — fired when a body or constraint falls asleep
1754
+ * - `BREAK` — fired when a constraint exceeds its `maxForce`/`maxError` and breaks
1755
+ * - `PRE` — fired before collision resolution; allows per-step accept/ignore decisions
1756
+ *
1757
+ * Valid events per listener type:
1758
+ * - {@link BodyListener}: `WAKE`, `SLEEP`
1759
+ * - {@link ConstraintListener}: `WAKE`, `SLEEP`, `BREAK`
1760
+ * - {@link InteractionListener}: `BEGIN`, `ONGOING`, `END`
1761
+ * - {@link PreListener}: always `PRE` (set internally)
1762
+ *
1763
+ * Converted from nape-compiled.js lines 516–657.
1615
1764
  */
1616
- declare class FluidProperties {
1765
+ declare class CbEvent {
1617
1766
  static __name__: string[];
1618
- constructor(density?: number, viscosity?: number);
1619
- get density(): number;
1620
- set density(value: number);
1621
- get viscosity(): number;
1622
- set viscosity(value: number);
1623
- get gravity(): any;
1624
- set gravity(gravity: any);
1625
- get userData(): Record<string, unknown>;
1626
- get shapes(): any;
1627
- copy(): FluidProperties;
1767
+ constructor();
1768
+ /** Interaction-start event. Fired once when two interactors first make contact. */
1769
+ static get BEGIN(): CbEvent;
1770
+ /** Interaction-continue event. Fired every step while the interaction persists. */
1771
+ static get ONGOING(): CbEvent;
1772
+ /** Interaction-end event. Fired once when two interactors separate. */
1773
+ static get END(): CbEvent;
1774
+ /** Wake event. Fired when a body or constraint wakes from sleep. */
1775
+ static get WAKE(): CbEvent;
1776
+ /** Sleep event. Fired when a body or constraint falls asleep. */
1777
+ static get SLEEP(): CbEvent;
1778
+ /** Break event. Fired when a constraint exceeds its `maxForce` or `maxError` limit. */
1779
+ static get BREAK(): CbEvent;
1780
+ /** Pre-interaction event. Fired before collision resolution; handler can accept or ignore. */
1781
+ static get PRE(): CbEvent;
1628
1782
  toString(): string;
1629
1783
  }
1630
1784
 
1631
1785
  /**
1632
- * Mass mode for a body.
1786
+ * Listener type classification.
1633
1787
  *
1634
- * - `DEFAULT` use computed mass from shapes
1635
- * - `FIXED` use a fixed mass value
1788
+ * - `BODY` body event listener
1789
+ * - `CONSTRAINT` constraint event listener
1790
+ * - `INTERACTION` — interaction event listener
1791
+ * - `PRE` — pre-interaction listener
1636
1792
  *
1637
- * Converted from nape-compiled.js lines 2696627013.
1793
+ * Converted from nape-compiled.js lines 25542646.
1638
1794
  */
1639
- declare class MassMode {
1795
+ declare class ListenerType {
1640
1796
  static __name__: string[];
1641
1797
  constructor();
1642
- static get DEFAULT(): MassMode;
1643
- static get FIXED(): MassMode;
1798
+ static get BODY(): ListenerType;
1799
+ static get CONSTRAINT(): ListenerType;
1800
+ static get INTERACTION(): ListenerType;
1801
+ static get PRE(): ListenerType;
1644
1802
  toString(): string;
1645
1803
  }
1646
1804
 
1647
1805
  /**
1648
- * Inertia mode for a body.
1806
+ * Listener Base class for all physics event listeners.
1649
1807
  *
1650
- * - `DEFAULT` use computed inertia from shapes
1651
- * - `FIXED` — use a fixed inertia value
1808
+ * Provides common properties (type, event, precedence, space) and
1809
+ * toString() for all listener subclasses.
1652
1810
  *
1653
- * Converted from nape-compiled.js lines 2634326390.
1811
+ * Fully modernized from nape-compiled.js lines 231433.
1654
1812
  */
1655
- declare class InertiaMode {
1656
- static __name__: string[];
1657
- constructor();
1658
- static get DEFAULT(): InertiaMode;
1659
- static get FIXED(): InertiaMode;
1660
- toString(): string;
1661
- }
1662
1813
 
1663
1814
  /**
1664
- * Gravity mass mode for a body.
1815
+ * Base class for all physics event listeners.
1665
1816
  *
1666
- * - `DEFAULT` — use computed mass for gravity
1667
- * - `FIXED` — use a fixed gravity mass value
1668
- * - `SCALED` — scale the computed gravity mass
1817
+ * Cannot be instantiated directly — use one of the concrete subclasses:
1818
+ * {@link BodyListener}, {@link ConstraintListener}, {@link InteractionListener},
1819
+ * or {@link PreListener}.
1669
1820
  *
1670
- * Converted from nape-compiled.js lines 26272–26342.
1821
+ * Provides common properties (`type`, `event`, `precedence`, `space`) shared
1822
+ * by all listener types.
1823
+ *
1824
+ * Fully modernized from nape-compiled.js lines 231–433.
1671
1825
  */
1672
- declare class GravMassMode {
1826
+ declare class Listener {
1673
1827
  static __name__: string[];
1674
1828
  constructor();
1675
- static get DEFAULT(): GravMassMode;
1676
- static get FIXED(): GravMassMode;
1677
- static get SCALED(): GravMassMode;
1829
+ /** The type of this listener (BODY, CONSTRAINT, INTERACTION, or PRE). */
1830
+ get type(): ListenerType;
1831
+ /**
1832
+ * The event this listener responds to.
1833
+ *
1834
+ * Valid values depend on the concrete listener type — see {@link CbEvent}.
1835
+ * Changing this while the listener is assigned to a space re-registers it.
1836
+ */
1837
+ get event(): CbEvent;
1838
+ set event(event: CbEvent);
1839
+ /**
1840
+ * Execution priority of this listener relative to other listeners for the
1841
+ * same event. Higher values execute first.
1842
+ *
1843
+ * @defaultValue `0`
1844
+ */
1845
+ get precedence(): number;
1846
+ set precedence(precedence: number);
1847
+ /**
1848
+ * The space this listener is currently registered in, or `null` if not registered.
1849
+ *
1850
+ * Assign to register/unregister the listener in a space:
1851
+ * ```ts
1852
+ * listener.space = mySpace; // register
1853
+ * listener.space = null; // unregister
1854
+ * ```
1855
+ */
1856
+ get space(): Space | null;
1857
+ set space(space: Space | null);
1678
1858
  toString(): string;
1679
1859
  }
1680
1860
 
1681
1861
  /**
1682
- * A rigid body in the physics simulation. Add shapes to give it geometry, then add it to a `Space` to participate in simulation.
1862
+ * Concrete type aliases for all dynamically-generated Nape list classes.
1863
+ *
1864
+ * These aliases use {@link TypedListLike} to give IDE-visible types to the
1865
+ * return values of Space and Body query methods, without requiring the
1866
+ * dynamic list classes to be statically importable.
1683
1867
  */
1684
- declare class Body extends Interactor {
1685
- static __name__: string[];
1686
- static __super__: typeof Interactor;
1687
- /** If true, this body is included in debug rendering. */
1688
- debugDraw: boolean;
1868
+
1869
+ type BodyList = TypedListLike<Body>;
1870
+ type CompoundList = TypedListLike<Compound>;
1871
+ type ShapeList = TypedListLike<Shape>;
1872
+ type ConstraintList = TypedListLike<Constraint>;
1873
+ type ArbiterList = TypedListLike<Arbiter>;
1874
+ type ListenerList = TypedListLike<Listener>;
1875
+ type RayResultList = TypedListLike<RayResult>;
1876
+ type ConvexResultList = TypedListLike<ConvexResult>;
1877
+
1878
+ /**
1879
+ * The physics world. Add bodies, shapes, and constraints, then call `step()` each frame to advance the simulation.
1880
+ */
1881
+ declare class Space {
1689
1882
  /**
1690
- * @param type - Body type (DYNAMIC by default).
1691
- * @param position - Initial world-space position (defaults to origin).
1883
+ * @param gravity - Initial gravity vector (default (0, 0)).
1884
+ * @param broadphase - Broadphase algorithm to use.
1692
1885
  */
1693
- constructor(type?: BodyType, position?: Vec2);
1694
- /** The body type: DYNAMIC, STATIC, or KINEMATIC. Cannot be changed mid-step. */
1695
- get type(): BodyType;
1696
- set type(value: BodyType);
1697
- /** Return true if this body is static. */
1698
- isStatic(): boolean;
1699
- /** Return true if this body is dynamic. */
1700
- isDynamic(): boolean;
1701
- /** Return true if this body is kinematic. */
1702
- isKinematic(): boolean;
1703
- /** World-space position of the body's origin. Live Vec2 — mutating it moves the body. */
1704
- get position(): Vec2;
1705
- set position(value: Vec2);
1886
+ constructor(gravity?: Vec2, broadphase?: Broadphase);
1887
+ /** Arbitrary user data attached to this Space. */
1888
+ get userData(): Record<string, unknown>;
1706
1889
  /**
1707
- * Rotation of the body in radians.
1708
- * @throws If set on a static body that is already in a space.
1890
+ * World gravity applied to all dynamic bodies each step. Live Vec2.
1891
+ * @throws If set to null or a disposed Vec2.
1709
1892
  */
1710
- get rotation(): number;
1711
- set rotation(value: number);
1712
- /** Linear velocity in world space (units/s). Live Vec2. Static bodies cannot have velocity. */
1713
- get velocity(): Vec2;
1714
- set velocity(value: Vec2);
1715
- /** Angular velocity in radians per second. */
1716
- get angularVel(): number;
1717
- set angularVel(value: number);
1718
- /** Desired velocity for kinematic bodies; the engine tries to match this each step. */
1719
- get kinematicVel(): Vec2;
1720
- set kinematicVel(value: Vec2);
1721
- /** Desired angular velocity for kinematic bodies. */
1722
- get kinAngVel(): number;
1723
- set kinAngVel(value: number);
1724
- /** Surface velocity used in friction calculations. */
1725
- get surfaceVel(): Vec2;
1726
- set surfaceVel(value: Vec2);
1727
- /** Accumulated force applied to this body for the current step (cleared after each step). */
1728
- get force(): Vec2;
1729
- set force(value: Vec2);
1730
- /** Accumulated torque applied to this body for the current step (only for DYNAMIC bodies). */
1731
- get torque(): number;
1732
- set torque(value: number);
1893
+ get gravity(): Vec2;
1894
+ set gravity(value: Vec2);
1895
+ /** The broadphase algorithm currently in use (SWEEP_AND_PRUNE or DYNAMIC_AABB_TREE). */
1896
+ get broadphase(): Broadphase;
1897
+ /** If true, contact points are sorted for determinism. Default: true. */
1898
+ get sortContacts(): boolean;
1899
+ set sortContacts(value: boolean);
1733
1900
  /**
1734
- * Mass in kg. Must be finite and > 0. Setting switches massMode to FIXED.
1735
- * @throws If the body is the world body, or if no shapes are present in DEFAULT mass mode.
1901
+ * Global angular drag coefficient applied to all bodies.
1902
+ * @throws If set to NaN.
1736
1903
  */
1737
- get mass(): number;
1738
- set mass(value: number);
1904
+ get worldAngularDrag(): number;
1905
+ set worldAngularDrag(value: number);
1739
1906
  /**
1740
- * Moment of inertia. Must be finite and > 0. Setting switches inertiaMode to FIXED.
1741
- * @throws If the body is the world body, or if no shapes are present in DEFAULT inertia mode.
1907
+ * Global linear drag coefficient applied to all bodies.
1908
+ * @throws If set to NaN.
1742
1909
  */
1743
- get inertia(): number;
1744
- set inertia(value: number);
1745
- /** Effective mass used by the constraint solver (accounts for allowMovement). */
1746
- get constraintMass(): number;
1747
- /** Effective inertia used by the constraint solver (accounts for allowRotation). */
1748
- get constraintInertia(): number;
1749
- /** Gravitational mass. Defaults to the same as `mass`. */
1750
- get gravMass(): number;
1751
- set gravMass(value: number);
1752
- /** Scale factor applied to gravMass relative to the dynamic mass. */
1753
- get gravMassScale(): number;
1754
- set gravMassScale(value: number);
1755
- /** If true, continuous collision detection (CCD) is enabled for this body. */
1756
- get isBullet(): boolean;
1757
- set isBullet(value: boolean);
1758
- /** If true, CCD is disabled even if `isBullet` is set. */
1759
- get disableCCD(): boolean;
1760
- set disableCCD(value: boolean);
1761
- /** If false, translational motion is frozen (infinite effective mass). */
1762
- get allowMovement(): boolean;
1763
- set allowMovement(value: boolean);
1764
- /** If false, rotational motion is frozen (infinite effective inertia). */
1765
- get allowRotation(): boolean;
1766
- set allowRotation(value: boolean);
1910
+ get worldLinearDrag(): number;
1911
+ set worldLinearDrag(value: number);
1912
+ /** Read-only list of all Compound objects in this space. */
1913
+ get compounds(): CompoundList;
1914
+ /** Read-only list of all Body objects directly in this space. */
1915
+ get bodies(): BodyList;
1916
+ /** Read-only list of bodies that are awake and actively simulated. */
1917
+ get liveBodies(): BodyList;
1918
+ /** Read-only list of all Constraint objects in this space. */
1919
+ get constraints(): ConstraintList;
1920
+ /** Read-only list of active (awake) constraints. */
1921
+ get liveConstraints(): ConstraintList;
1922
+ /** The static world body that acts as an immovable anchor for constraints. */
1923
+ get world(): Body;
1924
+ /** Read-only list of all active collision/fluid arbiters. */
1925
+ get arbiters(): ArbiterList;
1926
+ /** Read-only list of all event listeners registered to this space. */
1927
+ get listeners(): ListenerList;
1928
+ /** Number of `step()` calls made so far. */
1929
+ get timeStamp(): number;
1930
+ /** Cumulative time simulated (sum of all `deltaTime` values passed to `step()`). */
1931
+ get elapsedTime(): number;
1767
1932
  /**
1768
- * True if the body is currently sleeping.
1769
- * @throws If the body is not in a Space.
1933
+ * Advance the simulation by `deltaTime` seconds.
1934
+ * `velocityIterations` and `positionIterations` control solver accuracy (default 10 each).
1935
+ * @param deltaTime - Time step in seconds; must be strictly positive and not NaN.
1936
+ * @param velocityIterations - Number of velocity solver iterations (minimum 1).
1937
+ * @param positionIterations - Number of position solver iterations (minimum 1).
1938
+ * @throws If `deltaTime` is NaN, non-positive, or any iteration count is less than 1.
1770
1939
  */
1771
- get isSleeping(): boolean;
1772
- /** List of shapes attached to this body. */
1773
- get shapes(): NapeList<Shape>;
1774
- /** The Space this body belongs to. Setting adds/removes it from the space. */
1775
- get space(): Space;
1776
- set space(value: Space | null);
1777
- /** The Compound this body belongs to, or null. */
1778
- get compound(): Compound | null;
1779
- set compound(value: Compound | null);
1940
+ step(deltaTime: number, velocityIterations?: number, positionIterations?: number): void;
1780
1941
  /**
1781
- * World-space AABB enclosing all shapes.
1782
- * @throws If this is the world body.
1942
+ * Remove all bodies, constraints, and compounds from this space.
1943
+ * @throws If called during a `step()`.
1783
1944
  */
1784
- get bounds(): AABB;
1785
- /** Constraint-solved velocity (read-only view used by the solver). */
1786
- get constraintVelocity(): Vec2;
1945
+ clear(): void;
1787
1946
  /**
1788
- * Local-space centre of mass (read-only, lazy-computed from shapes).
1789
- * @throws If this is the world body.
1947
+ * Call `lambda` for every body in the space, including those inside compounds.
1948
+ * @param lambda - Callback invoked with each Body.
1949
+ * @throws If `lambda` is null.
1790
1950
  */
1791
- get localCOM(): Vec2;
1951
+ visitBodies(lambda: (body: Body) => void): void;
1792
1952
  /**
1793
- * World-space centre of mass (read-only, lazy-computed).
1794
- * @throws If this is the world body.
1953
+ * Call `lambda` for every constraint in the space, including those inside compounds.
1954
+ * @param lambda - Callback invoked with each Constraint.
1955
+ * @throws If `lambda` is null.
1795
1956
  */
1796
- get worldCOM(): Vec2;
1797
- /** Controls how mass is computed: DEFAULT (from shapes) or FIXED (manually set). */
1798
- get massMode(): MassMode;
1799
- set massMode(value: MassMode);
1800
- /** Controls how inertia is computed: DEFAULT or FIXED. */
1801
- get inertiaMode(): InertiaMode;
1802
- set inertiaMode(value: InertiaMode);
1803
- /** Controls gravitational mass: DEFAULT, FIXED, or SCALED. */
1804
- get gravMassMode(): GravMassMode;
1805
- set gravMassMode(value: GravMassMode);
1957
+ visitConstraints(lambda: (constraint: Constraint) => void): void;
1806
1958
  /**
1807
- * Create a deep copy of this body (shapes, mass properties, etc.).
1808
- * @returns A new Body with identical configuration.
1809
- * @throws If this is the world body.
1959
+ * Call `lambda` for every compound in the space (recursively).
1960
+ * @param lambda - Callback invoked with each Compound.
1961
+ * @throws If `lambda` is null.
1810
1962
  */
1811
- copy(): Body;
1963
+ visitCompounds(lambda: (compound: Compound) => void): void;
1812
1964
  /**
1813
- * String identifier like `(dynamic)#42`.
1814
- * @returns A human-readable description of this body.
1965
+ * Determine the type of interaction between two shapes (COLLISION, FLUID, SENSOR, or null if they don't interact).
1966
+ * @param shape1 - The first shape; must belong to a Body.
1967
+ * @param shape2 - The second shape; must belong to a Body.
1968
+ * @returns The InteractionType, or null if the shapes would not interact.
1969
+ * @throws If either shape is null or not attached to a Body.
1815
1970
  */
1816
- toString(): string;
1971
+ interactionType(shape1: Shape, shape2: Shape): InteractionType | null;
1817
1972
  /**
1818
- * Manually integrate the body's position and rotation by `deltaTime` seconds (outside of `Space.step`).
1819
- * @param deltaTime - Time in seconds to integrate over.
1820
- * @returns `this` for chaining.
1821
- * @throws If `deltaTime` is NaN.
1973
+ * Return all shapes whose geometry contains the given world-space point.
1974
+ * @param point - The world-space point to test.
1975
+ * @param filter - Optional interaction filter to restrict results.
1976
+ * @param output - Optional existing ShapeList to accumulate results into.
1977
+ * @returns A ShapeList of matching shapes.
1978
+ * @throws If `point` is null or disposed.
1822
1979
  */
1823
- integrate(deltaTime: number): Body;
1980
+ shapesUnderPoint(point: Vec2, filter?: InteractionFilter | null, output?: ShapeList | null): ShapeList;
1824
1981
  /**
1825
- * Transform a point from local body space to world space.
1826
- * @param point - The point in local space.
1827
- * @param weak - If true, the returned Vec2 is a weak (pooled) reference.
1828
- * @returns The transformed point in world space.
1982
+ * Return all bodies that have at least one shape containing the given world-space point.
1983
+ * @param point - The world-space point to test.
1984
+ * @param filter - Optional interaction filter to restrict results.
1985
+ * @param output - Optional existing BodyList to accumulate results into.
1986
+ * @returns A BodyList of matching bodies.
1987
+ * @throws If `point` is null or disposed.
1829
1988
  */
1830
- localPointToWorld(point: Vec2, weak?: boolean): Vec2;
1989
+ bodiesUnderPoint(point: Vec2, filter?: InteractionFilter | null, output?: BodyList | null): BodyList;
1831
1990
  /**
1832
- * Transform a point from world space to local body space.
1833
- * @param point - The point in world space.
1834
- * @param weak - If true, the returned Vec2 is a weak (pooled) reference.
1835
- * @returns The transformed point in local space.
1991
+ * Return all shapes that overlap with the given AABB.
1992
+ * @param aabb - The axis-aligned bounding box to test against.
1993
+ * @param containment - If true, only shapes fully contained within the AABB are returned.
1994
+ * @param strict - If true, exact shape geometry is tested; otherwise only AABBs are compared.
1995
+ * @param filter - Optional interaction filter to restrict results.
1996
+ * @param output - Optional existing ShapeList to accumulate results into.
1997
+ * @returns A ShapeList of matching shapes.
1998
+ * @throws If `aabb` is null or degenerate (zero width or height).
1836
1999
  */
1837
- worldPointToLocal(point: Vec2, weak?: boolean): Vec2;
2000
+ shapesInAABB(aabb: AABB, containment?: boolean, strict?: boolean, filter?: InteractionFilter | null, output?: ShapeList | null): ShapeList;
1838
2001
  /**
1839
- * Rotate a vector from local body space to world space (no translation).
1840
- * @param vector - The vector in local space.
1841
- * @param weak - If true, the returned Vec2 is a weak (pooled) reference.
1842
- * @returns The rotated vector in world space.
2002
+ * Return all bodies that have at least one shape overlapping the given AABB.
2003
+ * @param aabb - The axis-aligned bounding box to test against.
2004
+ * @param containment - If true, only shapes fully contained within the AABB count.
2005
+ * @param strict - If true, exact shape geometry is tested; otherwise only AABBs are compared.
2006
+ * @param filter - Optional interaction filter to restrict results.
2007
+ * @param output - Optional existing BodyList to accumulate results into.
2008
+ * @returns A BodyList of matching bodies.
2009
+ * @throws If `aabb` is null or degenerate (zero width or height).
1843
2010
  */
1844
- localVectorToWorld(vector: Vec2, weak?: boolean): Vec2;
2011
+ bodiesInAABB(aabb: AABB, containment?: boolean, strict?: boolean, filter?: InteractionFilter | null, output?: BodyList | null): BodyList;
1845
2012
  /**
1846
- * Rotate a vector from world space to local body space (no translation).
1847
- * @param vector - The vector in world space.
1848
- * @param weak - If true, the returned Vec2 is a weak (pooled) reference.
1849
- * @returns The rotated vector in local space.
2013
+ * Return all shapes that overlap with a circle defined by `position` and `radius`.
2014
+ * @param position - World-space centre of the query circle.
2015
+ * @param radius - Radius of the query circle; must be strictly positive and not NaN.
2016
+ * @param containment - If true, only shapes fully contained within the circle are returned.
2017
+ * @param filter - Optional interaction filter to restrict results.
2018
+ * @param output - Optional existing ShapeList to accumulate results into.
2019
+ * @returns A ShapeList of matching shapes.
2020
+ * @throws If `position` is null/disposed, or `radius` is NaN or non-positive.
1850
2021
  */
1851
- worldVectorToLocal(vector: Vec2, weak?: boolean): Vec2;
2022
+ shapesInCircle(position: Vec2, radius: number, containment?: boolean, filter?: InteractionFilter | null, output?: ShapeList | null): ShapeList;
1852
2023
  /**
1853
- * Apply a linear (and optionally angular) impulse to the body.
1854
- * If `pos` is given, it creates a torque about the body's centre.
1855
- * If `sleepable` is true, sleeping bodies are not woken.
1856
- * @param impulse - The linear impulse vector (world space).
1857
- * @param pos - Optional world-space point of application.
1858
- * @param sleepable - If true, the body will not be woken if sleeping.
1859
- * @returns `this` for chaining.
2024
+ * Return all bodies that have at least one shape overlapping a query circle.
2025
+ * @param position - World-space centre of the query circle.
2026
+ * @param radius - Radius of the query circle; must be strictly positive and not NaN.
2027
+ * @param containment - If true, only shapes fully contained within the circle count.
2028
+ * @param filter - Optional interaction filter to restrict results.
2029
+ * @param output - Optional existing BodyList to accumulate results into.
2030
+ * @returns A BodyList of matching bodies.
2031
+ * @throws If `position` is null/disposed, or `radius` is NaN or non-positive.
1860
2032
  */
1861
- applyImpulse(impulse: Vec2, pos?: Vec2, sleepable?: boolean): Body;
2033
+ bodiesInCircle(position: Vec2, radius: number, containment?: boolean, filter?: InteractionFilter | null, output?: BodyList | null): BodyList;
1862
2034
  /**
1863
- * Apply a direct angular impulse (change in angular velocity × inertia).
1864
- * @param impulse - The angular impulse magnitude.
1865
- * @param sleepable - If true, the body will not be woken if sleeping.
1866
- * @returns `this` for chaining.
2035
+ * Return all shapes in the space that overlap with `shape`.
2036
+ * @param shape - The query shape; must be attached to a Body.
2037
+ * @param containment - If true, only shapes fully contained within `shape` are returned.
2038
+ * @param filter - Optional interaction filter to restrict results.
2039
+ * @param output - Optional existing ShapeList to accumulate results into.
2040
+ * @returns A ShapeList of overlapping shapes.
2041
+ * @throws If `shape` is null, not attached to a Body, or is an invalid polygon.
1867
2042
  */
1868
- applyAngularImpulse(impulse: number, sleepable?: boolean): Body;
2043
+ shapesInShape(shape: Shape, containment?: boolean, filter?: InteractionFilter | null, output?: ShapeList | null): ShapeList;
1869
2044
  /**
1870
- * Set linear and angular velocity so the body reaches the given target pose in `deltaTime` seconds.
1871
- * Useful for kinematic or manually driven bodies.
1872
- * @param targetPosition - Desired world-space position.
1873
- * @param targetRotation - Desired rotation in radians.
1874
- * @param deltaTime - Time in seconds over which to reach the target.
1875
- * @returns `this` for chaining.
1876
- * @throws If `targetPosition` is null or `deltaTime` is zero.
2045
+ * Return all bodies in the space that have at least one shape overlapping `shape`.
2046
+ * @param shape - The query shape; must be attached to a Body.
2047
+ * @param containment - If true, only shapes fully contained within `shape` count.
2048
+ * @param filter - Optional interaction filter to restrict results.
2049
+ * @param output - Optional existing BodyList to accumulate results into.
2050
+ * @returns A BodyList of overlapping bodies.
2051
+ * @throws If `shape` is null, not attached to a Body, or is an invalid polygon.
1877
2052
  */
1878
- setVelocityFromTarget(targetPosition: Vec2, targetRotation: number, deltaTime: number): Body;
2053
+ bodiesInShape(shape: Shape, containment?: boolean, filter?: InteractionFilter | null, output?: BodyList | null): BodyList;
1879
2054
  /**
1880
- * Translate all shapes attached to this body in local space by `translation`.
1881
- * @param translation - Offset vector in local space.
1882
- * @returns `this` for chaining.
2055
+ * Return all shapes in the space that overlap with any shape attached to `body`.
2056
+ * Equivalent to calling `shapesInShape` for each of `body`'s shapes and merging results.
2057
+ * @param body - The body whose shapes are used as the query region.
2058
+ * @param filter - Optional interaction filter to restrict results.
2059
+ * @param output - Optional existing ShapeList to accumulate results into.
2060
+ * @returns A ShapeList of overlapping shapes.
2061
+ * @throws If `body` is null.
1883
2062
  */
1884
- translateShapes(translation: Vec2): Body;
2063
+ shapesInBody(body: Body, filter?: InteractionFilter | null, output?: ShapeList | null): ShapeList;
1885
2064
  /**
1886
- * Rotate all shapes attached to this body in local space by `angle` radians.
1887
- * @param angle - Rotation in radians.
1888
- * @returns `this` for chaining.
2065
+ * Return all bodies in the space that overlap with any shape attached to `body`.
2066
+ * Equivalent to calling `bodiesInShape` for each of `body`'s shapes and merging results.
2067
+ * @param body - The body whose shapes are used as the query region.
2068
+ * @param filter - Optional interaction filter to restrict results.
2069
+ * @param output - Optional existing BodyList to accumulate results into.
2070
+ * @returns A BodyList of overlapping bodies.
2071
+ * @throws If `body` is null.
1889
2072
  */
1890
- rotateShapes(angle: number): Body;
2073
+ bodiesInBody(body: Body, filter?: InteractionFilter | null, output?: BodyList | null): BodyList;
1891
2074
  /**
1892
- * Scale all shapes attached to this body in local space.
1893
- * @param scaleX - Horizontal scale factor.
1894
- * @param scaleY - Vertical scale factor.
1895
- * @returns `this` for chaining.
2075
+ * Sweep `shape` along its current velocity for `deltaTime` seconds and return the first hit.
2076
+ * @param shape - The shape to sweep; must belong to a Body.
2077
+ * @param deltaTime - Duration of the sweep; must be non-negative.
2078
+ * @param liveSweep - If true, other body velocities are considered during the sweep.
2079
+ * @param filter - Optional interaction filter to restrict results.
2080
+ * @returns The first RayResult hit, or null if nothing was struck.
2081
+ * @throws If `shape` is null, not attached to a Body, or `deltaTime` is negative/NaN.
1896
2082
  */
1897
- scaleShapes(scaleX: number, scaleY: number): Body;
2083
+ convexCast(shape: Shape, deltaTime: number, liveSweep?: boolean, filter?: InteractionFilter | null): ConvexResult | null;
1898
2084
  /**
1899
- * Apply an affine transform matrix to all shapes in local space.
1900
- * @param matrix - The 2D affine transformation matrix.
1901
- * @returns `this` for chaining.
2085
+ * Sweep `shape` along its current velocity for `deltaTime` seconds and return all hits.
2086
+ * @param shape - The shape to sweep; must belong to a Body.
2087
+ * @param deltaTime - Duration of the sweep; must be non-negative.
2088
+ * @param liveSweep - If true, other body velocities are considered during the sweep.
2089
+ * @param filter - Optional interaction filter to restrict results.
2090
+ * @param output - Optional existing RayResultList to accumulate results into.
2091
+ * @returns A RayResultList of all hits encountered during the sweep.
2092
+ * @throws If `shape` is null, not attached to a Body, or `deltaTime` is negative/NaN.
1902
2093
  */
1903
- transformShapes(matrix: Mat23): Body;
2094
+ convexMultiCast(shape: Shape, deltaTime: number, liveSweep?: boolean, filter?: InteractionFilter | null, output?: ConvexResultList | null): ConvexResultList;
1904
2095
  /**
1905
- * Translate all shapes and adjust the body position so the local centre of mass coincides with the body origin.
1906
- * @returns `this` for chaining.
1907
- * @throws If the body has no shapes.
2096
+ * Cast a ray into the space and return the closest hit.
2097
+ * @param ray - The ray to cast.
2098
+ * @param inner - If true, shapes are tested from the inside as well (useful for concave queries).
2099
+ * @param filter - Optional interaction filter to restrict results.
2100
+ * @returns The closest RayResult, or null if nothing was hit.
2101
+ * @throws If `ray` is null.
1908
2102
  */
1909
- align(): Body;
2103
+ rayCast(ray: Ray, inner?: boolean, filter?: InteractionFilter | null): RayResult | null;
1910
2104
  /**
1911
- * Rotate the body about a world-space pivot point by `angle` radians.
1912
- * Moves the body's position and increments its rotation.
1913
- * @param centre - World-space pivot point.
1914
- * @param angle - Rotation in radians.
1915
- * @returns `this` for chaining.
1916
- * @throws If `centre` is null or `angle` is NaN.
2105
+ * Cast a ray into the space and return all hits.
2106
+ * @param ray - The ray to cast.
2107
+ * @param inner - If true, shapes are tested from the inside as well.
2108
+ * @param filter - Optional interaction filter to restrict results.
2109
+ * @param output - Optional existing RayResultList to accumulate results into.
2110
+ * @returns A RayResultList of all shapes the ray intersected.
2111
+ * @throws If `ray` is null.
1917
2112
  */
1918
- rotate(centre: Vec2, angle: number): Body;
2113
+ rayMultiCast(ray: Ray, inner?: boolean, filter?: InteractionFilter | null, output?: RayResultList | null): RayResultList;
1919
2114
  /**
1920
- * Set the same `Material` on every shape attached to this body.
1921
- * @param material - The material to apply.
1922
- * @returns `this` for chaining.
2115
+ * Returns a brief string summary of this space.
2116
+ * @returns A string in the form `Space(bodies=N)`.
1923
2117
  */
1924
- setShapeMaterials(material: Material): Body;
2118
+ toString(): string;
2119
+ }
2120
+
2121
+ /**
2122
+ * Body type enumeration.
2123
+ *
2124
+ * - `STATIC` — immovable, infinite mass (walls, floors)
2125
+ * - `DYNAMIC` — fully simulated (default)
2126
+ * - `KINEMATIC` — moves only via velocity, not affected by forces
2127
+ *
2128
+ * Converted from nape-compiled.js lines 24640–24705.
2129
+ */
2130
+ declare class BodyType {
2131
+ static __name__: string[];
2132
+ constructor();
2133
+ static get STATIC(): BodyType;
2134
+ static get DYNAMIC(): BodyType;
2135
+ static get KINEMATIC(): BodyType;
2136
+ toString(): string;
2137
+ }
2138
+
2139
+ /**
2140
+ * Fluid properties for shapes that act as fluid regions.
2141
+ *
2142
+ * Controls density, viscosity, and per-fluid gravity override.
2143
+ * Internally wraps a ZPP_FluidProperties and is registered as
2144
+ * the public `nape.phys.FluidProperties` class in the compiled namespace.
2145
+ *
2146
+ * Converted from nape-compiled.js lines 37002–37511.
2147
+ */
2148
+ declare class FluidProperties {
2149
+ static __name__: string[];
2150
+ constructor(density?: number, viscosity?: number);
2151
+ get density(): number;
2152
+ set density(value: number);
2153
+ get viscosity(): number;
2154
+ set viscosity(value: number);
2155
+ get gravity(): any;
2156
+ set gravity(gravity: any);
2157
+ get userData(): Record<string, unknown>;
2158
+ get shapes(): any;
2159
+ copy(): FluidProperties;
2160
+ toString(): string;
2161
+ }
2162
+
2163
+ /**
2164
+ * Mass mode for a body.
2165
+ *
2166
+ * - `DEFAULT` — use computed mass from shapes
2167
+ * - `FIXED` — use a fixed mass value
2168
+ *
2169
+ * Converted from nape-compiled.js lines 26966–27013.
2170
+ */
2171
+ declare class MassMode {
2172
+ static __name__: string[];
2173
+ constructor();
2174
+ static get DEFAULT(): MassMode;
2175
+ static get FIXED(): MassMode;
2176
+ toString(): string;
2177
+ }
2178
+
2179
+ /**
2180
+ * Inertia mode for a body.
2181
+ *
2182
+ * - `DEFAULT` — use computed inertia from shapes
2183
+ * - `FIXED` — use a fixed inertia value
2184
+ *
2185
+ * Converted from nape-compiled.js lines 26343–26390.
2186
+ */
2187
+ declare class InertiaMode {
2188
+ static __name__: string[];
2189
+ constructor();
2190
+ static get DEFAULT(): InertiaMode;
2191
+ static get FIXED(): InertiaMode;
2192
+ toString(): string;
2193
+ }
2194
+
2195
+ /**
2196
+ * Gravity mass mode for a body.
2197
+ *
2198
+ * - `DEFAULT` — use computed mass for gravity
2199
+ * - `FIXED` — use a fixed gravity mass value
2200
+ * - `SCALED` — scale the computed gravity mass
2201
+ *
2202
+ * Converted from nape-compiled.js lines 26272–26342.
2203
+ */
2204
+ declare class GravMassMode {
2205
+ static __name__: string[];
2206
+ constructor();
2207
+ static get DEFAULT(): GravMassMode;
2208
+ static get FIXED(): GravMassMode;
2209
+ static get SCALED(): GravMassMode;
2210
+ toString(): string;
2211
+ }
2212
+
2213
+ /**
2214
+ * A rigid body in the physics simulation. Add shapes to give it geometry, then add it to a `Space` to participate in simulation.
2215
+ */
2216
+ declare class Body extends Interactor {
2217
+ static __name__: string[];
2218
+ static __super__: typeof Interactor;
2219
+ /** If true, this body is included in debug rendering. */
2220
+ debugDraw: boolean;
1925
2221
  /**
1926
- * Set the same `InteractionFilter` on every shape attached to this body.
1927
- * @param filter - The interaction filter to apply.
1928
- * @returns `this` for chaining.
2222
+ * @param type - Body type (DYNAMIC by default).
2223
+ * @param position - Initial world-space position (defaults to origin).
1929
2224
  */
1930
- setShapeFilters(filter: InteractionFilter): Body;
2225
+ constructor(type?: BodyType, position?: Vec2);
2226
+ /** The body type: DYNAMIC, STATIC, or KINEMATIC. Cannot be changed mid-step. */
2227
+ get type(): BodyType;
2228
+ set type(value: BodyType);
2229
+ /** Return true if this body is static. */
2230
+ isStatic(): boolean;
2231
+ /** Return true if this body is dynamic. */
2232
+ isDynamic(): boolean;
2233
+ /** Return true if this body is kinematic. */
2234
+ isKinematic(): boolean;
2235
+ /** World-space position of the body's origin. Live Vec2 — mutating it moves the body. */
2236
+ get position(): Vec2;
2237
+ set position(value: Vec2);
1931
2238
  /**
1932
- * Set the same `FluidProperties` on every shape attached to this body.
1933
- * @param fluidProperties - The fluid properties to apply.
1934
- * @returns `this` for chaining.
2239
+ * Rotation of the body in radians.
2240
+ * @throws If set on a static body that is already in a space.
1935
2241
  */
1936
- setShapeFluidProperties(fluidProperties: FluidProperties): Body;
2242
+ get rotation(): number;
2243
+ set rotation(value: number);
2244
+ /** Linear velocity in world space (units/s). Live Vec2. Static bodies cannot have velocity. */
2245
+ get velocity(): Vec2;
2246
+ set velocity(value: Vec2);
2247
+ /** Angular velocity in radians per second. */
2248
+ get angularVel(): number;
2249
+ set angularVel(value: number);
2250
+ /** Desired velocity for kinematic bodies; the engine tries to match this each step. */
2251
+ get kinematicVel(): Vec2;
2252
+ set kinematicVel(value: Vec2);
2253
+ /** Desired angular velocity for kinematic bodies. */
2254
+ get kinAngVel(): number;
2255
+ set kinAngVel(value: number);
2256
+ /** Surface velocity used in friction calculations. */
2257
+ get surfaceVel(): Vec2;
2258
+ set surfaceVel(value: Vec2);
2259
+ /** Accumulated force applied to this body for the current step (cleared after each step). */
2260
+ get force(): Vec2;
2261
+ set force(value: Vec2);
2262
+ /** Accumulated torque applied to this body for the current step (only for DYNAMIC bodies). */
2263
+ get torque(): number;
2264
+ set torque(value: number);
1937
2265
  /**
1938
- * Test whether a world-space point lies inside any shape attached to this body.
1939
- * @param point - The point to test in world space.
1940
- * @returns True if the point is inside at least one shape.
2266
+ * Mass in kg. Must be finite and > 0. Setting switches massMode to FIXED.
2267
+ * @throws If the body is the world body, or if no shapes are present in DEFAULT mass mode.
1941
2268
  */
1942
- contains(point: Vec2): boolean;
2269
+ get mass(): number;
2270
+ set mass(value: number);
1943
2271
  /**
1944
- * Return the set of bodies connected to this body via constraints.
1945
- * @param depth - Maximum traversal depth (-1 means unlimited).
1946
- * @param output - Optional existing list to accumulate results into.
1947
- * @returns A BodyList of connected bodies.
2272
+ * Moment of inertia. Must be finite and > 0. Setting switches inertiaMode to FIXED.
2273
+ * @throws If the body is the world body, or if no shapes are present in DEFAULT inertia mode.
1948
2274
  */
1949
- connectedBodies(depth?: number, output?: object | null): object;
2275
+ get inertia(): number;
2276
+ set inertia(value: number);
2277
+ /** Effective mass used by the constraint solver (accounts for allowMovement). */
2278
+ get constraintMass(): number;
2279
+ /** Effective inertia used by the constraint solver (accounts for allowRotation). */
2280
+ get constraintInertia(): number;
2281
+ /** Gravitational mass. Defaults to the same as `mass`. */
2282
+ get gravMass(): number;
2283
+ set gravMass(value: number);
2284
+ /** Scale factor applied to gravMass relative to the dynamic mass. */
2285
+ get gravMassScale(): number;
2286
+ set gravMassScale(value: number);
2287
+ /** If true, continuous collision detection (CCD) is enabled for this body. */
2288
+ get isBullet(): boolean;
2289
+ set isBullet(value: boolean);
2290
+ /** If true, CCD is disabled even if `isBullet` is set. */
2291
+ get disableCCD(): boolean;
2292
+ set disableCCD(value: boolean);
2293
+ /** If false, translational motion is frozen (infinite effective mass). */
2294
+ get allowMovement(): boolean;
2295
+ set allowMovement(value: boolean);
2296
+ /** If false, rotational motion is frozen (infinite effective inertia). */
2297
+ get allowRotation(): boolean;
2298
+ set allowRotation(value: boolean);
1950
2299
  /**
1951
- * Return the set of bodies currently interacting with this body via arbiters.
1952
- * @param type - Filter by interaction type (COLLISION, FLUID, SENSOR), or null for all.
1953
- * @param _depth - Unused; reserved for future use.
1954
- * @param output - Optional existing list to accumulate results into.
1955
- * @returns A BodyList of interacting bodies.
2300
+ * True if the body is currently sleeping.
2301
+ * @throws If the body is not in a Space.
1956
2302
  */
1957
- interactingBodies(type?: InteractionType | null, _depth?: number, output?: object | null): object;
2303
+ get isSleeping(): boolean;
2304
+ /** List of shapes attached to this body. */
2305
+ get shapes(): NapeList<Shape>;
2306
+ /** The Space this body belongs to. Setting adds/removes it from the space. */
2307
+ get space(): Space;
2308
+ set space(value: Space | null);
2309
+ /** The Compound this body belongs to, or null. */
2310
+ get compound(): Compound | null;
2311
+ set compound(value: Compound | null);
1958
2312
  /**
1959
- * Sum of normal (penetration-resolving) impulses received from collision arbiters this step.
1960
- * @param body - If provided, only arbiters shared with `body` are summed.
1961
- * @param freshOnly - If true, only newly created arbiters are considered.
1962
- * @returns A Vec3 where x/y are the linear component and z is the angular component.
2313
+ * World-space AABB enclosing all shapes.
2314
+ * @throws If this is the world body.
1963
2315
  */
1964
- normalImpulse(body?: Body | null, freshOnly?: boolean): Vec3;
2316
+ get bounds(): AABB;
2317
+ /** Constraint-solved velocity (read-only view used by the solver). */
2318
+ get constraintVelocity(): Vec2;
1965
2319
  /**
1966
- * Sum of tangent (friction) impulses received from collision arbiters this step.
1967
- * @param body - If provided, only arbiters shared with `body` are summed.
1968
- * @param freshOnly - If true, only newly created arbiters are considered.
1969
- * @returns A Vec3 where x/y are the linear component and z is the angular component.
2320
+ * Local-space centre of mass (read-only, lazy-computed from shapes).
2321
+ * @throws If this is the world body.
1970
2322
  */
1971
- tangentImpulse(body?: Body | null, freshOnly?: boolean): Vec3;
2323
+ get localCOM(): Vec2;
1972
2324
  /**
1973
- * Sum of total contact impulses (normal + tangent) from collision arbiters this step.
1974
- * @param body - If provided, only arbiters shared with `body` are summed.
1975
- * @param freshOnly - If true, only newly created arbiters are considered.
1976
- * @returns A Vec3 where x/y are the linear component and z is the angular component.
2325
+ * World-space centre of mass (read-only, lazy-computed).
2326
+ * @throws If this is the world body.
1977
2327
  */
1978
- totalContactsImpulse(body?: Body | null, freshOnly?: boolean): Vec3;
2328
+ get worldCOM(): Vec2;
2329
+ /** Controls how mass is computed: DEFAULT (from shapes) or FIXED (manually set). */
2330
+ get massMode(): MassMode;
2331
+ set massMode(value: MassMode);
2332
+ /** Controls how inertia is computed: DEFAULT or FIXED. */
2333
+ get inertiaMode(): InertiaMode;
2334
+ set inertiaMode(value: InertiaMode);
2335
+ /** Controls gravitational mass: DEFAULT, FIXED, or SCALED. */
2336
+ get gravMassMode(): GravMassMode;
2337
+ set gravMassMode(value: GravMassMode);
1979
2338
  /**
1980
- * Sum of rolling (angular friction) impulses from collision arbiters this step.
1981
- * @param body - If provided, only arbiters shared with `body` are summed.
1982
- * @param freshOnly - If true, only newly created arbiters are considered.
1983
- * @returns The total rolling impulse scalar.
2339
+ * Create a deep copy of this body (shapes, mass properties, etc.).
2340
+ * @returns A new Body with identical configuration.
2341
+ * @throws If this is the world body.
1984
2342
  */
1985
- rollingImpulse(body?: Body | null, freshOnly?: boolean): number;
2343
+ copy(): Body;
1986
2344
  /**
1987
- * Sum of buoyancy impulses received from fluid arbiters this step.
1988
- * @param body - If provided, only arbiters shared with `body` are summed.
1989
- * @returns A Vec3 where x/y are the linear component and z is the angular component.
2345
+ * String identifier like `(dynamic)#42`.
2346
+ * @returns A human-readable description of this body.
1990
2347
  */
1991
- buoyancyImpulse(body?: Body | null): Vec3;
2348
+ toString(): string;
1992
2349
  /**
1993
- * Sum of fluid drag impulses received from fluid arbiters this step.
1994
- * @param body - If provided, only arbiters shared with `body` are summed.
1995
- * @returns A Vec3 where x/y are the linear component and z is the angular component.
2350
+ * Manually integrate the body's position and rotation by `deltaTime` seconds (outside of `Space.step`).
2351
+ * @param deltaTime - Time in seconds to integrate over.
2352
+ * @returns `this` for chaining.
2353
+ * @throws If `deltaTime` is NaN.
1996
2354
  */
1997
- dragImpulse(body?: Body | null): Vec3;
2355
+ integrate(deltaTime: number): Body;
1998
2356
  /**
1999
- * Sum of total fluid impulses (buoyancy + drag) from fluid arbiters this step.
2000
- * @param body - If provided, only arbiters shared with `body` are summed.
2001
- * @returns A Vec3 where x/y are the linear component and z is the angular component.
2357
+ * Transform a point from local body space to world space.
2358
+ * @param point - The point in local space.
2359
+ * @param weak - If true, the returned Vec2 is a weak (pooled) reference.
2360
+ * @returns The transformed point in world space.
2002
2361
  */
2003
- totalFluidImpulse(body?: Body | null): Vec3;
2362
+ localPointToWorld(point: Vec2, weak?: boolean): Vec2;
2004
2363
  /**
2005
- * Sum of impulses applied to this body by all attached constraints this step.
2006
- * @returns A Vec3 where x/y are the linear component and z is the angular component.
2364
+ * Transform a point from world space to local body space.
2365
+ * @param point - The point in world space.
2366
+ * @param weak - If true, the returned Vec2 is a weak (pooled) reference.
2367
+ * @returns The transformed point in local space.
2007
2368
  */
2008
- constraintsImpulse(): Vec3;
2369
+ worldPointToLocal(point: Vec2, weak?: boolean): Vec2;
2009
2370
  /**
2010
- * Sum of all impulses (contacts + constraints) applied to this body this step, excluding sensor arbiters.
2011
- * @param body - If provided, only arbiters shared with `body` are summed.
2012
- * @param freshOnly - If true, only newly created contact arbiters are considered.
2013
- * @returns A Vec3 where x/y are the linear component and z is the angular component.
2371
+ * Rotate a vector from local body space to world space (no translation).
2372
+ * @param vector - The vector in local space.
2373
+ * @param weak - If true, the returned Vec2 is a weak (pooled) reference.
2374
+ * @returns The rotated vector in world space.
2014
2375
  */
2015
- totalImpulse(body?: Body | null, freshOnly?: boolean): Vec3;
2376
+ localVectorToWorld(vector: Vec2, weak?: boolean): Vec2;
2016
2377
  /**
2017
- * Compute a heuristic crush factor indicating how strongly this body is being compressed from multiple directions.
2018
- * A value near zero means balanced forces; larger values indicate compression.
2019
- * @returns The crush factor (dimensionless).
2020
- * @throws If the body is not in a Space.
2378
+ * Rotate a vector from world space to local body space (no translation).
2379
+ * @param vector - The vector in world space.
2380
+ * @param weak - If true, the returned Vec2 is a weak (pooled) reference.
2381
+ * @returns The rotated vector in local space.
2021
2382
  */
2022
- crushFactor(): number;
2023
- private _getArbiters;
2024
- private _getConstraints;
2025
- private _arbiterImpulseQuery;
2026
- }
2027
-
2028
- /**
2029
- * Shape type classification.
2030
- *
2031
- * - `CIRCLE` — circle shape
2032
- * - `POLYGON` — polygon shape
2033
- *
2034
- * Converted from nape-compiled.js lines 30435–30482.
2035
- */
2036
- declare class ShapeType {
2037
- static __name__: string[];
2038
- constructor();
2039
- static get CIRCLE(): ShapeType;
2040
- static get POLYGON(): ShapeType;
2041
- toString(): string;
2042
- }
2043
-
2044
- /**
2045
- * Base class for physics shapes (Circle, Polygon). Never instantiated directly — use
2046
- * `new Circle(...)` or `Polygon.box(...)` etc.
2047
- */
2048
- declare class Shape extends Interactor {
2049
- /** The shape type: CIRCLE or POLYGON. */
2050
- get type(): ShapeType;
2051
- /** Returns true if this is a Circle shape. */
2052
- isCircle(): boolean;
2053
- /** Returns true if this is a Polygon shape. */
2054
- isPolygon(): boolean;
2383
+ worldVectorToLocal(vector: Vec2, weak?: boolean): Vec2;
2055
2384
  /**
2056
- * The Body this shape belongs to. Setting moves the shape between bodies.
2385
+ * Apply a linear (and optionally angular) impulse to the body.
2386
+ * If `pos` is given, it creates a torque about the body's centre.
2387
+ * If `sleepable` is true, sleeping bodies are not woken.
2388
+ * @param impulse - The linear impulse vector (world space).
2389
+ * @param pos - Optional world-space point of application.
2390
+ * @param sleepable - If true, the body will not be woken if sleeping.
2391
+ * @returns `this` for chaining.
2057
2392
  */
2058
- get body(): Body;
2059
- set body(value: Body | null);
2060
- /** Cast to Circle, or null if this is not a circle. */
2061
- get castCircle(): Shape | null;
2062
- /** Cast to Polygon, or null if this is not a polygon. */
2063
- get castPolygon(): Shape | null;
2064
- /** World-space centre of mass of this shape (read-only, lazy-computed). */
2065
- get worldCOM(): Vec2;
2393
+ applyImpulse(impulse: Vec2, pos?: Vec2, sleepable?: boolean): Body;
2066
2394
  /**
2067
- * Local-space centre of mass. Can be set to override the default shape centroid.
2395
+ * Apply a direct angular impulse (change in angular velocity × inertia).
2396
+ * @param impulse - The angular impulse magnitude.
2397
+ * @param sleepable - If true, the body will not be woken if sleeping.
2398
+ * @returns `this` for chaining.
2068
2399
  */
2069
- get localCOM(): Vec2;
2070
- set localCOM(value: Vec2);
2071
- /** Cross-sectional area of this shape. */
2072
- get area(): number;
2073
- /** Contribution to moment of inertia (about local centroid, unit density). */
2074
- get inertia(): number;
2075
- /** Angular drag coefficient for this shape. */
2076
- get angDrag(): number;
2077
- /** The Material assigned to this shape (controls friction, elasticity, density). */
2078
- get material(): Material;
2079
- set material(value: Material);
2080
- /** The InteractionFilter controlling which shapes interact with this one. */
2081
- get filter(): InteractionFilter;
2082
- set filter(value: InteractionFilter);
2083
- /** Fluid simulation properties for this shape. Auto-created on first access. */
2084
- get fluidProperties(): FluidProperties;
2085
- set fluidProperties(value: FluidProperties);
2086
- /** Set of callback types registered on this shape for event dispatch. */
2087
- get cbTypes(): CbTypeSet;
2088
- /** If true, this shape participates in fluid interaction. */
2089
- get fluidEnabled(): boolean;
2090
- set fluidEnabled(value: boolean);
2091
- /** If true, this shape acts as a sensor (no physical response, only callbacks). */
2092
- get sensorEnabled(): boolean;
2093
- set sensorEnabled(value: boolean);
2094
- /** World-space AABB of this shape (updated each step). */
2095
- get bounds(): AABB;
2400
+ applyAngularImpulse(impulse: number, sleepable?: boolean): Body;
2096
2401
  /**
2097
- * Translate the shape's local vertices by the given vector (in-place).
2098
- * @param translation - The displacement vector to apply.
2402
+ * Set linear and angular velocity so the body reaches the given target pose in `deltaTime` seconds.
2403
+ * Useful for kinematic or manually driven bodies.
2404
+ * @param targetPosition - Desired world-space position.
2405
+ * @param targetRotation - Desired rotation in radians.
2406
+ * @param deltaTime - Time in seconds over which to reach the target.
2099
2407
  * @returns `this` for chaining.
2408
+ * @throws If `targetPosition` is null or `deltaTime` is zero.
2100
2409
  */
2101
- translate(translation: Vec2): Shape;
2410
+ setVelocityFromTarget(targetPosition: Vec2, targetRotation: number, deltaTime: number): Body;
2102
2411
  /**
2103
- * Scale the shape's local geometry. Circles require uniform scaling.
2104
- * @param scaleX - Horizontal scale factor (must be non-zero).
2105
- * @param scaleY - Vertical scale factor (must be non-zero).
2412
+ * Translate all shapes attached to this body in local space by `translation`.
2413
+ * @param translation - Offset vector in local space.
2106
2414
  * @returns `this` for chaining.
2107
2415
  */
2108
- scale(scaleX: number, scaleY: number): Shape;
2416
+ translateShapes(translation: Vec2): Body;
2109
2417
  /**
2110
- * Rotate the shape's local vertices by `angle` radians.
2418
+ * Rotate all shapes attached to this body in local space by `angle` radians.
2111
2419
  * @param angle - Rotation in radians.
2112
2420
  * @returns `this` for chaining.
2113
2421
  */
2114
- rotate(angle: number): Shape;
2422
+ rotateShapes(angle: number): Body;
2115
2423
  /**
2116
- * Apply a Mat23 affine transform to the shape's local geometry.
2117
- * @param matrix - The transformation matrix (must be non-singular; Circles require equiorthogonal).
2424
+ * Scale all shapes attached to this body in local space.
2425
+ * @param scaleX - Horizontal scale factor.
2426
+ * @param scaleY - Vertical scale factor.
2118
2427
  * @returns `this` for chaining.
2119
2428
  */
2120
- transform(matrix: {
2121
- _inner: NapeInner;
2122
- }): Shape;
2429
+ scaleShapes(scaleX: number, scaleY: number): Body;
2123
2430
  /**
2124
- * Return true if the given world-space point lies inside this shape.
2125
- * Requires the shape to be attached to a Body.
2126
- * @param point - The world-space point to test.
2127
- * @returns True if the point is inside this shape.
2431
+ * Apply an affine transform matrix to all shapes in local space.
2432
+ * @param matrix - The 2D affine transformation matrix.
2433
+ * @returns `this` for chaining.
2128
2434
  */
2129
- contains(point: Vec2): boolean;
2435
+ transformShapes(matrix: Mat23): Body;
2130
2436
  /**
2131
- * Create a deep copy of this shape with the same type, geometry, material, and filter.
2132
- * @returns A new Shape instance independent of this one.
2437
+ * Translate all shapes and adjust the body position so the local centre of mass coincides with the body origin.
2438
+ * @returns `this` for chaining.
2439
+ * @throws If the body has no shapes.
2133
2440
  */
2134
- copy(): Shape;
2135
- toString(): string;
2136
- /** Setup worldCOM lazy Vec2 wrapper */
2137
- private _setupWorldCOM;
2138
- }
2139
- /** Lightweight typed interface for the callback type set on a shape. */
2140
- interface CbTypeSet {
2141
- readonly _inner: NapeInner;
2142
- add(cbType: {
2143
- _inner: NapeInner;
2144
- }): void;
2145
- remove(cbType: {
2146
- _inner: NapeInner;
2147
- }): void;
2148
- has(cbType: {
2149
- _inner: NapeInner;
2150
- }): boolean;
2151
- clear(): void;
2152
- readonly length: number;
2153
- }
2154
-
2155
- /**
2156
- * Result from a convex-cast query.
2157
- *
2158
- * Provides the contact normal, position, time-of-impact, and shape hit.
2159
- * Instances are pooled — call `dispose()` when done to return to pool.
2160
- */
2161
- declare class ConvexResult {
2162
- static __name__: string[];
2163
- constructor();
2164
- get normal(): Vec2;
2165
- get position(): Vec2;
2166
- get toi(): number;
2167
- get shape(): Shape;
2168
- dispose(): void;
2169
- toString(): string;
2170
- }
2171
-
2172
- /**
2173
- * Result from a raycast query.
2174
- *
2175
- * Provides the contact normal, distance, inside-flag, and shape hit.
2176
- * Instances are pooled — call `dispose()` when done to return to pool.
2177
- */
2178
- declare class RayResult {
2179
- static __name__: string[];
2180
- constructor();
2181
- get normal(): Vec2;
2182
- get distance(): number;
2183
- get inner(): boolean;
2184
- get shape(): Shape;
2185
- dispose(): void;
2186
- toString(): string;
2187
- }
2188
-
2189
- /**
2190
- * Static utility class for geometric queries between shapes and bodies.
2191
- *
2192
- * Fully modernized — calls ZPP_Geom, ZPP_SweepDistance, and ZPP_Collide directly.
2193
- */
2194
- declare class Geom {
2195
- static __name__: string[];
2441
+ align(): Body;
2196
2442
  /**
2197
- * Calculate minimum distance between two bodies and return closest points.
2443
+ * Rotate the body about a world-space pivot point by `angle` radians.
2444
+ * Moves the body's position and increments its rotation.
2445
+ * @param centre - World-space pivot point.
2446
+ * @param angle - Rotation in radians.
2447
+ * @returns `this` for chaining.
2448
+ * @throws If `centre` is null or `angle` is NaN.
2198
2449
  */
2199
- static distanceBody(body1: Body, body2: Body, out1: Vec2, out2: Vec2): number;
2450
+ rotate(centre: Vec2, angle: number): Body;
2200
2451
  /**
2201
- * Calculate minimum distance between two shapes and return closest points.
2452
+ * Set the same `Material` on every shape attached to this body.
2453
+ * @param material - The material to apply.
2454
+ * @returns `this` for chaining.
2202
2455
  */
2203
- static distance(shape1: Shape, shape2: Shape, out1: Vec2, out2: Vec2): number;
2456
+ setShapeMaterials(material: Material): Body;
2204
2457
  /**
2205
- * Test if two bodies intersect (any of their shapes overlap).
2458
+ * Set the same `InteractionFilter` on every shape attached to this body.
2459
+ * @param filter - The interaction filter to apply.
2460
+ * @returns `this` for chaining.
2206
2461
  */
2207
- static intersectsBody(body1: Body, body2: Body): boolean;
2462
+ setShapeFilters(filter: InteractionFilter): Body;
2208
2463
  /**
2209
- * Test if two shapes intersect.
2464
+ * Set the same `FluidProperties` on every shape attached to this body.
2465
+ * @param fluidProperties - The fluid properties to apply.
2466
+ * @returns `this` for chaining.
2210
2467
  */
2211
- static intersects(shape1: Shape, shape2: Shape): boolean;
2468
+ setShapeFluidProperties(fluidProperties: FluidProperties): Body;
2212
2469
  /**
2213
- * Test if shape1 fully contains shape2.
2470
+ * Test whether a world-space point lies inside any shape attached to this body.
2471
+ * @param point - The point to test in world space.
2472
+ * @returns True if the point is inside at least one shape.
2214
2473
  */
2215
- static contains(shape1: Shape, shape2: Shape): boolean;
2216
- }
2217
-
2218
- /**
2219
- * A circular physics shape. The simplest and most performant collision shape.
2220
- */
2221
- declare class Circle extends Shape {
2222
- static __name__: string[];
2223
- static __super__: any;
2474
+ contains(point: Vec2): boolean;
2224
2475
  /**
2225
- * Create a circle with the given radius and optional local centre-of-mass offset.
2226
- * @param radius - Circle radius (must be > 0).
2227
- * @param localCOM - Local centre offset (defaults to origin).
2228
- * @param material - Material to assign (uses default if omitted).
2229
- * @param filter - InteractionFilter to assign (uses default if omitted).
2476
+ * Return the set of bodies connected to this body via constraints.
2477
+ * @param depth - Maximum traversal depth (-1 means unlimited).
2478
+ * @param output - Optional existing list to accumulate results into.
2479
+ * @returns A BodyList of connected bodies.
2230
2480
  */
2231
- constructor(radius?: number, localCOM?: Vec2, material?: Material, filter?: InteractionFilter);
2232
- /** The circle's radius. Must be > 0. */
2233
- get radius(): number;
2234
- set radius(value: number);
2235
- }
2236
-
2237
- /**
2238
- * A convex polygon physics shape.
2239
- */
2240
- declare class Polygon extends Shape {
2241
- static __name__: string[];
2242
- static __super__: any;
2481
+ connectedBodies(depth?: number, output?: BodyList | null): BodyList;
2243
2482
  /**
2244
- * Create a Polygon from a list of Vec2 vertices. Vertices must form a convex polygon
2245
- * in counter-clockwise order.
2246
- * @param localVerts - Vertices as `Array<Vec2>`, `Vec2List`, or `GeomPoly`.
2247
- * @param material - Material to assign (uses default if omitted).
2248
- * @param filter - InteractionFilter to assign (uses default if omitted).
2483
+ * Return the set of bodies currently interacting with this body via arbiters.
2484
+ * @param type - Filter by interaction type (COLLISION, FLUID, SENSOR), or null for all.
2485
+ * @param _depth - Unused; reserved for future use.
2486
+ * @param output - Optional existing list to accumulate results into.
2487
+ * @returns A BodyList of interacting bodies.
2249
2488
  */
2250
- constructor(localVerts?: Vec2[] | any, material?: Material, filter?: InteractionFilter);
2489
+ interactingBodies(type?: InteractionType | null, _depth?: number, output?: BodyList | null): BodyList;
2251
2490
  /**
2252
- * Create an axis-aligned rectangle at the given position.
2253
- * @param x - Left edge x coordinate.
2254
- * @param y - Top edge y coordinate.
2255
- * @param width - Rectangle width.
2256
- * @param height - Rectangle height.
2257
- * @param weak - If true, returned Vec2s are marked weak and will be auto-disposed.
2258
- * @returns Array of four Vec2 corner vertices.
2491
+ * Sum of normal (penetration-resolving) impulses received from collision arbiters this step.
2492
+ * @param body - If provided, only arbiters shared with `body` are summed.
2493
+ * @param freshOnly - If true, only newly created arbiters are considered.
2494
+ * @returns A Vec3 where x/y are the linear component and z is the angular component.
2259
2495
  */
2260
- static rect(x: number, y: number, width: number, height: number, weak?: boolean): Vec2[];
2496
+ normalImpulse(body?: Body | null, freshOnly?: boolean): Vec3;
2261
2497
  /**
2262
- * Create an axis-aligned rectangular polygon centred at the origin.
2263
- * @param width - Rectangle width.
2264
- * @param height - Rectangle height (defaults to `width` for a square).
2265
- * @param weak - If true, returned Vec2s are marked weak and will be auto-disposed.
2266
- * @returns Array of four Vec2 corner vertices.
2498
+ * Sum of tangent (friction) impulses received from collision arbiters this step.
2499
+ * @param body - If provided, only arbiters shared with `body` are summed.
2500
+ * @param freshOnly - If true, only newly created arbiters are considered.
2501
+ * @returns A Vec3 where x/y are the linear component and z is the angular component.
2267
2502
  */
2268
- static box(width: number, height?: number, weak?: boolean): Vec2[];
2503
+ tangentImpulse(body?: Body | null, freshOnly?: boolean): Vec3;
2269
2504
  /**
2270
- * Create a regular polygon (or ellipse approximation) centred at the origin.
2271
- * @param xRadius - Horizontal radius of the circumscribed ellipse.
2272
- * @param yRadius - Vertical radius of the circumscribed ellipse.
2273
- * @param edgeCount - Number of sides (must be >= 3).
2274
- * @param angleOffset - Rotation offset in radians applied to all vertices (default 0).
2275
- * @param weak - If true, returned Vec2s are marked weak and will be auto-disposed.
2276
- * @returns Array of `edgeCount` Vec2 vertices.
2505
+ * Sum of total contact impulses (normal + tangent) from collision arbiters this step.
2506
+ * @param body - If provided, only arbiters shared with `body` are summed.
2507
+ * @param freshOnly - If true, only newly created arbiters are considered.
2508
+ * @returns A Vec3 where x/y are the linear component and z is the angular component.
2277
2509
  */
2278
- static regular(xRadius: number, yRadius: number, edgeCount: number, angleOffset?: number, weak?: boolean): Vec2[];
2279
- /** The list of local-space vertices defining this polygon's shape. */
2280
- get localVerts(): any;
2281
- /** World-space vertices of this polygon, updated each simulation step. */
2282
- get worldVerts(): any;
2283
- /** The list of edges derived from this polygon's vertices. */
2284
- get edges(): any;
2510
+ totalContactsImpulse(body?: Body | null, freshOnly?: boolean): Vec3;
2285
2511
  /**
2286
- * Validate the polygon geometry and return a string describing any issues, or
2287
- * `"valid"` if the polygon is well-formed.
2288
- * @returns A validation result string from the underlying ZPP_Polygon.
2512
+ * Sum of rolling (angular friction) impulses from collision arbiters this step.
2513
+ * @param body - If provided, only arbiters shared with `body` are summed.
2514
+ * @param freshOnly - If true, only newly created arbiters are considered.
2515
+ * @returns The total rolling impulse scalar.
2289
2516
  */
2290
- validity(): any;
2291
- }
2292
-
2293
- /**
2294
- * An edge of a polygon shape.
2295
- *
2296
- * Edges are read-only and managed by the polygon they belong to.
2297
- * Cannot be instantiated directly — only obtained from Polygon.edges.
2298
- *
2299
- * Fully modernized — all getters access ZPP_Edge directly.
2300
- */
2301
- declare class Edge {
2302
- static __name__: string[];
2303
- constructor();
2304
- /** Parent polygon. */
2305
- get polygon(): Polygon;
2306
- /** Local-space normal vector (immutable Vec2). */
2307
- get localNormal(): Vec2;
2308
- /** World-space normal vector (immutable Vec2). Requires polygon in a body. */
2309
- get worldNormal(): Vec2;
2310
- /** Edge length. */
2311
- get length(): number;
2312
- /** Local-space projection along the edge normal. */
2313
- get localProjection(): number;
2314
- /** World-space projection. Requires polygon in a body. */
2315
- get worldProjection(): number;
2316
- /** First local vertex of this edge. */
2317
- get localVertex1(): Vec2;
2318
- /** Second local vertex of this edge. */
2319
- get localVertex2(): Vec2;
2320
- /** First world vertex. Requires polygon in a body. */
2321
- get worldVertex1(): Vec2;
2322
- /** Second world vertex. Requires polygon in a body. */
2323
- get worldVertex2(): Vec2;
2324
- toString(): string;
2517
+ rollingImpulse(body?: Body | null, freshOnly?: boolean): number;
2518
+ /**
2519
+ * Sum of buoyancy impulses received from fluid arbiters this step.
2520
+ * @param body - If provided, only arbiters shared with `body` are summed.
2521
+ * @returns A Vec3 where x/y are the linear component and z is the angular component.
2522
+ */
2523
+ buoyancyImpulse(body?: Body | null): Vec3;
2325
2524
  /**
2326
- * Wrap a ZPP_Vec2 vertex into its public Vec2 outer.
2327
- * Mirrors the compiled vertex wrapping pattern.
2525
+ * Sum of fluid drag impulses received from fluid arbiters this step.
2526
+ * @param body - If provided, only arbiters shared with `body` are summed.
2527
+ * @returns A Vec3 where x/y are the linear component and z is the angular component.
2328
2528
  */
2329
- private _wrapVert;
2330
- }
2331
-
2332
- /**
2333
- * Result of polygon shape validation.
2334
- *
2335
- * - `VALID` — shape is valid
2336
- * - `DEGENERATE` — shape is degenerate (e.g., zero area)
2337
- * - `CONCAVE` — shape is concave (must be convex)
2338
- * - `SELF_INTERSECTING` — shape edges self-intersect
2339
- *
2340
- * Converted from nape-compiled.js lines 30760–30856.
2341
- */
2342
- declare class ValidationResult {
2343
- static __name__: string[];
2344
- constructor();
2345
- static get VALID(): ValidationResult;
2346
- static get DEGENERATE(): ValidationResult;
2347
- static get CONCAVE(): ValidationResult;
2348
- static get SELF_INTERSECTING(): ValidationResult;
2349
- toString(): string;
2529
+ dragImpulse(body?: Body | null): Vec3;
2530
+ /**
2531
+ * Sum of total fluid impulses (buoyancy + drag) from fluid arbiters this step.
2532
+ * @param body - If provided, only arbiters shared with `body` are summed.
2533
+ * @returns A Vec3 where x/y are the linear component and z is the angular component.
2534
+ */
2535
+ totalFluidImpulse(body?: Body | null): Vec3;
2536
+ /**
2537
+ * Sum of impulses applied to this body by all attached constraints this step.
2538
+ * @returns A Vec3 where x/y are the linear component and z is the angular component.
2539
+ */
2540
+ constraintsImpulse(): Vec3;
2541
+ /**
2542
+ * Sum of all impulses (contacts + constraints) applied to this body this step, excluding sensor arbiters.
2543
+ * @param body - If provided, only arbiters shared with `body` are summed.
2544
+ * @param freshOnly - If true, only newly created contact arbiters are considered.
2545
+ * @returns A Vec3 where x/y are the linear component and z is the angular component.
2546
+ */
2547
+ totalImpulse(body?: Body | null, freshOnly?: boolean): Vec3;
2548
+ /**
2549
+ * Compute a heuristic crush factor indicating how strongly this body is being compressed from multiple directions.
2550
+ * A value near zero means balanced forces; larger values indicate compression.
2551
+ * @returns The crush factor (dimensionless).
2552
+ * @throws If the body is not in a Space.
2553
+ */
2554
+ crushFactor(): number;
2555
+ private _getArbiters;
2556
+ private _getConstraints;
2557
+ private _arbiterImpulseQuery;
2350
2558
  }
2351
2559
 
2352
2560
  /**
2353
- * Arbiter type classification.
2561
+ * Shape type classification.
2354
2562
  *
2355
- * - `COLLISION` collision arbiter
2356
- * - `SENSOR` sensor arbiter
2357
- * - `FLUID` — fluid arbiter
2563
+ * - `CIRCLE` circle shape
2564
+ * - `POLYGON` polygon shape
2358
2565
  *
2359
- * Converted from nape-compiled.js lines 1165311725.
2566
+ * Converted from nape-compiled.js lines 3043530482.
2360
2567
  */
2361
- declare class ArbiterType {
2568
+ declare class ShapeType {
2362
2569
  static __name__: string[];
2363
2570
  constructor();
2364
- static get COLLISION(): ArbiterType;
2365
- static get SENSOR(): ArbiterType;
2366
- static get FLUID(): ArbiterType;
2571
+ static get CIRCLE(): ShapeType;
2572
+ static get POLYGON(): ShapeType;
2367
2573
  toString(): string;
2368
2574
  }
2369
2575
 
2370
2576
  /**
2371
- * An arbiter representing a physical collision between two solid shapes.
2372
- *
2373
- * Provides access to contact points, collision normal, friction coefficients,
2374
- * elasticity, and impulse data. Properties marked _mutable in pre-handler_ can
2375
- * only be set within a {@link PreListener} handler.
2376
- *
2377
- * Obtain via {@link Arbiter.collisionArbiter} or by casting from a callback's
2378
- * arbiter list.
2379
- *
2380
- * Fully modernized — uses extracted ZPP_ColArbiter directly.
2577
+ * Base class for physics shapes (Circle, Polygon). Never instantiated directly — use
2578
+ * `new Circle(...)` or `Polygon.box(...)` etc.
2381
2579
  */
2382
- declare class CollisionArbiter extends Arbiter {
2383
- static __name__: string[];
2384
- static __super__: typeof Arbiter;
2385
- constructor();
2386
- /**
2387
- * The list of active contact points between the two shapes.
2388
- * Contains 1 or 2 {@link Contact} objects depending on the collision geometry.
2389
- */
2390
- get contacts(): object;
2580
+ declare class Shape extends Interactor {
2581
+ /** The shape type: CIRCLE or POLYGON. */
2582
+ get type(): ShapeType;
2583
+ /** Returns true if this is a Circle shape. */
2584
+ isCircle(): boolean;
2585
+ /** Returns true if this is a Polygon shape. */
2586
+ isPolygon(): boolean;
2391
2587
  /**
2392
- * Collision normal vector pointing from `shape1` toward `shape2`.
2393
- * Read-only; available after the arbiter is active.
2588
+ * The Body this shape belongs to. Setting moves the shape between bodies.
2394
2589
  */
2395
- get normal(): Vec2;
2396
- /** Sum of the radii of the two shapes at the collision point. */
2397
- get radius(): number;
2398
- /** Reference edge of shape1 (if polygon), or null. */
2399
- get referenceEdge1(): Edge | null;
2400
- /** Reference edge of shape2 (if polygon), or null. */
2401
- get referenceEdge2(): Edge | null;
2590
+ get body(): Body;
2591
+ set body(value: Body | null);
2592
+ /** Cast to Circle, or null if this is not a circle. */
2593
+ get castCircle(): Shape | null;
2594
+ /** Cast to Polygon, or null if this is not a polygon. */
2595
+ get castPolygon(): Shape | null;
2596
+ /** World-space centre of mass of this shape (read-only, lazy-computed). */
2597
+ get worldCOM(): Vec2;
2402
2598
  /**
2403
- * Coefficient of restitution (bounciness).
2404
- *
2405
- * Combined from the two shapes' `elasticity` values. Can be overridden
2406
- * inside a pre-handler. Must be `>= 0`.
2407
- *
2408
- * _Mutable in pre-handler only._
2599
+ * Local-space centre of mass. Can be set to override the default shape centroid.
2409
2600
  */
2410
- get elasticity(): number;
2411
- set elasticity(value: number);
2601
+ get localCOM(): Vec2;
2602
+ set localCOM(value: Vec2);
2603
+ /** Cross-sectional area of this shape. */
2604
+ get area(): number;
2605
+ /** Contribution to moment of inertia (about local centroid, unit density). */
2606
+ get inertia(): number;
2607
+ /** Angular drag coefficient for this shape. */
2608
+ get angDrag(): number;
2609
+ /** The Material assigned to this shape (controls friction, elasticity, density). */
2610
+ get material(): Material;
2611
+ set material(value: Material);
2612
+ /** The InteractionFilter controlling which shapes interact with this one. */
2613
+ get filter(): InteractionFilter;
2614
+ set filter(value: InteractionFilter);
2615
+ /** Fluid simulation properties for this shape. Auto-created on first access. */
2616
+ get fluidProperties(): FluidProperties;
2617
+ set fluidProperties(value: FluidProperties);
2618
+ /** Set of callback types registered on this shape for event dispatch. */
2619
+ get cbTypes(): CbTypeSet;
2620
+ /** If true, this shape participates in fluid interaction. */
2621
+ get fluidEnabled(): boolean;
2622
+ set fluidEnabled(value: boolean);
2623
+ /** If true, this shape acts as a sensor (no physical response, only callbacks). */
2624
+ get sensorEnabled(): boolean;
2625
+ set sensorEnabled(value: boolean);
2626
+ /** World-space AABB of this shape (updated each step). */
2627
+ get bounds(): AABB;
2412
2628
  /**
2413
- * Dynamic (kinetic) friction coefficient applied when the contact is sliding.
2414
- * Combined from the two shapes' material values. _Mutable in pre-handler only._
2629
+ * Translate the shape's local vertices by the given vector (in-place).
2630
+ * @param translation - The displacement vector to apply.
2631
+ * @returns `this` for chaining.
2415
2632
  */
2416
- get dynamicFriction(): number;
2417
- set dynamicFriction(value: number);
2633
+ translate(translation: Vec2): Shape;
2418
2634
  /**
2419
- * Static friction coefficient applied when the contact is at rest.
2420
- * Combined from the two shapes' material values. _Mutable in pre-handler only._
2635
+ * Scale the shape's local geometry. Circles require uniform scaling.
2636
+ * @param scaleX - Horizontal scale factor (must be non-zero).
2637
+ * @param scaleY - Vertical scale factor (must be non-zero).
2638
+ * @returns `this` for chaining.
2421
2639
  */
2422
- get staticFriction(): number;
2423
- set staticFriction(value: number);
2640
+ scale(scaleX: number, scaleY: number): Shape;
2424
2641
  /**
2425
- * Rolling friction coefficient resists rolling motion.
2426
- * Combined from the two shapes' material values. _Mutable in pre-handler only._
2642
+ * Rotate the shape's local vertices by `angle` radians.
2643
+ * @param angle - Rotation in radians.
2644
+ * @returns `this` for chaining.
2427
2645
  */
2428
- get rollingFriction(): number;
2429
- set rollingFriction(value: number);
2430
- /** Whether the first contact point lies on a polygon vertex (poly-circle only). */
2431
- firstVertex(): boolean;
2432
- /** Whether the second contact point lies on a polygon vertex (poly-circle only). */
2433
- secondVertex(): boolean;
2646
+ rotate(angle: number): Shape;
2434
2647
  /**
2435
- * Impulse applied in the normal (collision) direction, summed over all contacts.
2436
- * @param body - One of the two bodies, or `null` for the combined value.
2437
- * @param freshOnly - Only include new contact points. Default `false`.
2648
+ * Apply a Mat23 affine transform to the shape's local geometry.
2649
+ * @param matrix - The transformation matrix (must be non-singular; Circles require equiorthogonal).
2650
+ * @returns `this` for chaining.
2438
2651
  */
2439
- normalImpulse(body?: Body | null, freshOnly?: boolean): Vec3;
2652
+ transform(matrix: {
2653
+ _inner: NapeInner;
2654
+ }): Shape;
2440
2655
  /**
2441
- * Friction impulse applied in the tangent direction, summed over all contacts.
2442
- * @param body - One of the two bodies, or `null` for the combined value.
2443
- * @param freshOnly - Only include new contact points. Default `false`.
2656
+ * Return true if the given world-space point lies inside this shape.
2657
+ * Requires the shape to be attached to a Body.
2658
+ * @param point - The world-space point to test.
2659
+ * @returns True if the point is inside this shape.
2444
2660
  */
2445
- tangentImpulse(body?: Body | null, freshOnly?: boolean): Vec3;
2446
- /** Total impulse (normal + tangent + rolling) accumulated across all contacts. */
2447
- totalImpulse(body?: Body | null, freshOnly?: boolean): Vec3;
2661
+ contains(point: Vec2): boolean;
2448
2662
  /**
2449
- * Rolling impulse applied by this collision.
2450
- * @param body - One of the two bodies, or `null` for the combined value.
2451
- * @param freshOnly - Only include new contact points. Default `false`.
2663
+ * Create a deep copy of this shape with the same type, geometry, material, and filter.
2664
+ * @returns A new Shape instance independent of this one.
2452
2665
  */
2453
- rollingImpulse(body?: Body | null, freshOnly?: boolean): number;
2666
+ copy(): Shape;
2667
+ toString(): string;
2668
+ /** Setup worldCOM lazy Vec2 wrapper */
2669
+ private _setupWorldCOM;
2670
+ }
2671
+ /** Lightweight typed interface for the callback type set on a shape. */
2672
+ interface CbTypeSet {
2673
+ readonly _inner: NapeInner;
2674
+ add(cbType: {
2675
+ _inner: NapeInner;
2676
+ }): void;
2677
+ remove(cbType: {
2678
+ _inner: NapeInner;
2679
+ }): void;
2680
+ has(cbType: {
2681
+ _inner: NapeInner;
2682
+ }): boolean;
2683
+ clear(): void;
2684
+ readonly length: number;
2454
2685
  }
2455
2686
 
2456
2687
  /**
2457
- * An arbiter representing a fluid interaction between a fluid shape and a body.
2458
- *
2459
- * Provides access to buoyancy and drag impulses, the overlap area, and the
2460
- * centre of overlap. Properties marked _mutable in pre-handler_ can only be
2461
- * set within a {@link PreListener} handler.
2688
+ * Result from a convex-cast query.
2462
2689
  *
2463
- * Obtain via {@link Arbiter.fluidArbiter} or by casting from a callback arbiter.
2690
+ * Provides the contact normal, position, time-of-impact, and shape hit.
2691
+ * Instances are pooled — call `dispose()` when done to return to pool.
2692
+ */
2693
+ declare class ConvexResult {
2694
+ static __name__: string[];
2695
+ constructor();
2696
+ get normal(): Vec2;
2697
+ get position(): Vec2;
2698
+ get toi(): number;
2699
+ get shape(): Shape;
2700
+ dispose(): void;
2701
+ toString(): string;
2702
+ }
2703
+
2704
+ /**
2705
+ * Static utility class for geometric queries between shapes and bodies.
2464
2706
  *
2465
- * Fully modernized — uses extracted ZPP_FluidArbiter directly.
2707
+ * Fully modernized — calls ZPP_Geom, ZPP_SweepDistance, and ZPP_Collide directly.
2466
2708
  */
2467
- declare class FluidArbiter extends Arbiter {
2709
+ declare class Geom {
2468
2710
  static __name__: string[];
2469
- static __super__: typeof Arbiter;
2470
- constructor();
2471
2711
  /**
2472
- * Centre of the overlap region between the fluid and the body shape.
2473
- * _Mutable in pre-handler only._
2712
+ * Calculate minimum distance between two bodies and return closest points.
2474
2713
  */
2475
- get position(): Vec2;
2476
- set position(value: Vec2);
2714
+ static distanceBody(body1: Body, body2: Body, out1: Vec2, out2: Vec2): number;
2477
2715
  /**
2478
- * Area of the overlap region in pixels². Used to compute buoyancy force.
2479
- * Must be strictly positive and finite.
2480
- * _Mutable in pre-handler only._
2716
+ * Calculate minimum distance between two shapes and return closest points.
2481
2717
  */
2482
- get overlap(): number;
2483
- set overlap(value: number);
2718
+ static distance(shape1: Shape, shape2: Shape, out1: Vec2, out2: Vec2): number;
2484
2719
  /**
2485
- * Buoyancy impulse applied in the last step as `(fx, fy, torque)`.
2486
- * @param body - One of the two bodies, or `null` for the combined value.
2720
+ * Test if two bodies intersect (any of their shapes overlap).
2487
2721
  */
2488
- buoyancyImpulse(body?: Body | null): Vec3;
2722
+ static intersectsBody(body1: Body, body2: Body): boolean;
2489
2723
  /**
2490
- * Linear and angular drag impulse applied in the last step as `(fx, fy, torque)`.
2491
- * @param body - One of the two bodies, or `null` for the combined value.
2724
+ * Test if two shapes intersect.
2492
2725
  */
2493
- dragImpulse(body?: Body | null): Vec3;
2494
- /** Total impulse (buoyancy + drag). */
2495
- totalImpulse(body?: Body | null, _freshOnly?: boolean): Vec3;
2726
+ static intersects(shape1: Shape, shape2: Shape): boolean;
2727
+ /**
2728
+ * Test if shape1 fully contains shape2.
2729
+ */
2730
+ static contains(shape1: Shape, shape2: Shape): boolean;
2496
2731
  }
2497
2732
 
2498
2733
  /**
2499
- * Return value for {@link PreListener} handlers controls whether the interaction
2500
- * is resolved this step and in future steps.
2501
- *
2502
- * - `ACCEPT` — resolve the interaction (default if handler returns `null`)
2503
- * - `IGNORE` — suppress the interaction permanently until the next `BEGIN`
2504
- * - `ACCEPT_ONCE` — accept this step only, then revert to the previous flag
2505
- * - `IGNORE_ONCE` — ignore this step only, then revert to the previous flag
2506
- *
2507
- * Use `IGNORE`/`ACCEPT` for stateful decisions (e.g., one-way platforms).
2508
- * Use `*_ONCE` variants for single-step overrides.
2509
- *
2510
- * Converted from nape-compiled.js lines 2504–2591.
2734
+ * A circular physics shape. The simplest and most performant collision shape.
2511
2735
  */
2512
- declare class PreFlag {
2736
+ declare class Circle extends Shape {
2513
2737
  static __name__: string[];
2514
- constructor();
2515
- /** Accept and resolve the interaction normally. */
2516
- static get ACCEPT(): PreFlag;
2517
- /** Suppress the interaction permanently until the next `BEGIN` event. */
2518
- static get IGNORE(): PreFlag;
2519
- /** Accept this step only; revert to the previous flag next step. */
2520
- static get ACCEPT_ONCE(): PreFlag;
2521
- /** Ignore this step only; revert to the previous flag next step. */
2522
- static get IGNORE_ONCE(): PreFlag;
2523
- toString(): string;
2738
+ static __super__: any;
2739
+ /**
2740
+ * Create a circle with the given radius and optional local centre-of-mass offset.
2741
+ * @param radius - Circle radius (must be > 0).
2742
+ * @param localCOM - Local centre offset (defaults to origin).
2743
+ * @param material - Material to assign (uses default if omitted).
2744
+ * @param filter - InteractionFilter to assign (uses default if omitted).
2745
+ */
2746
+ constructor(radius?: number, localCOM?: Vec2, material?: Material, filter?: InteractionFilter);
2747
+ /** The circle's radius. Must be > 0. */
2748
+ get radius(): number;
2749
+ set radius(value: number);
2524
2750
  }
2525
2751
 
2526
2752
  /**
2527
- * Represents an active interaction between two shapes.
2528
- *
2529
- * Arbiters are created and pooled internally by the engine — they cannot be
2530
- * instantiated directly. Access them via:
2531
- * - `space.arbiters` — all active arbiters in the simulation
2532
- * - `body.arbiters` — arbiters involving a specific body
2533
- * - `InteractionCallback.arbiters` — arbiters in an interaction callback
2534
- * - `PreCallback.arbiter` — the arbiter in a pre-handler
2535
- *
2536
- * Use {@link Arbiter.collisionArbiter} or {@link Arbiter.fluidArbiter} to cast
2537
- * to a subtype for type-specific properties.
2753
+ * Result of polygon shape validation.
2538
2754
  *
2539
- * **Warning:** do not hold references to `Arbiter` objects after the current
2540
- * simulation step they are pooled and may be reused.
2755
+ * - `VALID` shape is valid
2756
+ * - `DEGENERATE` shape is degenerate (e.g., zero area)
2757
+ * - `CONCAVE` — shape is concave (must be convex)
2758
+ * - `SELF_INTERSECTING` — shape edges self-intersect
2541
2759
  *
2542
- * Fully modernized uses extracted ZPP_Arbiter directly.
2760
+ * Converted from nape-compiled.js lines 30760–30856.
2543
2761
  */
2544
- declare class Arbiter {
2762
+ declare class ValidationResult {
2545
2763
  static __name__: string[];
2546
2764
  constructor();
2547
- /**
2548
- * Whether both interacting bodies are currently sleeping.
2549
- * Throws if the arbiter is not active.
2550
- */
2551
- get isSleeping(): boolean;
2552
- /**
2553
- * The interaction type of this arbiter.
2554
- * @see {@link ArbiterType}
2555
- */
2556
- get type(): ArbiterType;
2557
- /** Cast to CollisionArbiter if this is a collision, else null. */
2558
- get collisionArbiter(): CollisionArbiter | null;
2559
- /** Cast to FluidArbiter if this is a fluid interaction, else null. */
2560
- get fluidArbiter(): FluidArbiter | null;
2561
- /** First shape (lower id). */
2562
- get shape1(): Shape;
2563
- /** Second shape (higher id). */
2564
- get shape2(): Shape;
2565
- /** Body of shape1. */
2566
- get body1(): Body;
2567
- /** Body of shape2. */
2568
- get body2(): Body;
2569
- /** The pre-handler state of this arbiter. */
2570
- get state(): PreFlag;
2571
- /** Whether this is a collision arbiter. */
2572
- isCollisionArbiter(): boolean;
2573
- /** Whether this is a fluid arbiter. */
2574
- isFluidArbiter(): boolean;
2575
- /** Whether this is a sensor arbiter. */
2576
- isSensorArbiter(): boolean;
2577
- /**
2578
- * Total impulse applied by this arbiter in the last step as `(fx, fy, torque)`.
2579
- *
2580
- * Pass a `body` to get the impulse applied specifically to that body.
2581
- * Pass `freshOnly = true` to include only new contact points (not persistent ones).
2582
- *
2583
- * Overridden by {@link CollisionArbiter} and {@link FluidArbiter}.
2584
- *
2585
- * @param body - One of the two interacting bodies, or `null` for the combined impulse.
2586
- * @param _freshOnly - When `true`, only count fresh (new) contacts. Default `false`.
2587
- */
2588
- totalImpulse(body?: Body | null, _freshOnly?: boolean): Vec3;
2765
+ static get VALID(): ValidationResult;
2766
+ static get DEGENERATE(): ValidationResult;
2767
+ static get CONCAVE(): ValidationResult;
2768
+ static get SELF_INTERSECTING(): ValidationResult;
2589
2769
  toString(): string;
2590
2770
  }
2591
2771
 
@@ -2637,48 +2817,6 @@ declare class Contact {
2637
2817
  toString(): string;
2638
2818
  }
2639
2819
 
2640
- /**
2641
- * Enumeration of physics callback event types.
2642
- *
2643
- * Use these singletons to specify which phase of an interaction a listener
2644
- * should respond to:
2645
- *
2646
- * - `BEGIN` — fired once when two interactors first make contact
2647
- * - `ONGOING` — fired every simulation step while the interaction persists
2648
- * - `END` — fired once when two interactors separate
2649
- * - `WAKE` — fired when a body or constraint wakes from sleep
2650
- * - `SLEEP` — fired when a body or constraint falls asleep
2651
- * - `BREAK` — fired when a constraint exceeds its `maxForce`/`maxError` and breaks
2652
- * - `PRE` — fired before collision resolution; allows per-step accept/ignore decisions
2653
- *
2654
- * Valid events per listener type:
2655
- * - {@link BodyListener}: `WAKE`, `SLEEP`
2656
- * - {@link ConstraintListener}: `WAKE`, `SLEEP`, `BREAK`
2657
- * - {@link InteractionListener}: `BEGIN`, `ONGOING`, `END`
2658
- * - {@link PreListener}: always `PRE` (set internally)
2659
- *
2660
- * Converted from nape-compiled.js lines 516–657.
2661
- */
2662
- declare class CbEvent {
2663
- static __name__: string[];
2664
- constructor();
2665
- /** Interaction-start event. Fired once when two interactors first make contact. */
2666
- static get BEGIN(): CbEvent;
2667
- /** Interaction-continue event. Fired every step while the interaction persists. */
2668
- static get ONGOING(): CbEvent;
2669
- /** Interaction-end event. Fired once when two interactors separate. */
2670
- static get END(): CbEvent;
2671
- /** Wake event. Fired when a body or constraint wakes from sleep. */
2672
- static get WAKE(): CbEvent;
2673
- /** Sleep event. Fired when a body or constraint falls asleep. */
2674
- static get SLEEP(): CbEvent;
2675
- /** Break event. Fired when a constraint exceeds its `maxForce` or `maxError` limit. */
2676
- static get BREAK(): CbEvent;
2677
- /** Pre-interaction event. Fired before collision resolution; handler can accept or ignore. */
2678
- static get PRE(): CbEvent;
2679
- toString(): string;
2680
- }
2681
-
2682
2820
  /**
2683
2821
  * Composite callback option type — combines include and exclude {@link CbType} lists
2684
2822
  * to express complex listener filter conditions.
@@ -2811,82 +2949,6 @@ declare class CbType {
2811
2949
  toString(): string;
2812
2950
  }
2813
2951
 
2814
- /**
2815
- * Listener type classification.
2816
- *
2817
- * - `BODY` — body event listener
2818
- * - `CONSTRAINT` — constraint event listener
2819
- * - `INTERACTION` — interaction event listener
2820
- * - `PRE` — pre-interaction listener
2821
- *
2822
- * Converted from nape-compiled.js lines 2554–2646.
2823
- */
2824
- declare class ListenerType {
2825
- static __name__: string[];
2826
- constructor();
2827
- static get BODY(): ListenerType;
2828
- static get CONSTRAINT(): ListenerType;
2829
- static get INTERACTION(): ListenerType;
2830
- static get PRE(): ListenerType;
2831
- toString(): string;
2832
- }
2833
-
2834
- /**
2835
- * Listener — Base class for all physics event listeners.
2836
- *
2837
- * Provides common properties (type, event, precedence, space) and
2838
- * toString() for all listener subclasses.
2839
- *
2840
- * Fully modernized from nape-compiled.js lines 231–433.
2841
- */
2842
-
2843
- /**
2844
- * Base class for all physics event listeners.
2845
- *
2846
- * Cannot be instantiated directly — use one of the concrete subclasses:
2847
- * {@link BodyListener}, {@link ConstraintListener}, {@link InteractionListener},
2848
- * or {@link PreListener}.
2849
- *
2850
- * Provides common properties (`type`, `event`, `precedence`, `space`) shared
2851
- * by all listener types.
2852
- *
2853
- * Fully modernized from nape-compiled.js lines 231–433.
2854
- */
2855
- declare class Listener {
2856
- static __name__: string[];
2857
- constructor();
2858
- /** The type of this listener (BODY, CONSTRAINT, INTERACTION, or PRE). */
2859
- get type(): ListenerType;
2860
- /**
2861
- * The event this listener responds to.
2862
- *
2863
- * Valid values depend on the concrete listener type — see {@link CbEvent}.
2864
- * Changing this while the listener is assigned to a space re-registers it.
2865
- */
2866
- get event(): CbEvent;
2867
- set event(event: CbEvent);
2868
- /**
2869
- * Execution priority of this listener relative to other listeners for the
2870
- * same event. Higher values execute first.
2871
- *
2872
- * @defaultValue `0`
2873
- */
2874
- get precedence(): number;
2875
- set precedence(precedence: number);
2876
- /**
2877
- * The space this listener is currently registered in, or `null` if not registered.
2878
- *
2879
- * Assign to register/unregister the listener in a space:
2880
- * ```ts
2881
- * listener.space = mySpace; // register
2882
- * listener.space = null; // unregister
2883
- * ```
2884
- */
2885
- get space(): Space | null;
2886
- set space(space: Space | null);
2887
- toString(): string;
2888
- }
2889
-
2890
2952
  /**
2891
2953
  * Base class for all physics engine callback objects.
2892
2954
  *
@@ -3850,4 +3912,4 @@ declare abstract class UserConstraint extends Constraint {
3850
3912
 
3851
3913
  declare const VERSION: string;
3852
3914
 
3853
- export { AABB, AngleJoint, Arbiter, ArbiterType, Body, BodyCallback, BodyListener, BodyType, Broadphase, Callback, CbEvent, CbType, type CbTypeSet, Circle, CollisionArbiter, Compound, Constraint, ConstraintCallback, ConstraintListener, Contact, ConvexResult, DistanceJoint, Edge, FluidArbiter, FluidProperties, Geom, GeomPoly, GravMassMode, InertiaMode, InteractionCallback, InteractionFilter, InteractionGroup, InteractionListener, InteractionType, Interactor, LineJoint, Listener, ListenerType, MarchingSquares, MassMode, Mat23, MatMN, Material, MotorJoint, NapeList, OptionType, PivotJoint, Polygon, PreCallback, PreFlag, PreListener, PulleyJoint, Ray, RayResult, Shape, ShapeType, Space, UserConstraint, VERSION, ValidationResult, Vec2, Vec3, WeldJoint, Winding };
3915
+ export { AABB, AngleJoint, Arbiter, type ArbiterList, ArbiterType, Body, BodyCallback, type BodyList, BodyListener, BodyType, Broadphase, Callback, CbEvent, CbType, type CbTypeSet, Circle, CollisionArbiter, Compound, type CompoundList, Constraint, ConstraintCallback, type ConstraintList, ConstraintListener, Contact, ConvexResult, type ConvexResultList, DistanceJoint, Edge, FluidArbiter, FluidProperties, Geom, GeomPoly, GravMassMode, InertiaMode, InteractionCallback, InteractionFilter, InteractionGroup, InteractionListener, InteractionType, Interactor, LineJoint, Listener, type ListenerList, ListenerType, MarchingSquares, MassMode, Mat23, MatMN, Material, MotorJoint, NapeList, OptionType, PivotJoint, Polygon, PreCallback, PreFlag, PreListener, PulleyJoint, Ray, RayResult, type RayResultList, Shape, type ShapeList, ShapeType, Space, type TypedListLike, UserConstraint, VERSION, ValidationResult, Vec2, Vec3, WeldJoint, Winding };