@pacem/pacem-numerical 1.0.0-abel
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/LICENSE +191 -0
- package/NOTICE +4 -0
- package/dist/browser/pacem-numerical.js +2622 -0
- package/dist/browser/pacem-numerical.js.map +1 -0
- package/dist/browser/pacem-numerical.min.js +2 -0
- package/dist/browser/pacem-numerical.min.js.map +1 -0
- package/dist/bundle/pacem-numerical.min.mjs +1 -0
- package/dist/bundle/pacem-numerical.mjs +2459 -0
- package/dist/bundle/pacem-numerical.mjs.map +7 -0
- package/dist/esm/index-geometry-linearalgebra.js +2 -0
- package/dist/esm/index-geometry.js +4 -0
- package/dist/esm/index-iife.js +3 -0
- package/dist/esm/index-mathematics-dataanalysis.js +5 -0
- package/dist/esm/index-mathematics.js +3 -0
- package/dist/esm/index.js +2 -0
- package/package.json +41 -0
- package/typings/index.d.ts +763 -0
|
@@ -0,0 +1,763 @@
|
|
|
1
|
+
import { Point } from '@pacem/pacem-foundation';
|
|
2
|
+
import { Rect } from '@pacem/pacem-foundation';
|
|
3
|
+
|
|
4
|
+
declare interface Complex {
|
|
5
|
+
readonly real: number;
|
|
6
|
+
readonly img: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare class Complex {
|
|
10
|
+
static build(z: Complex | number): Complex;
|
|
11
|
+
static build(real: number, img: number): Complex;
|
|
12
|
+
static add(a: Complex | number, b: Complex | number): Complex;
|
|
13
|
+
static subtract(from: Complex | number, what: Complex | number): Complex;
|
|
14
|
+
static multiply(a: Complex | number, b: Complex | number): Complex;
|
|
15
|
+
static divide(a: Complex | number, b: Complex | number): Complex;
|
|
16
|
+
static absSquare(c: Complex | number): number;
|
|
17
|
+
static modulus(c: Complex | number): number;
|
|
18
|
+
static isComplex(c: any): c is Complex;
|
|
19
|
+
static conjugate(a: Complex | number): Complex;
|
|
20
|
+
static equals(c1: Complex | number, c2: Complex | number): boolean;
|
|
21
|
+
static get NaC(): Complex;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export declare namespace DataAnalysis {
|
|
25
|
+
export {
|
|
26
|
+
Fourier,
|
|
27
|
+
Gaussian,
|
|
28
|
+
Interpolator,
|
|
29
|
+
Lagrange,
|
|
30
|
+
Lagrangian,
|
|
31
|
+
Pchip,
|
|
32
|
+
Newton,
|
|
33
|
+
Utils_2 as Utils,
|
|
34
|
+
SearchFunction,
|
|
35
|
+
SearchFunctions
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare class Fourier {
|
|
40
|
+
/**
|
|
41
|
+
* Checks the input vector and outputs a frequency vector using the best performing algo.
|
|
42
|
+
* @param data Input vector of any size
|
|
43
|
+
* @param normalize Whether to normalize the signal or not (default true)
|
|
44
|
+
*/
|
|
45
|
+
static transform(data: (Complex | number)[], normalize?: boolean): Complex[];
|
|
46
|
+
/**
|
|
47
|
+
* Checks the input vector and applies inverted fourier transform's best performing algo.
|
|
48
|
+
* @param data Input frequency vector
|
|
49
|
+
*/
|
|
50
|
+
static invert(data: Complex[], normalize?: boolean): Complex[];
|
|
51
|
+
/**
|
|
52
|
+
* Naive Discrete Fourier Transform implementation (O(n^2) algo).
|
|
53
|
+
* @param data Input vector of any size
|
|
54
|
+
* @param normalize Whether to normalize the signal or not (default true)
|
|
55
|
+
*/
|
|
56
|
+
static dft(data: (Complex | number)[], normalize?: boolean): Complex[];
|
|
57
|
+
/**
|
|
58
|
+
* Inverse Discrete Fourier Transform.
|
|
59
|
+
* @param data Input vector data of any size
|
|
60
|
+
*/
|
|
61
|
+
static idft(data: Complex[], normalize?: boolean): Complex[];
|
|
62
|
+
/**
|
|
63
|
+
* FFT processing using Cooley-Tukey.
|
|
64
|
+
* @param data Input vector (size MUST be power of 2)
|
|
65
|
+
*/
|
|
66
|
+
static fft(data: (Complex | number)[], normalize?: boolean): Complex[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
declare class Gaussian {
|
|
70
|
+
constructor(mean: number, stdev: number);
|
|
71
|
+
readonly mean: number;
|
|
72
|
+
readonly stdev: number;
|
|
73
|
+
readonly variance: number;
|
|
74
|
+
static get normal(): Gaussian;
|
|
75
|
+
/**
|
|
76
|
+
* Un-normalized probability density function.
|
|
77
|
+
* Can be useful as a weight function without requiring the integral w(x)dx to be 1.
|
|
78
|
+
* @param x Input value
|
|
79
|
+
*/
|
|
80
|
+
weight(x: number): number;
|
|
81
|
+
/**
|
|
82
|
+
* Probability density function (PDF).
|
|
83
|
+
* @param x Input value
|
|
84
|
+
*/
|
|
85
|
+
probabilityDensity(x: number): number;
|
|
86
|
+
private _z;
|
|
87
|
+
/**
|
|
88
|
+
* Returns the area under the PDF from -∞ to x
|
|
89
|
+
* @param x Input value
|
|
90
|
+
*/
|
|
91
|
+
probability(x: number): number;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export declare namespace Geometry {
|
|
95
|
+
export {
|
|
96
|
+
LinearAlgebra,
|
|
97
|
+
Segment,
|
|
98
|
+
Utils,
|
|
99
|
+
Polygon,
|
|
100
|
+
Ray,
|
|
101
|
+
Utils3D
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
declare interface Interpolator {
|
|
106
|
+
interpolate(x: number): number;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
declare class Lagrange implements Interpolator {
|
|
110
|
+
#private;
|
|
111
|
+
protected constructor(points: Point[]);
|
|
112
|
+
private _prepareBarycentric;
|
|
113
|
+
private _computeBarycentric;
|
|
114
|
+
interpolate(x: number): number;
|
|
115
|
+
static create(...values: number[]): Lagrange;
|
|
116
|
+
static create(...points: Point[]): Lagrange;
|
|
117
|
+
static create(points: Point[]): Lagrange;
|
|
118
|
+
static create(values: number[]): Lagrange;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @deprecated Use Lagrange instead. This alias is kept for backward compatibility.
|
|
123
|
+
*/
|
|
124
|
+
declare const Lagrangian: {
|
|
125
|
+
create: typeof Lagrange.create;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export declare namespace LinearAlgebra {
|
|
129
|
+
export {
|
|
130
|
+
Vector,
|
|
131
|
+
Point3D,
|
|
132
|
+
Vector3D,
|
|
133
|
+
Spherical,
|
|
134
|
+
Matrix3D,
|
|
135
|
+
Quaternion
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export declare namespace Mathematics {
|
|
140
|
+
export {
|
|
141
|
+
DataAnalysis,
|
|
142
|
+
NumberTheory,
|
|
143
|
+
Complex
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
declare interface Matrix3D {
|
|
148
|
+
m11: number;
|
|
149
|
+
m12: number;
|
|
150
|
+
m13: number;
|
|
151
|
+
m14: number;
|
|
152
|
+
m21: number;
|
|
153
|
+
m22: number;
|
|
154
|
+
m23: number;
|
|
155
|
+
m24: number;
|
|
156
|
+
m31: number;
|
|
157
|
+
m32: number;
|
|
158
|
+
m33: number;
|
|
159
|
+
m34: number;
|
|
160
|
+
offsetX: number;
|
|
161
|
+
offsetY: number;
|
|
162
|
+
offsetZ: number;
|
|
163
|
+
m44: number;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
declare class Matrix3D {
|
|
167
|
+
/**
|
|
168
|
+
* Identity 4x4 matrix.
|
|
169
|
+
* @returns
|
|
170
|
+
*/
|
|
171
|
+
static identity(): Matrix3D;
|
|
172
|
+
static from(...args: number[]): Matrix3D;
|
|
173
|
+
static transpose(m: Matrix3D): Matrix3D;
|
|
174
|
+
static toArray(m: Matrix3D): number[];
|
|
175
|
+
static clone(m: Matrix3D): Matrix3D;
|
|
176
|
+
static clone(m: Matrix3D, modifier: (m: Matrix3D) => void): Matrix3D;
|
|
177
|
+
static scale(m: Matrix3D, v: Vector3D): Matrix3D;
|
|
178
|
+
static scale(m: Matrix3D, scale: number): Matrix3D;
|
|
179
|
+
static scale(m: Matrix3D, sx: number, sy: number, sz: number): Matrix3D;
|
|
180
|
+
static translate(m: Matrix3D, offset: Vector3D): Matrix3D;
|
|
181
|
+
static parse(input: string): Matrix3D;
|
|
182
|
+
static isIdentity(m: Matrix3D): boolean;
|
|
183
|
+
static isAffine(m: Matrix3D): boolean;
|
|
184
|
+
static determinant(m: Matrix3D): number;
|
|
185
|
+
/**
|
|
186
|
+
* Multiplies two matrices in the provided order (i.e.: applies {@link m2} to {@link m1}).
|
|
187
|
+
* @param matrices Matrices to apply one to the other, sequentially.
|
|
188
|
+
* @returns Combination matrix.
|
|
189
|
+
*/
|
|
190
|
+
static multiply(...matrices: Matrix3D[]): Matrix3D;
|
|
191
|
+
static invert(m: Matrix3D): Matrix3D;
|
|
192
|
+
/**
|
|
193
|
+
* Moves a given point in 3D space given the transformation matrix.
|
|
194
|
+
* @param point
|
|
195
|
+
* @param matrix
|
|
196
|
+
*/
|
|
197
|
+
static transform(point: Point3D, matrix: Matrix3D): Point3D;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
declare interface Mesh extends Polygon {
|
|
201
|
+
triangleIndices: number[];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
declare class Newton implements Interpolator {
|
|
205
|
+
private xs;
|
|
206
|
+
private coeffs;
|
|
207
|
+
private constructor();
|
|
208
|
+
interpolate(x: number): number;
|
|
209
|
+
static create(...values: number[]): Newton;
|
|
210
|
+
static create(...points: Point[]): Newton;
|
|
211
|
+
static create(points: Point[]): Newton;
|
|
212
|
+
static create(values: number[]): Newton;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export declare namespace NumberTheory {
|
|
216
|
+
export {
|
|
217
|
+
Utils_3 as Utils
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
declare type NumericKeySelector<T> = (item: T, index?: number) => number;
|
|
222
|
+
|
|
223
|
+
declare class Pchip implements Interpolator {
|
|
224
|
+
private xs;
|
|
225
|
+
private ys;
|
|
226
|
+
private ms;
|
|
227
|
+
private constructor();
|
|
228
|
+
private computeDerivatives;
|
|
229
|
+
interpolate(x: number): number;
|
|
230
|
+
static create(...values: number[]): Pchip;
|
|
231
|
+
static create(...points: Point[]): Pchip;
|
|
232
|
+
static create(points: Point[]): Pchip;
|
|
233
|
+
static create(values: number[]): Pchip;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
declare interface Point3D {
|
|
237
|
+
x: number;
|
|
238
|
+
y: number;
|
|
239
|
+
z: number;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
declare interface Polygon {
|
|
243
|
+
vertices: Point[];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
declare class Polygon {
|
|
247
|
+
private static readonly _eps;
|
|
248
|
+
static isPolygon(obj: any): obj is Polygon;
|
|
249
|
+
static from(...points: Point[]): Polygon;
|
|
250
|
+
static contains(polygon: Polygon, p: Point): any;
|
|
251
|
+
static centroid(polygon: Polygon): Point;
|
|
252
|
+
static boundingBox(polygon: Polygon): Rect;
|
|
253
|
+
static sides(polygon: Polygon): Segment[];
|
|
254
|
+
static isConvex(polygon: Polygon): boolean;
|
|
255
|
+
/**
|
|
256
|
+
* Check whether a polygon is a self-intersecting one.
|
|
257
|
+
* @param polygon
|
|
258
|
+
* @returns
|
|
259
|
+
*/
|
|
260
|
+
static isSelfIntersecting(polygon: Polygon): boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Returns whether the vertices of the spcified polygon have been provided in counter-clockwise order.
|
|
263
|
+
* Meaningless in case of self-intersecting polygons.
|
|
264
|
+
* @param polygon
|
|
265
|
+
* @returns
|
|
266
|
+
*/
|
|
267
|
+
static isCounterClockwise(polygon: Polygon): boolean;
|
|
268
|
+
/**
|
|
269
|
+
* Expands (or contracts) a polygon by a provided offset.
|
|
270
|
+
* @param polygon
|
|
271
|
+
* @param offset
|
|
272
|
+
*
|
|
273
|
+
*/
|
|
274
|
+
static expand(polygon: Polygon, offset: number): Polygon;
|
|
275
|
+
/**
|
|
276
|
+
* Returns the area of a polygon using the shoelace algorithm. It's meaningless in case of self-intersecting polygons.
|
|
277
|
+
* @param polygon
|
|
278
|
+
* @returns
|
|
279
|
+
*/
|
|
280
|
+
static area(polygon: Polygon): number;
|
|
281
|
+
static intersect(polygon1: Polygon, polygon2: Polygon): Polygon[];
|
|
282
|
+
/**
|
|
283
|
+
* Returns the convex hull of a polygon.
|
|
284
|
+
* @param polygon
|
|
285
|
+
* @returns
|
|
286
|
+
*/
|
|
287
|
+
static convexHull(polygon: Polygon): Polygon;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
declare type PolygonCompound = 'union' | 'intersect' | 'difference';
|
|
291
|
+
|
|
292
|
+
declare interface Quaternion {
|
|
293
|
+
x: number;
|
|
294
|
+
y: number;
|
|
295
|
+
z: number;
|
|
296
|
+
w: number;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
declare class Quaternion {
|
|
300
|
+
static identity(): Quaternion;
|
|
301
|
+
static from(...args: number[]): Quaternion;
|
|
302
|
+
static parse(input: string): Quaternion;
|
|
303
|
+
static fromVectors(from: Vector3D, to: Vector3D): Quaternion;
|
|
304
|
+
/**
|
|
305
|
+
* In-place normalizarion of the provided quaternion
|
|
306
|
+
* @param q {Quaternion}
|
|
307
|
+
*/
|
|
308
|
+
static normalize(q: Quaternion): void;
|
|
309
|
+
/**
|
|
310
|
+
* Returns a normalized copy of the source quaternion.
|
|
311
|
+
* @param q {Quaternion}
|
|
312
|
+
*/
|
|
313
|
+
static unit(q: Quaternion): Quaternion;
|
|
314
|
+
/**
|
|
315
|
+
* Creates a quaternion instance given the rotation axis and an angle (in degrees).
|
|
316
|
+
* @param axis
|
|
317
|
+
* @param angleDeg
|
|
318
|
+
*/
|
|
319
|
+
static fromAxisAngle(axis: Vector3D, angleDeg: number): Quaternion;
|
|
320
|
+
/**
|
|
321
|
+
* Creates a quaternion instance given the rotation matrix.
|
|
322
|
+
* @param rotationMatrix
|
|
323
|
+
*/
|
|
324
|
+
static fromRotationMatrix(rotationMatrix: Matrix3D): Quaternion;
|
|
325
|
+
static conjugate(q: Quaternion): Quaternion;
|
|
326
|
+
/**
|
|
327
|
+
* Returns the magnitude/length of the provided quaternion.
|
|
328
|
+
* @param q {Quaternion}
|
|
329
|
+
*/
|
|
330
|
+
static mag(q: Quaternion): number;
|
|
331
|
+
static norm(q: Quaternion): number;
|
|
332
|
+
static axis(q: Quaternion): Vector3D;
|
|
333
|
+
static transform(v: Vector3D, q: Quaternion): Vector3D;
|
|
334
|
+
/**
|
|
335
|
+
* Returns the rotation angle (in degrees) of the provided quaternion.
|
|
336
|
+
* @param q
|
|
337
|
+
*/
|
|
338
|
+
static angle(q: Quaternion): number;
|
|
339
|
+
static toRotationMatrix(q: Quaternion): Matrix3D;
|
|
340
|
+
static invert(q: Quaternion): Quaternion;
|
|
341
|
+
/**
|
|
342
|
+
* Combines two quaternions.
|
|
343
|
+
* @param q1
|
|
344
|
+
* @param q2
|
|
345
|
+
*/
|
|
346
|
+
static multiply(q1: Quaternion, q2: Quaternion): Quaternion;
|
|
347
|
+
/**
|
|
348
|
+
* Returns the dot product of two quaternions.
|
|
349
|
+
* @param q1
|
|
350
|
+
* @param q2
|
|
351
|
+
*/
|
|
352
|
+
static dot(q1: Quaternion, q2: Quaternion): number;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
declare type Ray = [Point3D, Point3D];
|
|
356
|
+
|
|
357
|
+
declare type SearchFunction = (min: number, max: number, weight: (v: number) => number, tolerance?: number) => number;
|
|
358
|
+
|
|
359
|
+
declare const SearchFunctions: {
|
|
360
|
+
/**
|
|
361
|
+
* Creates a linear search function.
|
|
362
|
+
* @param segments How many segments to split the range into.
|
|
363
|
+
*/
|
|
364
|
+
linear: (segments?: number) => SearchFunction;
|
|
365
|
+
/** Golden section search function. */
|
|
366
|
+
goldenRatio: SearchFunction;
|
|
367
|
+
/** Gaussian search function. */
|
|
368
|
+
gaussian: SearchFunction;
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
declare type Segment = [Point, Point];
|
|
372
|
+
|
|
373
|
+
declare interface Spherical {
|
|
374
|
+
/** Azimuthal angle in degrees. */
|
|
375
|
+
theta: number;
|
|
376
|
+
/** Polar angle in degrees. */
|
|
377
|
+
phi: number;
|
|
378
|
+
/** Radial distance. */
|
|
379
|
+
rho: number;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
declare class Spherical {
|
|
383
|
+
/**
|
|
384
|
+
* Creates a new {@link Spherical} object.
|
|
385
|
+
* @param rho radius.
|
|
386
|
+
* @param theta Azimuth angle in degrees.
|
|
387
|
+
* @param phi Polar angle in degrees.
|
|
388
|
+
* @returns
|
|
389
|
+
*/
|
|
390
|
+
static from(rho: number, theta: number, phi: number): Spherical;
|
|
391
|
+
static fromVector(x: number, y: number, z: any): Spherical;
|
|
392
|
+
static fromVector(v: Vector3D): Spherical;
|
|
393
|
+
static toVector(coords: Spherical): Vector3D;
|
|
394
|
+
static toRotationMatrix(coords: Spherical): Matrix3D;
|
|
395
|
+
static toRotationMatrix(coords: {
|
|
396
|
+
theta: number;
|
|
397
|
+
phi: number;
|
|
398
|
+
}): Matrix3D;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
declare class Utils {
|
|
402
|
+
/**
|
|
403
|
+
* Computes the slope (in radians) of the segment joining two points.
|
|
404
|
+
* @param p1 Point 1
|
|
405
|
+
* @param p2 Point 2
|
|
406
|
+
*/
|
|
407
|
+
static slopeRad(p1: Point, p2: Point): number;
|
|
408
|
+
/**
|
|
409
|
+
* Computes the slope (in radians) of the segment joining two points and returns a strictly positive value (0 to 2*pi).
|
|
410
|
+
* @param p1 Point 1
|
|
411
|
+
* @param p2 Point 2
|
|
412
|
+
*/
|
|
413
|
+
static slopeRad2(p1: Point, p2: Point): number;
|
|
414
|
+
/**
|
|
415
|
+
* Computes the slope (in degrees) of the segment joining two points.
|
|
416
|
+
* @param p1 Point 1
|
|
417
|
+
* @param p2 Point 2
|
|
418
|
+
*/
|
|
419
|
+
static slopeDeg(p1: Point, p2: Point): number;
|
|
420
|
+
/**
|
|
421
|
+
* Computes the slope (in degrees) of the segment joining two points and returns a strictly positive value (0 to 360).
|
|
422
|
+
* @param p1 Point 1
|
|
423
|
+
* @param p2 Point 2
|
|
424
|
+
*/
|
|
425
|
+
static slopeDeg2(p1: Point, p2: Point): number;
|
|
426
|
+
/**
|
|
427
|
+
* Computes the intersection rect among a set of provided rects.
|
|
428
|
+
* @param rects Rects to intersect
|
|
429
|
+
*/
|
|
430
|
+
static intersect(...rects: Rect[]): Rect;
|
|
431
|
+
static intersect(polygon1: Polygon, polygon2: Polygon): Polygon[];
|
|
432
|
+
/**
|
|
433
|
+
* Computes the intersection point between two segments, if any.
|
|
434
|
+
* @param segment1
|
|
435
|
+
* @param segment2
|
|
436
|
+
*/
|
|
437
|
+
static intersect(segment1: Segment, segment2: Segment): Point;
|
|
438
|
+
static boundingBox(vertices: Point[]): Rect;
|
|
439
|
+
static combinePolygons(polygon1: Polygon, polygon2: Polygon, operator: PolygonCompound): {
|
|
440
|
+
polygons: Polygon[];
|
|
441
|
+
mesh?: Mesh;
|
|
442
|
+
triangles?: Polygon[];
|
|
443
|
+
} | null;
|
|
444
|
+
private static _mergePolygons;
|
|
445
|
+
/**
|
|
446
|
+
* Returns the 2D mesh (vertices and triangle indices) of the Delaunay triangulation for the provided points.
|
|
447
|
+
* @param points
|
|
448
|
+
*/
|
|
449
|
+
static mesh(...points: Point[]): any;
|
|
450
|
+
static mesh(points: Point[]): any;
|
|
451
|
+
/**
|
|
452
|
+
* Computes the intersection point between the lines whose two provided segments belong to, if any.
|
|
453
|
+
* @param segment1 First segment
|
|
454
|
+
* @param segment2 Second segment
|
|
455
|
+
*/
|
|
456
|
+
static intersectLines(segment1: Segment, segment2: Segment): Point;
|
|
457
|
+
/**
|
|
458
|
+
* Computes the intersection point between the lines having the respective 'm' and 'q'.
|
|
459
|
+
* @param m1 First line's 'm'
|
|
460
|
+
* @param q1 First line's 'q'
|
|
461
|
+
* @param m2 Second line's 'm'
|
|
462
|
+
* @param q2 Second line's 'q'
|
|
463
|
+
*/
|
|
464
|
+
static intersectLines(m1: number, q1: number, m2: number, q2: number): Point;
|
|
465
|
+
/**
|
|
466
|
+
* Computes the intersection point between the lines having the respective 'm' and 'q'.
|
|
467
|
+
* @param mq1 'm' and 'q' pair for line 1
|
|
468
|
+
* @param mq2 'm' and 'q' pair for line 2
|
|
469
|
+
*/
|
|
470
|
+
static intersectLines(mq1: [number, number], mq2: [number, number]): Point;
|
|
471
|
+
/**
|
|
472
|
+
* Returns the eigenvalue for two given linear equations of the form ax + by + c = 0.
|
|
473
|
+
* @param l1
|
|
474
|
+
* @param l2
|
|
475
|
+
*/
|
|
476
|
+
static cramer(l1: [number, number, number], l2: [number, number, number]): Point;
|
|
477
|
+
/**
|
|
478
|
+
* Returns the eigenvalue for two given linear equations of the form ax + by + c = 0.
|
|
479
|
+
* @param l1
|
|
480
|
+
* @param l2
|
|
481
|
+
*/
|
|
482
|
+
static cramer(l1: {
|
|
483
|
+
a: number;
|
|
484
|
+
b: number;
|
|
485
|
+
c: number;
|
|
486
|
+
}, l2: {
|
|
487
|
+
a: number;
|
|
488
|
+
b: number;
|
|
489
|
+
c: number;
|
|
490
|
+
}): Point;
|
|
491
|
+
/**
|
|
492
|
+
* Returns the slope (m) and the y-axis intersection (q) of the line joining two given points.
|
|
493
|
+
* @param p1
|
|
494
|
+
* @param p2
|
|
495
|
+
*/
|
|
496
|
+
static mq(p1: Point, p2: Point): [number, number];
|
|
497
|
+
/**
|
|
498
|
+
* Returns the slope (m) and the y-axis intersection (q) of the line containing the provided segment.
|
|
499
|
+
* @param segment
|
|
500
|
+
*/
|
|
501
|
+
static mq(segment: Segment): [number, number];
|
|
502
|
+
private static _intersectSegments;
|
|
503
|
+
private static _intersectRects;
|
|
504
|
+
private static _areClose;
|
|
505
|
+
static areClose(p1: Point, p2: Point): boolean;
|
|
506
|
+
static areClose(p1: Point, p2: Point, precision: number): boolean;
|
|
507
|
+
/**
|
|
508
|
+
* Returns the dot product between two vectors/points.
|
|
509
|
+
* @param v1
|
|
510
|
+
* @param v2
|
|
511
|
+
*/
|
|
512
|
+
static dot(v1: Point, v2: Point): number;
|
|
513
|
+
/**
|
|
514
|
+
* Returns the cross product between two vectors/points (magnitude along the z axis).
|
|
515
|
+
* @param v1
|
|
516
|
+
* @param v2
|
|
517
|
+
*/
|
|
518
|
+
static cross(v1: Point, v2: Point): number;
|
|
519
|
+
/**
|
|
520
|
+
* Returns the distance between two given points.
|
|
521
|
+
* @param p1
|
|
522
|
+
* @param p2
|
|
523
|
+
*/
|
|
524
|
+
static distance(p1: Point, p2: Point): number;
|
|
525
|
+
/**
|
|
526
|
+
* Returns the distance between a point and a line.
|
|
527
|
+
* @param p
|
|
528
|
+
* @param mq Line identified by a two-number array (slope and y-intercept).
|
|
529
|
+
*/
|
|
530
|
+
static distance(p: Point, mq: [number, number]): number;
|
|
531
|
+
static distance(segment: Segment): number;
|
|
532
|
+
private static _pointSegmentDistance;
|
|
533
|
+
static isWithin(p: Point, segment: Segment, clockwise: boolean): boolean;
|
|
534
|
+
static isWithin(p: Point, segment: Segment, clockwise: boolean, precision: number): boolean;
|
|
535
|
+
static isBeyond(p: Point, segment: Segment, clockwise: boolean): boolean;
|
|
536
|
+
static isBeyond(p: Point, segment: Segment, clockwise: boolean, precision: number): boolean;
|
|
537
|
+
static inLine(p: Point, segment: Segment): boolean;
|
|
538
|
+
static inLine(p: Point, segment: Segment, precision: number): boolean;
|
|
539
|
+
static inSegment(p: Point, segment: Segment): boolean;
|
|
540
|
+
static inSegment(p: Point, segment: Segment, precision: number): boolean;
|
|
541
|
+
static inTriangle(p: Point, triangle: [Point, Point, Point]): boolean;
|
|
542
|
+
/**
|
|
543
|
+
* Checks whether a given point lies inside a polygon in the 2d plane.
|
|
544
|
+
* @param p
|
|
545
|
+
* @param vertices Ordered polygon vertices
|
|
546
|
+
*/
|
|
547
|
+
static inPolygon(p: Point, vertices: Point[]): any;
|
|
548
|
+
/**
|
|
549
|
+
* Checks whether a given point lies inside a polygon in the 2d plane.
|
|
550
|
+
* @param p
|
|
551
|
+
* @param vertices Ordered polygon vertices
|
|
552
|
+
* @param precision Precision roundoff, strongly recommended in case of quasi-aligned geometries. Default value: 12)
|
|
553
|
+
*/
|
|
554
|
+
static inPolygon(p: Point, vertices: Point[], precision: number): any;
|
|
555
|
+
/**
|
|
556
|
+
* Returns the area of the polygon defined by the provided points.
|
|
557
|
+
* @param points Vertices of the polygon
|
|
558
|
+
*/
|
|
559
|
+
static area(...points: Point[]): number;
|
|
560
|
+
static area(points: Point[]): number;
|
|
561
|
+
/**
|
|
562
|
+
* Convex hull of a set of points using the Andrew's monotone chain algorithm. O(n log n) time complexity.
|
|
563
|
+
* @param points Points to hull
|
|
564
|
+
* @returns Convex hull vertices in counter-clockwise order, starting from the leftmost one.
|
|
565
|
+
*/
|
|
566
|
+
static convexHull(...points: Point[]): Point[];
|
|
567
|
+
static convexHull(points: Point[]): Point[];
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
declare class Utils3D {
|
|
571
|
+
/**
|
|
572
|
+
* Computes the intersection between a ray and a triangle in the 3D space - if any - using the Möller–Trumbore algorithm.
|
|
573
|
+
* @param ray Array of two points identifying a ray.
|
|
574
|
+
* @param triangle Array of three points identifying a triangle.
|
|
575
|
+
* @returns Intersection point if any, otherwise null.
|
|
576
|
+
*/
|
|
577
|
+
static intersect(ray: Ray, triangle: [Point3D, Point3D, Point3D]): Point3D | null;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/** Utility tools about statistics, probability, data analysis... */
|
|
581
|
+
declare class Utils_2 {
|
|
582
|
+
static sum<T>(set: T[], selector: NumericKeySelector<T>): number;
|
|
583
|
+
static sum(set: number[]): number;
|
|
584
|
+
static mean<T>(set: T[], selector: NumericKeySelector<T>): number;
|
|
585
|
+
static mean(set: number[]): number;
|
|
586
|
+
static median<T>(set: T[], selector: NumericKeySelector<T>): number;
|
|
587
|
+
static median(set: number[]): number;
|
|
588
|
+
static mode<T>(set: T[], selector: NumericKeySelector<T>): number;
|
|
589
|
+
static mode(set: number[]): number;
|
|
590
|
+
/**
|
|
591
|
+
* Variance of a sample set.
|
|
592
|
+
*/
|
|
593
|
+
static var<T>(set: T[], selector: NumericKeySelector<T>): number;
|
|
594
|
+
static var(set: number[]): number;
|
|
595
|
+
/**
|
|
596
|
+
* Variance of the population.
|
|
597
|
+
*/
|
|
598
|
+
static varp<T>(set: T[], selector: NumericKeySelector<T>): number;
|
|
599
|
+
static varp(set: number[]): number;
|
|
600
|
+
/**
|
|
601
|
+
* Standard deviation of the population.
|
|
602
|
+
*/
|
|
603
|
+
static stdevp<T>(population: T[], selector: NumericKeySelector<T>): number;
|
|
604
|
+
static stdevp(population: number[]): number;
|
|
605
|
+
/**
|
|
606
|
+
* Standard deviation of a sample set.
|
|
607
|
+
*/
|
|
608
|
+
static stdev<T>(set: T[], selector: NumericKeySelector<T>): number;
|
|
609
|
+
static stdev(set: number[]): number;
|
|
610
|
+
/**
|
|
611
|
+
* Pearson correlation coefficient.
|
|
612
|
+
*/
|
|
613
|
+
static correlation(setX: number[], setY: number[]): number;
|
|
614
|
+
static correlation<X, Y>(setX: X[], setY: Y[], selectorX: NumericKeySelector<X>, selectorY: NumericKeySelector<Y>): number;
|
|
615
|
+
static correlation<T>(set: T[], selectorX: NumericKeySelector<T>, selectorY: NumericKeySelector<T>): number;
|
|
616
|
+
/**
|
|
617
|
+
* Linear regression gradient and intercept.
|
|
618
|
+
*/
|
|
619
|
+
static linearRegression(setX: number[], setY: number[]): [number, number];
|
|
620
|
+
static linearRegression<X, Y>(setX: X[], setY: Y[], selectorX: NumericKeySelector<X>, selectorY: NumericKeySelector<Y>): [number, number];
|
|
621
|
+
static linearRegression(set: Point[]): [number, number];
|
|
622
|
+
static linearRegression<T>(set: T[], selectorX: NumericKeySelector<T>, selectorY: NumericKeySelector<T>): [number, number];
|
|
623
|
+
/**
|
|
624
|
+
* Returns a set of utilities for gaussian distribution computations.
|
|
625
|
+
* @param mean
|
|
626
|
+
* @param stdev
|
|
627
|
+
*/
|
|
628
|
+
static gaussian(mean: number, stdev: number): Gaussian;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/** Utility tools about number theory, 'diophantine' stuff... */
|
|
632
|
+
declare class Utils_3 {
|
|
633
|
+
static lcd(...args: number[]): number;
|
|
634
|
+
static gcd(a: number, b: number): any;
|
|
635
|
+
static rebaseInt(v: number | string, from: number, to: number): string;
|
|
636
|
+
static rebaseFloat(v: number | string, fromRadix: number, toRadix: number, precision?: number): string | number;
|
|
637
|
+
static rebaseFloatNTo10(v: string, radix: number, precision?: number): number;
|
|
638
|
+
static rebaseFloat10ToNIntBase(v: number, radix: number, precision?: number): string;
|
|
639
|
+
static rebaseFloat10ToN(v: number, radix: number, precision?: number): string;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/** Represents a vector in the 2D space */
|
|
643
|
+
declare interface Vector extends Point {
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/** 2D vector utils. */
|
|
647
|
+
declare class Vector {
|
|
648
|
+
/**
|
|
649
|
+
* Returns the unit (normalized) vector having the same direction and sense of the provided one.
|
|
650
|
+
* @param v
|
|
651
|
+
*/
|
|
652
|
+
static unit(v: Vector): Vector;
|
|
653
|
+
static magSqr(v: Vector): number;
|
|
654
|
+
static mag(v: Vector): number;
|
|
655
|
+
/**
|
|
656
|
+
* Normalizes the provided vector in place.
|
|
657
|
+
* @param v
|
|
658
|
+
*/
|
|
659
|
+
static normalize(v: Vector): void;
|
|
660
|
+
/**
|
|
661
|
+
* Returns the vector joining two points.
|
|
662
|
+
* @param p1 Start point
|
|
663
|
+
* @param p2 End point
|
|
664
|
+
*/
|
|
665
|
+
static from(p1: Point, p2: Point): Vector;
|
|
666
|
+
/**
|
|
667
|
+
* Returns the dot product between two vectors/points.
|
|
668
|
+
* @param v1
|
|
669
|
+
* @param v2
|
|
670
|
+
*/
|
|
671
|
+
static dot(v1: Point, v2: Point): number;
|
|
672
|
+
/**
|
|
673
|
+
* Returns the cross product between two vectors/points (magnitude along the z axis).
|
|
674
|
+
* @param v1
|
|
675
|
+
* @param v2
|
|
676
|
+
*/
|
|
677
|
+
static cross(v1: Point, v2: Point): number;
|
|
678
|
+
/**
|
|
679
|
+
* Checks if the two points are effectively the same location.
|
|
680
|
+
* @param v1 The first point.
|
|
681
|
+
* @param v2 The second point.
|
|
682
|
+
* @returns True if the points are considered coincident within tolerance; otherwise, false.
|
|
683
|
+
*/
|
|
684
|
+
static areClose(v1: Point, v2: Point): boolean;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/** Represents a vector in the 3D space */
|
|
688
|
+
declare interface Vector3D extends Point3D {
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
declare class Vector3D {
|
|
692
|
+
static from(...args: number[]): Vector3D;
|
|
693
|
+
static parse(input: string): Vector3D;
|
|
694
|
+
static i(): Vector3D;
|
|
695
|
+
static j(): Vector3D;
|
|
696
|
+
static k(): Vector3D;
|
|
697
|
+
static zero(): Vector3D;
|
|
698
|
+
/**
|
|
699
|
+
* Subtracts a point p from another and returns the resulting vector.
|
|
700
|
+
* @param p Point to subtract
|
|
701
|
+
* @param from Point to be subtracted from
|
|
702
|
+
*/
|
|
703
|
+
static subtract(p: Point3D, from: Point3D): Point3D;
|
|
704
|
+
/**
|
|
705
|
+
* Adds a set of points together and returns the resulting vector.
|
|
706
|
+
* @param points Points to add
|
|
707
|
+
*/
|
|
708
|
+
static add(...points: Point3D[]): Point3D;
|
|
709
|
+
/**
|
|
710
|
+
* Returns the dot product between two vectors/points.
|
|
711
|
+
* @param v1
|
|
712
|
+
* @param v2
|
|
713
|
+
*/
|
|
714
|
+
static dot(v1: Point3D, v2: Point3D): number;
|
|
715
|
+
/**
|
|
716
|
+
* Returns the cross product between two vectors/points (as a vector itself).
|
|
717
|
+
* @param v1
|
|
718
|
+
* @param v2
|
|
719
|
+
*/
|
|
720
|
+
static cross(v1: Point3D, v2: Point3D): Vector3D;
|
|
721
|
+
static scale(v: Vector3D, f: number): Vector3D;
|
|
722
|
+
static scale(v: Vector3D, fx: number, fy: number, fz: number): Vector3D;
|
|
723
|
+
static magSqr(v: Point3D): number;
|
|
724
|
+
/**
|
|
725
|
+
* Checks if the two points are effectively the same location.
|
|
726
|
+
* @param v1 The first point.
|
|
727
|
+
* @param v2 The second point.
|
|
728
|
+
* @returns True if the points are considered coincident within tolerance; otherwise, false.
|
|
729
|
+
*/
|
|
730
|
+
static areClose(v1: Point3D, v2: Point3D): boolean;
|
|
731
|
+
static mag(v: Point3D): number;
|
|
732
|
+
static negate(v: Vector3D): Vector3D;
|
|
733
|
+
/**
|
|
734
|
+
* Returns the unit (normalized) vector having the same direction and sense of the provided one.
|
|
735
|
+
* @param v
|
|
736
|
+
*/
|
|
737
|
+
static unit(v: Vector3D): Vector3D;
|
|
738
|
+
/**
|
|
739
|
+
* Normalizes the provided vector in place.
|
|
740
|
+
* @param v
|
|
741
|
+
*/
|
|
742
|
+
static normalize(v: Vector3D): void;
|
|
743
|
+
/**
|
|
744
|
+
* Returns the angle (in degrees) between two vectors.
|
|
745
|
+
* @param vector1
|
|
746
|
+
* @param vector2
|
|
747
|
+
*/
|
|
748
|
+
static angleBetween(vector1: Vector3D, vector2: Vector3D): number;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
declare global {
|
|
754
|
+
namespace Pacem {
|
|
755
|
+
export {
|
|
756
|
+
DataAnalysis,
|
|
757
|
+
Geometry,
|
|
758
|
+
LinearAlgebra,
|
|
759
|
+
Mathematics,
|
|
760
|
+
NumberTheory
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
}
|