@pacem/pacem-numerical 1.0.0-bessel → 1.0.0-dirac

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.
@@ -1,23 +1,80 @@
1
1
  import { Point } from '@pacem/pacem-foundation';
2
2
  import { Rect } from '@pacem/pacem-foundation';
3
3
 
4
+ /** Represents a complex number as an immutable pair of real and imaginary components. */
4
5
  declare interface Complex {
6
+ /** Real part. */
5
7
  readonly real: number;
8
+ /** Imaginary part. */
6
9
  readonly img: number;
7
10
  }
8
11
 
12
+ /** Utility tools to build and operate on {@link Complex} numbers. */
9
13
  declare class Complex {
14
+ /**
15
+ * Returns the provided value unchanged if it is already a {@link Complex} number.
16
+ * @param z A complex number (or a real number, treated as having a zero imaginary part).
17
+ */
10
18
  static build(z: Complex | number): Complex;
19
+ /**
20
+ * Builds a new {@link Complex} number from its real and imaginary components.
21
+ * @param real Real part.
22
+ * @param img Imaginary part.
23
+ */
11
24
  static build(real: number, img: number): Complex;
25
+ /**
26
+ * Adds two complex numbers (real numbers are treated as having a zero imaginary part).
27
+ * @param a First addend.
28
+ * @param b Second addend.
29
+ */
12
30
  static add(a: Complex | number, b: Complex | number): Complex;
31
+ /**
32
+ * Subtracts one complex number from another.
33
+ * @param from Minuend.
34
+ * @param what Subtrahend.
35
+ */
13
36
  static subtract(from: Complex | number, what: Complex | number): Complex;
37
+ /**
38
+ * Multiplies two complex numbers.
39
+ * @param a First factor.
40
+ * @param b Second factor.
41
+ */
14
42
  static multiply(a: Complex | number, b: Complex | number): Complex;
43
+ /**
44
+ * Divides one complex number by another.
45
+ * @param a Dividend.
46
+ * @param b Divisor.
47
+ * @returns The quotient, or {@link Complex.NaC} if the divisor is (close to) zero.
48
+ */
15
49
  static divide(a: Complex | number, b: Complex | number): Complex;
50
+ /**
51
+ * Returns the squared modulus (|z|²) of the complex number, i.e. real² + img².
52
+ * Cheaper than {@link modulus} since it avoids the square root.
53
+ * @param c
54
+ */
16
55
  static absSquare(c: Complex | number): number;
56
+ /**
57
+ * Returns the modulus (magnitude) of the complex number.
58
+ * @param c
59
+ */
17
60
  static modulus(c: Complex | number): number;
61
+ /**
62
+ * Type guard checking whether the provided value is a {@link Complex} number.
63
+ * @param c
64
+ */
18
65
  static isComplex(c: any): c is Complex;
66
+ /**
67
+ * Returns the complex conjugate: same real part, negated imaginary part.
68
+ * @param a
69
+ */
19
70
  static conjugate(a: Complex | number): Complex;
71
+ /**
72
+ * Checks whether two complex numbers have the same real and imaginary parts.
73
+ * @param c1
74
+ * @param c2
75
+ */
20
76
  static equals(c1: Complex | number, c2: Complex | number): boolean;
77
+ /** The "Not a Complex" sentinel value (`NaN + NaNi`), returned by operations on invalid input. */
21
78
  static get NaC(): Complex;
22
79
  }
23
80
 
@@ -36,6 +93,7 @@ export declare namespace DataAnalysis {
36
93
  }
37
94
  }
38
95
 
