@newkrok/nape-js 3.5.3 → 3.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -72,6 +72,36 @@ declare class Vec2 {
72
72
  * const v = Vec2.fromPolar(1, Math.PI / 4); // 45-degree unit vector
73
73
  */
74
74
  static fromPolar(length: number, angle: number, weak?: boolean): Vec2;
75
+ /**
76
+ * Create a unit Vec2 pointing in the given direction (angle in radians).
77
+ * Equivalent to `Vec2.fromPolar(1, radians)`.
78
+ *
79
+ * @param radians - The angle in radians, measured counter-clockwise from the +x axis.
80
+ * @param weak - If true, the returned Vec2 is auto-disposed after one use (default false).
81
+ * @returns A unit Vec2 at the given angle.
82
+ */
83
+ static fromAngle(radians: number, weak?: boolean): Vec2;
84
+ /**
85
+ * Linearly interpolate between two Vec2s. Returns `a + t * (b - a)`.
86
+ * Disposes weak arguments after use.
87
+ *
88
+ * @param a - The start Vec2 (t = 0).
89
+ * @param b - The end Vec2 (t = 1).
90
+ * @param t - The interpolation factor (typically 0–1, but not clamped).
91
+ * @param weak - If true, the returned Vec2 is auto-disposed after one use (default false).
92
+ * @returns A new Vec2 at the interpolated position.
93
+ */
94
+ static lerp(a: Vec2, b: Vec2, t: number, weak?: boolean): Vec2;
95
+ /**
96
+ * Check whether two Vec2s are component-wise equal, within an optional epsilon tolerance.
97
+ * Disposes weak arguments after comparison.
98
+ *
99
+ * @param a - The first Vec2.
100
+ * @param b - The second Vec2.
101
+ * @param epsilon - Maximum allowed difference per component (default 0).
102
+ * @returns `true` if both components differ by at most `epsilon`.
103
+ */
104
+ static eq(a: Vec2, b: Vec2, epsilon?: number): boolean;
75
105
  /**
76
106
  * Squared Euclidean distance between two Vec2s. Avoids a square root when
77
107
  * only comparison is needed.
@@ -140,6 +170,20 @@ declare class Vec2 {
140
170
  * @returns `this` for chaining.
141
171
  */
142
172
  setxy(x: number, y: number): this;
173
+ /**
174
+ * Return a new Vec2 with the same components. Alias for `copy()`.
175
+ *
176
+ * @returns A new Vec2 with the same x and y values.
177
+ */
178
+ clone(): Vec2;
179
+ /**
180
+ * Check whether this Vec2 is component-wise equal to another, within an optional epsilon tolerance.
181
+ *
182
+ * @param other - The Vec2 to compare against.
183
+ * @param epsilon - Maximum allowed difference per component (default 0).
184
+ * @returns `true` if both components differ by at most `epsilon`.
185
+ */
186
+ equals(other: Vec2, epsilon?: number): boolean;
143
187
  /**
144
188
  * Return a new Vec2 with the same components.
145
189
  *
@@ -333,6 +377,19 @@ declare class Vec3 {
333
377
  * @returns `this` for chaining.
334
378
  */
335
379
  setxyz(x: number, y: number, z: number): this;
380
+ /**
381
+ * Check whether this Vec3 is component-wise equal to another, within an optional epsilon tolerance.
382
+ *
383
+ * @param other - The Vec3 to compare against.
384
+ * @param epsilon - Maximum allowed difference per component (default 0).
385
+ * @returns `true` if all three components differ by at most `epsilon`.
386
+ */
387
+ equals(other: Vec3, epsilon?: number): boolean;
388
+ /**
389
+ * Return a new Vec3 with the same components.
390
+ * @returns A copy of this vector.
391
+ */
392
+ clone(): Vec3;
336
393
  /**
337
394
  * Return the x and y components as a new Vec2.
338
395
  * @param weak - If true, the returned Vec2 is a weak (pooled) reference.
@@ -416,6 +473,19 @@ declare class Mat23 {
416
473
  set ty(v: number);
417
474
  /** The determinant of the linear 2×2 part (ad − bc). */
418
475
  get determinant(): number;
476
+ /**
477
+ * Return a new Mat23 with the same components. Alias for `copy()`.
478
+ * @returns A new Mat23 with the same components.
479
+ */
480
+ clone(): Mat23;
481
+ /**
482
+ * Check whether this Mat23 is component-wise equal to another, within an optional epsilon tolerance.
483
+ *
484
+ * @param other - The Mat23 to compare against.
485
+ * @param epsilon - Maximum allowed difference per component (default 0).
486
+ * @returns `true` if all six components differ by at most `epsilon`.
487
+ */
488
+ equals(other: Mat23, epsilon?: number): boolean;
419
489
  /**
420
490
  * Return a new Mat23 with the same components.
421
491
  * @returns A deep copy of this matrix.
@@ -601,6 +671,14 @@ declare class AABB {
601
671
  * @param height - The height of the box (default 0). Must be ≥ 0.
602
672
  */
603
673
  constructor(x?: number, y?: number, width?: number, height?: number);
674
+ /**
675
+ * Create the smallest AABB that contains all the given points.
676
+ * Disposes weak Vec2 arguments after use.
677
+ *
678
+ * @param points - An array of Vec2 points to enclose. Must contain at least one point.
679
+ * @returns A new AABB enclosing all the points.
680
+ */
681
+ static fromPoints(points: Vec2[]): AABB;
604
682
  /** The x position of the left edge (minx). Setting shifts the box horizontally. */
605
683
  get x(): number;
606
684
  /** The x position of the left edge (minx). Setting shifts the box horizontally. */
@@ -640,6 +718,20 @@ declare class AABB {
640
718
  * @param max - A Vec2 whose components become the new (maxx, maxy).
641
719
  */
642
720
  set max(max: any);
721
+ /**
722
+ * Return a new AABB with the same bounds. Alias for `copy()`.
723
+ *
724
+ * @returns A new AABB with the same position and dimensions.
725
+ */
726
+ clone(): AABB;
727
+ /**
728
+ * Check whether this AABB is equal to another, within an optional epsilon tolerance.
729
+ *
730
+ * @param other - The AABB to compare against.
731
+ * @param epsilon - Maximum allowed difference per component (default 0).
732
+ * @returns `true` if all four bounds (minx, miny, maxx, maxy) differ by at most `epsilon`.
733
+ */
734
+ equals(other: AABB, epsilon?: number): boolean;
643
735
  /**
644
736
  * Return a new AABB with the same bounds.
645
737
  *
@@ -686,6 +778,20 @@ declare class MatMN {
686
778
  * @returns The written value.
687
779
  */
688
780
  setx(row: number, col: number, value: number): number;
781
+ /**
782
+ * Check whether this MatMN is element-wise equal to another, within an optional epsilon tolerance.
783
+ * Matrices must have the same dimensions.
784
+ *
785
+ * @param other - The MatMN to compare against.
786
+ * @param epsilon - Maximum allowed difference per element (default 0).
787
+ * @returns `true` if dimensions match and all elements differ by at most `epsilon`.
788
+ */
789
+ equals(other: MatMN, epsilon?: number): boolean;
790
+ /**
791
+ * Return a new MatMN with the same dimensions and element values.
792
+ * @returns A deep copy of this matrix.
793
+ */
794
+ clone(): MatMN;
689
795
  /**
690
796
  * String representation with rows separated by semicolons.
691
797
  * @returns A human-readable string of the matrix elements.
@@ -777,6 +883,11 @@ declare class Ray {
777
883
  * @returns The point `origin + distance * normalised_direction`.
778
884
  */
779
885
  at(distance: number, weak?: boolean): Vec2;
886
+ /**
887
+ * Return a new Ray with the same origin, direction, and maxDistance. Alias for `copy()`.
888
+ * @returns A new Ray with the same properties.
889
+ */
890
+ clone(): Ray;
780
891
  /**
781
892
  * Return a new Ray with the same origin, direction, and maxDistance.
782
893
  * @returns A deep copy of this Ray.
@@ -1075,13 +1186,13 @@ declare class Constraint {
1075
1186
  * The impulse applied to `body` by this constraint in the last simulation step,
1076
1187
  * expressed as a {@link Vec3} `(fx, fy, torque)`.
1077
1188
  *
1078
- * @param body - Must be one of the bodies linked to this constraint.
1189
+ * @param _body - Must be one of the bodies linked to this constraint.
1079
1190
  */
1080
1191
  bodyImpulse(_body: Body): Vec3 | null;
1081
1192
  /**
1082
1193
  * Invokes `fn` once for each distinct body linked to this constraint.
1083
1194
  *
1084
- * @param fn - Function to call for each body.
1195
+ * @param _fn - Function to call for each body.
1085
1196
  */
1086
1197
  visitBodies(_fn: (body: Body) => void): void;
1087
1198
  /**
@@ -1103,25 +1214,58 @@ declare class Constraint {
1103
1214
  */
1104
1215
  declare class InteractionFilter {
1105
1216
  static __name__: string[];
1217
+ /**
1218
+ * @param collisionGroup - Collision group bits (default 1).
1219
+ * @param collisionMask - Collision mask bits (default -1, all bits set).
1220
+ * @param sensorGroup - Sensor group bits (default 1).
1221
+ * @param sensorMask - Sensor mask bits (default -1, all bits set).
1222
+ * @param fluidGroup - Fluid group bits (default 1).
1223
+ * @param fluidMask - Fluid mask bits (default -1, all bits set).
1224
+ */
1106
1225
  constructor(collisionGroup?: number, collisionMask?: number, sensorGroup?: number, sensorMask?: number, fluidGroup?: number, fluidMask?: number);
1226
+ /** Bit-mask identifying which collision group(s) this shape belongs to. */
1107
1227
  get collisionGroup(): number;
1108
1228
  set collisionGroup(value: number);
1229
+ /** Bit-mask of collision groups this shape will collide with. */
1109
1230
  get collisionMask(): number;
1110
1231
  set collisionMask(value: number);
1232
+ /** Bit-mask identifying which sensor group(s) this shape belongs to. */
1111
1233
  get sensorGroup(): number;
1112
1234
  set sensorGroup(value: number);
1235
+ /** Bit-mask of sensor groups this shape will sense. */
1113
1236
  get sensorMask(): number;
1114
1237
  set sensorMask(value: number);
1238
+ /** Bit-mask identifying which fluid group(s) this shape belongs to. */
1115
1239
  get fluidGroup(): number;
1116
1240
  set fluidGroup(value: number);
1241
+ /** Bit-mask of fluid groups this shape will interact with as a fluid. */
1117
1242
  get fluidMask(): number;
1118
1243
  set fluidMask(value: number);
1244
+ /** Arbitrary user data attached to this filter. */
1119
1245
  get userData(): Record<string, unknown>;
1246
+ /** Read-only list of shapes currently using this filter. */
1120
1247
  get shapes(): any;
1248
+ /**
1249
+ * Test whether two filters allow collision interaction.
1250
+ * @param filter - The other filter to test against.
1251
+ * @returns `true` if the two filters' group/mask bits permit collision.
1252
+ */
1121
1253
  shouldCollide(filter: InteractionFilter): boolean;
1254
+ /**
1255
+ * Test whether two filters allow sensor interaction.
1256
+ * @param filter - The other filter to test against.
1257
+ * @returns `true` if the two filters' group/mask bits permit sensing.
1258
+ */
1122
1259
  shouldSense(filter: InteractionFilter): boolean;
1260
+ /**
1261
+ * Test whether two filters allow fluid interaction.
1262
+ * @param filter - The other filter to test against.
1263
+ * @returns `true` if the two filters' group/mask bits permit fluid interaction.
1264
+ */
1123
1265
  shouldFlow(filter: InteractionFilter): boolean;
1266
+ /** Create a copy of this filter with the same group/mask values. */
1124
1267
  copy(): InteractionFilter;
1268
+ /** Return a hex-formatted string representation of all group/mask pairs. */
1125
1269
  toString(): string;
1126
1270
  }
1127
1271
 
@@ -2439,7 +2583,7 @@ declare class Arbiter {
2439
2583
  * Overridden by {@link CollisionArbiter} and {@link FluidArbiter}.
2440
2584
  *
2441
2585
  * @param body - One of the two interacting bodies, or `null` for the combined impulse.
2442
- * @param freshOnly - When `true`, only count fresh (new) contacts. Default `false`.
2586
+ * @param _freshOnly - When `true`, only count fresh (new) contacts. Default `false`.
2443
2587
  */
2444
2588
  totalImpulse(body?: Body | null, _freshOnly?: boolean): Vec3;
2445
2589
  toString(): string;
@@ -3516,6 +3660,194 @@ declare class PulleyJoint extends Constraint {
3516
3660
  visitBodies(lambda: (body: Body) => void): void;
3517
3661
  }
3518
3662
 
3663
+ /**
3664
+ * ZPP_Constraint — Internal base class for all constraints / joints.
3665
+ *
3666
+ * Manages activation/deactivation, callback types, space integration,
3667
+ * and provides stubs for solver methods overridden by joint subclasses.
3668
+ *
3669
+ * Converted from nape-compiled.js lines 21424–21827.
3670
+ */
3671
+ declare class ZPP_Constraint {
3672
+ static __name__: string[];
3673
+ /**
3674
+ * Namespace references, set by the compiled module after import.
3675
+ * _nape = the `nape` public namespace (for CbTypeIterator in copyto)
3676
+ * _zpp = the `zpp_nape` internal namespace (for ZNPList_*, ZPP_CbSet, etc.)
3677
+ */
3678
+ static _nape: any;
3679
+ static _zpp: any;
3680
+ outer: any;
3681
+ id: number;
3682
+ userData: any;
3683
+ compound: any;
3684
+ space: any;
3685
+ active: boolean;
3686
+ stiff: boolean;
3687
+ frequency: number;
3688
+ damping: number;
3689
+ maxForce: number;
3690
+ maxError: number;
3691
+ breakUnderForce: boolean;
3692
+ breakUnderError: boolean;
3693
+ removeOnBreak: boolean;
3694
+ component: any;
3695
+ ignore: boolean;
3696
+ __velocity: boolean;
3697
+ cbTypes: any;
3698
+ cbSet: any;
3699
+ wrap_cbTypes: any;
3700
+ pre_dt: number;
3701
+ __class__: any;
3702
+ constructor();
3703
+ /**
3704
+ * Initialise base constraint fields.
3705
+ * Extracted into a separate method because compiled joint subclasses
3706
+ * call `ZPP_Constraint.call(this)` — ES classes can't be invoked that
3707
+ * way, so the compiled wrapper delegates to this method instead.
3708
+ */
3709
+ _initBase(): void;
3710
+ clear(): void;
3711
+ activeBodies(): void;
3712
+ inactiveBodies(): void;
3713
+ clearcache(): void;
3714
+ validate(): void;
3715
+ wake_connected(): void;
3716
+ forest(): void;
3717
+ broken(): void;
3718
+ warmStart(): void;
3719
+ draw(_g: any): void;
3720
+ pair_exists(_id: any, _di: any): boolean;
3721
+ preStep(_dt: number): boolean;
3722
+ applyImpulseVel(): boolean;
3723
+ applyImpulsePos(): boolean;
3724
+ copy(_dict?: any, _todo?: any): any;
3725
+ immutable_midstep(name: string): void;
3726
+ setupcbTypes(): void;
3727
+ immutable_cbTypes(): void;
3728
+ wrap_cbTypes_subber(pcb: any): void;
3729
+ wrap_cbTypes_adder(cb: any): boolean;
3730
+ insert_cbtype(cb: any): void;
3731
+ alloc_cbSet(): void;
3732
+ dealloc_cbSet(): void;
3733
+ activate(): void;
3734
+ deactivate(): void;
3735
+ addedToSpace(): void;
3736
+ removedFromSpace(): void;
3737
+ activeInSpace(): void;
3738
+ inactiveOrOutSpace(): void;
3739
+ wake(): void;
3740
+ copyto(ret: any): void;
3741
+ static _findRoot(comp: any): any;
3742
+ static _unionComponents(a: any, b: any): void;
3743
+ }
3744
+
3745
+ /**
3746
+ * ZPP_UserBody — pairs a body with a reference count for user constraints.
3747
+ *
3748
+ * Converted from nape-compiled.js lines 28038–28054.
3749
+ */
3750
+ declare class ZPP_UserBody {
3751
+ static __name__: string[];
3752
+ cnt: number;
3753
+ body: any;
3754
+ constructor(cnt: number, body: any);
3755
+ }
3756
+
3757
+ /**
3758
+ * ZPP_UserConstraint — Internal N-DOF user-defined constraint with Cholesky decomposition.
3759
+ *
3760
+ * A generic constraint where the user supplies callbacks for effective mass,
3761
+ * velocity/position errors, impulse application, and clamping. The solver
3762
+ * factorises the effective-mass matrix via Cholesky (solve/transform) and
3763
+ * drives the constraint each step through warmStart / applyImpulseVel /
3764
+ * applyImpulsePos.
3765
+ *
3766
+ * Converted from nape-compiled.js lines 27368–28037.
3767
+ */
3768
+
3769
+ declare class ZPP_UserConstraint extends ZPP_Constraint {
3770
+ static __name__: string[];
3771
+ static __super__: typeof ZPP_Constraint;
3772
+ outer_zn: any;
3773
+ bodies: ZPP_UserBody[];
3774
+ dim: number;
3775
+ jAcc: number[];
3776
+ bias: number[];
3777
+ stepped: boolean;
3778
+ L: number[];
3779
+ y: number[];
3780
+ soft: number;
3781
+ gamma: number;
3782
+ velonly: boolean;
3783
+ jMax: number;
3784
+ Keff: number[];
3785
+ vec3: any;
3786
+ J: number[];
3787
+ jOld: number[];
3788
+ __class__: any;
3789
+ constructor(dim: number, velonly: boolean);
3790
+ bindVec2_invalidate(_: any): void;
3791
+ addBody(b: any): void;
3792
+ remBody(b: any): boolean;
3793
+ bodyImpulse(b: any): any;
3794
+ activeBodies(): void;
3795
+ inactiveBodies(): void;
3796
+ copy(_dict: any, _todo: any): any;
3797
+ validate(): void;
3798
+ wake_connected(): void;
3799
+ forest(): void;
3800
+ pair_exists(id: number, di: number): boolean;
3801
+ broken(): void;
3802
+ clearcache(): void;
3803
+ lsq(v: number[]): number;
3804
+ _clamp(v: number[], max: number): void;
3805
+ solve(m: number[]): number[];
3806
+ transform(L: number[], x: number[]): void;
3807
+ preStep(dt: number): boolean;
3808
+ warmStart(): void;
3809
+ applyImpulseVel(): boolean;
3810
+ applyImpulsePos(): boolean;
3811
+ draw(g: any): void;
3812
+ }
3813
+
3814
+ /**
3815
+ * Base class for user-defined N-DOF constraints.
3816
+ *
3817
+ * Fully modernized — uses ZPP_UserConstraint directly (extracted to TypeScript).
3818
+ * Subclass and override the abstract callback methods to define custom constraints.
3819
+ */
3820
+ declare abstract class UserConstraint extends Constraint {
3821
+ zpp_inner: ZPP_UserConstraint;
3822
+ constructor(dimensions: number, velocityOnly?: boolean);
3823
+ __bindVec2(): Vec2;
3824
+ /** Create a copy of this constraint. Must be overridden. */
3825
+ __copy(): UserConstraint;
3826
+ /** Called when the constraint breaks. Optional override. */
3827
+ __broken(): void;
3828
+ /** Called to validate the constraint. Optional override. */
3829
+ __validate(): void;
3830
+ /** Draw debug visualization. Optional override. */
3831
+ __draw(_debug: any): void;
3832
+ /** Prepare the constraint for solving. Optional override. */
3833
+ __prepare(): void;
3834
+ /** Compute positional error. Must be overridden for non-velocity-only constraints. */
3835
+ __position(_err: number[]): void;
3836
+ /** Compute velocity error. Must be overridden. */
3837
+ __velocity(_err: number[]): void;
3838
+ /** Compute effective mass matrix (upper triangle). Must be overridden. */
3839
+ __eff_mass(_eff: number[]): void;
3840
+ /** Clamp accumulated impulse. Optional override. */
3841
+ __clamp(_jAcc: number[]): void;
3842
+ /** Apply impulse to a body. Must be overridden. */
3843
+ __impulse(_imp: number[], _body: Body, _out: any): void;
3844
+ impulse(): MatMN;
3845
+ bodyImpulse(body: Body): Vec3;
3846
+ visitBodies(lambda: (body: Body) => void): void;
3847
+ __invalidate(): void;
3848
+ __registerBody(oldBody: Body | null, newBody: Body | null): Body | null;
3849
+ }
3850
+
3519
3851
  declare const VERSION: string;
3520
3852
 
3521
- export { AABB, AngleJoint, Arbiter, ArbiterType, Body, BodyCallback, BodyListener, BodyType, Broadphase, Callback, CbEvent, CbType, Circle, CollisionArbiter, Compound, Constraint, ConstraintCallback, ConstraintListener, Contact, ConvexResult, DistanceJoint, Edge, FluidArbiter, FluidProperties, Geom, GeomPoly, GravMassMode, InertiaMode, InteractionCallback, InteractionFilter, InteractionGroup, InteractionListener, InteractionType, Interactor, LineJoint, Listener, ListenerType, MarchingSquares, MassMode, Mat23, MatMN, Material, MotorJoint, NapeList, OptionType, PivotJoint, Polygon, PreCallback, PreFlag, PreListener, PulleyJoint, Ray, RayResult, Shape, ShapeType, Space, VERSION, ValidationResult, Vec2, Vec3, WeldJoint, Winding };
3853
+ export { AABB, AngleJoint, Arbiter, ArbiterType, Body, BodyCallback, BodyListener, BodyType, Broadphase, Callback, CbEvent, CbType, type CbTypeSet, Circle, CollisionArbiter, Compound, Constraint, ConstraintCallback, ConstraintListener, Contact, ConvexResult, DistanceJoint, Edge, FluidArbiter, FluidProperties, Geom, GeomPoly, GravMassMode, InertiaMode, InteractionCallback, InteractionFilter, InteractionGroup, InteractionListener, InteractionType, Interactor, LineJoint, Listener, ListenerType, MarchingSquares, MassMode, Mat23, MatMN, Material, MotorJoint, NapeList, OptionType, PivotJoint, Polygon, PreCallback, PreFlag, PreListener, PulleyJoint, Ray, RayResult, Shape, ShapeType, Space, UserConstraint, VERSION, ValidationResult, Vec2, Vec3, WeldJoint, Winding };