@newkrok/nape-js 3.5.3 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -32
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +111 -0
- package/dist/index.d.ts +111 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
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.
|
package/dist/index.d.ts
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.
|