96
+ /** Discrete Fourier Transform (DFT) utilities, including a Cooley-Tukey FFT fast path for power-of-two inputs. */
39
97
  declare class Fourier {
40
98
  /**
41
99
  * Checks the input vector and outputs a frequency vector using the best performing algo.
@@ -66,11 +124,21 @@ declare class Fourier {
66
124
  static fft(data: (Complex | number)[], normalize?: boolean): Complex[];
67
125
  }
68
126
 
127
+ /** Represents a Gaussian (normal) distribution and exposes its density and cumulative probability functions. */
69
128
  declare class Gaussian {
129
+ /**
130
+ * Creates a new {@link Gaussian} distribution with the given mean and standard deviation.
131
+ * @param mean Mean (μ) of the distribution.
132
+ * @param stdev Standard deviation (σ) of the distribution (its absolute value is used).
133
+ */
70
134
  constructor(mean: number, stdev: number);
135
+ /** Mean (μ) of the distribution. */
71
136
  readonly mean: number;
137
+ /** Standard deviation (σ) of the distribution. */
72
138
  readonly stdev: number;
139
+ /** Variance (σ²) of the distribution. */
73
140
  readonly variance: number;
141
+ /** The standard normal distribution (mean 0, standard deviation 1). */
74
142
  static get normal(): Gaussian;
75
143
  /**
76
144
  * Un-normalized probability density function.
@@ -102,19 +170,52 @@ export declare namespace Geometry {
102
170
  }
103
171
  }
104
172
 
173
+ /** Common contract for the interpolation strategies of this module: given an x, returns the estimated y. */
105
174
  declare interface Interpolator {
175
+ /**
176
+ * Evaluates the interpolated function at the given x.
177
+ * @param x Input value.
178
+ * @returns The interpolated y value.
179
+ */
106
180
  interpolate(x: number): number;
107
181
  }
108
182
 
183
+ /**
184
+ * Lagrange polynomial interpolation, evaluated using the numerically stable barycentric form.
185
+ * Given a set of `(x, y)` points, builds the unique polynomial of minimal degree passing through
186
+ * all of them and evaluates it at arbitrary x values.
187
+ */
109
188
  declare class Lagrange implements Interpolator {
110
189
  #private;
190
+ /** Use {@link Lagrange.create} to build an instance. */
111
191
  protected constructor(points: Point[]);
112
192
  private _prepareBarycentric;
113
193
  private _computeBarycentric;
194
+ /**
195
+ * Evaluates the Lagrange interpolating polynomial at the given x, using barycentric weights.
196
+ * @param x Input value.
197
+ * @returns The interpolated y value (the exact node y if x coincides with a node).
198
+ */
114
199
  interpolate(x: number): number;
200
+ /**
201
+ * Builds a {@link Lagrange} interpolator from a set of y values, using their array index as x.
202
+ * @param values y values, implicitly located at x = 0, 1, 2, ...
203
+ */
115
204
  static create(...values: number[]): Lagrange;
205
+ /**
206
+ * Builds a {@link Lagrange} interpolator from a set of points.
207
+ * @param points Points to interpolate through.
208
+ */
116
209
  static create(...points: Point[]): Lagrange;
210
+ /**
211
+ * Builds a {@link Lagrange} interpolator from a set of points.
212
+ * @param points Points to interpolate through.
213
+ */
117
214
  static create(points: Point[]): Lagrange;
215
+ /**
216
+ * Builds a {@link Lagrange} interpolator from a set of y values, using their array index as x.
217
+ * @param values y values, implicitly located at x = 0, 1, 2, ...
218
+ */
118
219
  static create(values: number[]): Lagrange;
119
220
  }
120
221
 
@@ -144,6 +245,10 @@ export declare namespace Mathematics {
144
245
  }
145
246
  }
146
247
 
248
+ /**
249
+ * Represents a 4x4 transformation matrix in 3D space, in row-major layout (`m{row}{col}`, with the
250
+ * 4th column split out as `offsetX`/`offsetY`/`offsetZ`/`m44` for the translation and perspective terms).
251
+ */
147
252
  declare interface Matrix3D {
148
253
  m11: number;
149
254
  m12: number;
@@ -163,24 +268,87 @@ declare interface Matrix3D {
163
268
  m44: number;
164
269
  }
165
270
 
271
+ /** Utilities to build, combine and invert 4x4 transformation matrices ({@link Matrix3D}) in 3D space. */
166
272
  declare class Matrix3D {
167
273
  /**
168
274
  * Identity 4x4 matrix.
169
275
  * @returns
170
276
  */
171
277
  static identity(): Matrix3D;
278
+ /**
279
+ * Builds a {@link Matrix3D} from its 16 components, in row-major order.
280
+ * @param args Exactly 16 numbers.
281
+ * @throws If the number of arguments is not exactly 16.
282
+ */
172
283
  static from(...args: number[]): Matrix3D;
284
+ /**
285
+ * Returns the transpose of the given matrix (rows and columns swapped).
286
+ * @param m
287
+ */
173
288
  static transpose(m: Matrix3D): Matrix3D;
289
+ /**
290
+ * Flattens the matrix into a 16-number array, in row-major order (the same order accepted by {@link from}).
291
+ * @param m
292
+ */
174
293
  static toArray(m: Matrix3D): number[];
294
+ /**
295
+ * Returns a copy of the given matrix.
296
+ * @param m
297
+ */
175
298
  static clone(m: Matrix3D): Matrix3D;
299
+ /**
300
+ * Returns a copy of the given matrix, after applying an in-place modification callback to it.
301
+ * @param m
302
+ * @param modifier Callback invoked on the cloned matrix to alter its content.
303
+ */
176
304
  static clone(m: Matrix3D, modifier: (m: Matrix3D) => void): Matrix3D;
305
+ /**
306
+ * Returns a copy of the matrix scaled by the components of a vector.
307
+ * @param m
308
+ * @param v Per-axis scale factors.
309
+ */
177
310
  static scale(m: Matrix3D, v: Vector3D): Matrix3D;
311
+ /**
312
+ * Returns a copy of the matrix uniformly scaled by a single factor.
313
+ * @param m
314
+ * @param scale
315
+ */
178
316
  static scale(m: Matrix3D, scale: number): Matrix3D;
317
+ /**
318
+ * Returns a copy of the matrix scaled by independent per-axis factors.
319
+ * @param m
320
+ * @param sx
321
+ * @param sy
322
+ * @param sz
323
+ */
179
324
  static scale(m: Matrix3D, sx: number, sy: number, sz: number): Matrix3D;
325
+ /**
326
+ * Returns a copy of the matrix translated (offset) by the given vector.
327
+ * @param m
328
+ * @param offset
329
+ */
180
330
  static translate(m: Matrix3D, offset: Vector3D): Matrix3D;
331
+ /**
332
+ * Parses a string representation of a matrix (16 numbers) into a {@link Matrix3D}.
333
+ * @param input String to parse.
334
+ * @throws If the input cannot be parsed as exactly 16 numbers.
335
+ */
181
336
  static parse(input: string): Matrix3D;
337
+ /**
338
+ * Checks whether the matrix is the identity matrix.
339
+ * @param m
340
+ */
182
341
  static isIdentity(m: Matrix3D): boolean;
342
+ /**
343
+ * Checks whether the matrix represents a pure affine transform, i.e. it has no perspective
344
+ * component (its 4th column is `(0, 0, 0, 1)`).
345
+ * @param m
346
+ */
183
347
  static isAffine(m: Matrix3D): boolean;
348
+ /**
349
+ * Computes the determinant of the matrix.
350
+ * @param m
351
+ */
184
352
  static determinant(m: Matrix3D): number;
185
353
  /**
186
354
  * Multiplies two matrices in the provided order (i.e.: applies {@link m2} to {@link m1}).
@@ -188,6 +356,12 @@ declare class Matrix3D {
188
356
  * @returns Combination matrix.
189
357
  */
190
358
  static multiply(...matrices: Matrix3D[]): Matrix3D;
359
+ /**
360
+ * Computes the inverse of the matrix, using the cofactor/adjugate method (with a specialized,
361
+ * cheaper path for affine matrices).
362
+ * @param m
363
+ * @returns The inverse matrix, or `null` if the matrix is singular (determinant is 0).
364
+ */
191
365
  static invert(m: Matrix3D): Matrix3D;
192
366
  /**
193
367
  * Moves a given point in 3D space given the transformation matrix.
@@ -201,14 +375,42 @@ declare interface Mesh extends Polygon {
201
375
  triangleIndices: number[];
202
376
  }
203
377
 
378
+ /**
379
+ * Newton's divided-difference polynomial interpolation.
380
+ * Builds the same interpolating polynomial as {@link Lagrange} but represents it in Newton form
381
+ * (a nested/Horner-like product of divided differences), which is efficient to evaluate and to
382
+ * extend incrementally as new points are added.
383
+ */
204
384
  declare class Newton implements Interpolator {
205
385
  private xs;
206
386
  private coeffs;
387
+ /** Use {@link Newton.create} to build an instance. */
207
388
  private constructor();
389
+ /**
390
+ * Evaluates the Newton form of the interpolating polynomial at the given x, via nested multiplication.
391
+ * @param x Input value.
392
+ * @returns The interpolated y value (`NaN` if the interpolator has no points).
393
+ */
208
394
  interpolate(x: number): number;
395
+ /**
396
+ * Builds a {@link Newton} interpolator from a set of y values, using their array index as x.
397
+ * @param values y values, implicitly located at x = 0, 1, 2, ...
398
+ */
209
399
  static create(...values: number[]): Newton;
400
+ /**
401
+ * Builds a {@link Newton} interpolator from a set of points.
402
+ * @param points Points to interpolate through.
403
+ */
210
404
  static create(...points: Point[]): Newton;
405
+ /**
406
+ * Builds a {@link Newton} interpolator from a set of points.
407
+ * @param points Points to interpolate through.
408
+ */
211
409
  static create(points: Point[]): Newton;
410
+ /**
411
+ * Builds a {@link Newton} interpolator from a set of y values, using their array index as x.
412
+ * @param values y values, implicitly located at x = 0, 1, 2, ...
413
+ */
212
414
  static create(values: number[]): Newton;
213
415
  }
214
416
 
@@ -220,37 +422,100 @@ export declare namespace NumberTheory {
220
422
 
221
423
  declare type NumericKeySelector<T> = (item: T, index?: number) => number;
222
424
 
425
+ /**
426
+ * Piecewise Cubic Hermite Interpolating Polynomial (PCHIP).
427
+ * Builds a shape-preserving (monotonicity-respecting) piecewise-cubic curve through a set of
428
+ * `(x, y)` points: unlike {@link Lagrange}, it does not overshoot between nodes, at the cost of
429
+ * only being C¹ (continuous first derivative, not second).
430
+ */
223
431
  declare class Pchip implements Interpolator {
224
432
  private xs;
225
433
  private ys;
226
434
  private ms;
435
+ /** Use {@link Pchip.create} to build an instance. */
227
436
  private constructor();
228
437
  private computeDerivatives;
438
+ /**
439
+ * Evaluates the PCHIP curve at the given x, using cubic Hermite interpolation on the enclosing segment.
440
+ * Values outside the node range are linearly extrapolated using the boundary derivative.
441
+ * @param x Input value.
442
+ * @returns The interpolated y value.
443
+ */
229
444
  interpolate(x: number): number;
445
+ /**
446
+ * Builds a {@link Pchip} interpolator from a set of y values, using their array index as x.
447
+ * @param values y values, implicitly located at x = 0, 1, 2, ...
448
+ */
230
449
  static create(...values: number[]): Pchip;
450
+ /**
451
+ * Builds a {@link Pchip} interpolator from a set of points (at least 2).
452
+ * @param points Points to interpolate through.
453
+ */
231
454
  static create(...points: Point[]): Pchip;
455
+ /**
456
+ * Builds a {@link Pchip} interpolator from a set of points (at least 2).
457
+ * @param points Points to interpolate through.
458
+ */
232
459
  static create(points: Point[]): Pchip;
460
+ /**
461
+ * Builds a {@link Pchip} interpolator from a set of y values, using their array index as x.
462
+ * @param values y values, implicitly located at x = 0, 1, 2, ...
463
+ */
233
464
  static create(values: number[]): Pchip;
234
465
  }
235
466
 
467
+ /** A point (or free vector) in 3D space. */
236
468
  declare interface Point3D {
237
469
  x: number;
238
470
  y: number;
239
471
  z: number;
240
472
  }
241
473
 
474
+ /** A (2D) polygon, represented as its ordered list of vertices. */
242
475
  declare interface Polygon {
243
476
  vertices: Point[];
244
477
  }
245
478
 
479
+ /** Utility tools to build and inspect {@link Polygon}s. */
246
480
  declare class Polygon {
247
481
  private static readonly _eps;
482
+ /**
483
+ * Type guard checking whether the provided value is a valid {@link Polygon} (has at least 3 point vertices).
484
+ * @param obj
485
+ */
248
486
  static isPolygon(obj: any): obj is Polygon;
487
+ /**
488
+ * Builds a polygon from the provided vertices, in order.
489
+ * @param points Vertices of the polygon.
490
+ */
249
491
  static from(...points: Point[]): Polygon;
492
+ /**
493
+ * Checks whether a point lies inside the polygon.
494
+ * @param polygon
495
+ * @param p Point to test.
496
+ */
250
497
  static contains(polygon: Polygon, p: Point): any;
498
+ /**
499
+ * Returns the center of the polygon's bounding box.
500
+ * Note: this is not the geometric centroid (center of mass) for non-symmetric polygons.
501
+ * @param polygon
502
+ */
251
503
  static centroid(polygon: Polygon): Point;
504
+ /**
505
+ * Computes the axis-aligned bounding box of the polygon.
506
+ * @param polygon
507
+ */
252
508
  static boundingBox(polygon: Polygon): Rect;
509
+ /**
510
+ * Returns the polygon's edges as an ordered list of segments, each joining a vertex to the next
511
+ * (the last one wrapping back to the first).
512
+ * @param polygon
513
+ */
253
514
  static sides(polygon: Polygon): Segment[];
515
+ /**
516
+ * Checks whether the polygon is convex, i.e. all its interior angles turn in the same rotational direction.
517
+ * @param polygon
518
+ */
254
519
  static isConvex(polygon: Polygon): boolean;
255
520
  /**
256
521
  * Check whether a polygon is a self-intersecting one.
@@ -278,6 +543,12 @@ declare class Polygon {
278
543
  * @returns
279
544
  */
280
545
  static area(polygon: Polygon): number;
546
+ /**
547
+ * Computes the intersection area(s) between two polygons.
548
+ * @param polygon1
549
+ * @param polygon2
550
+ * @returns The overlapping area(s) as one or more polygons.
551
+ */
281
552
  static intersect(polygon1: Polygon, polygon2: Polygon): Polygon[];
282
553
  /**
283
554
  * Returns the convex hull of a polygon.
@@ -289,6 +560,10 @@ declare class Polygon {
289
560
 
290
561
  declare type PolygonCompound = 'union' | 'intersect' | 'difference';
291
562
 
563
+ /**
564
+ * Represents a rotation in 3D space as a unit quaternion `x·i + y·j + z·k + w`, avoiding the gimbal-lock
565
+ * issues of Euler angles and allowing smooth interpolation between orientations.
566
+ */
292
567
  declare interface Quaternion {
293
568
  x: number;
294
569
  y: number;
@@ -296,10 +571,28 @@ declare interface Quaternion {
296
571
  w: number;
297
572
  }
298
573
 
574
+ /** Utilities to build, combine and convert {@link Quaternion} rotations. */
299
575
  declare class Quaternion {
576
+ /** Returns the identity quaternion (no rotation). */
300
577
  static identity(): Quaternion;
578
+ /**
579
+ * Builds a {@link Quaternion} from its x, y, z, w components, in that order.
580
+ * @param args Exactly 4 numbers: x, y, z, w.
581
+ * @throws If the number of arguments is not exactly 4.
582
+ */
301
583
  static from(...args: number[]): Quaternion;
584
+ /**
585
+ * Parses a string representation of a quaternion (4 numbers) into a {@link Quaternion}.
586
+ * @param input String to parse.
587
+ * @throws If the input cannot be parsed as exactly 4 numbers.
588
+ */
302
589
  static parse(input: string): Quaternion;
590
+ /**
591
+ * Builds the (shortest-arc) quaternion representing the rotation that takes one unit vector onto another.
592
+ * Normalizes both input vectors in place as a side effect.
593
+ * @param from Source direction.
594
+ * @param to Target direction.
595
+ */
303
596
  static fromVectors(from: Vector3D, to: Vector3D): Quaternion;
304
597
  /**
305
598
  * In-place normalizarion of the provided quaternion
@@ -322,21 +615,48 @@ declare class Quaternion {
322
615
  * @param rotationMatrix
323
616
  */
324
617
  static fromRotationMatrix(rotationMatrix: Matrix3D): Quaternion;
618
+ /**
619
+ * Returns the conjugate of the quaternion (vector part negated). For a unit quaternion, this
620
+ * represents the inverse rotation.
621
+ * @param q
622
+ */
325
623
  static conjugate(q: Quaternion): Quaternion;
326
624
  /**
327
625
  * Returns the magnitude/length of the provided quaternion.
328
626
  * @param q {Quaternion}
329
627
  */
330
628
  static mag(q: Quaternion): number;
629
+ /**
630
+ * Returns the squared magnitude of the vector (imaginary) part of the quaternion.
631
+ * @param q
632
+ */
331
633
  static norm(q: Quaternion): number;
634
+ /**
635
+ * Returns the (unit) rotation axis represented by the quaternion, defaulting to the y axis
636
+ * when the quaternion has no vector part (i.e. represents no rotation).
637
+ * @param q
638
+ */
332
639
  static axis(q: Quaternion): Vector3D;
640
+ /**
641
+ * Rotates a vector by the given quaternion (normalizes the quaternion in place as a side effect).
642
+ * @param v Vector to rotate.
643
+ * @param q Rotation quaternion.
644
+ */
333
645
  static transform(v: Vector3D, q: Quaternion): Vector3D;
334
646
  /**
335
647
  * Returns the rotation angle (in degrees) of the provided quaternion.
336
648
  * @param q
337
649
  */
338
650
  static angle(q: Quaternion): number;
651
+ /**
652
+ * Builds the rotation matrix equivalent to the given quaternion.
653
+ * @param q
654
+ */
339
655
  static toRotationMatrix(q: Quaternion): Matrix3D;
656
+ /**
657
+ * Returns the inverse rotation of the given quaternion (the conjugate of its normalized form).
658
+ * @param q
659
+ */
340
660
  static invert(q: Quaternion): Quaternion;
341
661
  /**
342
662
  * Combines two quaternions.
@@ -352,10 +672,16 @@ declare class Quaternion {
352
672
  static dot(q1: Quaternion, q2: Quaternion): number;
353
673
  }
354
674
 
675
+ /** A ray in 3D space, represented as its start and end points (direction goes from the first to the second). */
355
676
  declare type Ray = [Point3D, Point3D];
356
677
 
678
+ /**
679
+ * A search function that finds (approximately) the value in `[min, max]` minimizing the given weight function,
680
+ * within the given tolerance. See {@link SearchFunctions} for ready-made implementations.
681
+ */
357
682
  declare type SearchFunction = (min: number, max: number, weight: (v: number) => number, tolerance?: number) => number;
358
683
 
684
+ /** Ready-made {@link SearchFunction} implementations for unimodal minimum-search over an interval. */
359
685
  declare const SearchFunctions: {
360
686
  /**
361
687
  * Creates a linear search function.
@@ -368,8 +694,10 @@ declare const SearchFunctions: {
368
694
  gaussian: SearchFunction;
369
695
  };
370
696
 
697
+ /** A line segment, represented as its two endpoints. */
371
698
  declare type Segment = [Point, Point];
372
699
 
700
+ /** Represents a point in 3D space using spherical coordinates (radial distance and two angles). */
373
701
  declare interface Spherical {
374
702
  /** Azimuthal angle in degrees. */
375
703
  theta: number;
@@ -379,6 +707,10 @@ declare interface Spherical {
379
707
  rho: number;
380
708
  }
381
709
 
710
+ /**
711
+ * Utilities to convert between spherical coordinates (radial distance `rho`, azimuth `theta` and
712
+ * polar angle `phi`) and their cartesian ({@link Vector3D}) or rotation-matrix ({@link Matrix3D}) equivalents.
713
+ */
382
714
  declare class Spherical {
383
715
  /**
384
716
  * Creates a new {@link Spherical} object.
@@ -388,16 +720,39 @@ declare class Spherical {
388
720
  * @returns
389
721
  */
390
722
  static from(rho: number, theta: number, phi: number): Spherical;
723
+ /**
724
+ * Computes the {@link Spherical} coordinates equivalent to the given cartesian x, y, z components.
725
+ * @param x
726
+ * @param y
727
+ * @param z
728
+ */
391
729
  static fromVector(x: number, y: number, z: any): Spherical;
730
+ /**
731
+ * Computes the {@link Spherical} coordinates equivalent to the given 3D vector.
732
+ * @param v
733
+ */
392
734
  static fromVector(v: Vector3D): Spherical;
735
+ /**
736
+ * Converts {@link Spherical} coordinates back into cartesian {@link Vector3D} coordinates.
737
+ * @param coords
738
+ */
393
739
  static toVector(coords: Spherical): Vector3D;
740
+ /**
741
+ * Builds the rotation matrix corresponding to the given azimuth (`theta`) and polar (`phi`) angles.
742
+ * @param coords
743
+ */
394
744
  static toRotationMatrix(coords: Spherical): Matrix3D;
745
+ /**
746
+ * Builds the rotation matrix corresponding to the given azimuth (`theta`) and polar (`phi`) angles.
747
+ * @param coords
748
+ */
395
749
  static toRotationMatrix(coords: {
396
750
  theta: number;
397
751
  phi: number;
398
752
  }): Matrix3D;
399
753
  }
400
754
 
755
+ /** Utility tools for 2D geometry: points, segments, polygons and their interactions. */
401
756
  declare class Utils {
402
757
  /**
403
758
  * Computes the slope (in radians) of the segment joining two points.
@@ -428,6 +783,12 @@ declare class Utils {
428
783
  * @param rects Rects to intersect
429
784
  */
430
785
  static intersect(...rects: Rect[]): Rect;
786
+ /**
787
+ * Computes the intersection polygon(s) between two polygons.
788
+ * @param polygon1 First polygon.
789
+ * @param polygon2 Second polygon.
790
+ * @returns The overlapping area(s) as one or more polygons.
791
+ */
431
792
  static intersect(polygon1: Polygon, polygon2: Polygon): Polygon[];
432
793
  /**
433
794
  * Computes the intersection point between two segments, if any.
@@ -435,7 +796,21 @@ declare class Utils {
435
796
  * @param segment2
436
797
  */
437
798
  static intersect(segment1: Segment, segment2: Segment): Point;
799
+ /**
800
+ * Computes the axis-aligned bounding box of a set of points.
801
+ * @param vertices Points to enclose.
802
+ * @returns The smallest rect containing all provided points.
803
+ */
438
804
  static boundingBox(vertices: Point[]): Rect;
805
+ /**
806
+ * Combines two polygons using a boolean set operator (union, intersection or difference).
807
+ * Internally triangulates the merged vertex set (via {@link mesh}) and filters the resulting
808
+ * triangles by whether their barycenter falls inside either source polygon.
809
+ * @param polygon1 First polygon.
810
+ * @param polygon2 Second polygon.
811
+ * @param operator Boolean operator to apply.
812
+ * @returns The resulting polygon(s), plus the underlying triangulation mesh and triangles used to compute them; or `null` if the operation yields no polygon.
813
+ */
439
814
  static combinePolygons(polygon1: Polygon, polygon2: Polygon, operator: PolygonCompound): {
440
815
  polygons: Polygon[];
441
816
  mesh?: Mesh;
@@ -502,6 +877,13 @@ declare class Utils {
502
877
  private static _intersectSegments;
503
878
  private static _intersectRects;
504
879
  private static _areClose;
880
+ /**
881
+ * Checks if the two points are effectively the same location.
882
+ * @param p1 The first point.
883
+ * @param p2 The second point.
884
+ * @param precision Optional precision roundoff for the proximity check.
885
+ * @returns True if the points are considered coincident within tolerance; otherwise, false.
886
+ */
505
887
  static areClose(p1: Point, p2: Point): boolean;
506
888
  static areClose(p1: Point, p2: Point, precision: number): boolean;
507
889
  /**
@@ -528,16 +910,54 @@ declare class Utils {
528
910
  * @param mq Line identified by a two-number array (slope and y-intercept).
529
911
  */
530
912
  static distance(p: Point, mq: [number, number]): number;
913
+ /**
914
+ * Returns the length of a segment.
915
+ * @param segment
916
+ */
531
917
  static distance(segment: Segment): number;
532
918
  private static _pointSegmentDistance;
919
+ /**
920
+ * Checks whether a point lies on the given side (clockwise or counter-clockwise) of the line
921
+ * through a segment, strictly off the line.
922
+ * @param p Point to test.
923
+ * @param segment Segment identifying the reference line and its direction.
924
+ * @param clockwise Side to test for: `true` for the clockwise side, `false` for counter-clockwise.
925
+ * @param precision Optional precision roundoff used to consider the point "on the line" (and thus not "within" either side).
926
+ */
533
927
  static isWithin(p: Point, segment: Segment, clockwise: boolean): boolean;
534
928
  static isWithin(p: Point, segment: Segment, clockwise: boolean, precision: number): boolean;
929
+ /**
930
+ * Checks whether a point lies on the opposite side (clockwise or counter-clockwise) of the line
931
+ * through a segment, strictly off the line. Complementary to {@link isWithin}.
932
+ * @param p Point to test.
933
+ * @param segment Segment identifying the reference line and its direction.
934
+ * @param clockwise Side to test *against*: `true` tests for the counter-clockwise side, `false` for clockwise.
935
+ * @param precision Optional precision roundoff used to consider the point "on the line".
936
+ */
535
937
  static isBeyond(p: Point, segment: Segment, clockwise: boolean): boolean;
536
938
  static isBeyond(p: Point, segment: Segment, clockwise: boolean, precision: number): boolean;
939
+ /**
940
+ * Checks whether a point lies on the (infinite) line through a segment.
941
+ * @param p Point to test.
942
+ * @param segment Segment identifying the reference line.
943
+ * @param precision Optional precision roundoff for the proximity check.
944
+ */
537
945
  static inLine(p: Point, segment: Segment): boolean;
538
946
  static inLine(p: Point, segment: Segment, precision: number): boolean;
947
+ /**
948
+ * Checks whether a point lies on the segment itself (on its line, and within its bounding box).
949
+ * @param p Point to test.
950
+ * @param segment Segment to test against.
951
+ * @param precision Optional precision roundoff for the proximity check.
952
+ */
539
953
  static inSegment(p: Point, segment: Segment): boolean;
540
954
  static inSegment(p: Point, segment: Segment, precision: number): boolean;
955
+ /**
956
+ * Checks whether a point lies inside (or on the boundary of) a triangle, by verifying that it
957
+ * is on the same rotational side of all three edges.
958
+ * @param p Point to test.
959
+ * @param triangle Triangle vertices.
960
+ */
541
961
  static inTriangle(p: Point, triangle: [Point, Point, Point]): boolean;
542
962
  /**
543
963
  * Checks whether a given point lies inside a polygon in the 2d plane.
@@ -567,6 +987,7 @@ declare class Utils {
567
987
  static convexHull(points: Point[]): Point[];
568
988
  }
569
989
 
990
+ /** Utility tools for 3D geometry: rays, triangles and their interactions. */
570
991
  declare class Utils3D {
571
992
  /**
572
993
  * Computes the intersection between a ray and a triangle in the 3D space - if any - using the Möller–Trumbore algorithm.
@@ -579,12 +1000,32 @@ declare class Utils3D {
579
1000
 
580
1001
  /** Utility tools about statistics, probability, data analysis... */
581
1002
  declare class Utils_2 {
1003
+ /**
1004
+ * Sums the (selected) values of a set.
1005
+ * @param set Input set.
1006
+ * @param selector Optional projection from item (and index) to the numeric value to sum. Defaults to the identity.
1007
+ */
582
1008
  static sum<T>(set: T[], selector: NumericKeySelector<T>): number;
583
1009
  static sum(set: number[]): number;
1010
+ /**
1011
+ * Arithmetic mean (average) of the (selected) values of a set.
1012
+ * @param set Input set.
1013
+ * @param selector Optional projection from item (and index) to the numeric value to average. Defaults to the identity.
1014
+ */
584
1015
  static mean<T>(set: T[], selector: NumericKeySelector<T>): number;
585
1016
  static mean(set: number[]): number;
1017
+ /**
1018
+ * Median (middle value, or average of the two middle values) of the (selected) values of a set.
1019
+ * @param set Input set.
1020
+ * @param selector Optional projection from item (and index) to the numeric value. Defaults to the identity.
1021
+ */
586
1022
  static median<T>(set: T[], selector: NumericKeySelector<T>): number;
587
1023
  static median(set: number[]): number;
1024
+ /**
1025
+ * Mode (most frequently occurring value) of the (selected) values of a set.
1026
+ * @param set Input set.
1027
+ * @param selector Optional projection from item (and index) to the numeric value. Defaults to the identity.
1028
+ */
588
1029
  static mode<T>(set: T[], selector: NumericKeySelector<T>): number;
589
1030
  static mode(set: number[]): number;
590
1031
  /**
@@ -630,12 +1071,65 @@ declare class Utils_2 {
630
1071
 
631
1072
  /** Utility tools about number theory, 'diophantine' stuff... */
632
1073
  declare class Utils_3 {
1074
+ /**
1075
+ * Computes the least common multiple (LCM) of the given numbers (each rounded to the nearest integer).
1076
+ * @param args Two or more numbers.
1077
+ * @returns The least common multiple.
1078
+ * @throws If fewer than two numbers are provided.
1079
+ */
633
1080
  static lcd(...args: number[]): number;
1081
+ /**
1082
+ * Computes the greatest common divisor (GCD) of two numbers (each rounded to the nearest integer)
1083
+ * using the Euclidean algorithm.
1084
+ * @param a
1085
+ * @param b
1086
+ */
634
1087
  static gcd(a: number, b: number): any;
1088
+ /**
1089
+ * Converts an integer value from one numeric base (radix) to another.
1090
+ * @param v Value to convert, in the source radix.
1091
+ * @param from Source radix.
1092
+ * @param to Target radix.
1093
+ * @returns The value re-expressed in the target radix, as a string.
1094
+ */
635
1095
  static rebaseInt(v: number | string, from: number, to: number): string;
1096
+ /**
1097
+ * Converts a (possibly fractional) numeric value from one radix to another, dispatching to the
1098
+ * appropriate specialized conversion routine depending on whether base-10 is the source, the
1099
+ * target, or neither.
1100
+ * @param v Value to convert, in the source radix.
1101
+ * @param fromRadix Source radix.
1102
+ * @param toRadix Target radix.
1103
+ * @param precision Maximum number of digits to compute for the fractional part (default 12).
1104
+ * @returns The converted value: a number when converting to base 10, otherwise a string.
1105
+ */
636
1106
  static rebaseFloat(v: number | string, fromRadix: number, toRadix: number, precision?: number): string | number;
1107
+ /**
1108
+ * Converts a numeric string expressed in the given radix into its base-10 (decimal) value.
1109
+ * @param v Value to convert, expressed in the source radix (digits from `0-9a-z`).
1110
+ * @param radix Source radix (must be greater than 1 and no larger than the size of the digit alphabet).
1111
+ * @param precision Unused for the integer part; reserved for symmetry with the sibling conversion methods.
1112
+ * @returns The base-10 numeric value, or `NaN` if the input contains invalid digits.
1113
+ * @throws If radix is out of range.
1114
+ */
637
1115
  static rebaseFloatNTo10(v: string, radix: number, precision?: number): number;
1116
+ /**
1117
+ * Converts a base-10 number into its representation in another **integer** radix.
1118
+ * @param v Base-10 value to convert.
1119
+ * @param radix Target integer radix (must be greater than 1 and no larger than the size of the digit alphabet).
1120
+ * @param precision Maximum number of digits to compute for the fractional part (default 12).
1121
+ * @returns The value re-expressed in the target radix, as a string.
1122
+ * @throws If radix is out of range.
1123
+ */
638
1124
  static rebaseFloat10ToNIntBase(v: number, radix: number, precision?: number): string;
1125
+ /**
1126
+ * Converts a base-10 number into its representation in another (possibly non-integer) radix.
1127
+ * @param v Base-10 value to convert.
1128
+ * @param radix Target radix, possibly fractional (must be greater than 1 and no larger than the size of the digit alphabet).
1129
+ * @param precision Maximum number of digits to compute for the fractional part (default 12).
1130
+ * @returns The value re-expressed in the target radix, as a string.
1131
+ * @throws If radix is out of range.
1132
+ */
639
1133
  static rebaseFloat10ToN(v: number, radix: number, precision?: number): string;
640
1134
  }
641
1135
 
@@ -650,7 +1144,15 @@ declare class Vector {
650
1144
  * @param v
651
1145
  */
652
1146
  static unit(v: Vector): Vector;
1147
+ /**
1148
+ * Returns the squared magnitude (length) of the vector. Cheaper than {@link mag} since it avoids the square root.
1149
+ * @param v
1150
+ */
653
1151
  static magSqr(v: Vector): number;
1152
+ /**
1153
+ * Returns the magnitude (length) of the vector.
1154
+ * @param v
1155
+ */
654
1156
  static mag(v: Vector): number;
655
1157
  /**
656
1158
  * Normalizes the provided vector in place.
@@ -688,12 +1190,27 @@ declare class Vector {
688
1190
  declare interface Vector3D extends Point3D {
689
1191
  }
690
1192
 
1193
+ /** 3D vector utils. */
691
1194
  declare class Vector3D {
1195
+ /**
1196
+ * Builds a {@link Vector3D} from its x, y, z components, in that order.
1197
+ * @param args Exactly 3 numbers: x, y, z.
1198
+ * @throws If the number of arguments is not exactly 3.
1199
+ */
692
1200
  static from(...args: number[]): Vector3D;
1201
+ /**
1202
+ * Parses a string representation (e.g. `"1 2 3"` or `"1,2,3"`) into a {@link Vector3D}.
1203
+ * @param input String to parse.
1204
+ * @throws If the input cannot be parsed as exactly 3 numbers.
1205
+ */
693
1206
  static parse(input: string): Vector3D;
1207
+ /** Returns the unit vector along the x axis: `(1, 0, 0)`. */
694
1208
  static i(): Vector3D;
1209
+ /** Returns the unit vector along the y axis: `(0, 1, 0)`. */
695
1210
  static j(): Vector3D;
1211
+ /** Returns the unit vector along the z axis: `(0, 0, 1)`. */
696
1212
  static k(): Vector3D;
1213
+ /** Returns the zero vector: `(0, 0, 0)`. */
697
1214
  static zero(): Vector3D;
698
1215
  /**
699
1216
  * Subtracts a point p from another and returns the resulting vector.
@@ -718,8 +1235,24 @@ declare class Vector3D {
718
1235
  * @param v2
719
1236
  */
720
1237
  static cross(v1: Point3D, v2: Point3D): Vector3D;
1238
+ /**
1239
+ * Scales a vector by a single factor applied uniformly to all axes.
1240
+ * @param v Vector to scale.
1241
+ * @param f Scale factor for x, y and z.
1242
+ */
721
1243
  static scale(v: Vector3D, f: number): Vector3D;
1244
+ /**
1245
+ * Scales a vector by independent per-axis factors.
1246
+ * @param v Vector to scale.
1247
+ * @param fx Scale factor for x.
1248
+ * @param fy Scale factor for y.
1249
+ * @param fz Scale factor for z.
1250
+ */
722
1251
  static scale(v: Vector3D, fx: number, fy: number, fz: number): Vector3D;
1252
+ /**
1253
+ * Returns the squared magnitude (length) of the vector. Cheaper than {@link mag} since it avoids the square root.
1254
+ * @param v
1255
+ */
723
1256
  static magSqr(v: Point3D): number;
724
1257
  /**
725
1258
  * Checks if the two points are effectively the same location.
@@ -728,7 +1261,15 @@ declare class Vector3D {
728
1261
  * @returns True if the points are considered coincident within tolerance; otherwise, false.
729
1262
  */
730
1263
  static areClose(v1: Point3D, v2: Point3D): boolean;
1264
+ /**
1265
+ * Returns the magnitude (length) of the vector.
1266
+ * @param v
1267
+ */
731
1268
  static mag(v: Point3D): number;
1269
+ /**
1270
+ * Returns the opposite vector (each component negated).
1271
+ * @param v
1272
+ */
732
1273
  static negate(v: Vector3D): Vector3D;
733
1274
  /**
734
1275
  * Returns the unit (normalized) vector having the same direction and sense of the provided one.