diff --git a/src/aabb_c.js b/src/aabb_c.js index 186c163..51127a3 100644 --- a/src/aabb_c.js +++ b/src/aabb_c.js @@ -11,6 +11,10 @@ import * as b2Math from './include/math_functions_h.js'; * @namespace Aabb */ +/** + * @import {b2AABB} from './include/math_functions_h.js' + */ + // Get surface area of an AABB (the perimeter length) export function b2Perimeter(a) { diff --git a/src/block_array_c.js b/src/block_array_c.js index b3f6018..1094d1c 100644 --- a/src/block_array_c.js +++ b/src/block_array_c.js @@ -43,6 +43,7 @@ export class b2ContactArray { constructor(capacity = 0) { + /** @type {b2ContactSim[]} */ this.data = []; this.count = 0; this.capacity = capacity; diff --git a/src/body_c.js b/src/body_c.js index da6301e..5e60ffd 100644 --- a/src/body_c.js +++ b/src/body_c.js @@ -28,6 +28,11 @@ import { b2MassData } from './include/collision_h.js'; * @namespace Body */ +/** + * @import {b2WorldId} from './include/id_h.js' + * @import {b2BodyDef, b2ContactData} from './include/types_h.js' + */ + export function b2MakeSweep(bodySim, out) { out.c1.x = bodySim.center0X; diff --git a/src/debug_draw.js b/src/debug_draw.js index ff6a458..8b7d64f 100644 --- a/src/debug_draw.js +++ b/src/debug_draw.js @@ -520,13 +520,18 @@ export function CreateDebugDraw(canvas, ctx, scale = 20.0) return draw; } +/** + * @callback RAFCallback + * @param {number} deltaTime - Time elapsed since last frame in seconds, capped at 0.1s + * @param {number} totalTime - Total accumulated time in seconds + * @param {number} currentFps - Current frames per second, updated once per second + * @returns {void} + */ + /** * @function RAF * @summary Implements a requestAnimationFrame loop with timing and FPS tracking - * @param {function} callback - Function to call each frame with signature (deltaTime, totalTime, currentFps) - * @param {number} callback.deltaTime - Time elapsed since last frame in seconds, capped at 0.1s - * @param {number} callback.totalTime - Total accumulated time in seconds - * @param {number} callback.currentFps - Current frames per second, updated once per second + * @param {RAFCallback} callback - Function to call each frame with signature (deltaTime, totalTime, currentFps) * @description * Creates an animation loop using requestAnimationFrame that tracks timing information * and FPS. The callback is invoked each frame with the time delta, total time, and @@ -593,7 +598,7 @@ function loadPNGImage(imageUrl) * Attach a graphic image to a physics body * @function AttachImage * @param {number} worldId - The ID of the Box2D world - * @param {number} bodyId - The ID of the body to attach the image to + * @param {b2BodyId} bodyId - The ID of the body to attach the image to * @param {string} path - Directory path where the image is located * @param {string} imgName - Name of the image file * @param {b2Vec2} [drawOffset=null] - Offset vector for drawing the image diff --git a/src/distance_c.js b/src/distance_c.js index 62f0653..9f4299d 100644 --- a/src/distance_c.js +++ b/src/distance_c.js @@ -52,6 +52,10 @@ import { b2_linearSlop } from './include/core_h.js'; * @namespace Distance */ +/** + * @import {b2ShapeCastPairInput, b2TOIInput} from './include/collision_h' + */ + /** * @function b2GetSweepTransform * @summary Computes an interpolated transform at a specified time during a sweep motion. diff --git a/src/distance_joint_c.js b/src/distance_joint_c.js index 9b9fbb9..7fd39ec 100644 --- a/src/distance_joint_c.js +++ b/src/distance_joint_c.js @@ -31,6 +31,10 @@ import { b2MakeSoft } from './include/solver_h.js'; /** * @namespace DistanceJoint +*/ + +/** + * @import {b2JointId} from './include/id_h' */ /** diff --git a/src/dynamic_tree_c.js b/src/dynamic_tree_c.js index a4eaf7a..f3edf07 100644 --- a/src/dynamic_tree_c.js +++ b/src/dynamic_tree_c.js @@ -18,6 +18,11 @@ import { b2TreeNode } from './include/collision_h.js'; * @namespace DynamicTree */ +/** + * @import {b2AABB, b2Vec2} from './include/math_functions_h.js' + * @import {b2RayCastInput, b2ShapeCastInput} from './include/collision_h.js' + */ + const B2_TREE_STACK_SIZE = 1024; function b2IsLeaf(node) diff --git a/src/geometry_c.js b/src/geometry_c.js index 7ecc08d..81e9c49 100644 --- a/src/geometry_c.js +++ b/src/geometry_c.js @@ -44,6 +44,10 @@ import { b2ValidateHull } from './include/hull_h.js'; * @namespace Geometry */ +/** + * @import {b2Hull, b2RayCastInput, b2Segment, b2ShapeCastInput} from './include/collision_h.js' + */ + /** * Validates a ray cast input structure. * @function b2IsValidRay @@ -537,7 +541,7 @@ export function b2ComputePolygonMass(shape, density) * @function b2ComputeCircleAABB * @summary Computes an Axis-Aligned Bounding Box (AABB) for a circle shape after applying a transform. * @param {b2Circle} shape - The circle shape containing center point and radius. - * @param {b2Transform} xf2 - The transform to be applied, consisting of a position (p) and rotation (q). + * @param {b2Transform} xf - The transform to be applied, consisting of a position (p) and rotation (q). * @returns {b2AABB} An AABB object defined by minimum and maximum points that bound the transformed circle. * @description * Calculates the AABB by transforming the circle's center point using the provided transform @@ -559,7 +563,7 @@ export function b2ComputeCircleAABB(shape, xf) * @function b2ComputeCapsuleAABB * @summary Computes an Axis-Aligned Bounding Box (AABB) for a capsule shape. * @param {b2Capsule} shape - A capsule shape defined by two centers and a radius. - * @param {b2Transform} xf2 - A transform containing position and rotation to be applied to the capsule. + * @param {b2Transform} xf - A transform containing position and rotation to be applied to the capsule. * @returns {b2AABB} An AABB that encompasses the transformed capsule shape. * @description * Calculates the minimum and maximum bounds of a capsule after applying a transform. @@ -587,7 +591,7 @@ export function b2ComputeCapsuleAABB(shape, xf) * Computes the Axis-Aligned Bounding Box (AABB) for a polygon shape after applying a transform. * The AABB includes the polygon's radius in its calculations. * @param {b2Polygon} shape - The polygon shape containing vertices and radius - * @param {b2Transform} xf2 - The transform to apply, consisting of position (p) and rotation (q) + * @param {b2Transform} xf - The transform to apply, consisting of position (p) and rotation (q) * @returns {b2AABB} An AABB object with lower and upper bounds that encompass the transformed polygon */ export function b2ComputePolygonAABB(shape, xf) @@ -634,7 +638,7 @@ export function b2ComputePolygonAABB(shape, xf) * @summary Computes an Axis-Aligned Bounding Box (AABB) for a line segment. * @function b2ComputeSegmentAABB * @param {b2Segment} shape - A line segment defined by two points (point1 and point2) - * @param {b2Transform} xf2 - A transform containing position and rotation to be applied to the segment + * @param {b2Transform} xf - A transform containing position and rotation to be applied to the segment * @returns {b2AABB} An AABB that contains the transformed line segment * @description * Transforms the segment's endpoints using the provided transform, then creates an AABB diff --git a/src/hull_c.js b/src/hull_c.js index 5a410e3..f05eeff 100644 --- a/src/hull_c.js +++ b/src/hull_c.js @@ -15,6 +15,10 @@ import { b2_linearSlop } from './include/core_h.js'; * @namespace Hull */ +/** + * @import {b2Vec2} from './include/math_functions_h.js' + */ + // quickhull recursion function b2RecurseHull(p1, p2, ps, count) { diff --git a/src/include/collision_h.js b/src/include/collision_h.js index edf2a61..563c390 100644 --- a/src/include/collision_h.js +++ b/src/include/collision_h.js @@ -649,3 +649,11 @@ export class b2TreeNode this.enlarged = false; } } + + +/** + * These are performance results returned by dynamic tree queries. + * @typedef {Object} b2TreeStats + * @property {number} nodeVisits - Number of internal nodes visited during the query. + * @property {number} leafVisits - Number of leaf nodes visited during the query. + */ diff --git a/src/include/core_h.js b/src/include/core_h.js index c8af4c8..2a47238 100644 --- a/src/include/core_h.js +++ b/src/include/core_h.js @@ -55,8 +55,6 @@ export function B2_ARRAY_COUNT(A) /** * @summary Sets custom memory allocator functions for Box2D (Not supported in Phaser Box2D JS) * @function b2SetAllocator - * @param {Function} allocFcn - Memory allocation function pointer - * @param {Function} freeFcn - Memory deallocation function pointer * @returns {void} * @description * This function is intended to set custom memory allocation and deallocation functions @@ -72,7 +70,7 @@ export function b2SetAllocator() /** * @summary Returns the byte count for Box2D memory usage. * @function b2GetByteCount - * @returns {number} An integer representing the total bytes used by Box2D. + * @returns {void} * @description * This function is a stub that warns users that byte count tracking is not * supported in the JavaScript implementation of Box2D for Phaser. @@ -85,7 +83,7 @@ export function b2GetByteCount() /** * @summary Creates a timer object for performance measurement. * @function b2CreateTimer - * @returns {b2Timer} A timer object for measuring elapsed time. + * @returns {void} A timer object for measuring elapsed time. * @description * This function creates a timer object but is not supported in the Phaser Box2D JS implementation. * When called, it issues a console warning about lack of support. @@ -98,7 +96,7 @@ export function b2CreateTimer() /** * @summary Gets system ticks for timing purposes * @function b2GetTicks - * @returns {number} Returns 0 since this function not supported + * @returns {void} Returns 0 since this function not supported * @description * This is a stub function that exists for compatibility with Box2D but is not * implemented in the Phaser Box2D JS port. It logs a warning when called. @@ -112,7 +110,7 @@ export function b2GetTicks() /** * @summary Gets the elapsed time in milliseconds. * @function b2GetMilliseconds - * @returns {number} The elapsed time in milliseconds. + * @returns {void} The elapsed time in milliseconds. * @description * This function is a stub that warns that millisecond timing is not supported * in the Phaser Box2D JS implementation. @@ -126,15 +124,14 @@ export function b2GetMilliseconds() /** * @summary Gets elapsed milliseconds from a b2Timer and resets it. * @function b2GetMillisecondsAndReset - * @param {b2Timer} timer - The Box2D timer object to query and reset - * @returns {number} The elapsed time in milliseconds + * @returns {void} The elapsed time in milliseconds * @description * This function returns the elapsed milliseconds from a Box2D timer object and resets it. * In the JavaScript implementation for Phaser Box2D, this functionality is not supported * and will trigger a warning. * @throws {Warning} Logs a console warning that this function is not supported */ -export function b2GetMillisecondsAndReset(timer) +export function b2GetMillisecondsAndReset() { console.warn("b2GetMillisecondsAndReset not supported"); } diff --git a/src/include/math_functions_h.js b/src/include/math_functions_h.js index 42ea889..c75fad5 100644 --- a/src/include/math_functions_h.js +++ b/src/include/math_functions_h.js @@ -635,8 +635,8 @@ function b2Distance(a, b) /** * @function b2DistanceSquared * @summary Calculates the squared distance between two 2D points. - * @param {b2Vec2} a - The first 2D vector point - * @param {b2Vec2} b - The second 2D vector point + * @param {b2Vec2 | {x: number, y: number}} a - The first 2D vector point + * @param {b2Vec2 | {x: number, y: number}} b - The second 2D vector point * @returns {number} The squared distance between points a and b * @description * Computes the squared Euclidean distance between two points without taking the square root. diff --git a/src/include/types_h.js b/src/include/types_h.js index 3b786c9..4efa043 100644 --- a/src/include/types_h.js +++ b/src/include/types_h.js @@ -691,6 +691,87 @@ export class b2ContactData } } +/** + * Prototype for a contact filter callback. + * This is called when a contact pair is considered for collision. This allows you to + * perform custom logic to prevent collision between shapes. This is only called if + * one of the two shapes has custom filtering enabled. + * + * **Notes:** + * - This function must be thread-safe. + * - This is only called if one of the two shapes has enabled custom filtering. + * - This is called only for awake dynamic bodies. + * + * @warning Do not attempt to modify the world inside this callback. + * @see b2ShapeDef + * @ingroup world + * @callback b2CustomFilterFcn + * @param {b2ShapeId} shapeIdA - The first shape ID. + * @param {b2ShapeId} shapeIdB - The second shape ID. + * @param {any} context - User-defined context. + * @returns {boolean} False to disable the collision. + */ + +/** + * Prototype for a pre-solve callback. + * This is called after a contact is updated. This allows you to inspect a + * contact before it goes to the solver. If you are careful, you can modify the + * contact manifold (e.g., modify the normal). + * + * **Notes:** + * - This function must be thread-safe. + * - This is only called if the shape has enabled pre-solve events. + * - This is called only for awake dynamic bodies. + * - This is not called for sensors. + * - The supplied manifold has impulse values from the previous step. + * + * @warning Do not attempt to modify the world inside this callback. + * @ingroup world + * @callback b2PreSolveFcn + * @param {b2ShapeId} shapeIdA - The first shape ID. + * @param {b2ShapeId} shapeIdB - The second shape ID. + * @param {b2Manifold} manifold - The contact manifold. + * @param {any} context - User-defined context. + * @returns {boolean} False to disable the contact this step. + */ + +/** + * Prototype callback for overlap queries. + * Called for each shape found in the query. + * + * @see b2World_OverlapABB + * @ingroup world + * @callback b2OverlapResultFcn + * @param {b2ShapeId} shapeId - The shape ID found in the query. + * @param {any} context - User-defined context. + * @returns {boolean} False to terminate the query. + */ + +/** + * Prototype callback for ray casts. + * Called for each shape found in the query. You control how the ray cast proceeds by returning a float: + * + * - `-1`: Ignore this shape and continue. + * - `0`: Terminate the ray cast. + * - `fraction`: Clip the ray to this point. + * - `1`: Don't clip the ray and continue. + * + * @see b2World_CastRay + * @ingroup world + * @callback b2CastResultFcn + * @param {b2ShapeId} shapeId - The shape hit by the ray. + * @param {b2Vec2} point - The point of initial intersection. + * @param {b2Vec2} normal - The normal vector at the point of intersection. + * @param {number} fraction - The fraction along the ray at the point of intersection. + * @param {any} context - User-defined context. + * @returns {number} - `-1` to filter, `0` to terminate, `fraction` to clip the ray for closest hit, `1` to continue. + */ + + +/// These colors are used for debug draw and mostly match the named SVG colors. +/// See https://www.rapidtables.com/web/color/index.html +/// https://johndecember.com/html/spec/colorsvg.html +/// https://upload.wikimedia.org/wikipedia/commons/2/2b/SVG_Recognized_color_keyword_names.svg export const b2HexColor = { b2_colorAliceBlue: 0xf0f8ff, b2_colorAntiqueWhite: 0xfaebd7, diff --git a/src/include/world_h.js b/src/include/world_h.js index fde5c76..c439fb1 100644 --- a/src/include/world_h.js +++ b/src/include/world_h.js @@ -5,6 +5,10 @@ * - Copyright 2024 Phaser Studio Inc, released under the MIT license. */ +/** + * @import {b2WorldId} from './id_h.js' + */ + export const b2_maxWorkers = 1; export { @@ -29,13 +33,12 @@ export { * @summary Gets the performance profile data for a Box2D world. * @function b2World_GetProfile * @param {b2WorldId} worldId - The identifier of the Box2D world. - * @returns {b2Profile} A profile object containing performance metrics. + * @returns {void} A profile object containing performance metrics. * @description * This function returns performance profiling data for a Box2D world. * Not supported in Phaser Box2D JS implementation. - * @throws {Error} Outputs a console warning indicating lack of support in Phaser Box2D JS. */ -export function b2World_GetProfile() +export function b2World_GetProfile(worldId) { console.warn("b2World_GetProfile not supported"); } @@ -44,12 +47,12 @@ export function b2World_GetProfile() * Gets the current counters from a Box2D world instance. * @function b2World_GetCounters * @param {b2WorldId} worldId - The ID of the Box2D world instance. - * @returns {b2Counters} An object containing various Box2D performance counters. + * @returns {void} An object containing various Box2D performance counters. * @description * This function is not supported in the Phaser Box2D JS implementation and will * generate a console warning when called. */ -export function b2World_GetCounters() +export function b2World_GetCounters(worldId) { console.warn("b2World_GetCounters not supported"); } @@ -63,7 +66,7 @@ export function b2World_GetCounters() * This function is a stub that displays a warning message indicating that memory statistics * dumping is not supported in the Phaser Box2D JavaScript implementation. */ -export function b2World_DumpMemoryStats() +export function b2World_DumpMemoryStats(worldId) { console.warn("b2World_DumpMemoryStats not supported"); } diff --git a/src/joint_c.js b/src/joint_c.js index e3a3c93..a506a7c 100644 --- a/src/joint_c.js +++ b/src/joint_c.js @@ -36,6 +36,10 @@ import { b2JointId } from "./include/id_h.js"; * @namespace Joint */ +/** + * @import {b2WorldId, b2BodyId} from './include/id_h.js' + */ + /** * Creates a default distance joint definition with preset values. * @function b2DefaultDistanceJointDef diff --git a/src/manifold_c.js b/src/manifold_c.js index 08c4f5a..873198a 100644 --- a/src/manifold_c.js +++ b/src/manifold_c.js @@ -42,6 +42,10 @@ import { resetProperties } from './body_c.js'; * @namespace Manifold */ +/** + * @import {b2Segment, b2Circle, b2ChainSegment, b2DistanceCache, b2Manifold} from './include/collision_h.js' + */ + const B2_MAKE_ID = (A, B) => ((A & 0xFF) << 8) | (B & 0xFF); const xf = new b2Transform(new b2Vec2(), new b2Rot()); @@ -762,7 +766,14 @@ const constCapsule = new b2Capsule(); * @param {b2Transform} xfA - Transform for segmentA containing position and rotation * @param {b2Capsule} capsuleB - A capsule shape defined by two points and a radius * @param {b2Transform} xfB - Transform for capsuleB containing position and rotation - * @returns {b2Manifold} Collision manifold containing contact points and normal + * @param {b2Manifold} manifold - Output collision manifold + * @returns {void} Modifies the manifold parameter with collision data: + * - normalX/Y: Collision normal vector + * - pointCount: Number of contact points (0-2) + * - points[]: Contact point data including: + * - anchorA/B: Contact points in local coordinates + * - separation: Penetration depth + * - id: Contact ID * @description * Converts the segment to a zero-radius capsule and delegates to b2CollideCapsules * for the actual collision computation. @@ -1488,9 +1499,9 @@ export function b2CollideChainSegmentAndCircle(chainSegmentA, xfA, circleB, xfB, * @param {b2Transform} xfA - Transform for segmentA * @param {b2Capsule} capsuleB - The capsule shape defined by two centers and a radius * @param {b2Transform} xfB - Transform for capsuleB - * @param {b2SimplexCache} cache - Simplex cache for persistent contact information + * @param {b2DistanceCache} cache - Simplex cache for persistent contact information * @param {b2Manifold} manifold - Contact manifold to store collision results - * @returns {void} + * @returns {b2Manifold} - Modified manifold */ export function b2CollideChainSegmentAndCapsule(segmentA, xfA, capsuleB, xfB, cache, manifold) { diff --git a/src/math_functions_c.js b/src/math_functions_c.js index efcc939..49453dd 100644 --- a/src/math_functions_c.js +++ b/src/math_functions_c.js @@ -11,6 +11,10 @@ import { b2IsNormalized, b2Length, b2Vec2, eps } from "./include/math_functions_ * @namespace MathFunctions */ +/** + * @import {b2Rot} from './include/math_functions_h.js' + */ + /** * @summary Checks if a number is valid (finite and not NaN). * @function b2IsValid @@ -39,7 +43,7 @@ export function b2Vec2_IsValid(v) /** * Validates a 2D rotation object. * @function b2Rot_IsValid - * @param {b2Rot} q4 - A rotation object containing sine (s) and cosine (c) components + * @param {b2Rot} q - A rotation object containing sine (s) and cosine (c) components * @returns {boolean} True if the rotation is valid, false otherwise * @description * Checks if a b2Rot object is valid by verifying: diff --git a/src/motor_joint_c.js b/src/motor_joint_c.js index c10e9fa..c7578a0 100644 --- a/src/motor_joint_c.js +++ b/src/motor_joint_c.js @@ -13,6 +13,7 @@ import { b2CrossSV, b2GetInverse22, b2LengthSquared, + b2Mat22, b2MulAdd, b2MulMV, b2MulSV, @@ -35,6 +36,10 @@ import { b2SetType } from './include/world_h.js'; * @namespace MotorJoint */ +/** + * @import {b2JointId} from './include/id_h.js' + */ + /** * @summary Sets the target linear offset for a motor joint. * @function b2MotorJoint_SetLinearOffset @@ -251,10 +256,10 @@ export function b2PrepareMotorJoint(base, context) joint.deltaAngle = b2UnwindAngle(joint.deltaAngle); const rA = joint.anchorA; const rB = joint.anchorB; - const K = { - cx: new b2Vec2(0, 0), - cy: new b2Vec2(0, 0) - }; + const K = new b2Mat22( + new b2Vec2(0, 0), + new b2Vec2(0, 0) + ); K.cx.x = mA + mB + rA.y * rA.y * iA + rB.y * rB.y * iB; K.cx.y = -rA.y * rA.x * iA - rB.y * rB.x * iB; K.cy.x = K.cx.y; diff --git a/src/mouse_joint_c.js b/src/mouse_joint_c.js index f85dd6f..5578bff 100644 --- a/src/mouse_joint_c.js +++ b/src/mouse_joint_c.js @@ -5,7 +5,7 @@ * - Copyright 2024 Phaser Studio Inc, released under the MIT license. */ -import { b2Add, b2Cross, b2CrossSV, b2GetInverse22, b2Length, b2MulAdd, b2MulMV, b2MulSV, b2Normalize, b2RotateVector, b2Sub, b2Vec2 } from "./include/math_functions_h.js"; +import { b2Add, b2Cross, b2CrossSV, b2GetInverse22, b2Length, b2Mat22, b2MulAdd, b2MulMV, b2MulSV, b2Normalize, b2RotateVector, b2Sub, b2Vec2 } from "./include/math_functions_h.js"; import { b2GetJointSimCheckType, b2Joint_WakeBodies } from "./include/joint_h.js"; import { B2_NULL_INDEX } from "./include/core_h.js"; @@ -17,6 +17,10 @@ import { b2SetType } from "./include/world_h.js"; * @namespace MouseJoint */ +/** + * @import {b2JointId} from './include/id_h.js' + */ + /** * @summary Sets the target position for a mouse joint. * @function b2MouseJoint_SetTarget @@ -193,10 +197,10 @@ export function b2PrepareMouseJoint(base, context) const mB = bodySimB.invMass; const iB = bodySimB.invInertia; - const K = { - cx: new b2Vec2(mB + iB * rB.y * rB.y, -iB * rB.x * rB.y), - cy: new b2Vec2(-iB * rB.x * rB.y, mB + iB * rB.x * rB.x) - }; + const K = new b2Mat22( + new b2Vec2(mB + iB * rB.y * rB.y, -iB * rB.x * rB.y), + new b2Vec2(-iB * rB.x * rB.y, mB + iB * rB.x * rB.x) + ); joint.linearMass = b2GetInverse22(K); joint.deltaCenter = b2Sub(bodySimB.center, joint.targetA); diff --git a/src/physics.js b/src/physics.js index 413f20a..41c3d17 100644 --- a/src/physics.js +++ b/src/physics.js @@ -35,6 +35,13 @@ import { b2ComputeHull } from './include/hull_h.js'; * @namespace Physics */ +/** + * @import {b2WorldDef, b2ShapeDef, b2BodyDef} from './include/types_h.js' + * @import {b2ShapeId, b2WorldId, b2BodyId, b2JointId} from './include/id_h.js' + * @import {b2Polygon} from './include/collision_h.js' + * @import {b2Body} from './include/body_h.js' + */ + // local function setIfDef (obj, prop, value) @@ -222,9 +229,8 @@ export function UpdateWorldSprites (worldId) * Converts a Box2D Body's position and rotation to a Sprite's position and rotation. * * This is called automatically by `UpdateWorldSprites`. - * * @export - * @param {b2Body} body + * @param {{ bodyId: { world0: number; }; }} body * @param {Sprite} sprite */ export function BodyToSprite (body, sprite) @@ -353,7 +359,7 @@ let _accumulator = 0; * Steps a physics world to match fixedTimeStep. * Returns the average time spent in the step function. * - * @param {WorldConfig} data - Configuration for the world. + * @param {WorldStepConfig} data - Configuration for the world. * @returns {number} totalTime - Time spent processing the step function, in seconds. */ export function WorldStep (data) @@ -415,7 +421,7 @@ export function WorldStep (data) * @typedef {Object} BodyCapsule * @property {b2BodyId} bodyId - ID for the body to attach the capsule to. * @property {b2ShapeId} shapeId - ID for the shape to attach the capsule to. - * @propery {b2Capsule} object - The capsule object to attach. + * @property {b2Capsule} object - The capsule object to attach. */ /** @@ -905,7 +911,7 @@ export function CreatePolygon (data) * @property {number} [friction] - Friction of the polygon. * @property {number} [restitution=0.1] - Restitution of the polygon. * @property {any} [color] - Custom color for the polygon. - * @property {number[]} indices - List of indices to the vertices for the polygon. + * @property {number[][]} indices - List of indices to the vertices for the polygon. * @property {number[]} vertices - List of vertices for the polygon in number pairs [x0,y0, x1,y1, ... xN,yN]. * @property {b2Vec2} vertexOffset - Offset to recenter the vertices if they are not zero based. * @property {b2Vec2} vertexScale - Scale for the vertices, defaults to 1, 1. diff --git a/src/prismatic_joint_c.js b/src/prismatic_joint_c.js index ebdf7f9..95dbefb 100644 --- a/src/prismatic_joint_c.js +++ b/src/prismatic_joint_c.js @@ -34,6 +34,10 @@ import { b2MakeSoft } from './include/solver_h.js'; * @namespace PrismaticJoint */ +/** + * @import {b2JointId} from './include/id_h.js' + */ + /** * @function b2PrismaticJoint_EnableSpring * @summary Enables or disables the spring functionality of a prismatic joint. diff --git a/src/revolute_joint_c.js b/src/revolute_joint_c.js index ccce23a..b9c0243 100644 --- a/src/revolute_joint_c.js +++ b/src/revolute_joint_c.js @@ -10,6 +10,7 @@ import { b2ClampFloat, b2Cross, b2CrossSV, + b2Mat22, b2MulAdd, b2MulSV, b2MulSub, @@ -33,6 +34,10 @@ import { b2MakeSoft } from './include/solver_h.js'; * @namespace RevoluteJoint */ +/** + * @import {b2JointId} from './include/id_h.js' + */ + /** * @function b2RevoluteJoint_EnableSpring * @description @@ -626,10 +631,10 @@ export function b2SolveRevoluteJoint(base, context, useBias) impulseScale = context.jointSoftness.impulseScale; } - const K = { - cx: new b2Vec2(0, 0), - cy: new b2Vec2(0, 0) - }; + const K = new b2Mat22( + new b2Vec2(0, 0), + new b2Vec2(0, 0) + ); K.cx.x = mA + mB + rA.y * rA.y * iA + rB.y * rB.y * iB; K.cy.x = -rA.y * rA.x * iA - rB.y * rB.x * iB; K.cx.y = K.cy.x; diff --git a/src/shape_c.js b/src/shape_c.js index 750f266..e13ae4c 100644 --- a/src/shape_c.js +++ b/src/shape_c.js @@ -58,6 +58,12 @@ import { b2MakeProxy, b2ShapeDistance } from './include/distance_h.js'; * @namespace Shape */ +/** + * @import {b2BodyId} from './include/id_h.js' + * @import {b2ShapeDef, b2ChainDef, b2Filter} from './include/types_h.js' + * @import {b2Capsule, b2Polygon, b2Manifold} from './include/collision_h.js' + */ + function b2GetShape(world, shapeId) { const id = shapeId.index1 - 1; diff --git a/src/solver_set_c.js b/src/solver_set_c.js index 703137e..b91deee 100644 --- a/src/solver_set_c.js +++ b/src/solver_set_c.js @@ -38,6 +38,10 @@ import { b2ClearBit } from './include/bitset_h.js'; * @namespace SolverSet */ +/** + * @import {b2World} from './include/world_h.js' + */ + // This holds solver set data. The following sets are used: // - static set for all static bodies (no contacts or joints) // - active set for all active bodies with body states (no contacts or joints) @@ -90,6 +94,10 @@ export function b2DestroySolverSet(world, setIndex) world.solverSetArray[setIndex] = set; } +/** + * @param {b2World} world + * @param {number} setIndex + */ export function b2WakeSolverSet(world, setIndex) { console.assert(setIndex >= b2SetType.b2_firstSleepingSet); @@ -172,8 +180,8 @@ export function b2WakeSolverSet(world, setIndex) { const contactSim = set.contacts.data[i]; const contact = contacts[contactSim.contactId]; - console.assert(contact.flags & b2ContactFlags.b2_contactTouchingFlag); - console.assert(contactSim.simFlags & b2ContactSimFlags.b2_simTouchingFlag); + console.assert(!!(contact.flags & b2ContactFlags.b2_contactTouchingFlag)); + console.assert(!!(contactSim.simFlags & b2ContactSimFlags.b2_simTouchingFlag)); console.assert(contactSim.manifold.pointCount > 0); console.assert(contact.setIndex === setIndex); b2AddContactToGraph(world, contactSim, contact); diff --git a/src/weld_joint_c.js b/src/weld_joint_c.js index 1fcb296..e902c6d 100644 --- a/src/weld_joint_c.js +++ b/src/weld_joint_c.js @@ -32,6 +32,10 @@ import { b2SetType } from './include/world_h.js'; * @namespace WeldJoint */ +/** + * @import {b2JointId} from './include/id_h.js' + */ + /** * Sets the linear frequency (hertz) for a weld joint. * @function b2WeldJoint_SetLinearHertz diff --git a/src/wheel_joint_c.js b/src/wheel_joint_c.js index 6091444..e08486e 100644 --- a/src/wheel_joint_c.js +++ b/src/wheel_joint_c.js @@ -18,6 +18,10 @@ import { b2MakeSoft } from './include/solver_h.js'; * @namespace WheelJoint */ +/** + * @import {b2JointId} from './include/id_h.js' + */ + /** * @function b2WheelJoint_EnableSpring * @description diff --git a/src/world_c.js b/src/world_c.js index 91111be..b040900 100644 --- a/src/world_c.js +++ b/src/world_c.js @@ -72,6 +72,13 @@ import { b2HexColor } from './include/types_h.js'; * @namespace World */ +/** + * @import {b2WorldDef, b2DebugDraw, b2QueryFilter} from './include/types_h.js' + * @import {b2ChainId, b2JointId} from './include/id_h.js' + * @import {b2PreSolveFcn, b2CastResultFcn, b2OverlapResultFcn, b2CustomFilterFcn} from './include/types_h.js' + * @import {b2TreeStats, b2Circle, b2Capsule, b2Polygon} from './include/collision_h.js' + */ + export const B2_MAX_WORLDS = 32; export const b2SetType = @@ -92,12 +99,16 @@ export class b2World bodyArray = []; // solverSetIdPool = new b2IdPool(); + + /** @type {b2SolverSet[]} */ solverSetArray = []; // jointIdPool = new b2IdPool(); jointArray = []; // contactIdPool = new b2IdPool(); + + /** @type {b2Contact[]} */ contactArray = []; // islandIdPool = new b2IdPool(); diff --git a/types/aabb_c.d.ts b/types/aabb_c.d.ts index c9b670f..7a6a751 100644 --- a/types/aabb_c.d.ts +++ b/types/aabb_c.d.ts @@ -1,6 +1,9 @@ /** * @namespace Aabb */ +/** + * @import {b2AABB} from './include/math_functions_h.js' + */ export function b2Perimeter(a: any): number; export function b2EnlargeAABB(a: any, b: any): boolean; export function b2AABB_Overlaps(a: any, b: any): boolean; @@ -16,4 +19,5 @@ export function b2AABB_Overlaps(a: any, b: any): boolean; * 3. The height (upperBoundY - lowerBoundY) is non-negative * 4. All coordinate values are valid numbers */ -export function b2AABB_IsValid(aabb: b2AABB): boolean; +export function b2AABB_IsValid(aabb: b2Math.b2AABB): boolean; +import * as b2Math from './include/math_functions_h.js'; diff --git a/types/block_array_c.d.ts b/types/block_array_c.d.ts index 7397dfb..c9f7f25 100644 --- a/types/block_array_c.d.ts +++ b/types/block_array_c.d.ts @@ -27,7 +27,8 @@ export class b2BodyStateArray { } export class b2ContactArray { constructor(capacity?: number); - data: any[]; + /** @type {b2ContactSim[]} */ + data: b2ContactSim[]; count: number; capacity: number; } @@ -43,3 +44,4 @@ export class b2JointArray { count: number; capacity: number; } +import { b2ContactSim } from './include/contact_h.js'; diff --git a/types/body_c.d.ts b/types/body_c.d.ts index 7c793df..f275ab0 100644 --- a/types/body_c.d.ts +++ b/types/body_c.d.ts @@ -1,6 +1,10 @@ /** * @namespace Body */ +/** + * @import {b2WorldId} from './include/id_h.js' + * @import {b2BodyDef, b2ContactData} from './include/types_h.js' + */ export function b2MakeSweep(bodySim: any, out: any): any; export function b2GetBody(world: any, bodyId: any): any; export function b2GetBodyFullId(world: any, bodyId: any): any; @@ -376,15 +380,15 @@ export function b2Body_GetUserData(bodyId: b2BodyId): object; */ export function b2Body_GetMass(bodyId: b2BodyId): number; /** - * Gets the inertia tensor value for a specified body. - * @function b2Body_GetInertiaTensor + * Get the rotational inertia of the body, typically in kg*m^2 + * @function b2Body_GetRotationalInertia * @param {b2BodyId} bodyId - The ID of the body to get the inertia tensor from. * @returns {number} The inertia tensor value of the body. * @description * Retrieves the rotational inertia value from a body's simulation data using the body's ID. * The inertia tensor represents the body's resistance to rotational acceleration. */ -export function b2Body_GetInertiaTensor(bodyId: b2BodyId): number; +export function b2Body_GetRotationalInertia(bodyId: b2BodyId): number; /** * Gets the local center of mass for a body. * @function b2Body_GetLocalCenterOfMass @@ -558,13 +562,13 @@ export function b2Body_IsSleepEnabled(bodyId: b2BodyId): boolean; * Sets the sleep threshold velocity for a body. * @function b2Body_SetSleepThreshold * @param {b2BodyId} bodyId - The identifier for the body to modify. - * @param {number} sleepVelocity - The velocity threshold below which the body can sleep. + * @param {number} sleepThreshold - The velocity threshold below which the body can sleep. * @returns {void} * @description * Sets the minimum velocity threshold that determines when a body can transition to a sleeping state. * When a body's velocity falls below this threshold, it becomes eligible for sleeping. */ -export function b2Body_SetSleepThreshold(bodyId: b2BodyId, sleepVelocity: number): void; +export function b2Body_SetSleepThreshold(bodyId: b2BodyId, sleepThreshold: number): void; /** * Gets the sleep threshold value for a body. * @function b2Body_GetSleepThreshold @@ -711,6 +715,9 @@ export function b2Body_GetJoints(bodyId: b2BodyId, jointArray: b2JointId[], capa export function b2ShouldBodiesCollide(world: any, bodyA: any, bodyB: any): boolean; export function resetProperties(obj: any): void; import { b2BodyId } from './include/id_h.js'; +import type { b2WorldId } from './include/id_h.js'; +import type { b2BodyDef } from './include/types_h.js'; +import type { b2ContactData } from './include/types_h.js'; import { b2AABB } from './include/math_functions_h.js'; import { b2Vec2 } from './include/math_functions_h.js'; import { b2Rot } from './include/math_functions_h.js'; diff --git a/types/contact_c.d.ts b/types/contact_c.d.ts index 73f4f06..23de9d5 100644 --- a/types/contact_c.d.ts +++ b/types/contact_c.d.ts @@ -5,10 +5,10 @@ export function b2PolygonAndCircleManifold(shapeA: any, xfA: any, shapeB: any, x export function b2PolygonAndCapsuleManifold(shapeA: any, xfA: any, shapeB: any, xfB: any, cache: any, manifold: any): b2Manifold; export function b2PolygonManifold(shapeA: any, xfA: any, shapeB: any, xfB: any, cache: any, manifold: any): b2Manifold; export function b2SegmentAndCircleManifold(shapeA: any, xfA: any, shapeB: any, xfB: any, cache: any, manifold: any): b2Manifold; -export function b2SegmentAndCapsuleManifold(shapeA: any, xfA: any, shapeB: any, xfB: any, cache: any, manifold: any): b2Manifold; +export function b2SegmentAndCapsuleManifold(shapeA: any, xfA: any, shapeB: any, xfB: any, cache: any, manifold: any): void; export function b2SegmentAndPolygonManifold(shapeA: any, xfA: any, shapeB: any, xfB: any, cache: any, manifold: any): b2Manifold; export function b2ChainSegmentAndCircleManifold(shapeA: any, xfA: any, shapeB: any, xfB: any, cache: any, manifold: any): any; -export function b2ChainSegmentAndCapsuleManifold(shapeA: any, xfA: any, shapeB: any, xfB: any, cache: any, manifold: any): void; +export function b2ChainSegmentAndCapsuleManifold(shapeA: any, xfA: any, shapeB: any, xfB: any, cache: any, manifold: any): b2Manifold; export function b2ChainSegmentAndPolygonManifold(shapeA: any, xfA: any, shapeB: any, xfB: any, cache: any, manifold: any): b2Manifold; export function b2AddType(fcn: any, type1: any, type2: any): void; export function b2InitializeContactRegisters(): void; diff --git a/types/debug_draw.d.ts b/types/debug_draw.d.ts index 5e935aa..454dbd5 100644 --- a/types/debug_draw.d.ts +++ b/types/debug_draw.d.ts @@ -19,24 +19,28 @@ * - Transforms */ export function CreateDebugDraw(canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D, scale?: number): b2DebugDraw; +/** + * @callback RAFCallback + * @param {number} deltaTime - Time elapsed since last frame in seconds, capped at 0.1s + * @param {number} totalTime - Total accumulated time in seconds + * @param {number} currentFps - Current frames per second, updated once per second + * @returns {void} + */ /** * @function RAF * @summary Implements a requestAnimationFrame loop with timing and FPS tracking - * @param {function} callback - Function to call each frame with signature (deltaTime, totalTime, currentFps) - * @param {number} callback.deltaTime - Time elapsed since last frame in seconds, capped at 0.1s - * @param {number} callback.totalTime - Total accumulated time in seconds - * @param {number} callback.currentFps - Current frames per second, updated once per second + * @param {RAFCallback} callback - Function to call each frame with signature (deltaTime, totalTime, currentFps) * @description * Creates an animation loop using requestAnimationFrame that tracks timing information * and FPS. The callback is invoked each frame with the time delta, total time, and * current FPS. Frame delta time is capped at 100ms to avoid large time steps. */ -export function RAF(callback: Function): void; +export function RAF(callback: RAFCallback): void; /** * Attach a graphic image to a physics body * @function AttachImage * @param {number} worldId - The ID of the Box2D world - * @param {number} bodyId - The ID of the body to attach the image to + * @param {b2BodyId} bodyId - The ID of the body to attach the image to * @param {string} path - Directory path where the image is located * @param {string} imgName - Name of the image file * @param {b2Vec2} [drawOffset=null] - Offset vector for drawing the image @@ -49,7 +53,7 @@ export function RAF(callback: Function): void; * asynchronously and sets up drawing parameters including offset, scale, and source * rectangle coordinates. The image is stored in the shape's properties for later rendering. */ -export function AttachImage(worldId: number, bodyId: number, path: string, imgName: string, drawOffset?: b2Vec2, drawScale?: b2Vec2, sourcePosition?: b2Vec2, sourceSize?: b2Vec2): any; +export function AttachImage(worldId: number, bodyId: b2BodyId, path: string, imgName: string, drawOffset?: b2Vec2, drawScale?: b2Vec2, sourcePosition?: b2Vec2, sourceSize?: b2Vec2): any; /** * @function ConvertScreenToWorld * @description @@ -77,5 +81,7 @@ export function ConvertScreenToWorld(canvas: HTMLCanvasElement, drawScale: numbe * screen pixels. */ export function ConvertWorldToScreen(canvas: HTMLCanvasElement, drawScale: number, pw: b2Vec2): b2Vec2; +export type RAFCallback = (deltaTime: number, totalTime: number, currentFps: number) => void; import { b2DebugDraw } from './include/types_h.js'; +import { b2BodyId } from './main.js'; import { b2Vec2 } from './include/math_functions_h.js'; diff --git a/types/distance_c.d.ts b/types/distance_c.d.ts index 215d407..482ee73 100644 --- a/types/distance_c.d.ts +++ b/types/distance_c.d.ts @@ -1,6 +1,9 @@ /** * @namespace Distance */ +/** + * @import {b2ShapeCastPairInput, b2TOIInput} from './include/collision_h' + */ /** * @function b2GetSweepTransform * @summary Computes an interpolated transform at a specified time during a sweep motion. @@ -102,6 +105,7 @@ import { b2DistanceCache } from './include/collision_h.js'; import { b2DistanceInput } from './include/collision_h.js'; import { b2Simplex } from './include/collision_h.js'; import { b2DistanceOutput } from './include/collision_h.js'; +import type { b2ShapeCastPairInput } from './include/collision_h'; import { b2CastOutput } from './include/collision_h.js'; declare class b2SeparationFunction { proxyA: any; @@ -118,5 +122,6 @@ declare class MinSeparationReturn { indexB: any; separation: any; } +import type { b2TOIInput } from './include/collision_h'; import { b2TOIOutput } from './include/collision_h.js'; export {}; diff --git a/types/distance_joint_c.d.ts b/types/distance_joint_c.d.ts index a31a658..3db71f1 100644 --- a/types/distance_joint_c.d.ts +++ b/types/distance_joint_c.d.ts @@ -1,5 +1,8 @@ /** * @namespace DistanceJoint +*/ +/** + * @import {b2JointId} from './include/id_h' */ /** * @function b2DistanceJoint_SetLength @@ -135,20 +138,20 @@ export function b2DistanceJoint_SetSpringHertz(jointId: b2JointId, hertz: number export function b2DistanceJoint_SetSpringDampingRatio(jointId: b2JointId, dampingRatio: number): void; /** * Gets the hertz frequency parameter of a distance joint. - * @function b2DistanceJoint_GetHertz + * @function b2DistanceJoint_GetSpringHertz * @param {number} jointId - The identifier for the distance joint. * @returns {number} The hertz frequency value of the distance joint. * @throws {Error} If the joint is not a distance joint or the jointId is invalid. */ -export function b2DistanceJoint_GetHertz(jointId: number): number; +export function b2DistanceJoint_GetSpringHertz(jointId: number): number; /** * Gets the damping ratio of a distance joint. - * @function b2DistanceJoint_GetDampingRatio + * @function b2DistanceJoint_GetSpringDampingRatio * @param {number} jointId - The identifier for the distance joint. * @returns {number} The damping ratio of the distance joint. * @throws {Error} If the joint is not a distance joint or the jointId is invalid. */ -export function b2DistanceJoint_GetDampingRatio(jointId: number): number; +export function b2DistanceJoint_GetSpringDampingRatio(jointId: number): number; /** * @function b2DistanceJoint_EnableMotor * @description @@ -218,3 +221,4 @@ export function b2PrepareDistanceJoint(base: any, context: any): void; export function b2WarmStartDistanceJoint(base: any, context: any): void; export function b2SolveDistanceJoint(base: any, context: any, useBias: any): void; export function b2DrawDistanceJoint(draw: any, base: any, transformA: any, transformB: any): void; +import type { b2JointId } from './include/id_h'; diff --git a/types/dynamic_tree_c.d.ts b/types/dynamic_tree_c.d.ts index 063c567..dac060f 100644 --- a/types/dynamic_tree_c.d.ts +++ b/types/dynamic_tree_c.d.ts @@ -38,7 +38,7 @@ export function b2RemoveLeaf(tree: any, leaf: any): void; * @returns {number} The ID of the created proxy node * @throws {Error} Throws assertion error if AABB bounds are outside valid range */ -export function b2DynamicTree_CreateProxy(tree: b2DynamicTree, aabb: b2AABB, categoryBits: number, userData: number): number; +export function b2DynamicTree_CreateProxy(tree: b2DynamicTree, aabb: b2Math.b2AABB, categoryBits: number, userData: number): number; /** * @function b2DynamicTree_DestroyProxy * @summary Removes and frees a proxy from the dynamic tree. @@ -79,7 +79,7 @@ export function b2DynamicTree_GetProxyCount(tree: b2DynamicTree): number; * - The proxyId is out of bounds * - The node at proxyId is not a leaf node */ -export function b2DynamicTree_MoveProxy(tree: b2DynamicTree, proxyId: number, aabb: b2AABB): void; +export function b2DynamicTree_MoveProxy(tree: b2DynamicTree, proxyId: number, aabb: b2Math.b2AABB): void; /** * @function b2DynamicTree_EnlargeProxy * @description @@ -96,7 +96,7 @@ export function b2DynamicTree_MoveProxy(tree: b2DynamicTree, proxyId: number, aa * - The node is not a leaf * - The new AABB is contained within the old one */ -export function b2DynamicTree_EnlargeProxy(tree: b2DynamicTree, proxyId: number, aabb: b2AABB): void; +export function b2DynamicTree_EnlargeProxy(tree: b2DynamicTree, proxyId: number, aabb: b2Math.b2AABB): void; /** * @summary Gets the height of a dynamic tree * @function b2DynamicTree_GetHeight @@ -161,7 +161,7 @@ export function b2DynamicTree_RebuildBottomUp(tree: b2DynamicTree): void; * Updates the axis-aligned bounding boxes (AABBs) of all nodes in the tree by * subtracting the newOrigin vector from both their lower and upper bounds. */ -export function b2DynamicTree_ShiftOrigin(tree: b2DynamicTree, newOrigin: b2Vec2): void; +export function b2DynamicTree_ShiftOrigin(tree: b2DynamicTree, newOrigin: b2Math.b2Vec2): void; /** * @function b2DynamicTree_GetByteCount * @summary Calculates the approximate memory usage of a dynamic tree in bytes. @@ -187,7 +187,7 @@ export function b2DynamicTree_GetByteCount(tree: b2DynamicTree): number; * @param {*} context - User context data passed to the callback function * @returns {void} */ -export function b2DynamicTree_Query(tree: b2DynamicTree, aabb: b2AABB, maskBits: number, callback: Function, context: any): void; +export function b2DynamicTree_Query(tree: b2DynamicTree, aabb: b2Math.b2AABB, maskBits: number, callback: Function, context: any): void; export function b2DynamicTree_QueryAll(tree: any, aabb: any, context: any): void; /** * @summary Performs a ray cast query on a dynamic tree @@ -239,3 +239,6 @@ export function b2DynamicTree_ShapeCast(tree: b2DynamicTree, input: b2ShapeCastI */ export function b2DynamicTree_Rebuild(tree: b2DynamicTree): number; import { b2DynamicTree } from './include/dynamic_tree_h.js'; +import * as b2Math from './include/math_functions_h.js'; +import type { b2RayCastInput } from './include/collision_h.js'; +import type { b2ShapeCastInput } from './include/collision_h.js'; diff --git a/types/geometry_c.d.ts b/types/geometry_c.d.ts index a95e42f..82bddcd 100644 --- a/types/geometry_c.d.ts +++ b/types/geometry_c.d.ts @@ -1,6 +1,9 @@ /** * @namespace Geometry */ +/** + * @import {b2Hull, b2RayCastInput, b2Segment, b2ShapeCastInput} from './include/collision_h.js' + */ /** * Validates a ray cast input structure. * @function b2IsValidRay @@ -84,14 +87,14 @@ export function b2MakeRoundedBox(hx: number, hy: number, radius: number): b2Poly * @param {number} hx - Half-width of the box along the x-axis * @param {number} hy - Half-height of the box along the y-axis * @param {b2Vec2} center - The center position of the box - * @param {number} angle - The rotation angle of the box in radians + * @param {b2Rot} rotation - The 2D rotation of the box * @returns {b2Polygon} A polygon shape representing the box with 4 vertices and normals * @description * Creates a b2Polygon representing a rectangle with the given dimensions. The box is centered * at the specified position and rotated by the given angle. The resulting polygon includes * 4 vertices, 4 normals, and has its centroid set to the center position. */ -export function b2MakeOffsetBox(hx: number, hy: number, center: b2Vec2, angle?: number): b2Polygon; +export function b2MakeOffsetBox(hx: number, hy: number, center: b2Vec2, rotation: b2Rot): b2Polygon; /** * @function b2TransformPolygon * @summary Transforms a polygon by applying a rigid body transformation. @@ -152,47 +155,47 @@ export function b2ComputePolygonMass(shape: b2Polygon, density: number): b2MassD * @function b2ComputeCircleAABB * @summary Computes an Axis-Aligned Bounding Box (AABB) for a circle shape after applying a transform. * @param {b2Circle} shape - The circle shape containing center point and radius. - * @param {b2Transform} xf2 - The transform to be applied, consisting of a position (p) and rotation (q). + * @param {b2Transform} xf - The transform to be applied, consisting of a position (p) and rotation (q). * @returns {b2AABB} An AABB object defined by minimum and maximum points that bound the transformed circle. * @description * Calculates the AABB by transforming the circle's center point using the provided transform * and extending the bounds by the circle's radius in each direction. */ -export function b2ComputeCircleAABB(shape: b2Circle, xf: any): b2AABB; +export function b2ComputeCircleAABB(shape: b2Circle, xf: b2Transform): b2AABB; /** * @function b2ComputeCapsuleAABB * @summary Computes an Axis-Aligned Bounding Box (AABB) for a capsule shape. * @param {b2Capsule} shape - A capsule shape defined by two centers and a radius. - * @param {b2Transform} xf2 - A transform containing position and rotation to be applied to the capsule. + * @param {b2Transform} xf - A transform containing position and rotation to be applied to the capsule. * @returns {b2AABB} An AABB that encompasses the transformed capsule shape. * @description * Calculates the minimum and maximum bounds of a capsule after applying a transform. * The AABB is computed by transforming the capsule's center points and extending * the bounds by the capsule's radius in all directions. */ -export function b2ComputeCapsuleAABB(shape: b2Capsule, xf: any): b2AABB; +export function b2ComputeCapsuleAABB(shape: b2Capsule, xf: b2Transform): b2AABB; /** * @function b2ComputePolygonAABB * @description * Computes the Axis-Aligned Bounding Box (AABB) for a polygon shape after applying a transform. * The AABB includes the polygon's radius in its calculations. * @param {b2Polygon} shape - The polygon shape containing vertices and radius - * @param {b2Transform} xf2 - The transform to apply, consisting of position (p) and rotation (q) + * @param {b2Transform} xf - The transform to apply, consisting of position (p) and rotation (q) * @returns {b2AABB} An AABB object with lower and upper bounds that encompass the transformed polygon */ -export function b2ComputePolygonAABB(shape: b2Polygon, xf: any): b2AABB; +export function b2ComputePolygonAABB(shape: b2Polygon, xf: b2Transform): b2AABB; /** * @summary Computes an Axis-Aligned Bounding Box (AABB) for a line segment. * @function b2ComputeSegmentAABB * @param {b2Segment} shape - A line segment defined by two points (point1 and point2) - * @param {b2Transform} xf2 - A transform containing position and rotation to be applied to the segment + * @param {b2Transform} xf - A transform containing position and rotation to be applied to the segment * @returns {b2AABB} An AABB that contains the transformed line segment * @description * Transforms the segment's endpoints using the provided transform, then creates an AABB * that encompasses the transformed segment by finding the minimum and maximum coordinates * of the transformed endpoints. */ -export function b2ComputeSegmentAABB(shape: b2Segment, xf: any): b2AABB; +export function b2ComputeSegmentAABB(shape: b2Segment, xf: b2Transform): b2AABB; /** * @summary Determines if a point lies within a circle. * @function b2PointInCircle @@ -334,11 +337,16 @@ export function b2ShapeCastSegment(input: b2ShapeCastInput, shape: b2Segment): b * @returns {b2CastOutput} The result of the shape cast operation */ export function b2ShapeCastPolygon(input: b2ShapeCastInput, shape: b2Polygon): b2CastOutput; +import type { b2RayCastInput } from './include/collision_h.js'; +import type { b2Hull } from './include/collision_h.js'; import { b2Polygon } from './include/collision_h.js'; import { b2Transform } from './include/math_functions_h.js'; import { b2Vec2 } from './include/math_functions_h.js'; +import { b2Rot } from './include/math_functions_h.js'; import { b2Circle } from './include/collision_h.js'; import { b2MassData } from './include/collision_h.js'; import { b2Capsule } from './include/collision_h.js'; import { b2AABB } from './include/math_functions_h.js'; +import type { b2Segment } from './include/collision_h.js'; import { b2CastOutput } from './include/collision_h.js'; +import type { b2ShapeCastInput } from './include/collision_h.js'; diff --git a/types/hull_c.d.ts b/types/hull_c.d.ts index fd32de1..157c6c5 100644 --- a/types/hull_c.d.ts +++ b/types/hull_c.d.ts @@ -27,4 +27,5 @@ export function b2ComputeHull(points: b2Vec2[], count: number): b2Hull; * @throws {Warning} Console warnings are issued explaining validation failures */ export function b2ValidateHull(hull: b2Hull): boolean; +import type { b2Vec2 } from './include/math_functions_h.js'; import { b2Hull } from './include/collision_h.js'; diff --git a/types/include/body_h.d.ts b/types/include/body_h.d.ts index 0a916b2..1796ccd 100644 --- a/types/include/body_h.d.ts +++ b/types/include/body_h.d.ts @@ -60,4 +60,4 @@ export class b2BodySim { import { b2Vec2 } from './math_functions_h.js'; import { b2Rot } from './math_functions_h.js'; import { b2Transform } from './math_functions_h.js'; -export { b2CreateBody, b2DestroyBody, b2GetBodyFullId, b2GetBody, b2GetBodyTransformQuick, b2GetBodyTransform, b2MakeBodyId, b2ShouldBodiesCollide, b2IsBodyAwake, b2GetBodySim, b2GetBodyState, b2WakeBody, b2UpdateBodyMassData, b2Body_IsEnabled, b2Body_GetType, b2Body_SetType, b2Body_GetUserData, b2Body_SetUserData, b2Body_GetLocalPoint, b2Body_GetPosition, b2Body_GetRotation, b2Body_SetTransform, b2Body_GetMassData, b2Body_SetMassData, b2Body_GetMass, b2Body_GetTransform, b2Body_ApplyTorque, b2Body_GetWorldPoint, b2Body_GetWorldVector, b2Body_GetLinearDamping, b2Body_SetLinearDamping, b2Body_GetLinearVelocity, b2Body_SetLinearVelocity, b2Body_ApplyLinearImpulse, b2Body_ApplyLinearImpulseToCenter, b2Body_GetAngularVelocity, b2Body_SetAngularVelocity, b2Body_ApplyAngularImpulse, b2Body_GetInertiaTensor, b2Body_GetLocalCenterOfMass, b2Body_GetWorldCenterOfMass, b2Body_ApplyMassFromShapes, b2Body_SetAngularDamping, b2Body_GetAngularDamping, b2Body_SetGravityScale, b2Body_GetGravityScale, b2Body_EnableSleep, b2Body_IsSleepEnabled, b2Body_SetSleepThreshold, b2Body_GetSleepThreshold, b2Body_Enable, b2Body_Disable, b2Body_SetFixedRotation, b2Body_IsFixedRotation, b2Body_GetLocalVector, b2Body_SetBullet, b2Body_IsBullet, b2Body_EnableHitEvents, b2Body_GetShapeCount, b2Body_GetShapes, b2Body_GetJointCount, b2Body_GetJoints, b2Body_ApplyForce, b2Body_SetAwake, b2Body_IsAwake, b2Body_ApplyForceToCenter, b2Body_GetContactCapacity, b2Body_GetContactData, b2Body_ComputeAABB, b2MakeSweep, resetProperties } from "../body_c.js"; +export { b2CreateBody, b2DestroyBody, b2GetBodyFullId, b2GetBody, b2GetBodyTransformQuick, b2GetBodyTransform, b2MakeBodyId, b2ShouldBodiesCollide, b2IsBodyAwake, b2GetBodySim, b2GetBodyState, b2WakeBody, b2UpdateBodyMassData, b2Body_IsEnabled, b2Body_GetType, b2Body_SetType, b2Body_GetUserData, b2Body_SetUserData, b2Body_GetLocalPoint, b2Body_GetPosition, b2Body_GetRotation, b2Body_SetTransform, b2Body_GetMassData, b2Body_SetMassData, b2Body_GetMass, b2Body_GetTransform, b2Body_ApplyTorque, b2Body_GetWorldPoint, b2Body_GetWorldVector, b2Body_GetLinearDamping, b2Body_SetLinearDamping, b2Body_GetLinearVelocity, b2Body_SetLinearVelocity, b2Body_ApplyLinearImpulse, b2Body_ApplyLinearImpulseToCenter, b2Body_GetAngularVelocity, b2Body_SetAngularVelocity, b2Body_ApplyAngularImpulse, b2Body_GetRotationalInertia, b2Body_GetLocalCenterOfMass, b2Body_GetWorldCenterOfMass, b2Body_ApplyMassFromShapes, b2Body_SetAngularDamping, b2Body_GetAngularDamping, b2Body_SetGravityScale, b2Body_GetGravityScale, b2Body_EnableSleep, b2Body_IsSleepEnabled, b2Body_SetSleepThreshold, b2Body_GetSleepThreshold, b2Body_Enable, b2Body_Disable, b2Body_SetFixedRotation, b2Body_IsFixedRotation, b2Body_GetLocalVector, b2Body_SetBullet, b2Body_IsBullet, b2Body_EnableHitEvents, b2Body_GetShapeCount, b2Body_GetShapes, b2Body_GetJointCount, b2Body_GetJoints, b2Body_ApplyForce, b2Body_SetAwake, b2Body_IsAwake, b2Body_ApplyForceToCenter, b2Body_GetContactCapacity, b2Body_GetContactData, b2Body_ComputeAABB, b2MakeSweep, resetProperties } from "../body_c.js"; diff --git a/types/include/collision_h.d.ts b/types/include/collision_h.d.ts index 62aba55..399553c 100644 --- a/types/include/collision_h.d.ts +++ b/types/include/collision_h.d.ts @@ -378,5 +378,18 @@ export class b2TreeNode { height: number; enlarged: boolean; } +/** + * These are performance results returned by dynamic tree queries. + */ +export type b2TreeStats = { + /** + * - Number of internal nodes visited during the query. + */ + nodeVisits: number; + /** + * - Number of leaf nodes visited during the query. + */ + leafVisits: number; +}; import { b2Transform } from './math_functions_h.js'; import { b2Vec2 } from './math_functions_h.js'; diff --git a/types/include/core_h.d.ts b/types/include/core_h.d.ts index 5319034..16c9cb4 100644 --- a/types/include/core_h.d.ts +++ b/types/include/core_h.d.ts @@ -2,8 +2,6 @@ export function B2_ARRAY_COUNT(A: any): any; /** * @summary Sets custom memory allocator functions for Box2D (Not supported in Phaser Box2D JS) * @function b2SetAllocator - * @param {Function} allocFcn - Memory allocation function pointer - * @param {Function} freeFcn - Memory deallocation function pointer * @returns {void} * @description * This function is intended to set custom memory allocation and deallocation functions @@ -15,53 +13,52 @@ export function b2SetAllocator(): void; /** * @summary Returns the byte count for Box2D memory usage. * @function b2GetByteCount - * @returns {number} An integer representing the total bytes used by Box2D. + * @returns {void} * @description * This function is a stub that warns users that byte count tracking is not * supported in the JavaScript implementation of Box2D for Phaser. */ -export function b2GetByteCount(): number; +export function b2GetByteCount(): void; /** * @summary Creates a timer object for performance measurement. * @function b2CreateTimer - * @returns {b2Timer} A timer object for measuring elapsed time. + * @returns {void} A timer object for measuring elapsed time. * @description * This function creates a timer object but is not supported in the Phaser Box2D JS implementation. * When called, it issues a console warning about lack of support. */ -export function b2CreateTimer(): b2Timer; +export function b2CreateTimer(): void; /** * @summary Gets system ticks for timing purposes * @function b2GetTicks - * @returns {number} Returns 0 since this function not supported + * @returns {void} Returns 0 since this function not supported * @description * This is a stub function that exists for compatibility with Box2D but is not * implemented in the Phaser Box2D JS port. It logs a warning when called. * @throws {Warning} Logs a console warning that the function is not supported */ -export function b2GetTicks(): number; +export function b2GetTicks(): void; /** * @summary Gets the elapsed time in milliseconds. * @function b2GetMilliseconds - * @returns {number} The elapsed time in milliseconds. + * @returns {void} The elapsed time in milliseconds. * @description * This function is a stub that warns that millisecond timing is not supported * in the Phaser Box2D JS implementation. * @throws {Warning} Console warning indicating lack of support. */ -export function b2GetMilliseconds(): number; +export function b2GetMilliseconds(): void; /** * @summary Gets elapsed milliseconds from a b2Timer and resets it. * @function b2GetMillisecondsAndReset - * @param {b2Timer} timer - The Box2D timer object to query and reset - * @returns {number} The elapsed time in milliseconds + * @returns {void} The elapsed time in milliseconds * @description * This function returns the elapsed milliseconds from a Box2D timer object and resets it. * In the JavaScript implementation for Phaser Box2D, this functionality is not supported * and will trigger a warning. * @throws {Warning} Logs a console warning that this function is not supported */ -export function b2GetMillisecondsAndReset(timer: b2Timer): number; +export function b2GetMillisecondsAndReset(): void; /** * @summary Placeholder function for sleep functionality in Box2D JS * @function b2SleepMilliseconds diff --git a/types/include/distance_joint_h.d.ts b/types/include/distance_joint_h.d.ts index 4997665..0d0e202 100644 --- a/types/include/distance_joint_h.d.ts +++ b/types/include/distance_joint_h.d.ts @@ -1 +1 @@ -export { b2DistanceJoint_SetLength, b2DistanceJoint_GetLength, b2DistanceJoint_EnableLimit, b2DistanceJoint_IsLimitEnabled, b2DistanceJoint_SetLengthRange, b2DistanceJoint_GetMinLength, b2DistanceJoint_GetMaxLength, b2DistanceJoint_GetCurrentLength, b2DistanceJoint_EnableSpring, b2DistanceJoint_IsSpringEnabled, b2DistanceJoint_SetSpringHertz, b2DistanceJoint_SetSpringDampingRatio, b2DistanceJoint_GetHertz, b2DistanceJoint_GetDampingRatio, b2DistanceJoint_EnableMotor, b2DistanceJoint_IsMotorEnabled, b2DistanceJoint_SetMotorSpeed, b2DistanceJoint_GetMotorSpeed, b2DistanceJoint_GetMotorForce, b2DistanceJoint_SetMaxMotorForce, b2DistanceJoint_GetMaxMotorForce, b2GetDistanceJointForce, b2PrepareDistanceJoint, b2WarmStartDistanceJoint, b2SolveDistanceJoint, b2DrawDistanceJoint } from "../distance_joint_c.js"; +export { b2DistanceJoint_SetLength, b2DistanceJoint_GetLength, b2DistanceJoint_EnableLimit, b2DistanceJoint_IsLimitEnabled, b2DistanceJoint_SetLengthRange, b2DistanceJoint_GetMinLength, b2DistanceJoint_GetMaxLength, b2DistanceJoint_GetCurrentLength, b2DistanceJoint_EnableSpring, b2DistanceJoint_IsSpringEnabled, b2DistanceJoint_SetSpringHertz, b2DistanceJoint_SetSpringDampingRatio, b2DistanceJoint_GetSpringHertz, b2DistanceJoint_GetSpringDampingRatio, b2DistanceJoint_EnableMotor, b2DistanceJoint_IsMotorEnabled, b2DistanceJoint_SetMotorSpeed, b2DistanceJoint_GetMotorSpeed, b2DistanceJoint_GetMotorForce, b2DistanceJoint_SetMaxMotorForce, b2DistanceJoint_GetMaxMotorForce, b2GetDistanceJointForce, b2PrepareDistanceJoint, b2WarmStartDistanceJoint, b2SolveDistanceJoint, b2DrawDistanceJoint } from "../distance_joint_c.js"; diff --git a/types/include/math_functions_h.d.ts b/types/include/math_functions_h.d.ts index 0a2d16d..3bd484b 100644 --- a/types/include/math_functions_h.d.ts +++ b/types/include/math_functions_h.d.ts @@ -391,14 +391,20 @@ export function b2Distance(a: b2Vec2, b: b2Vec2): number; /** * @function b2DistanceSquared * @summary Calculates the squared distance between two 2D points. - * @param {b2Vec2} a - The first 2D vector point - * @param {b2Vec2} b - The second 2D vector point + * @param {b2Vec2 | {x: number, y: number}} a - The first 2D vector point + * @param {b2Vec2 | {x: number, y: number}} b - The second 2D vector point * @returns {number} The squared distance between points a and b * @description * Computes the squared Euclidean distance between two points without taking the square root. * The calculation is (b.x - a.x)² + (b.y - a.y)² */ -export function b2DistanceSquared(a: b2Vec2, b: b2Vec2): number; +export function b2DistanceSquared(a: b2Vec2 | { + x: number; + y: number; +}, b: b2Vec2 | { + x: number; + y: number; +}): number; /** * Creates a new b2Rot object representing a 2D rotation. * @function b2MakeRot diff --git a/types/include/types_h.d.ts b/types/include/types_h.d.ts index 8088855..964cca3 100644 --- a/types/include/types_h.d.ts +++ b/types/include/types_h.d.ts @@ -775,6 +775,47 @@ export class b2QueryFilter { categoryBits: number; maskBits: number; } +/** + * Prototype for a contact filter callback. + * This is called when a contact pair is considered for collision. This allows you to + * perform custom logic to prevent collision between shapes. This is only called if + * one of the two shapes has custom filtering enabled. + * + * **Notes:** + * - This function must be thread-safe. + * - This is only called if one of the two shapes has enabled custom filtering. + * - This is called only for awake dynamic bodies. + */ +export type b2CustomFilterFcn = (shapeIdA: b2ShapeId, shapeIdB: b2ShapeId, context: any) => boolean; +/** + * Prototype for a pre-solve callback. + * This is called after a contact is updated. This allows you to inspect a + * contact before it goes to the solver. If you are careful, you can modify the + * contact manifold (e.g., modify the normal). + * + * **Notes:** + * - This function must be thread-safe. + * - This is only called if the shape has enabled pre-solve events. + * - This is called only for awake dynamic bodies. + * - This is not called for sensors. + * - The supplied manifold has impulse values from the previous step. + */ +export type b2PreSolveFcn = (shapeIdA: b2ShapeId, shapeIdB: b2ShapeId, manifold: b2Manifold, context: any) => boolean; +/** + * Prototype callback for overlap queries. + * Called for each shape found in the query. + */ +export type b2OverlapResultFcn = (shapeId: b2ShapeId, context: any) => boolean; +/** + * Prototype callback for ray casts. + * Called for each shape found in the query. You control how the ray cast proceeds by returning a float: + * + * - `-1`: Ignore this shape and continue. + * - `0`: Terminate the ray cast. + * - `fraction`: Clip the ray to this point. + * - `1`: Don't clip the ray and continue. + */ +export type b2CastResultFcn = (shapeId: b2ShapeId, point: b2Vec2, normal: b2Vec2, fraction: number, context: any) => number; import { b2Vec2 } from './math_functions_h.js'; import { b2Rot } from './math_functions_h.js'; import { b2AABB } from './math_functions_h.js'; diff --git a/types/include/world_h.d.ts b/types/include/world_h.d.ts index 26818ea..fcda86a 100644 --- a/types/include/world_h.d.ts +++ b/types/include/world_h.d.ts @@ -2,23 +2,22 @@ * @summary Gets the performance profile data for a Box2D world. * @function b2World_GetProfile * @param {b2WorldId} worldId - The identifier of the Box2D world. - * @returns {b2Profile} A profile object containing performance metrics. + * @returns {void} A profile object containing performance metrics. * @description * This function returns performance profiling data for a Box2D world. * Not supported in Phaser Box2D JS implementation. - * @throws {Error} Outputs a console warning indicating lack of support in Phaser Box2D JS. */ -export function b2World_GetProfile(): b2Profile; +export function b2World_GetProfile(worldId: b2WorldId): void; /** * Gets the current counters from a Box2D world instance. * @function b2World_GetCounters * @param {b2WorldId} worldId - The ID of the Box2D world instance. - * @returns {b2Counters} An object containing various Box2D performance counters. + * @returns {void} An object containing various Box2D performance counters. * @description * This function is not supported in the Phaser Box2D JS implementation and will * generate a console warning when called. */ -export function b2World_GetCounters(): b2Counters; +export function b2World_GetCounters(worldId: b2WorldId): void; /** * @summary Dumps memory statistics for a Box2D world (Not supported in Phaser Box2D JS) * @function b2World_DumpMemoryStats @@ -28,12 +27,16 @@ export function b2World_GetCounters(): b2Counters; * This function is a stub that displays a warning message indicating that memory statistics * dumping is not supported in the Phaser Box2D JavaScript implementation. */ -export function b2World_DumpMemoryStats(): void; +export function b2World_DumpMemoryStats(worldId: b2WorldId): void; /** * This file includes code that is: * * - Copyright 2023 Erin Catto, released under the MIT license. * - Copyright 2024 Phaser Studio Inc, released under the MIT license. */ +/** + * @import {b2WorldId} from './id_h.js' + */ export const b2_maxWorkers: 1; +import type { b2WorldId } from './id_h.js'; export { b2SetType, b2World, b2CreateWorldArray, b2GetWorldFromId, b2GetWorld, b2GetWorldLocked, b2CreateWorld, b2World_Step, b2DestroyWorld, b2World_Draw, b2World_OverlapAABB, b2World_OverlapCapsule, b2World_OverlapCircle, b2World_OverlapPolygon, b2World_Explode, b2World_CastCapsule, b2World_CastCircle, b2World_CastPolygon, b2World_CastRay, b2World_CastRayClosest, b2World_GetBodyEvents, b2World_GetContactEvents, b2World_GetGravity, b2World_GetSensorEvents, b2World_SetContactTuning, b2World_SetJointTuning, b2World_SetPreSolveCallback, b2World_SetCustomFilterCallback, b2World_SetGravity, b2World_SetHitEventThreshold, b2World_SetRestitutionThreshold, b2World_IsValid, b2Joint_IsValid, b2World_EnableSleeping, b2World_EnableContinuous, b2World_EnableWarmStarting, b2ValidateConnectivity, b2ValidateSolverSets, b2ValidateContacts, b2CheckIndex, b2Body_IsValid, b2Chain_IsValid, b2Shape_IsValid } from "../world_c.js"; diff --git a/types/island_c.d.ts b/types/island_c.d.ts index a644847..b57f3c8 100644 --- a/types/island_c.d.ts +++ b/types/island_c.d.ts @@ -3,7 +3,7 @@ export function b2DestroyIsland(world: any, islandId: any): void; export function b2GetIsland(world: any, islandId: any): any; export function b2LinkContact(world: any, contact: any): void; export function b2UnlinkContact(world: any, contact: any): void; -export function b2LinkJoint(world: any, joint: any): void; +export function b2LinkJoint(world: any, joint: any, mergeIslands: any): void; export function b2UnlinkJoint(world: any, joint: any): void; export function b2MergeAwakeIslands(world: any): void; export function b2SplitIsland(world: any, baseId: any): void; diff --git a/types/joint_c.d.ts b/types/joint_c.d.ts index 30eeecd..ad32e69 100644 --- a/types/joint_c.d.ts +++ b/types/joint_c.d.ts @@ -1,6 +1,9 @@ /** * @namespace Joint */ +/** + * @import {b2WorldId, b2BodyId} from './include/id_h.js' + */ /** * Creates a default distance joint definition with preset values. * @function b2DefaultDistanceJointDef @@ -415,6 +418,8 @@ declare class b2JointPair { joint: any; jointSim: any; } +import type { b2WorldId } from './include/id_h.js'; import { b2JointId } from "./include/id_h.js"; +import type { b2BodyId } from './include/id_h.js'; import { b2Vec2 } from "./include/math_functions_h.js"; export {}; diff --git a/types/main-prod.d.ts b/types/main-prod.d.ts index 9e2c561..e9f0b1d 100644 --- a/types/main-prod.d.ts +++ b/types/main-prod.d.ts @@ -5,10 +5,10 @@ export { b2MinFloat, b2MaxFloat, b2AbsFloat, b2ClampFloat, b2MinInt, b2MaxInt, b export { b2SetAllocator, b2GetByteCount, b2SetAssertFcn, b2GetVersion, b2CreateTimer, b2GetTicks, b2GetMilliseconds, b2GetMillisecondsAndReset, b2SleepMilliseconds, b2Yield, b2SetLengthUnitsPerMeter, b2GetLengthUnitsPerMeter, B2_NULL_INDEX } from "./include/core_h.js"; export { B2_ID_EQUALS, B2_IS_NULL, B2_IS_NON_NULL, b2WorldId, b2ShapeId, b2BodyId, b2JointId, b2ChainId } from "./include/id_h.js"; export { b2CreateWorld, b2CreateWorldArray, b2DestroyWorld, b2World_IsValid, b2World_Step, b2World_Draw, b2World_GetBodyEvents, b2World_GetSensorEvents, b2World_GetContactEvents, b2World_SetGravity, b2World_GetGravity, b2World_GetProfile, b2World_GetCounters, b2World_OverlapAABB, b2World_OverlapCircle, b2World_OverlapCapsule, b2World_OverlapPolygon, b2World_CastRay, b2World_CastRayClosest, b2World_CastCircle, b2World_CastCapsule, b2World_CastPolygon, b2World_EnableSleeping, b2World_EnableContinuous, b2World_SetRestitutionThreshold, b2World_SetHitEventThreshold, b2World_SetCustomFilterCallback, b2World_SetPreSolveCallback, b2World_Explode, b2World_SetContactTuning, b2World_EnableWarmStarting, b2World_DumpMemoryStats, b2Body_IsValid, b2Shape_IsValid, b2Joint_IsValid, b2Chain_IsValid } from "./include/world_h.js"; -export { b2CreateBody, b2DestroyBody, b2Body_GetType, b2Body_SetType, b2Body_GetPosition, b2Body_GetRotation, b2Body_GetTransform, b2Body_SetTransform, b2Body_ApplyForce, b2Body_ApplyTorque, b2Body_ApplyLinearImpulse, b2Body_ApplyAngularImpulse, b2Body_SetUserData, b2Body_GetUserData, b2Body_GetLocalPoint, b2Body_GetWorldPoint, b2Body_GetLocalVector, b2Body_GetWorldVector, b2Body_GetLinearVelocity, b2Body_GetAngularVelocity, b2Body_SetLinearVelocity, b2Body_SetAngularVelocity, b2Body_ApplyForceToCenter, b2Body_ApplyLinearImpulseToCenter, b2Body_GetMass, b2Body_GetInertiaTensor, b2Body_GetLocalCenterOfMass, b2Body_GetWorldCenterOfMass, b2Body_SetMassData, b2Body_GetMassData, b2Body_ApplyMassFromShapes, b2Body_SetLinearDamping, b2Body_GetLinearDamping, b2Body_SetAngularDamping, b2Body_GetAngularDamping, b2Body_SetGravityScale, b2Body_GetGravityScale, b2Body_IsAwake, b2Body_SetAwake, b2Body_EnableSleep, b2Body_IsSleepEnabled, b2Body_SetSleepThreshold, b2Body_GetSleepThreshold, b2Body_IsEnabled, b2Body_Disable, b2Body_Enable, b2Body_SetFixedRotation, b2Body_IsFixedRotation, b2Body_SetBullet, b2Body_IsBullet, b2Body_EnableHitEvents, b2Body_GetShapeCount, b2Body_GetShapes, b2Body_GetJointCount, b2Body_GetJoints, b2Body_GetContactCapacity, b2Body_GetContactData, b2Body_ComputeAABB } from "./include/body_h.js"; +export { b2CreateBody, b2DestroyBody, b2Body_GetType, b2Body_SetType, b2Body_GetPosition, b2Body_GetRotation, b2Body_GetTransform, b2Body_SetTransform, b2Body_ApplyForce, b2Body_ApplyTorque, b2Body_ApplyLinearImpulse, b2Body_ApplyAngularImpulse, b2Body_SetUserData, b2Body_GetUserData, b2Body_GetLocalPoint, b2Body_GetWorldPoint, b2Body_GetLocalVector, b2Body_GetWorldVector, b2Body_GetLinearVelocity, b2Body_GetAngularVelocity, b2Body_SetLinearVelocity, b2Body_SetAngularVelocity, b2Body_ApplyForceToCenter, b2Body_ApplyLinearImpulseToCenter, b2Body_GetMass, b2Body_GetRotationalInertia, b2Body_GetLocalCenterOfMass, b2Body_GetWorldCenterOfMass, b2Body_SetMassData, b2Body_GetMassData, b2Body_ApplyMassFromShapes, b2Body_SetLinearDamping, b2Body_GetLinearDamping, b2Body_SetAngularDamping, b2Body_GetAngularDamping, b2Body_SetGravityScale, b2Body_GetGravityScale, b2Body_IsAwake, b2Body_SetAwake, b2Body_EnableSleep, b2Body_IsSleepEnabled, b2Body_SetSleepThreshold, b2Body_GetSleepThreshold, b2Body_IsEnabled, b2Body_Disable, b2Body_Enable, b2Body_SetFixedRotation, b2Body_IsFixedRotation, b2Body_SetBullet, b2Body_IsBullet, b2Body_EnableHitEvents, b2Body_GetShapeCount, b2Body_GetShapes, b2Body_GetJointCount, b2Body_GetJoints, b2Body_GetContactCapacity, b2Body_GetContactData, b2Body_ComputeAABB } from "./include/body_h.js"; export { b2CreateCircleShape, b2CreateSegmentShape, b2CreateCapsuleShape, b2CreatePolygonShape, b2DestroyShape, b2Shape_GetType, b2Shape_TestPoint, b2Shape_RayCast, b2Shape_GetBody, b2Shape_IsSensor, b2Shape_SetUserData, b2Shape_GetUserData, b2Shape_SetDensity, b2Shape_GetDensity, b2Shape_SetFriction, b2Shape_GetFriction, b2Shape_SetRestitution, b2Shape_GetRestitution, b2Shape_GetFilter, b2Shape_SetFilter, b2Shape_EnableSensorEvents, b2Shape_AreSensorEventsEnabled, b2Shape_EnableContactEvents, b2Shape_AreContactEventsEnabled, b2Shape_EnablePreSolveEvents, b2Shape_ArePreSolveEventsEnabled, b2Shape_EnableHitEvents, b2Shape_AreHitEventsEnabled, b2Shape_GetCircle, b2Shape_GetSegment, b2Shape_GetChainSegment, b2Shape_GetCapsule, b2Shape_GetPolygon, b2Shape_SetCircle, b2Shape_SetCapsule, b2Shape_SetSegment, b2Shape_SetPolygon, b2Shape_GetParentChain, b2Shape_GetContactCapacity, b2Shape_GetContactData, b2Shape_GetAABB, b2Shape_GetClosestPoint, b2CreateChain, b2Chain_SetFriction, b2Chain_SetRestitution, b2DestroyChain } from "./include/shape_h.js"; export { b2CreateDistanceJoint, b2CreateMotorJoint, b2CreateMouseJoint, b2CreatePrismaticJoint, b2CreateRevoluteJoint, b2CreateWeldJoint, b2CreateWheelJoint, b2DestroyJoint, b2Joint_GetType, b2Joint_GetBodyA, b2Joint_GetBodyB, b2Joint_GetLocalAnchorA, b2Joint_GetLocalAnchorB, b2Joint_SetCollideConnected, b2Joint_GetCollideConnected, b2Joint_SetUserData, b2Joint_GetUserData, b2Joint_WakeBodies, b2Joint_GetConstraintForce, b2Joint_GetConstraintTorque, b2DefaultDistanceJointDef, b2DefaultMotorJointDef, b2DefaultMouseJointDef, b2DefaultPrismaticJointDef, b2DefaultRevoluteJointDef, b2DefaultWeldJointDef, b2DefaultWheelJointDef } from "./include/joint_h.js"; -export { b2DistanceJoint_SetLength, b2DistanceJoint_GetLength, b2DistanceJoint_EnableSpring, b2DistanceJoint_IsSpringEnabled, b2DistanceJoint_SetSpringHertz, b2DistanceJoint_SetSpringDampingRatio, b2DistanceJoint_GetHertz, b2DistanceJoint_GetDampingRatio, b2DistanceJoint_EnableLimit, b2DistanceJoint_IsLimitEnabled, b2DistanceJoint_SetLengthRange, b2DistanceJoint_GetMinLength, b2DistanceJoint_GetMaxLength, b2DistanceJoint_GetCurrentLength, b2DistanceJoint_EnableMotor, b2DistanceJoint_IsMotorEnabled, b2DistanceJoint_SetMotorSpeed, b2DistanceJoint_GetMotorSpeed, b2DistanceJoint_SetMaxMotorForce, b2DistanceJoint_GetMaxMotorForce, b2DistanceJoint_GetMotorForce } from "./include/distance_joint_h.js"; +export { b2DistanceJoint_SetLength, b2DistanceJoint_GetLength, b2DistanceJoint_EnableSpring, b2DistanceJoint_IsSpringEnabled, b2DistanceJoint_SetSpringHertz, b2DistanceJoint_SetSpringDampingRatio, b2DistanceJoint_GetSpringHertz, b2DistanceJoint_GetSpringDampingRatio, b2DistanceJoint_EnableLimit, b2DistanceJoint_IsLimitEnabled, b2DistanceJoint_SetLengthRange, b2DistanceJoint_GetMinLength, b2DistanceJoint_GetMaxLength, b2DistanceJoint_GetCurrentLength, b2DistanceJoint_EnableMotor, b2DistanceJoint_IsMotorEnabled, b2DistanceJoint_SetMotorSpeed, b2DistanceJoint_GetMotorSpeed, b2DistanceJoint_SetMaxMotorForce, b2DistanceJoint_GetMaxMotorForce, b2DistanceJoint_GetMotorForce } from "./include/distance_joint_h.js"; export { b2MotorJoint_SetLinearOffset, b2MotorJoint_GetLinearOffset, b2MotorJoint_SetAngularOffset, b2MotorJoint_GetAngularOffset, b2MotorJoint_SetMaxForce, b2MotorJoint_GetMaxForce, b2MotorJoint_SetMaxTorque, b2MotorJoint_GetMaxTorque, b2MotorJoint_SetCorrectionFactor, b2MotorJoint_GetCorrectionFactor } from "./include/motor_joint_h.js"; export { b2MouseJoint_SetTarget, b2MouseJoint_GetTarget, b2MouseJoint_SetSpringHertz, b2MouseJoint_GetSpringHertz, b2MouseJoint_SetSpringDampingRatio, b2MouseJoint_GetSpringDampingRatio, b2MouseJoint_SetMaxForce, b2MouseJoint_GetMaxForce } from "./include/mouse_joint_h.js"; export { b2PrismaticJoint_EnableSpring, b2PrismaticJoint_IsSpringEnabled, b2PrismaticJoint_SetSpringHertz, b2PrismaticJoint_GetSpringHertz, b2PrismaticJoint_SetSpringDampingRatio, b2PrismaticJoint_GetSpringDampingRatio, b2PrismaticJoint_EnableLimit, b2PrismaticJoint_IsLimitEnabled, b2PrismaticJoint_GetLowerLimit, b2PrismaticJoint_GetUpperLimit, b2PrismaticJoint_SetLimits, b2PrismaticJoint_EnableMotor, b2PrismaticJoint_IsMotorEnabled, b2PrismaticJoint_SetMotorSpeed, b2PrismaticJoint_GetMotorSpeed, b2PrismaticJoint_SetMaxMotorForce, b2PrismaticJoint_GetMaxMotorForce, b2PrismaticJoint_GetMotorForce } from "./include/prismatic_joint_h.js"; diff --git a/types/main.d.ts b/types/main.d.ts index 340419d..7901746 100644 --- a/types/main.d.ts +++ b/types/main.d.ts @@ -5,10 +5,10 @@ export { b2MinFloat, b2MaxFloat, b2AbsFloat, b2ClampFloat, b2MinInt, b2MaxInt, b export { b2SetAllocator, b2GetByteCount, b2SetAssertFcn, b2GetVersion, b2CreateTimer, b2GetTicks, b2GetMilliseconds, b2GetMillisecondsAndReset, b2SleepMilliseconds, b2Yield, b2SetLengthUnitsPerMeter, b2GetLengthUnitsPerMeter, B2_NULL_INDEX } from "./include/core_h.js"; export { B2_ID_EQUALS, B2_IS_NULL, B2_IS_NON_NULL, b2WorldId, b2ShapeId, b2BodyId, b2JointId, b2ChainId } from "./include/id_h.js"; export { b2CreateWorld, b2CreateWorldArray, b2DestroyWorld, b2World_IsValid, b2World_Step, b2World_Draw, b2World_GetBodyEvents, b2World_GetSensorEvents, b2World_GetContactEvents, b2World_SetGravity, b2World_GetGravity, b2World_GetProfile, b2World_GetCounters, b2World_OverlapAABB, b2World_OverlapCircle, b2World_OverlapCapsule, b2World_OverlapPolygon, b2World_CastRay, b2World_CastRayClosest, b2World_CastCircle, b2World_CastCapsule, b2World_CastPolygon, b2World_EnableSleeping, b2World_EnableContinuous, b2World_SetRestitutionThreshold, b2World_SetHitEventThreshold, b2World_SetCustomFilterCallback, b2World_SetPreSolveCallback, b2World_Explode, b2World_SetContactTuning, b2World_EnableWarmStarting, b2World_DumpMemoryStats, b2Body_IsValid, b2Shape_IsValid, b2Joint_IsValid, b2Chain_IsValid } from "./include/world_h.js"; -export { b2CreateBody, b2DestroyBody, b2Body_GetType, b2Body_SetType, b2Body_GetPosition, b2Body_GetRotation, b2Body_GetTransform, b2Body_SetTransform, b2Body_ApplyForce, b2Body_ApplyTorque, b2Body_ApplyLinearImpulse, b2Body_ApplyAngularImpulse, b2Body_SetUserData, b2Body_GetUserData, b2Body_GetLocalPoint, b2Body_GetWorldPoint, b2Body_GetLocalVector, b2Body_GetWorldVector, b2Body_GetLinearVelocity, b2Body_GetAngularVelocity, b2Body_SetLinearVelocity, b2Body_SetAngularVelocity, b2Body_ApplyForceToCenter, b2Body_ApplyLinearImpulseToCenter, b2Body_GetMass, b2Body_GetInertiaTensor, b2Body_GetLocalCenterOfMass, b2Body_GetWorldCenterOfMass, b2Body_SetMassData, b2Body_GetMassData, b2Body_ApplyMassFromShapes, b2Body_SetLinearDamping, b2Body_GetLinearDamping, b2Body_SetAngularDamping, b2Body_GetAngularDamping, b2Body_SetGravityScale, b2Body_GetGravityScale, b2Body_IsAwake, b2Body_SetAwake, b2Body_EnableSleep, b2Body_IsSleepEnabled, b2Body_SetSleepThreshold, b2Body_GetSleepThreshold, b2Body_IsEnabled, b2Body_Disable, b2Body_Enable, b2Body_SetFixedRotation, b2Body_IsFixedRotation, b2Body_SetBullet, b2Body_IsBullet, b2Body_EnableHitEvents, b2Body_GetShapeCount, b2Body_GetShapes, b2Body_GetJointCount, b2Body_GetJoints, b2Body_GetContactCapacity, b2Body_GetContactData, b2Body_ComputeAABB } from "./include/body_h.js"; +export { b2CreateBody, b2DestroyBody, b2Body_GetType, b2Body_SetType, b2Body_GetPosition, b2Body_GetRotation, b2Body_GetTransform, b2Body_SetTransform, b2Body_ApplyForce, b2Body_ApplyTorque, b2Body_ApplyLinearImpulse, b2Body_ApplyAngularImpulse, b2Body_SetUserData, b2Body_GetUserData, b2Body_GetLocalPoint, b2Body_GetWorldPoint, b2Body_GetLocalVector, b2Body_GetWorldVector, b2Body_GetLinearVelocity, b2Body_GetAngularVelocity, b2Body_SetLinearVelocity, b2Body_SetAngularVelocity, b2Body_ApplyForceToCenter, b2Body_ApplyLinearImpulseToCenter, b2Body_GetMass, b2Body_GetRotationalInertia, b2Body_GetLocalCenterOfMass, b2Body_GetWorldCenterOfMass, b2Body_SetMassData, b2Body_GetMassData, b2Body_ApplyMassFromShapes, b2Body_SetLinearDamping, b2Body_GetLinearDamping, b2Body_SetAngularDamping, b2Body_GetAngularDamping, b2Body_SetGravityScale, b2Body_GetGravityScale, b2Body_IsAwake, b2Body_SetAwake, b2Body_EnableSleep, b2Body_IsSleepEnabled, b2Body_SetSleepThreshold, b2Body_GetSleepThreshold, b2Body_IsEnabled, b2Body_Disable, b2Body_Enable, b2Body_SetFixedRotation, b2Body_IsFixedRotation, b2Body_SetBullet, b2Body_IsBullet, b2Body_EnableHitEvents, b2Body_GetShapeCount, b2Body_GetShapes, b2Body_GetJointCount, b2Body_GetJoints, b2Body_GetContactCapacity, b2Body_GetContactData, b2Body_ComputeAABB } from "./include/body_h.js"; export { b2CreateCircleShape, b2CreateSegmentShape, b2CreateCapsuleShape, b2CreatePolygonShape, b2DestroyShape, b2Shape_GetType, b2Shape_TestPoint, b2Shape_RayCast, b2Shape_GetBody, b2Shape_IsSensor, b2Shape_SetUserData, b2Shape_GetUserData, b2Shape_SetDensity, b2Shape_GetDensity, b2Shape_SetFriction, b2Shape_GetFriction, b2Shape_SetRestitution, b2Shape_GetRestitution, b2Shape_GetFilter, b2Shape_SetFilter, b2Shape_EnableSensorEvents, b2Shape_AreSensorEventsEnabled, b2Shape_EnableContactEvents, b2Shape_AreContactEventsEnabled, b2Shape_EnablePreSolveEvents, b2Shape_ArePreSolveEventsEnabled, b2Shape_EnableHitEvents, b2Shape_AreHitEventsEnabled, b2Shape_GetCircle, b2Shape_GetSegment, b2Shape_GetChainSegment, b2Shape_GetCapsule, b2Shape_GetPolygon, b2Shape_SetCircle, b2Shape_SetCapsule, b2Shape_SetSegment, b2Shape_SetPolygon, b2Shape_GetParentChain, b2Shape_GetContactCapacity, b2Shape_GetContactData, b2Shape_GetAABB, b2Shape_GetClosestPoint, b2CreateChain, b2Chain_SetFriction, b2Chain_SetRestitution, b2DestroyChain } from "./include/shape_h.js"; export { b2CreateDistanceJoint, b2CreateMotorJoint, b2CreateMouseJoint, b2CreatePrismaticJoint, b2CreateRevoluteJoint, b2CreateWeldJoint, b2CreateWheelJoint, b2DestroyJoint, b2Joint_GetType, b2Joint_GetBodyA, b2Joint_GetBodyB, b2Joint_GetLocalAnchorA, b2Joint_GetLocalAnchorB, b2Joint_SetCollideConnected, b2Joint_GetCollideConnected, b2Joint_SetUserData, b2Joint_GetUserData, b2Joint_WakeBodies, b2Joint_GetConstraintForce, b2Joint_GetConstraintTorque, b2DefaultDistanceJointDef, b2DefaultMotorJointDef, b2DefaultMouseJointDef, b2DefaultPrismaticJointDef, b2DefaultRevoluteJointDef, b2DefaultWeldJointDef, b2DefaultWheelJointDef } from "./include/joint_h.js"; -export { b2DistanceJoint_SetLength, b2DistanceJoint_GetLength, b2DistanceJoint_EnableSpring, b2DistanceJoint_IsSpringEnabled, b2DistanceJoint_SetSpringHertz, b2DistanceJoint_SetSpringDampingRatio, b2DistanceJoint_GetHertz, b2DistanceJoint_GetDampingRatio, b2DistanceJoint_EnableLimit, b2DistanceJoint_IsLimitEnabled, b2DistanceJoint_SetLengthRange, b2DistanceJoint_GetMinLength, b2DistanceJoint_GetMaxLength, b2DistanceJoint_GetCurrentLength, b2DistanceJoint_EnableMotor, b2DistanceJoint_IsMotorEnabled, b2DistanceJoint_SetMotorSpeed, b2DistanceJoint_GetMotorSpeed, b2DistanceJoint_SetMaxMotorForce, b2DistanceJoint_GetMaxMotorForce, b2DistanceJoint_GetMotorForce } from "./include/distance_joint_h.js"; +export { b2DistanceJoint_SetLength, b2DistanceJoint_GetLength, b2DistanceJoint_EnableSpring, b2DistanceJoint_IsSpringEnabled, b2DistanceJoint_SetSpringHertz, b2DistanceJoint_SetSpringDampingRatio, b2DistanceJoint_GetSpringHertz, b2DistanceJoint_GetSpringDampingRatio, b2DistanceJoint_EnableLimit, b2DistanceJoint_IsLimitEnabled, b2DistanceJoint_SetLengthRange, b2DistanceJoint_GetMinLength, b2DistanceJoint_GetMaxLength, b2DistanceJoint_GetCurrentLength, b2DistanceJoint_EnableMotor, b2DistanceJoint_IsMotorEnabled, b2DistanceJoint_SetMotorSpeed, b2DistanceJoint_GetMotorSpeed, b2DistanceJoint_SetMaxMotorForce, b2DistanceJoint_GetMaxMotorForce, b2DistanceJoint_GetMotorForce } from "./include/distance_joint_h.js"; export { b2MotorJoint_SetLinearOffset, b2MotorJoint_GetLinearOffset, b2MotorJoint_SetAngularOffset, b2MotorJoint_GetAngularOffset, b2MotorJoint_SetMaxForce, b2MotorJoint_GetMaxForce, b2MotorJoint_SetMaxTorque, b2MotorJoint_GetMaxTorque, b2MotorJoint_SetCorrectionFactor, b2MotorJoint_GetCorrectionFactor } from "./include/motor_joint_h.js"; export { b2MouseJoint_SetTarget, b2MouseJoint_GetTarget, b2MouseJoint_SetSpringHertz, b2MouseJoint_GetSpringHertz, b2MouseJoint_SetSpringDampingRatio, b2MouseJoint_GetSpringDampingRatio, b2MouseJoint_SetMaxForce, b2MouseJoint_GetMaxForce } from "./include/mouse_joint_h.js"; export { b2PrismaticJoint_EnableSpring, b2PrismaticJoint_IsSpringEnabled, b2PrismaticJoint_SetSpringHertz, b2PrismaticJoint_GetSpringHertz, b2PrismaticJoint_SetSpringDampingRatio, b2PrismaticJoint_GetSpringDampingRatio, b2PrismaticJoint_EnableLimit, b2PrismaticJoint_IsLimitEnabled, b2PrismaticJoint_GetLowerLimit, b2PrismaticJoint_GetUpperLimit, b2PrismaticJoint_SetLimits, b2PrismaticJoint_EnableMotor, b2PrismaticJoint_IsMotorEnabled, b2PrismaticJoint_SetMotorSpeed, b2PrismaticJoint_GetMotorSpeed, b2PrismaticJoint_SetMaxMotorForce, b2PrismaticJoint_GetMaxMotorForce, b2PrismaticJoint_GetMotorForce } from "./include/prismatic_joint_h.js"; diff --git a/types/manifold_c.d.ts b/types/manifold_c.d.ts index 93c7b87..54ef50e 100644 --- a/types/manifold_c.d.ts +++ b/types/manifold_c.d.ts @@ -67,12 +67,19 @@ export function b2CollideCapsules(capsuleA: b2Capsule, xfA: b2Transform, capsule * @param {b2Transform} xfA - Transform for segmentA containing position and rotation * @param {b2Capsule} capsuleB - A capsule shape defined by two points and a radius * @param {b2Transform} xfB - Transform for capsuleB containing position and rotation - * @returns {b2Manifold} Collision manifold containing contact points and normal + * @param {b2Manifold} manifold - Output collision manifold + * @returns {void} Modifies the manifold parameter with collision data: + * - normalX/Y: Collision normal vector + * - pointCount: Number of contact points (0-2) + * - points[]: Contact point data including: + * - anchorA/B: Contact points in local coordinates + * - separation: Penetration depth + * - id: Contact ID * @description * Converts the segment to a zero-radius capsule and delegates to b2CollideCapsules * for the actual collision computation. */ -export function b2CollideSegmentAndCapsule(segmentA: b2Segment, xfA: b2Transform, capsuleB: b2Capsule, xfB: b2Transform, manifold: any): b2Manifold; +export function b2CollideSegmentAndCapsule(segmentA: b2Segment, xfA: b2Transform, capsuleB: b2Capsule, xfB: b2Transform, manifold: b2Manifold): void; /** * @function b2CollidePolygonAndCapsule * @description @@ -157,11 +164,11 @@ export function b2CollideChainSegmentAndCircle(chainSegmentA: any, xfA: any, cir * @param {b2Transform} xfA - Transform for segmentA * @param {b2Capsule} capsuleB - The capsule shape defined by two centers and a radius * @param {b2Transform} xfB - Transform for capsuleB - * @param {b2SimplexCache} cache - Simplex cache for persistent contact information + * @param {b2DistanceCache} cache - Simplex cache for persistent contact information * @param {b2Manifold} manifold - Contact manifold to store collision results - * @returns {void} + * @returns {b2Manifold} - Modified manifold */ -export function b2CollideChainSegmentAndCapsule(segmentA: b2ChainSegment, xfA: b2Transform, capsuleB: b2Capsule, xfB: b2Transform, cache: b2SimplexCache, manifold: b2Manifold): void; +export function b2CollideChainSegmentAndCapsule(segmentA: b2ChainSegment, xfA: b2Transform, capsuleB: b2Capsule, xfB: b2Transform, cache: b2DistanceCache, manifold: b2Manifold): b2Manifold; /** * @function b2CollideChainSegmentAndPolygon * @param {b2ChainSegment} chainSegmentA - The chain segment shape A @@ -178,6 +185,11 @@ export function b2CollideChainSegmentAndCapsule(segmentA: b2ChainSegment, xfA: b * and can contain 0, 1 or 2 contact points depending on the collision configuration. */ export function b2CollideChainSegmentAndPolygon(chainSegmentA: b2ChainSegment, xfA: b2Transform, polygonB: b2Polygon, xfB: b2Transform, cache: b2DistanceCache, manifold: b2Manifold): b2Manifold; +import type { b2Circle } from './include/collision_h.js'; import { b2Transform } from './include/math_functions_h.js'; +import type { b2Manifold } from './include/collision_h.js'; import { b2Capsule } from './include/collision_h.js'; import { b2Polygon } from './include/collision_h.js'; +import type { b2Segment } from './include/collision_h.js'; +import type { b2ChainSegment } from './include/collision_h.js'; +import type { b2DistanceCache } from './include/collision_h.js'; diff --git a/types/math_functions_c.d.ts b/types/math_functions_c.d.ts index 32017b9..f9cde6e 100644 --- a/types/math_functions_c.d.ts +++ b/types/math_functions_c.d.ts @@ -1,6 +1,9 @@ /** * @namespace MathFunctions */ +/** + * @import {b2Rot} from './include/math_functions_h.js' + */ /** * @summary Checks if a number is valid (finite and not NaN). * @function b2IsValid @@ -21,7 +24,7 @@ export function b2Vec2_IsValid(v: b2Vec2): boolean; /** * Validates a 2D rotation object. * @function b2Rot_IsValid - * @param {b2Rot} q4 - A rotation object containing sine (s) and cosine (c) components + * @param {b2Rot} q - A rotation object containing sine (s) and cosine (c) components * @returns {boolean} True if the rotation is valid, false otherwise * @description * Checks if a b2Rot object is valid by verifying: @@ -29,7 +32,7 @@ export function b2Vec2_IsValid(v: b2Vec2): boolean; * 2. Both sine and cosine components contain valid numbers * 3. The rotation is properly normalized (s² + c² = 1) */ -export function b2Rot_IsValid(q: any): boolean; +export function b2Rot_IsValid(q: b2Rot): boolean; /** * @function b2Normalize * @summary Normalizes a 2D vector to unit length. @@ -64,3 +67,4 @@ export function b2GetLengthAndNormalize(v: b2Vec2): { normal: b2Vec2; }; import { b2Vec2 } from "./include/math_functions_h.js"; +import type { b2Rot } from './include/math_functions_h.js'; diff --git a/types/motor_joint_c.d.ts b/types/motor_joint_c.d.ts index e318b58..a378c38 100644 --- a/types/motor_joint_c.d.ts +++ b/types/motor_joint_c.d.ts @@ -1,6 +1,9 @@ /** * @namespace MotorJoint */ +/** + * @import {b2JointId} from './include/id_h.js' + */ /** * @summary Sets the target linear offset for a motor joint. * @function b2MotorJoint_SetLinearOffset @@ -100,4 +103,5 @@ export function b2GetMotorJointTorque(world: any, base: any): number; export function b2PrepareMotorJoint(base: any, context: any): void; export function b2WarmStartMotorJoint(base: any, context: any): void; export function b2SolveMotorJoint(base: any, context: any, useBias: any): void; +import type { b2JointId } from './include/id_h.js'; import { b2Vec2 } from './include/math_functions_h.js'; diff --git a/types/mouse_joint_c.d.ts b/types/mouse_joint_c.d.ts index 6cd1e23..667dd78 100644 --- a/types/mouse_joint_c.d.ts +++ b/types/mouse_joint_c.d.ts @@ -1,6 +1,9 @@ /** * @namespace MouseJoint */ +/** + * @import {b2JointId} from './include/id_h.js' + */ /** * @summary Sets the target position for a mouse joint. * @function b2MouseJoint_SetTarget @@ -79,4 +82,5 @@ export function b2GetMouseJointTorque(world: any, base: any): number; export function b2PrepareMouseJoint(base: any, context: any): void; export function b2WarmStartMouseJoint(base: any, context: any): void; export function b2SolveMouseJoint(base: any, context: any): void; +import type { b2JointId } from './include/id_h.js'; import { b2Vec2 } from "./include/math_functions_h.js"; diff --git a/types/physics.d.ts b/types/physics.d.ts index 53d4fb1..e634e36 100644 --- a/types/physics.d.ts +++ b/types/physics.d.ts @@ -92,12 +92,15 @@ export function UpdateWorldSprites(worldId: number): void; * Converts a Box2D Body's position and rotation to a Sprite's position and rotation. * * This is called automatically by `UpdateWorldSprites`. - * * @export - * @param {b2Body} body + * @param {{ bodyId: { world0: number; }; }} body * @param {Sprite} sprite */ -export function BodyToSprite(body: b2Body, sprite: Sprite): void; +export function BodyToSprite(body: { + bodyId: { + world0: number; + }; +}, sprite: Sprite): void; /** * @typedef {Object} Sprite * @property {number} x - The x position of the sprite. @@ -156,10 +159,10 @@ export function CreateWorld(data: WorldConfig): { * Steps a physics world to match fixedTimeStep. * Returns the average time spent in the step function. * - * @param {WorldConfig} data - Configuration for the world. + * @param {WorldStepConfig} data - Configuration for the world. * @returns {number} totalTime - Time spent processing the step function, in seconds. */ -export function WorldStep(data: WorldConfig): number; +export function WorldStep(data: WorldStepConfig): number; /** * @typedef {Object} ChainConfig * @property {b2WorldId} worldId - ID for the world. @@ -179,7 +182,7 @@ export function WorldStep(data: WorldConfig): number; * @typedef {Object} BodyCapsule * @property {b2BodyId} bodyId - ID for the body to attach the capsule to. * @property {b2ShapeId} shapeId - ID for the shape to attach the capsule to. - * @propery {b2Capsule} object - The capsule object to attach. + * @property {b2Capsule} object - The capsule object to attach. */ /** * Creates a chain of capsules with each one linked to the previous and next one. @@ -345,7 +348,7 @@ export function CreatePolygon(data: PolygonConfig): { * @property {number} [friction] - Friction of the polygon. * @property {number} [restitution=0.1] - Restitution of the polygon. * @property {any} [color] - Custom color for the polygon. - * @property {number[]} indices - List of indices to the vertices for the polygon. + * @property {number[][]} indices - List of indices to the vertices for the polygon. * @property {number[]} vertices - List of vertices for the polygon in number pairs [x0,y0, x1,y1, ... xN,yN]. * @property {b2Vec2} vertexOffset - Offset to recenter the vertices if they are not zero based. * @property {b2Vec2} vertexScale - Scale for the vertices, defaults to 1, 1. @@ -666,6 +669,10 @@ export type BodyCapsule = { * - ID for the shape to attach the capsule to. */ shapeId: b2ShapeId; + /** + * - The capsule object to attach. + */ + object: b2Capsule; }; export type CircleConfig = { /** @@ -1037,7 +1044,7 @@ export type PolygonVertexConfig = { /** * - List of indices to the vertices for the polygon. */ - indices: number[]; + indices: number[][]; /** * - List of vertices for the polygon in number pairs [x0,y0, x1,y1, ... xN,yN]. */ @@ -1474,7 +1481,17 @@ export type WorldStepConfig = { }; import { b2Vec2 } from './include/math_functions_h.js'; import { b2Rot } from './include/math_functions_h.js'; +import type { b2Body } from './include/body_h.js'; +import type { b2BodyId } from './include/id_h.js'; +import type { b2ShapeId } from './include/id_h.js'; +import type { b2Polygon } from './include/collision_h.js'; import { b2Circle } from './include/collision_h.js'; +import type { b2WorldId } from './include/id_h.js'; +import type { b2JointId } from './include/id_h.js'; +import type { b2WorldDef } from './include/types_h.js'; +import { b2Capsule } from './include/collision_h.js'; +import type { b2BodyDef } from './include/types_h.js'; +import type { b2ShapeDef } from './include/types_h.js'; import { b2RevoluteJointDef } from './include/types_h.js'; import { b2WeldJointDef } from './include/types_h.js'; import { b2DistanceJointDef } from './include/types_h.js'; diff --git a/types/prismatic_joint_c.d.ts b/types/prismatic_joint_c.d.ts index a013ad3..c3c9826 100644 --- a/types/prismatic_joint_c.d.ts +++ b/types/prismatic_joint_c.d.ts @@ -1,6 +1,9 @@ /** * @namespace PrismaticJoint */ +/** + * @import {b2JointId} from './include/id_h.js' + */ /** * @function b2PrismaticJoint_EnableSpring * @summary Enables or disables the spring functionality of a prismatic joint. @@ -177,4 +180,5 @@ export function b2PreparePrismaticJoint(base: any, context: any): void; export function b2WarmStartPrismaticJoint(base: any, context: any): void; export function b2SolvePrismaticJoint(base: any, context: any, useBias: any): void; export function b2DrawPrismaticJoint(draw: any, base: any, transformA: any, transformB: any): void; +import type { b2JointId } from './include/id_h.js'; import { b2Vec2 } from './include/math_functions_h.js'; diff --git a/types/revolute_joint_c.d.ts b/types/revolute_joint_c.d.ts index 04fc9c9..9f0ee51 100644 --- a/types/revolute_joint_c.d.ts +++ b/types/revolute_joint_c.d.ts @@ -1,6 +1,9 @@ /** * @namespace RevoluteJoint */ +/** + * @import {b2JointId} from './include/id_h.js' + */ /** * @function b2RevoluteJoint_EnableSpring * @description @@ -191,4 +194,5 @@ export function b2PrepareRevoluteJoint(base: any, context: any): void; export function b2WarmStartRevoluteJoint(base: any, context: any): void; export function b2SolveRevoluteJoint(base: any, context: any, useBias: any): void; export function b2DrawRevoluteJoint(draw: any, base: any, transformA: any, transformB: any, drawSize: any): void; +import type { b2JointId } from './include/id_h.js'; import { b2Vec2 } from './include/math_functions_h.js'; diff --git a/types/shape_c.d.ts b/types/shape_c.d.ts index bffc22e..d641a5c 100644 --- a/types/shape_c.d.ts +++ b/types/shape_c.d.ts @@ -542,8 +542,13 @@ export function b2Shape_GetAABB(shapeId: b2ShapeId): b2AABB; */ export function b2Shape_GetClosestPoint(shapeId: b2ShapeId, target: b2Vec2): b2Vec2; import { b2ShapeId } from './include/id_h.js'; +import type { b2BodyId } from './include/id_h.js'; +import type { b2ShapeDef } from './include/types_h.js'; import { b2Circle } from './include/collision_h.js'; +import type { b2Capsule } from './include/collision_h.js'; +import type { b2Polygon } from './include/collision_h.js'; import { b2Segment } from './include/collision_h.js'; +import type { b2ChainDef } from './include/types_h.js'; import { b2ChainId } from './include/id_h.js'; import { b2AABB } from './include/math_functions_h.js'; import { b2MassData } from './include/collision_h.js'; @@ -552,3 +557,5 @@ import { b2CastOutput } from './include/collision_h.js'; import { b2DistanceProxy } from './include/collision_h.js'; import { b2WorldId } from './include/id_h.js'; import { b2Vec2 } from './include/math_functions_h.js'; +import type { b2Filter } from './include/types_h.js'; +import type { b2Manifold } from './include/collision_h.js'; diff --git a/types/solver_set_c.d.ts b/types/solver_set_c.d.ts index 6d76648..f4fd00b 100644 --- a/types/solver_set_c.d.ts +++ b/types/solver_set_c.d.ts @@ -1,5 +1,9 @@ export function b2DestroySolverSet(world: any, setIndex: any): void; -export function b2WakeSolverSet(world: any, setIndex: any): void; +/** + * @param {b2World} world + * @param {number} setIndex + */ +export function b2WakeSolverSet(world: b2World, setIndex: number): void; export function b2TrySleepIsland(world: any, islandId: any): void; export function b2MergeSolverSets(world: any, setId1: any, setId2: any): void; export function b2TransferBody(world: any, targetSet: any, sourceSet: any, body: any): void; @@ -7,6 +11,9 @@ export function b2TransferJoint(world: any, targetSet: any, sourceSet: any, join /** * @namespace SolverSet */ +/** + * @import {b2World} from './include/world_h.js' + */ export class b2SolverSet { sims: b2BodySimArray; states: b2BodyStateArray; @@ -15,6 +22,7 @@ export class b2SolverSet { islands: b2IslandArray; setIndex: number; } +import type { b2World } from './include/world_h.js'; import { b2BodySimArray } from './include/block_array_h.js'; import { b2BodyStateArray } from './include/block_array_h.js'; import { b2JointArray } from './include/block_array_h.js'; diff --git a/types/weld_joint_c.d.ts b/types/weld_joint_c.d.ts index 4babb04..a6903a7 100644 --- a/types/weld_joint_c.d.ts +++ b/types/weld_joint_c.d.ts @@ -1,6 +1,9 @@ /** * @namespace WeldJoint */ +/** + * @import {b2JointId} from './include/id_h.js' + */ /** * Sets the linear frequency (hertz) for a weld joint. * @function b2WeldJoint_SetLinearHertz @@ -75,4 +78,5 @@ export function b2GetWeldJointTorque(world: any, base: any): number; export function b2PrepareWeldJoint(base: any, context: any): void; export function b2WarmStartWeldJoint(base: any, context: any): void; export function b2SolveWeldJoint(base: any, context: any, useBias: any): void; +import type { b2JointId } from './include/id_h.js'; import { b2Vec2 } from './include/math_functions_h.js'; diff --git a/types/wheel_joint_c.d.ts b/types/wheel_joint_c.d.ts index a6fe52d..c5603a1 100644 --- a/types/wheel_joint_c.d.ts +++ b/types/wheel_joint_c.d.ts @@ -1,6 +1,9 @@ /** * @namespace WheelJoint */ +/** + * @import {b2JointId} from './include/id_h.js' + */ /** * @function b2WheelJoint_EnableSpring * @description @@ -181,3 +184,4 @@ export function b2PrepareWheelJoint(base: any, context: any): void; export function b2WarmStartWheelJoint(base: any, context: any): void; export function b2SolveWheelJoint(base: any, context: any, useBias: any): void; export function b2DrawWheelJoint(draw: any, base: any, transformA: any, transformB: any): void; +import type { b2JointId } from './include/id_h.js'; diff --git a/types/world_c.d.ts b/types/world_c.d.ts index 08ecd5e..0987422 100644 --- a/types/world_c.d.ts +++ b/types/world_c.d.ts @@ -496,6 +496,12 @@ export function b2ValidateContacts(world: any): void; /** * @namespace World */ +/** + * @import {b2WorldDef, b2DebugDraw, b2QueryFilter} from './include/types_h.js' + * @import {b2ChainId, b2JointId} from './include/id_h.js' + * @import {b2PreSolveFcn, b2CastResultFcn, b2OverlapResultFcn, b2CustomFilterFcn} from './include/types_h.js' + * @import {b2TreeStats, b2Circle, b2Capsule, b2Polygon} from './include/collision_h.js' + */ export const B2_MAX_WORLDS: 32; export namespace b2SetType { let b2_staticSet: number; @@ -508,9 +514,11 @@ export class b2World { broadPhase: b2BroadPhase; constraintGraph: b2ConstraintGraph; bodyArray: any[]; - solverSetArray: any[]; + /** @type {b2SolverSet[]} */ + solverSetArray: b2SolverSet[]; jointArray: any[]; - contactArray: any[]; + /** @type {b2Contact[]} */ + contactArray: b2Contact[]; islandArray: any[]; shapeArray: any[]; chainArray: any[]; @@ -558,17 +566,32 @@ export class b2TaskContext { splitSleepTime: number; splitIslandId: number; } +import type { b2WorldDef } from './include/types_h.js'; import { b2WorldId } from './include/id_h.js'; +import type { b2DebugDraw } from './include/types_h.js'; import { b2BodyEvents } from './include/types_h.js'; import { b2SensorEvents } from './include/types_h.js'; import { b2ContactEvents } from './include/types_h.js'; import { b2BodyId } from './include/id_h.js'; import { b2ShapeId } from './include/id_h.js'; +import type { b2ChainId } from './include/id_h.js'; +import type { b2JointId } from './include/id_h.js'; import { b2AABB } from './include/math_functions_h.js'; +import type { b2QueryFilter } from './include/types_h.js'; +import type { b2OverlapResultFcn } from './include/types_h.js'; +import type { b2Circle } from './include/collision_h.js'; import { b2Transform } from './include/math_functions_h.js'; +import type { b2Capsule } from './include/collision_h.js'; +import type { b2Polygon } from './include/collision_h.js'; import { b2Vec2 } from './include/math_functions_h.js'; +import type { b2CastResultFcn } from './include/types_h.js'; +import type { b2TreeStats } from './include/collision_h.js'; import { b2RayResult } from './include/types_h.js'; +import type { b2PreSolveFcn } from './include/types_h.js'; +import type { b2CustomFilterFcn } from './include/types_h.js'; import { b2StackAllocator } from './include/stack_allocator_h.js'; import { b2BroadPhase } from './include/broad_phase_h.js'; import { b2ConstraintGraph } from './include/constraint_graph_h.js'; +import { b2SolverSet } from './include/solver_set_h.js'; +import { b2Contact } from './include/contact_h.js'; import { b2BitSet } from './include/bitset_h.js';