pacem 0.53.0 → 0.60.1-landau
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/css/pacem-dark-content.min.css +1 -1
- package/dist/css/pacem-dark-shell.min.css +1 -1
- package/dist/css/pacem-dark.min.css +1 -1
- package/dist/css/pacem-light-content.min.css +1 -1
- package/dist/css/pacem-light-shell.min.css +1 -1
- package/dist/css/pacem-light.min.css +1 -1
- package/dist/css/pacem-phousys-content.min.css +1 -1
- package/dist/css/pacem-phousys-shell.min.css +1 -1
- package/dist/css/pacem-phousys.min.css +1 -1
- package/dist/js/azure-maps.d.ts +1 -1
- package/dist/js/pacem-2d.d.ts +1 -1
- package/dist/js/pacem-2d.js +1 -1
- package/dist/js/pacem-2d.min.js +1 -1
- package/dist/js/pacem-3d.d.ts +1 -1
- package/dist/js/pacem-3d.js +1 -1
- package/dist/js/pacem-3d.min.js +1 -1
- package/dist/js/pacem-charts.d.ts +1 -1
- package/dist/js/pacem-charts.js +1 -1
- package/dist/js/pacem-charts.min.js +1 -1
- package/dist/js/pacem-cms.d.ts +1 -1
- package/dist/js/pacem-cms.js +1 -1
- package/dist/js/pacem-cms.min.js +1 -1
- package/dist/js/pacem-core.d.ts +1 -1
- package/dist/js/pacem-core.js +1 -1
- package/dist/js/pacem-core.min.js +1 -1
- package/dist/js/pacem-foundation.d.ts +1 -1
- package/dist/js/pacem-foundation.js +1 -1
- package/dist/js/pacem-foundation.min.js +1 -1
- package/dist/js/pacem-fx.d.ts +1 -1
- package/dist/js/pacem-fx.js +1 -1
- package/dist/js/pacem-fx.min.js +1 -1
- package/dist/js/pacem-logging.d.ts +1 -1
- package/dist/js/pacem-logging.js +1 -1
- package/dist/js/pacem-logging.min.js +1 -1
- package/dist/js/pacem-maps.d.ts +1 -1
- package/dist/js/pacem-maps.js +1 -1
- package/dist/js/pacem-maps.min.js +1 -1
- package/dist/js/pacem-media.d.ts +1 -1
- package/dist/js/pacem-media.js +1 -1
- package/dist/js/pacem-media.min.js +1 -1
- package/dist/js/pacem-networking.d.ts +1 -1
- package/dist/js/pacem-networking.js +1 -1
- package/dist/js/pacem-networking.min.js +1 -1
- package/dist/js/pacem-numerical.d.ts +32 -7
- package/dist/js/pacem-numerical.js +332 -27
- package/dist/js/pacem-numerical.min.js +2 -2
- package/dist/js/pacem-plus.d.ts +1 -1
- package/dist/js/pacem-plus.js +1 -1
- package/dist/js/pacem-plus.min.js +1 -1
- package/dist/js/pacem-scaffolding.d.ts +1 -1
- package/dist/js/pacem-scaffolding.js +1 -1
- package/dist/js/pacem-scaffolding.min.js +1 -1
- package/dist/js/pacem-ui.d.ts +1 -1
- package/dist/js/pacem-ui.js +1 -1
- package/dist/js/pacem-ui.min.js +1 -1
- package/dist/js/swagger-types.d.ts +1 -1
- package/package.json +1 -1
package/dist/js/azure-maps.d.ts
CHANGED
package/dist/js/pacem-2d.d.ts
CHANGED
package/dist/js/pacem-2d.js
CHANGED
package/dist/js/pacem-2d.min.js
CHANGED
package/dist/js/pacem-3d.d.ts
CHANGED
package/dist/js/pacem-3d.js
CHANGED
package/dist/js/pacem-3d.min.js
CHANGED
package/dist/js/pacem-charts.js
CHANGED
package/dist/js/pacem-cms.d.ts
CHANGED
package/dist/js/pacem-cms.js
CHANGED
package/dist/js/pacem-cms.min.js
CHANGED
package/dist/js/pacem-core.d.ts
CHANGED
package/dist/js/pacem-core.js
CHANGED
package/dist/js/pacem-fx.d.ts
CHANGED
package/dist/js/pacem-fx.js
CHANGED
package/dist/js/pacem-fx.min.js
CHANGED
package/dist/js/pacem-logging.js
CHANGED
package/dist/js/pacem-maps.d.ts
CHANGED
package/dist/js/pacem-maps.js
CHANGED
package/dist/js/pacem-media.d.ts
CHANGED
package/dist/js/pacem-media.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* pacem v0.
|
|
2
|
+
* pacem v0.60.1-landau (https://js.pacem.it)
|
|
3
3
|
* Copyright 2026 Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
@@ -18,14 +18,34 @@ declare namespace Pacem.Geometry.LinearAlgebra {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
declare namespace Pacem.Geometry {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
class Delaunay {
|
|
22
|
+
static triangulate(vertices: Point[]): number[];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
declare namespace Pacem.Geometry {
|
|
26
|
+
export type Segment = [Point, Point];
|
|
27
|
+
export interface Polygon {
|
|
28
|
+
vertices: Point[];
|
|
29
|
+
}
|
|
30
|
+
type Mesh = Polygon & {
|
|
31
|
+
triangleIndices: number[];
|
|
32
|
+
};
|
|
33
|
+
type PolygonCompound = 'union' | 'intersect' | 'difference';
|
|
34
|
+
export class Utils {
|
|
23
35
|
static slopeRad(p1: Point, p2: Point): number;
|
|
24
36
|
static slopeRad2(p1: Point, p2: Point): number;
|
|
25
37
|
static slopeDeg(p1: Point, p2: Point): number;
|
|
26
38
|
static slopeDeg2(p1: Point, p2: Point): number;
|
|
27
39
|
static intersect(...rects: Rect[]): Rect;
|
|
40
|
+
static intersect(polygon1: Polygon, polygon2: Polygon): Polygon[];
|
|
28
41
|
static intersect(segment1: Segment, segment2: Segment): Point;
|
|
42
|
+
static combinePolygons(polygon1: Polygon, polygon2: Polygon, operator: PolygonCompound): {
|
|
43
|
+
polygons: Polygon[];
|
|
44
|
+
mesh: Mesh;
|
|
45
|
+
} | null;
|
|
46
|
+
private static _mergePolygons;
|
|
47
|
+
static mesh(...points: Point[]): any;
|
|
48
|
+
static mesh(points: Point[]): any;
|
|
29
49
|
static intersectLines(segment1: Segment, segment2: Segment): Point;
|
|
30
50
|
static intersectLines(m1: number, q1: number, m2: number, q2: number): Point;
|
|
31
51
|
static intersectLines(mq1: [number, number], mq2: [number, number]): Point;
|
|
@@ -43,21 +63,27 @@ declare namespace Pacem.Geometry {
|
|
|
43
63
|
static mq(segment: Segment): [number, number];
|
|
44
64
|
private static _intersectSegments;
|
|
45
65
|
private static _intersectRects;
|
|
66
|
+
private static _areClose;
|
|
67
|
+
static areClose(p1: Point, p2: Point, precision?: number): boolean;
|
|
46
68
|
static dot(v1: Point, v2: Point): number;
|
|
47
69
|
static cross(v1: Point, v2: Point): number;
|
|
48
70
|
static distance(p1: Point, p2: Point): number;
|
|
49
71
|
static distance(p: Point, mq: [number, number]): number;
|
|
50
72
|
static distance(segment: Segment): number;
|
|
73
|
+
private static _pointSegmentDistance;
|
|
74
|
+
static isWithin(p: Point, segment: Segment, clockwise: boolean): boolean;
|
|
75
|
+
static isBeyond(p: Point, segment: Segment, clockwise: boolean): boolean;
|
|
51
76
|
static inLine(p: Point, segment: Segment): boolean;
|
|
52
77
|
static inSegment(p: Point, segment: Segment): boolean;
|
|
53
78
|
static inTriangle(p: Point, triangle: [Point, Point, Point]): boolean;
|
|
54
79
|
static inPolygon(p: Point, vertices: Point[]): any;
|
|
55
80
|
static inPolygon(p: Point, vertices: Point[], precision: number): any;
|
|
56
|
-
static area(points: Point[]): number;
|
|
57
81
|
static area(...points: Point[]): number;
|
|
82
|
+
static area(points: Point[]): number;
|
|
58
83
|
static convexHull(...points: Point[]): Point[];
|
|
59
84
|
static convexHull(points: Point[]): Point[];
|
|
60
85
|
}
|
|
86
|
+
export {};
|
|
61
87
|
}
|
|
62
88
|
declare namespace Pacem.Geometry.LinearAlgebra {
|
|
63
89
|
interface Point3D {
|
|
@@ -177,10 +203,8 @@ declare namespace Pacem.Geometry {
|
|
|
177
203
|
export {};
|
|
178
204
|
}
|
|
179
205
|
declare namespace Pacem.Geometry {
|
|
180
|
-
interface Polygon {
|
|
181
|
-
vertices: Point[];
|
|
182
|
-
}
|
|
183
206
|
class Polygon {
|
|
207
|
+
private static readonly _eps;
|
|
184
208
|
static isPolygon(obj: any): obj is Polygon;
|
|
185
209
|
static from(...points: Point[]): Polygon;
|
|
186
210
|
static contains(polygon: Polygon, p: Point): any;
|
|
@@ -192,6 +216,7 @@ declare namespace Pacem.Geometry {
|
|
|
192
216
|
static isCounterClockwise(polygon: Polygon): boolean;
|
|
193
217
|
static expand(polygon: Polygon, offset: number): Polygon;
|
|
194
218
|
static area(polygon: Polygon): number;
|
|
219
|
+
static intersect(polygon1: Polygon, polygon2: Polygon): Polygon[];
|
|
195
220
|
static convexHull(polygon: Polygon): Polygon;
|
|
196
221
|
}
|
|
197
222
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* pacem v0.
|
|
2
|
+
* pacem v0.60.1-landau (https://js.pacem.it)
|
|
3
3
|
* Copyright 2026 Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
@@ -50,6 +50,150 @@ var Pacem;
|
|
|
50
50
|
})(Geometry = Pacem.Geometry || (Pacem.Geometry = {}));
|
|
51
51
|
})(Pacem || (Pacem = {}));
|
|
52
52
|
var Pacem;
|
|
53
|
+
(function (Pacem) {
|
|
54
|
+
var Geometry;
|
|
55
|
+
(function (Geometry) {
|
|
56
|
+
class Vertex {
|
|
57
|
+
x;
|
|
58
|
+
y;
|
|
59
|
+
index;
|
|
60
|
+
constructor(x, y, index = -1) {
|
|
61
|
+
this.x = x;
|
|
62
|
+
this.y = y;
|
|
63
|
+
this.index = index;
|
|
64
|
+
}
|
|
65
|
+
equals(other) {
|
|
66
|
+
return this.x === other.x && this.y === other.y;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function calcCircumCirc(v0, v1, v2) {
|
|
70
|
+
const ax = v0.x, ay = v0.y;
|
|
71
|
+
const bx = v1.x, by = v1.y;
|
|
72
|
+
const cx = v2.x, cy = v2.y;
|
|
73
|
+
const d = 2 * (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by));
|
|
74
|
+
if (Math.abs(d) < 1e-12) {
|
|
75
|
+
return { c: { x: 0, y: 0 }, r: Infinity };
|
|
76
|
+
}
|
|
77
|
+
const ux = ((ax * ax + ay * ay) * (by - cy) +
|
|
78
|
+
(bx * bx + by * by) * (cy - ay) +
|
|
79
|
+
(cx * cx + cy * cy) * (ay - by)) /
|
|
80
|
+
d;
|
|
81
|
+
const uy = ((ax * ax + ay * ay) * (cx - bx) +
|
|
82
|
+
(bx * bx + by * by) * (ax - cx) +
|
|
83
|
+
(cx * cx + cy * cy) * (bx - ax)) /
|
|
84
|
+
d;
|
|
85
|
+
const r = Math.hypot(ux - ax, uy - ay);
|
|
86
|
+
return { c: { x: ux, y: uy }, r };
|
|
87
|
+
}
|
|
88
|
+
class Triangle {
|
|
89
|
+
v0;
|
|
90
|
+
v1;
|
|
91
|
+
v2;
|
|
92
|
+
circumCirc;
|
|
93
|
+
constructor(v0, v1, v2) {
|
|
94
|
+
this.v0 = v0;
|
|
95
|
+
this.v1 = v1;
|
|
96
|
+
this.v2 = v2;
|
|
97
|
+
this.circumCirc = calcCircumCirc(v0, v1, v2);
|
|
98
|
+
}
|
|
99
|
+
inCircumcircle(v) {
|
|
100
|
+
const dx = this.circumCirc.c.x - v.x;
|
|
101
|
+
const dy = this.circumCirc.c.y - v.y;
|
|
102
|
+
return Math.hypot(dx, dy) <= this.circumCirc.r + 1e-9;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function superTriangle(vertices) {
|
|
106
|
+
let minX = Infinity, minY = Infinity;
|
|
107
|
+
let maxX = -Infinity, maxY = -Infinity;
|
|
108
|
+
for (const v of vertices) {
|
|
109
|
+
minX = Math.min(minX, v.x);
|
|
110
|
+
minY = Math.min(minY, v.y);
|
|
111
|
+
maxX = Math.max(maxX, v.x);
|
|
112
|
+
maxY = Math.max(maxY, v.y);
|
|
113
|
+
}
|
|
114
|
+
const dx = (maxX - minX) * 10;
|
|
115
|
+
const dy = (maxY - minY) * 10;
|
|
116
|
+
const v0 = new Vertex(minX - dx, minY - dy * 3);
|
|
117
|
+
const v1 = new Vertex(minX - dx, maxY + dy);
|
|
118
|
+
const v2 = new Vertex(maxX + dx * 3, maxY + dy);
|
|
119
|
+
return new Triangle(v0, v1, v2);
|
|
120
|
+
}
|
|
121
|
+
function uniqueEdges(edges) {
|
|
122
|
+
const unique = [];
|
|
123
|
+
for (let i = 0; i < edges.length; ++i) {
|
|
124
|
+
let isUnique = true;
|
|
125
|
+
for (let j = 0; j < edges.length; ++j) {
|
|
126
|
+
if (i !== j) {
|
|
127
|
+
const e1 = edges[i];
|
|
128
|
+
const e2 = edges[j];
|
|
129
|
+
if ((e1.v0.equals(e2.v0) && e1.v1.equals(e2.v1)) ||
|
|
130
|
+
(e1.v0.equals(e2.v1) && e1.v1.equals(e2.v0))) {
|
|
131
|
+
isUnique = false;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (isUnique)
|
|
137
|
+
unique.push(edges[i]);
|
|
138
|
+
}
|
|
139
|
+
return unique;
|
|
140
|
+
}
|
|
141
|
+
function addVertex(vertex, triangles) {
|
|
142
|
+
const edges = [];
|
|
143
|
+
triangles = triangles.filter((triangle) => {
|
|
144
|
+
if (triangle.inCircumcircle(vertex)) {
|
|
145
|
+
edges.push({ v0: triangle.v0, v1: triangle.v1 });
|
|
146
|
+
edges.push({ v0: triangle.v1, v1: triangle.v2 });
|
|
147
|
+
edges.push({ v0: triangle.v2, v1: triangle.v0 });
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
return true;
|
|
151
|
+
});
|
|
152
|
+
const unique = uniqueEdges(edges);
|
|
153
|
+
for (const edge of unique) {
|
|
154
|
+
triangles.push(new Triangle(edge.v0, edge.v1, vertex));
|
|
155
|
+
}
|
|
156
|
+
return triangles;
|
|
157
|
+
}
|
|
158
|
+
function triangulate(vertices) {
|
|
159
|
+
if (vertices.length < 3)
|
|
160
|
+
return [];
|
|
161
|
+
const st = superTriangle(vertices);
|
|
162
|
+
let triangles = [st];
|
|
163
|
+
for (const vertex of vertices) {
|
|
164
|
+
triangles = addVertex(vertex, triangles);
|
|
165
|
+
}
|
|
166
|
+
triangles = triangles.filter((t) => !(t.v0 === st.v0 ||
|
|
167
|
+
t.v0 === st.v1 ||
|
|
168
|
+
t.v0 === st.v2 ||
|
|
169
|
+
t.v1 === st.v0 ||
|
|
170
|
+
t.v1 === st.v1 ||
|
|
171
|
+
t.v1 === st.v2 ||
|
|
172
|
+
t.v2 === st.v0 ||
|
|
173
|
+
t.v2 === st.v1 ||
|
|
174
|
+
t.v2 === st.v2));
|
|
175
|
+
return triangles;
|
|
176
|
+
}
|
|
177
|
+
function delaunayTriangulation(vertices) {
|
|
178
|
+
if (vertices.length < 3)
|
|
179
|
+
return [];
|
|
180
|
+
const vertList = vertices.map((p, idx) => new Vertex(p.x, p.y, idx));
|
|
181
|
+
const triangles = triangulate(vertList);
|
|
182
|
+
const indices = [];
|
|
183
|
+
for (const t of triangles) {
|
|
184
|
+
indices.push(t.v0.index, t.v1.index, t.v2.index);
|
|
185
|
+
}
|
|
186
|
+
return indices;
|
|
187
|
+
}
|
|
188
|
+
class Delaunay {
|
|
189
|
+
static triangulate(vertices) {
|
|
190
|
+
return delaunayTriangulation(vertices);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
Geometry.Delaunay = Delaunay;
|
|
194
|
+
})(Geometry = Pacem.Geometry || (Pacem.Geometry = {}));
|
|
195
|
+
})(Pacem || (Pacem = {}));
|
|
196
|
+
var Pacem;
|
|
53
197
|
(function (Pacem) {
|
|
54
198
|
var Geometry;
|
|
55
199
|
(function (Geometry) {
|
|
@@ -68,21 +212,159 @@ var Pacem;
|
|
|
68
212
|
return Math.atan2(p2.y - p1.y, p2.x - p1.x);
|
|
69
213
|
}
|
|
70
214
|
static slopeRad2(p1, p2) {
|
|
71
|
-
return (RAD_ROUND +
|
|
215
|
+
return (RAD_ROUND + Utils.slopeRad(p1, p2)) % RAD_ROUND;
|
|
72
216
|
}
|
|
73
217
|
static slopeDeg(p1, p2) {
|
|
74
|
-
return
|
|
218
|
+
return Utils.slopeRad(p1, p2) * RAD2DEG;
|
|
75
219
|
}
|
|
76
220
|
static slopeDeg2(p1, p2) {
|
|
77
|
-
return (360 +
|
|
221
|
+
return (360 + Utils.slopeDeg(p1, p2)) % 360;
|
|
78
222
|
}
|
|
79
223
|
static intersect(arg1, arg2, ...args) {
|
|
80
224
|
if (Array.isArray(arg1) && Array.isArray(arg2)) {
|
|
81
|
-
return
|
|
225
|
+
return Utils._intersectSegments(arg1, arg2, true);
|
|
226
|
+
}
|
|
227
|
+
else if (Pacem.Rect.isRect(arg1)) {
|
|
228
|
+
return Utils._intersectRects(...arguments);
|
|
229
|
+
}
|
|
230
|
+
else if ('vertices' in arg1) {
|
|
231
|
+
return Utils._mergePolygons(arg1, arg2, 'intersect')?.polygons ?? [];
|
|
82
232
|
}
|
|
83
233
|
else {
|
|
84
|
-
return
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
static combinePolygons(polygon1, polygon2, operator) {
|
|
238
|
+
return Utils._mergePolygons(polygon1, polygon2, operator);
|
|
239
|
+
}
|
|
240
|
+
static _mergePolygons(polygon1, polygon2, operator) {
|
|
241
|
+
if (Pacem.NullChecker.isNullOrEmpty(polygon1?.vertices) || Pacem.NullChecker.isNullOrEmpty(polygon2?.vertices)) {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
const { vertices: vertices1 } = polygon1, { vertices: vertices2 } = polygon2;
|
|
245
|
+
if (vertices1.length < 3 || vertices2.length < 3) {
|
|
246
|
+
return null;
|
|
85
247
|
}
|
|
248
|
+
const sideBuilderCallback = (v, j, arr) => [v, arr[(j + 1) % arr.length]];
|
|
249
|
+
const verticesSortCallback = (a, b) => a.x === b.x ? a.y - b.y : a.x - b.x;
|
|
250
|
+
const edges1 = vertices1.map(sideBuilderCallback), edges2 = vertices2.map(sideBuilderCallback);
|
|
251
|
+
const outputVertices = vertices1.concat(vertices2);
|
|
252
|
+
const memoizer = new Map();
|
|
253
|
+
const ensureMemoizer = e => {
|
|
254
|
+
if (!memoizer.has(e)) {
|
|
255
|
+
const retval = [];
|
|
256
|
+
memoizer.set(e, retval);
|
|
257
|
+
}
|
|
258
|
+
return memoizer.get(e);
|
|
259
|
+
};
|
|
260
|
+
for (let edge1 of edges1) {
|
|
261
|
+
const additionalVertices1 = ensureMemoizer(edge1);
|
|
262
|
+
for (let edge2 of edges2) {
|
|
263
|
+
const additionalVertices2 = ensureMemoizer(edge2);
|
|
264
|
+
const intersection = Utils.intersect(edge1, edge2);
|
|
265
|
+
if (!Pacem.NullChecker.isNull(intersection)) {
|
|
266
|
+
outputVertices.push(intersection);
|
|
267
|
+
additionalVertices1.push(intersection);
|
|
268
|
+
additionalVertices2.push(intersection);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
const constraints = [];
|
|
273
|
+
for (let edge of edges1.concat(edges2)) {
|
|
274
|
+
const additionalVertices = ensureMemoizer(edge);
|
|
275
|
+
if (Pacem.NullChecker.isNullOrEmpty(additionalVertices)) {
|
|
276
|
+
constraints.push(edge);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
const totalVertices = edge.concat(additionalVertices).sort(verticesSortCallback);
|
|
280
|
+
for (let j = 0; j < totalVertices.length - 1; j++) {
|
|
281
|
+
constraints.push([totalVertices[j], totalVertices[j + 1]]);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
var dirty = false;
|
|
286
|
+
var mesh;
|
|
287
|
+
do {
|
|
288
|
+
outputVertices.sort(verticesSortCallback);
|
|
289
|
+
outputVertices.filter((v, i, arr) => { return i === 0 || !Utils.areClose(v, arr[i - 1]); });
|
|
290
|
+
mesh = Utils.mesh(outputVertices);
|
|
291
|
+
const { vertices, triangleIndices } = mesh;
|
|
292
|
+
dirty = false;
|
|
293
|
+
for (let j = 0; j < triangleIndices.length; j += 3) {
|
|
294
|
+
const indexA = triangleIndices[j], indexB = triangleIndices[j + 1], indexC = triangleIndices[j + 2];
|
|
295
|
+
const A = vertices[indexA], B = vertices[indexB], C = vertices[indexC];
|
|
296
|
+
const sides = [[A, B], [B, C], [C, A]];
|
|
297
|
+
for (let constraint of constraints) {
|
|
298
|
+
for (let side of sides) {
|
|
299
|
+
const consecutive = Utils.areClose(side[0], constraint[0])
|
|
300
|
+
|| Utils.areClose(side[1], constraint[1])
|
|
301
|
+
|| Utils.areClose(side[0], constraint[1])
|
|
302
|
+
|| Utils.areClose(side[1], constraint[0]);
|
|
303
|
+
const intersection = consecutive ? null : Utils.intersect(side, constraint);
|
|
304
|
+
if (!Pacem.NullChecker.isNull(intersection) && outputVertices.findIndex(p => Utils.areClose(p, intersection, 4)) === -1) {
|
|
305
|
+
dirty = true;
|
|
306
|
+
outputVertices.push(intersection);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
} while (dirty);
|
|
312
|
+
const { vertices, triangleIndices } = mesh;
|
|
313
|
+
const triangles = [];
|
|
314
|
+
for (let j = 0; j < triangleIndices.length; j += 3) {
|
|
315
|
+
const A = vertices[triangleIndices[j]], B = vertices[triangleIndices[j + 1]], C = vertices[triangleIndices[j + 2]];
|
|
316
|
+
const O = { x: (A.x + B.x + C.x) / 3, y: (A.y + B.y + C.y) / 3 };
|
|
317
|
+
const in1 = Utils.inPolygon(O, vertices1), in2 = Utils.inPolygon(O, vertices2);
|
|
318
|
+
if (in1 && in2 && operator === 'intersect'
|
|
319
|
+
|| (in1 || in2) && operator === 'union'
|
|
320
|
+
|| (in1 && !in2 || !in1 && in2) && operator === 'difference') {
|
|
321
|
+
triangles.push([A, B, C]);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const edges = triangles.flatMap(([A, B, C]) => [[A, B], [B, C], [C, A]]);
|
|
325
|
+
const uniqueEdges = [];
|
|
326
|
+
for (let j = 0; j < edges.length; j++) {
|
|
327
|
+
const edge = edges[j];
|
|
328
|
+
if (j == 0) {
|
|
329
|
+
uniqueEdges.push(edge);
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
const alreadyIn = uniqueEdges.findIndex(e => Utils.areClose(e[0], edge[0]) && Utils.areClose(e[1], edge[1]) || Utils.areClose(e[0], edge[1]) && Utils.areClose(e[1], edge[0]));
|
|
333
|
+
if (alreadyIn === -1) {
|
|
334
|
+
uniqueEdges.push(edge);
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
uniqueEdges.splice(alreadyIn, 1);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (uniqueEdges.length < 3) {
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
const polygons = [];
|
|
344
|
+
const [P0, P1] = uniqueEdges.shift();
|
|
345
|
+
const boundaryVertices = [P0, P1];
|
|
346
|
+
while (uniqueEdges.length > 1) {
|
|
347
|
+
const lastVertex = boundaryVertices[boundaryVertices.length - 1];
|
|
348
|
+
const nextEdgeIndex = uniqueEdges.findIndex(e => Utils.areClose(e[0], lastVertex) || Utils.areClose(e[1], lastVertex));
|
|
349
|
+
if (nextEdgeIndex === -1) {
|
|
350
|
+
polygons.push({ vertices: boundaryVertices.splice(0) });
|
|
351
|
+
const [P2, P3] = uniqueEdges.shift();
|
|
352
|
+
boundaryVertices.push(P2, P3);
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
const [nextEdge] = uniqueEdges.splice(nextEdgeIndex, 1);
|
|
356
|
+
const nextVertex = Utils.areClose(nextEdge[0], lastVertex) ? nextEdge[1] : (Utils.areClose(nextEdge[1], lastVertex) ? nextEdge[0] : null);
|
|
357
|
+
boundaryVertices.push(nextVertex);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
polygons.push({ vertices: boundaryVertices });
|
|
361
|
+
return {
|
|
362
|
+
polygons, mesh
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
static mesh(point, ...points) {
|
|
366
|
+
const vertices = [].concat(point).concat(points), triangleIndices = Geometry.Delaunay.triangulate(vertices);
|
|
367
|
+
return { vertices, triangleIndices };
|
|
86
368
|
}
|
|
87
369
|
static intersectLines(segment1, segment2, m2, q2) {
|
|
88
370
|
let s1, s2;
|
|
@@ -109,7 +391,7 @@ var Pacem;
|
|
|
109
391
|
s1 = segment1;
|
|
110
392
|
s2 = segment2;
|
|
111
393
|
}
|
|
112
|
-
return
|
|
394
|
+
return Utils._intersectSegments(s1, s2, false);
|
|
113
395
|
}
|
|
114
396
|
static cramer(l1, l2) {
|
|
115
397
|
if (Array.isArray(l1)) {
|
|
@@ -156,8 +438,8 @@ var Pacem;
|
|
|
156
438
|
if (excludeProjection && (xCD > xAB || XCD < XAB)) {
|
|
157
439
|
return null;
|
|
158
440
|
}
|
|
159
|
-
const mqCD =
|
|
160
|
-
retval =
|
|
441
|
+
const mqCD = Utils.mq(C, D);
|
|
442
|
+
retval = Utils.cramer([1, 0, -xAB], [mqCD[0], -1, mqCD[1]]);
|
|
161
443
|
if (excludeProjection && outOfYBounds(retval)) {
|
|
162
444
|
retval = null;
|
|
163
445
|
}
|
|
@@ -166,8 +448,8 @@ var Pacem;
|
|
|
166
448
|
if (excludeProjection && (xAB > xCD || XAB < XCD)) {
|
|
167
449
|
return null;
|
|
168
450
|
}
|
|
169
|
-
const mqAB =
|
|
170
|
-
retval =
|
|
451
|
+
const mqAB = Utils.mq(A, B);
|
|
452
|
+
retval = Utils.cramer([mqAB[0], -1, mqAB[1]], [1, 0, -xCD]);
|
|
171
453
|
if (excludeProjection && outOfYBounds(retval)) {
|
|
172
454
|
retval = null;
|
|
173
455
|
}
|
|
@@ -176,8 +458,8 @@ var Pacem;
|
|
|
176
458
|
if (excludeProjection && (yCD > yAB || YCD < YAB)) {
|
|
177
459
|
return null;
|
|
178
460
|
}
|
|
179
|
-
const mqCD =
|
|
180
|
-
retval =
|
|
461
|
+
const mqCD = Utils.mq(C, D);
|
|
462
|
+
retval = Utils.cramer([0, 1, -yAB], [mqCD[0], -1, mqCD[1]]);
|
|
181
463
|
if (excludeProjection && outOfXBounds(retval)) {
|
|
182
464
|
retval = null;
|
|
183
465
|
}
|
|
@@ -186,8 +468,8 @@ var Pacem;
|
|
|
186
468
|
if (excludeProjection && (yAB > yCD || YAB < YCD)) {
|
|
187
469
|
return null;
|
|
188
470
|
}
|
|
189
|
-
const mqAB =
|
|
190
|
-
retval =
|
|
471
|
+
const mqAB = Utils.mq(A, B);
|
|
472
|
+
retval = Utils.cramer([mqAB[0], -1, mqAB[1]], [0, 1, -yCD]);
|
|
191
473
|
if (excludeProjection && outOfXBounds(retval)) {
|
|
192
474
|
retval = null;
|
|
193
475
|
}
|
|
@@ -195,13 +477,13 @@ var Pacem;
|
|
|
195
477
|
else {
|
|
196
478
|
let intersection;
|
|
197
479
|
if (!excludeProjection ||
|
|
198
|
-
((intersection =
|
|
480
|
+
((intersection = Utils._intersectRects({ x: xAB, y: yAB, width: wAB, height: hAB }, { x: xCD, y: yCD, width: wCD, height: hCD }))
|
|
199
481
|
&& intersection.width > 0
|
|
200
482
|
&& intersection.height > 0)) {
|
|
201
|
-
const mqAB =
|
|
483
|
+
const mqAB = Utils.mq(A, B), mqCD = Utils.mq(C, D);
|
|
202
484
|
const mAB = mqAB[0], mCD = mqCD[0], qAB = mqAB[1], qCD = mqCD[1];
|
|
203
485
|
if (mAB !== mCD) {
|
|
204
|
-
retval =
|
|
486
|
+
retval = Utils.cramer([mAB, -1, qAB], [mCD, -1, qCD]);
|
|
205
487
|
let xR = retval.x, yR = retval.y;
|
|
206
488
|
if (excludeProjection
|
|
207
489
|
&& (xR < intersection.x || xR > (intersection.x + intersection.width)
|
|
@@ -217,7 +499,13 @@ var Pacem;
|
|
|
217
499
|
return { x: retval.x, y: retval.y };
|
|
218
500
|
}
|
|
219
501
|
static _intersectRects(...args) {
|
|
220
|
-
return Pacem.Rect.intersect
|
|
502
|
+
return Pacem.Rect.intersect(...args);
|
|
503
|
+
}
|
|
504
|
+
static _areClose(p1, p2, precision = 12) {
|
|
505
|
+
return Math.abs(p1.x - p2.x).isCloseTo(0, precision) && Math.abs(p1.y - p2.y).isCloseTo(0, precision);
|
|
506
|
+
}
|
|
507
|
+
static areClose(p1, p2, precision = 12) {
|
|
508
|
+
return Utils._areClose(p1, p2, precision);
|
|
221
509
|
}
|
|
222
510
|
static dot(v1, v2) {
|
|
223
511
|
return Vector.dot(v1, v2);
|
|
@@ -237,19 +525,32 @@ var Pacem;
|
|
|
237
525
|
return Math.abs(m * p1.x - p1.y + q) / Math.sqrt(Math.pow(m, 2) + 1);
|
|
238
526
|
}
|
|
239
527
|
}
|
|
528
|
+
static _pointSegmentDistance(p, segment) {
|
|
529
|
+
const v1 = Vector.from(segment[0], segment[1]), v2 = Vector.from(segment[0], p);
|
|
530
|
+
return Utils.cross(v1, v2);
|
|
531
|
+
}
|
|
532
|
+
static isWithin(p, segment, clockwise) {
|
|
533
|
+
const cross = Utils._pointSegmentDistance(p, segment);
|
|
534
|
+
if (cross.isCloseTo(0)) {
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
537
|
+
return clockwise ? cross < 0 : cross > 0;
|
|
538
|
+
}
|
|
539
|
+
static isBeyond(p, segment, clockwise) {
|
|
540
|
+
return Utils.isWithin(p, segment, !clockwise);
|
|
541
|
+
}
|
|
240
542
|
static inLine(p, segment) {
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
return prod.isCloseTo(0);
|
|
543
|
+
const cross = Utils._pointSegmentDistance(p, segment);
|
|
544
|
+
return cross.isCloseTo(0);
|
|
244
545
|
}
|
|
245
546
|
static inSegment(p, segment) {
|
|
246
547
|
const minx = Math.min(segment[0].x, segment[1].x), maxx = Math.max(segment[0].x, segment[1].x), miny = Math.min(segment[0].y, segment[1].y), maxy = Math.max(segment[0].y, segment[1].y);
|
|
247
|
-
return p.x >= minx && p.x <= maxx && p.y >= miny && p.y <= maxy &&
|
|
548
|
+
return p.x >= minx && p.x <= maxx && p.y >= miny && p.y <= maxy && Utils.inLine(p, segment);
|
|
248
549
|
}
|
|
249
550
|
static inTriangle(p, triangle) {
|
|
250
551
|
let last;
|
|
251
552
|
for (let j = 0; j < 3; j++) {
|
|
252
|
-
const p1 = triangle[j], p2 = triangle[(j + 1) % 3], v1 = Pacem.Point.subtract(p2, p), v2 = Pacem.Point.subtract(p1, p), current =
|
|
553
|
+
const p1 = triangle[j], p2 = triangle[(j + 1) % 3], v1 = Pacem.Point.subtract(p2, p), v2 = Pacem.Point.subtract(p1, p), current = Utils.cross(v1, v2);
|
|
253
554
|
if (j > 0 && (current * last) <= 0) {
|
|
254
555
|
return false;
|
|
255
556
|
}
|
|
@@ -257,13 +558,13 @@ var Pacem;
|
|
|
257
558
|
}
|
|
258
559
|
return true;
|
|
259
560
|
}
|
|
260
|
-
static inPolygon(p, vertices, precision) {
|
|
561
|
+
static inPolygon(p, vertices, precision = 12) {
|
|
261
562
|
if (!(vertices?.length >= 3)) {
|
|
262
563
|
throw `Not enough vertices`;
|
|
263
564
|
}
|
|
264
565
|
const length = vertices.length;
|
|
265
566
|
if (length === 3) {
|
|
266
|
-
return
|
|
567
|
+
return Utils.inTriangle(p, [vertices[0], vertices[1], vertices[2]]);
|
|
267
568
|
}
|
|
268
569
|
if (precision > 0) {
|
|
269
570
|
vertices = vertices.map(v => { return { x: v.x.roundoff(precision), y: v.y.roundoff(precision) }; });
|
|
@@ -294,7 +595,7 @@ var Pacem;
|
|
|
294
595
|
continue;
|
|
295
596
|
}
|
|
296
597
|
else {
|
|
297
|
-
if (
|
|
598
|
+
if (Utils.intersect(side, test) != null) {
|
|
298
599
|
intersections++;
|
|
299
600
|
}
|
|
300
601
|
}
|
|
@@ -973,6 +1274,7 @@ var Pacem;
|
|
|
973
1274
|
&& vertices.every(i => Pacem.Point.isPoint(i));
|
|
974
1275
|
}
|
|
975
1276
|
class Polygon {
|
|
1277
|
+
static _eps = 1e-12;
|
|
976
1278
|
static isPolygon(obj) {
|
|
977
1279
|
return isPolygon(obj);
|
|
978
1280
|
}
|
|
@@ -1068,6 +1370,9 @@ var Pacem;
|
|
|
1068
1370
|
static area(polygon) {
|
|
1069
1371
|
return Geometry.Utils.area(polygon.vertices);
|
|
1070
1372
|
}
|
|
1373
|
+
static intersect(polygon1, polygon2) {
|
|
1374
|
+
return Pacem.Geometry.Utils.intersect(polygon1, polygon2);
|
|
1375
|
+
}
|
|
1071
1376
|
static convexHull(polygon) {
|
|
1072
1377
|
const vertices = Geometry.Utils.convexHull(polygon.vertices);
|
|
1073
1378
|
return { vertices };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* pacem v0.
|
|
2
|
+
* pacem v0.60.1-landau (https://js.pacem.it)
|
|
3
3
|
* Copyright 2026 Pacem (https://pacem.it)
|
|
4
4
|
* Licensed under Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
"use strict";var Pacem;!function(t){!function(e){!function(e){class Vector{static unit(t){const e={x:t.x,y:t.y};return this.normalize(e),e}static magSqr(t){return t.x*t.x+t.y*t.y}static mag(t){return Math.sqrt(Vector.magSqr(t))}static normalize(t){const e=Vector.mag(t);if(e<=0)throw"Cannot normalize a vector of length 0.";const r=1/e;t.x*=r,t.y*=r}static from(e,r){return t.Point.subtract(e,r)}static dot(t,e){return t.x*e.x+t.y*e.y}static cross(t,e){return t.x*e.y-t.y*e.x}static areClose(t,e){return(e.x-t.x).isCloseTo(0)&&(e.y-t.y).isCloseTo(0)}}e.Vector=Vector}(e.LinearAlgebra||(e.LinearAlgebra={}))}(t.Geometry||(t.Geometry={}))}(Pacem||(Pacem={})),function(t){!function(e){const r=180/Math.PI,n=2*Math.PI,s=e.LinearAlgebra.Vector;function a(e){return t.Point.isPoint(e)}e.Utils=class Utils{static slopeRad(t,e){return Math.atan2(e.y-t.y,e.x-t.x)}static slopeRad2(t,e){return(n+this.slopeRad(t,e))%n}static slopeDeg(t,e){return this.slopeRad(t,e)*r}static slopeDeg2(t,e){return(360+this.slopeDeg(t,e))%360}static intersect(t,e,...r){return Array.isArray(t)&&Array.isArray(e)?this._intersectSegments(t,e,!0):this._intersectRects.apply(this,arguments)}static intersectLines(t,e,r,n){let s,a;if(Array.isArray(t)&&Array.isArray(e)&&2===t.length&&2===e.length&&"number"==typeof t[0]&&"number"==typeof e[0]&&"number"==typeof t[1]&&"number"==typeof e[1]&&(r=e[0],n=e[1],e=t[1],t=t[0]),"number"==typeof t&&"number"==typeof e){s=[{x:0,y:e},{x:1,y:t+e}],a=[{x:0,y:n},{x:1,y:r+n}]}else s=t,a=e;return this._intersectSegments(s,a,!1)}static cramer(t,e){Array.isArray(t)&&(t={a:t[0],b:t[1],c:t[2]}),Array.isArray(e)&&(e={a:e[0],b:e[1],c:e[2]});let r=(t.b*e.c-t.c*e.b)/(t.b*e.a-t.a*e.b),n=(t.c*e.a-t.a*e.c)/(t.b*e.a-t.a*e.b);return{x:-r.roundoff(),y:-n.roundoff()}}static mq(t,e){let r;if(a(t)?r=t:(r=t[0],e=t[1]),r.x===e.x)return[Number.NaN,Number.NaN];const n=(e.y-r.y)/(e.x-r.x);return[n,r.y-n*r.x]}static _intersectSegments(t,e,r){const n=t[0],s=t[1],a=e[0],o=e[1],i=Math.min(n.x,s.x),m=Math.min(n.y,s.y),c=Math.max(n.x,s.x),f=c-i,u=Math.max(n.y,s.y),l=u-m,h=Math.min(a.x,o.x),y=Math.min(a.y,o.y),x=Math.max(a.x,o.x),g=x-h,M=Math.max(a.y,o.y),p=M-y;if(0===f&&0===g)return null;if(0===l&&0===p)return null;const d=t=>t.x<h||t.x>x||t.x<i||t.x>c,b=t=>t.y<y||t.y>M||t.y<m||t.y>u;var z=null;if(0===f){if(r&&(h>i||x<c))return null;const t=this.mq(a,o);z=this.cramer([1,0,-i],[t[0],-1,t[1]]),r&&b(z)&&(z=null)}else if(0===g){if(r&&(i>h||c<x))return null;const t=this.mq(n,s);z=this.cramer([t[0],-1,t[1]],[1,0,-h]),r&&b(z)&&(z=null)}else if(0===l){if(r&&(y>m||M<u))return null;const t=this.mq(a,o);z=this.cramer([0,1,-m],[t[0],-1,t[1]]),r&&d(z)&&(z=null)}else if(0===p){if(r&&(m>y||u<M))return null;const t=this.mq(n,s);z=this.cramer([t[0],-1,t[1]],[0,1,-y]),r&&d(z)&&(z=null)}else{let t;if(!r||(t=this._intersectRects({x:i,y:m,width:f,height:l},{x:h,y:y,width:g,height:p}))&&t.width>0&&t.height>0){const e=this.mq(n,s),i=this.mq(a,o),m=e[0],c=i[0],f=e[1],u=i[1];if(m!==c){let e=(z=this.cramer([m,-1,f],[c,-1,u])).x,n=z.y;r&&(e<t.x||e>t.x+t.width||n<t.y||n>t.y+t.height)&&(z=null)}}}return null===z?null:{x:z.x,y:z.y}}static _intersectRects(...e){return t.Rect.intersect.apply(this,e)}static dot(t,e){return s.dot(t,e)}static cross(t,e){return s.cross(t,e)}static distance(e,r){if(null!=(n=e)&&Array.isArray(n)&&2===n.length&&a(n[0])&&a(n[1]))return t.Point.distance(e[0],e[1]);if(a(r))return t.Point.distance(e,r);{const t=r[0],n=r[1];return Math.abs(t*e.x-e.y+n)/Math.sqrt(Math.pow(t,2)+1)}var n}static inLine(t,e){const r=s.from(e[0],t),n=s.from(t,e[1]);return this.cross(r,n).isCloseTo(0)}static inSegment(t,e){const r=Math.min(e[0].x,e[1].x),n=Math.max(e[0].x,e[1].x),s=Math.min(e[0].y,e[1].y),a=Math.max(e[0].y,e[1].y);return t.x>=r&&t.x<=n&&t.y>=s&&t.y<=a&&this.inLine(t,e)}static inTriangle(e,r){let n;for(let s=0;s<3;s++){const a=r[s],o=r[(s+1)%3],i=t.Point.subtract(o,e),m=t.Point.subtract(a,e),c=this.cross(i,m);if(s>0&&c*n<=0)return!1;n=c}return!0}static inPolygon(t,e,r){if(!(e?.length>=3))throw"Not enough vertices";const n=e.length;if(3===n)return this.inTriangle(t,[e[0],e[1],e[2]]);r>0&&(e=e.map(t=>({x:t.x.roundoff(r),y:t.y.roundoff(r)})),t={x:t.x.roundoff(r),y:t.y.roundoff(r)});let s=Number.MAX_VALUE,a=Number.MAX_VALUE,o=Number.MIN_VALUE,i=Number.MIN_VALUE;for(let t=0;t<n;t++){const r=e[t];s=Math.min(s,r.x),a=Math.min(a,r.y),o=Math.max(o,r.x),i=Math.max(i,r.y)}if(t.x<s||t.x>o||t.y<a||t.y>i)return!1;const m=[{x:s-1,y:t.y},t];let c=0;for(let r=0;r<n;r++){const s=e[r],a=e[(r+1)%n],o=[s,a];if(s.y===t.y){const o=e[(r-1+n)%n];t.x>s.x&&(o.y-t.y)*(a.y-t.y)<0&&c++}else{if(a.y===t.y)continue;null!=this.intersect(o,m)&&c++}}return c%2==1}static area(t,...e){const r=[].concat(t).concat(e);let n=0;const s=r.length;if(s>=3){for(let t=0;t<r.length;t++){const{x:e,y:a}=r[t],o=t===s-1?0:t+1,{x:i,y:m}=r[o];n+=e*m-a*i}n*=.5}return Math.abs(n.roundoff())}static convexHull(t,...e){const r=[].concat(t).concat(e);if(!(r?.length>1))return r?.slice()??[];const n=r.map(t=>({x:t.x,y:t.y})).sort((t,e)=>t.x===e.x?t.y-e.y:t.x-e.x),s=[];for(const t of n){const e=s[s.length-1];e&&e.x===t.x&&e.y===t.y||s.push(t)}if(s.length<=2)return s;const a=(t,e,r)=>(e.x-t.x)*(r.y-t.y)-(e.y-t.y)*(r.x-t.x),o=[];for(const t of s){for(;o.length>=2&&a(o[o.length-2],o[o.length-1],t)<=0;)o.pop();o.push(t)}const i=[];for(let t=s.length-1;t>=0;t--){const e=s[t];for(;i.length>=2&&a(i[i.length-2],i[i.length-1],e)<=0;)i.pop();i.push(e)}return o.pop(),i.pop(),o.concat(i)}}}(t.Geometry||(t.Geometry={}))}(Pacem||(Pacem={})),function(t){!function(e){!function(e){const r=180/Math.PI,n=1/r;class Vector3D{static from(...t){if(3!==t.length)throw new RangeError("Must provide exactly 3 numbers");return{x:t[0],y:t[1],z:t[2]}}static parse(e){const r=t.parseAsNumericalArray(e);if(r&&3===r.length)return Vector3D.from.apply(null,r);throw new Error(`Cannot parse "${e}" as a valid Vector3D.`)}static i(){return{x:1,y:0,z:0}}static j(){return{x:0,y:1,z:0}}static k(){return{x:0,y:0,z:1}}static zero(){return{x:0,y:0,z:0}}static subtract(t,e){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}static add(...t){var e={x:0,y:0,z:0};for(var r of t)e.x+=r.x,e.y+=r.y,e.z+=r.z;return e}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}static cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}static scale(t,e,r=e,n=e){return{x:t.x*e,y:t.y*r,z:t.z*n}}static magSqr(t){return t.x*t.x+t.y*t.y+t.z*t.z}static areClose(t,e){return(e.x-t.x).isCloseTo(0)&&(e.y-t.y).isCloseTo(0)&&(e.z-t.z).isCloseTo(0)}static mag(t){return Math.sqrt(Vector3D.magSqr(t))}static negate(t){return{x:-t.x,y:-t.y,z:-t.z}}static unit(t){const e={x:t.x,y:t.y,z:t.z};return this.normalize(e),e}static normalize(t){const e=Vector3D.mag(t);if(e<=0)throw"Cannot normalize a vector of length 0.";const r=1/e;t.x*=r,t.y*=r,t.z*=r}static angleBetween(t,e){let n;const s=Vector3D.unit(t),a=Vector3D.unit(e);if(Vector3D.dot(s,a)<0){const t={x:-s.x-a.x,y:-s.y-a.y,z:-s.z-a.z},e=Vector3D.mag(t);n=Math.PI-2*Math.asin(e/2)}else{const t={x:s.x-a.x,y:s.y-a.y,z:s.z-a.z},e=Vector3D.mag(t);n=2*Math.asin(e/2)}return r*n}}e.Vector3D=Vector3D;class Spherical{static from(t,e,r){return{rho:t.clamp(0,1/0),theta:e.clamp(-180,180),phi:r.clamp(0,360)}}static fromVector(t,e,n){"number"==typeof t&&(t=Vector3D.from(t,e,n));const s=Vector3D.mag(t);if(s.isCloseTo(0))return Spherical.from(0,0,0);const a=Math.atan2(t.x,t.z),o=Math.acos((t.y/s).clamp(-1,1));return Spherical.from(s,a*r,o*r)}static toVector(t){const{rho:e,theta:r,phi:s}=t,a=s*n,o=r*n,i=Math.sin(a)*e;return{x:i*Math.sin(o),y:Math.cos(a)*e,z:i*Math.cos(o)}}static toRotationMatrix(t){const{theta:e,phi:r}=t,s=n*e,a=Math.sin(s),o=Math.cos(s),i=n*r,m=Math.sin(i),c=Math.cos(i);return Matrix3D.from(a*c,a*m,o,0,o*c,o*m,-a,0,-m,c,0,0,0,0,0,1)}}e.Spherical=Spherical;class Matrix3DUtils{static modify(t,e){const{m11:r,m12:n,m13:s,m14:a,m21:o,m22:i,m23:m,m24:c,m31:f,m32:u,m33:l,m34:h,offsetX:y,offsetY:x,offsetZ:g,m44:M}=t,p={m11:r,m12:n,m13:s,m14:a,m21:o,m22:i,m23:m,m24:c,m31:f,m32:u,m33:l,m34:h,offsetX:y,offsetY:x,offsetZ:g,m44:M};return e(p),p}static clone(t){return Matrix3DUtils.modify(t,t=>{})}static multiply(t,e){return Matrix3D.isIdentity(t)?e:Matrix3D.isIdentity(e)?t:Matrix3D.from(t.m11*e.m11+t.m12*e.m21+t.m13*e.m31+t.m14*e.offsetX,t.m11*e.m12+t.m12*e.m22+t.m13*e.m32+t.m14*e.offsetY,t.m11*e.m13+t.m12*e.m23+t.m13*e.m33+t.m14*e.offsetZ,t.m11*e.m14+t.m12*e.m24+t.m13*e.m34+t.m14*e.m44,t.m21*e.m11+t.m22*e.m21+t.m23*e.m31+t.m24*e.offsetX,t.m21*e.m12+t.m22*e.m22+t.m23*e.m32+t.m24*e.offsetY,t.m21*e.m13+t.m22*e.m23+t.m23*e.m33+t.m24*e.offsetZ,t.m21*e.m14+t.m22*e.m24+t.m23*e.m34+t.m24*e.m44,t.m31*e.m11+t.m32*e.m21+t.m33*e.m31+t.m34*e.offsetX,t.m31*e.m12+t.m32*e.m22+t.m33*e.m32+t.m34*e.offsetY,t.m31*e.m13+t.m32*e.m23+t.m33*e.m33+t.m34*e.offsetZ,t.m31*e.m14+t.m32*e.m24+t.m33*e.m34+t.m34*e.m44,t.offsetX*e.m11+t.offsetY*e.m21+t.offsetZ*e.m31+t.m44*e.offsetX,t.offsetX*e.m12+t.offsetY*e.m22+t.offsetZ*e.m32+t.m44*e.offsetY,t.offsetX*e.m13+t.offsetY*e.m23+t.offsetZ*e.m33+t.m44*e.offsetZ,t.offsetX*e.m14+t.offsetY*e.m24+t.offsetZ*e.m34+t.m44*e.m44)}}class Matrix3D{static identity(){return{m11:1,m12:0,m13:0,m14:0,m21:0,m22:1,m23:0,m24:0,m31:0,m32:0,m33:1,m34:0,offsetX:0,offsetY:0,offsetZ:0,m44:1}}static from(...t){if(16!==t.length)throw new RangeError("Must provide exactly 16 numbers");return{m11:t[0],m12:t[1],m13:t[2],m14:t[3],m21:t[4],m22:t[5],m23:t[6],m24:t[7],m31:t[8],m32:t[9],m33:t[10],m34:t[11],offsetX:t[12],offsetY:t[13],offsetZ:t[14],m44:t[15]}}static transpose(t){return Matrix3D.from(t.m11,t.m21,t.m31,t.offsetX,t.m12,t.m22,t.m32,t.offsetY,t.m13,t.m23,t.m33,t.offsetZ,t.m14,t.m24,t.m34,t.m44)}static toArray(t){return[t.m11,t.m12,t.m13,t.m14,t.m21,t.m22,t.m23,t.m24,t.m31,t.m32,t.m33,t.m34,t.offsetX,t.offsetY,t.offsetZ,t.m44]}static clone(t,e){return"function"==typeof e?Matrix3DUtils.modify(t,e):Matrix3DUtils.clone(t)}static scale(t,e,r,n){return"number"==typeof e?(r??=e,n??=e):(n=e.z,r=e.y,e=e.x),Matrix3DUtils.modify(t,t=>{t.m11*=e,t.m22*=r,t.m33*=n})}static translate(t,e){return Matrix3DUtils.modify(t,t=>{t.offsetX+=e.x,t.offsetY+=e.y,t.offsetZ+=e.z})}static parse(e){const r=t.parseAsNumericalArray(e);if(r&&16===r.length)return Matrix3D.from.apply(null,r);throw new Error(`Cannot parse "${e}" as a valid Matrix3D.`)}static isIdentity(t){return 1==t.m11&&0==t.m12&&0==t.m13&&0==t.m14&&0==t.m21&&1==t.m22&&0==t.m23&&0==t.m24&&0==t.m31&&0==t.m32&&1==t.m33&&0==t.m34&&0==t.offsetX&&0==t.offsetY&&0==t.offsetZ&&1==t.m44}static isAffine(t){return 0==t.m14&&0==t.m24&&0==t.m34&&1==t.m44}static determinant(t){if(Matrix3D.isIdentity(t))return 1;if(Matrix3D.isAffine(t))return t.m11*(t.m22*t.m33-t.m32*t.m23)-t.m12*(t.m21*t.m33-t.m31*t.m23)+t.m13*(t.m21*t.m32-t.m31*t.m22);{const e=t.m13*t.m24-t.m23*t.m14,r=t.m13*t.m34-t.m33*t.m14,n=t.m13*t.m44-t.offsetZ*t.m14,s=t.m23*t.m34-t.m33*t.m24,a=t.m23*t.m44-t.offsetZ*t.m24,o=t.m33*t.m44-t.offsetZ*t.m34,i=t.m22*r-t.m32*e-t.m12*s,m=t.m12*a-t.m22*n+t.offsetY*e,c=t.m32*n-t.offsetY*r-t.m12*o,f=t.m22*o-t.m32*a+t.offsetY*s;return t.offsetX*i+t.m31*m+t.m21*c+t.m11*f}}static multiply(...t){if(0===t.length)throw new ReferenceError("Matrix not provided.");const e=Array.from(t);let r=e[0];for(let t=1;t<e.length;t++)r=Matrix3DUtils.multiply(r,e[t]);return r}static invert(t){if(Matrix3D.isAffine(t)){const e=Matrix3D.determinant(t);if(0==e)return null;const r=t.m12*t.m23-t.m22*t.m13,n=t.m32*t.m13-t.m12*t.m33,s=t.m22*t.m33-t.m32*t.m23,a=t.m21*t.m13-t.m11*t.m23,o=t.m11*t.m33-t.m31*t.m13,i=t.m31*t.m23-t.m21*t.m33,m=t.m11*t.m22-t.m21*t.m12,c=t.m11*t.m32-t.m31*t.m12,f=t.m11*t.offsetY-t.offsetX*t.m12,u=t.m21*t.m32-t.m31*t.m22,l=t.m21*t.offsetY-t.offsetX*t.m22,h=t.m31*t.offsetY-t.offsetX*t.m32,y=t.m23*f-t.offsetZ*m-t.m13*l,x=t.m13*h-t.m33*f+t.offsetZ*c,g=t.m33*l-t.offsetZ*u-t.m23*h,M=m,p=-c,d=u,b=1/e;return Matrix3D.from(s*b,n*b,r*b,0,i*b,o*b,a*b,0,d*b,p*b,M*b,0,g*b,x*b,y*b,1)}{const e=Matrix3D.determinant(t);if(0==e)return null;const r=t.m33*t.m44-t.m34*t.offsetZ,n=t.m32*t.m44-t.m34*t.offsetY,s=t.m31*t.m44-t.m34*t.offsetX,a=t.m32*t.offsetZ-t.m33*t.offsetY,o=t.m31*t.offsetZ-t.m33*t.offsetX,i=t.m31*t.offsetY-t.m32*t.offsetX,m=t.m33*t.m44-t.m34*t.offsetZ,c=t.m32*t.m44-t.m34*t.offsetY,f=t.m31*t.m44-t.m34*t.offsetX,u=t.m32*t.offsetZ-t.m33*t.offsetY,l=t.m31*t.offsetZ-t.m33*t.offsetX,h=t.m31*t.offsetY-t.m32*t.offsetX,y=t.m23*t.m44-t.m24*t.offsetZ,x=t.m22*t.m44-t.m24*t.offsetY,g=t.m21*t.m44-t.m24*t.offsetX,M=t.m22*t.offsetZ-t.m23*t.offsetY,p=t.m21*t.offsetZ-t.m23*t.offsetX,d=t.m21*t.offsetY-t.m22*t.offsetX,b=t.m23*t.m34-t.m24*t.m33,z=t.m22*t.m34-t.m24*t.m32,w=t.m21*t.m34-t.m24*t.m31,A=t.m22*t.m33-t.m23*t.m32,v=t.m21*t.m33-t.m23*t.m31,D=t.m21*t.m32-t.m22*t.m31,N=t.m22*r-t.m23*n+t.m24*a,P=-(t.m21*r-t.m23*s+t.m24*o),C=t.m21*n-t.m22*s+t.m24*i,V=-(t.m21*a-t.m22*o+t.m23*i),X=-(t.m12*m-t.m13*c+t.m14*u),q=t.m11*m-t.m13*f+t.m14*l,U=-(t.m11*c-t.m12*f+t.m14*h),Y=t.m11*u-t.m12*l+t.m13*h,Z=t.m12*y-t.m13*x+t.m14*M,S=-(t.m11*y-t.m13*g+t.m14*p),L=t.m11*x-t.m12*g+t.m14*d,E=-(t.m11*M-t.m12*p+t.m13*d),Q=-(t.m12*b-t.m13*z+t.m14*A),T=t.m11*b-t.m13*w+t.m14*v,I=-(t.m11*z-t.m12*w+t.m14*D),R=t.m11*A-t.m12*v+t.m13*D,_=1/e;return Matrix3D.from(N*_,X*_,Z*_,Q*_,P*_,q*_,S*_,T*_,C*_,U*_,L*_,I*_,V*_,Y*_,E*_,R*_)}}static transform(t,e){var r={x:t.x,y:t.y,z:t.z};if(!Matrix3D.isIdentity(e)){var n=r.x,s=r.y,a=r.z;if(r.x=n*e.m11+s*e.m21+a*e.m31+e.offsetX,r.y=n*e.m12+s*e.m22+a*e.m32+e.offsetY,r.z=n*e.m13+s*e.m23+a*e.m33+e.offsetZ,!Matrix3D.isAffine(e)){var o=n*e.m14+s*e.m24+a*e.m34+e.m44;0!=o&&(r.x/=o,r.y/=o,r.z/=o)}}return r}}e.Matrix3D=Matrix3D;class Quaternion{static identity(){return Quaternion.from(0,0,0,1)}static from(...t){if(4!==t.length)throw new RangeError("Must provide exactly 4 numbers");return{x:t[0],y:t[1],z:t[2],w:t[3]}}static parse(e){const r=t.parseAsNumericalArray(e);if(r&&4===r.length)return Quaternion.from.apply(null,r);throw new Error(`Cannot parse "${e}" as a valid Quaternion.`)}static fromVectors(t,e){Vector3D.normalize(t),Vector3D.normalize(e);const r=(t,e,r,n)=>{const s=Quaternion.from(t,e,r,n);return Quaternion.normalize(s),s};let n=Vector3D.dot(t,e)+1;return n.isCloseTo(0)?Math.abs(t.x)>Math.abs(t.z)?r(-t.y,t.x,0,0):r(0,-t.z,t.y,0):r(t.y*e.z-t.z*e.y,t.z*e.x-t.x*e.z,t.x*e.y-t.y*e.x,n)}static normalize(t){const e=Quaternion.mag(t);if(e.isCloseTo(0))t.x=t.y=t.z=0,t.w=1;else{const r=1/e;t.x*=r,t.y*=r,t.z*=r,t.w*=r}}static unit(t){const e=Quaternion.from(t.x,t.y,t.z,t.w);return Quaternion.normalize(e),e}static fromAxisAngle(t,e){var r=n*(e%=360),s=Vector3D.mag(t);if(0==s)throw new RangeError("Invalid argument");var a=Math.sin(.5*r)/s,o=t.x*a,i=t.y*a,m=t.z*a;return Quaternion.from(o,i,m,Math.cos(.5*r))}static fromRotationMatrix(t){const e=t.m11+t.m22+t.m33+t.m44;if(e>0){const r=.5/Math.sqrt(e),n=.25/r,s=(t.m23-t.m32)*r,a=(t.m31-t.m13)*r,o=(t.m12-t.m21)*r;return Quaternion.from(s,a,o,n)}if(t.m11>t.m22&&t.m11>t.m22){const e=.5/Math.sqrt(t.m44+t.m11-t.m22-t.m33),r=(t.m23-t.m32)*e,n=.25/e,s=(t.m12+t.m21)*e,a=(t.m31+t.m13)*e;return Quaternion.from(n,s,a,r)}if(t.m22>t.m33){const e=.5/Math.sqrt(t.m44+t.m22-t.m11-t.m33),r=(t.m23+t.m32)*e,n=.25/e,s=(t.m12+t.m21)*e,a=(t.m31-t.m13)*e;return Quaternion.from(s,n,r,a)}{const e=.5/Math.sqrt(t.m44+t.m33-t.m11-t.m22),r=(t.m23+t.m32)*e,n=.25/e,s=(t.m12-t.m21)*e,a=(t.m31-t.m13)*e;return Quaternion.from(a,r,n,s)}}static conjugate(t){return Quaternion.from(-t.x,-t.y,-t.z,t.w)}static mag(t){return Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z+t.w*t.w)}static norm(t){return t.x*t.x+t.y*t.y+t.z*t.z}static axis(t){return 0==t.x&&0==t.y&&0==t.z?Vector3D.j():Vector3D.unit(t)}static transform(t,e){Quaternion.normalize(e);const r=Vector3D.cross(e,t),n=Vector3D.scale(r,2),s=Vector3D.cross(e,n);return{x:t.x+e.w*n.x+s.x,y:t.y+e.w*n.y+s.y,z:t.z+e.w*n.z+s.z}}static angle(t){let e=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z),r=t.w;if(e>Number.MAX_VALUE){const n=Math.max(Math.abs(t.x),Math.max(Math.abs(t.y),Math.abs(t.z))),s=t.x/n,a=t.y/n,o=t.z/n;e=Math.sqrt(s*s+a*a+o*o),r/=n}return 114.59155902616465*Math.atan2(e,r)}static toRotationMatrix(t){var e=Matrix3D.identity(),r=t.x,n=t.y,s=t.z,a=t.w;return e.m11=1-2*n*n-2*s*s,e.m12=2*r*n+2*a*s,e.m13=2*r*s-2*a*n,e.m21=2*r*n-2*a*s,e.m22=1-2*r*r-2*s*s,e.m23=2*n*s+2*a*r,e.m31=2*a*n+2*r*s,e.m32=2*n*s-2*a*r,e.m33=1-2*r*r-2*n*n,e}static invert(t){const e=Quaternion.unit(t);return Quaternion.conjugate(e)}static multiply(t,e){return Quaternion.from(t.w*e.x+t.x+e.w+t.y*e.z-t.z*e.y,t.w*e.y-t.x*e.z+t.y*e.w+t.z*e.x,t.w*e.z+t.x*e.y-t.y*e.x+t.z*e.w,t.w*e.w-t.x*e.x-t.y*e.y-t.z*e.z)}static dot(t,e){return Quaternion.multiply(t,Quaternion.conjugate(e)).w}}e.Quaternion=Quaternion}(e.LinearAlgebra||(e.LinearAlgebra={}))}(t.Geometry||(t.Geometry={}))}(Pacem||(Pacem={})),function(t){!function(e){const r=t.Geometry.LinearAlgebra.Vector3D;t.Geometry.LinearAlgebra.Matrix3D;e.Utils3D=class Utils3D{static intersect(t,e){const[n,s]=t,a=r.subtract(n,s),[o,i,m]=e,c=r.subtract(o,i),f=r.subtract(o,m),u=r.cross(a,f),l=r.dot(c,u);if(l.isCloseTo(0))return null;const h=1/l,y=r.subtract(n,o),x=h*r.dot(y,u);if(x<0||x>1)return null;const g=r.cross(y,c),M=h*r.dot(a,g);if(M<0||x+M>1)return null;const p=h*r.dot(f,g);return p<0||p.isCloseTo(0)?null:r.add(n,r.scale(a,p))}}}(t.Geometry||(t.Geometry={}))}(Pacem||(Pacem={})),function(t){!function(e){class Polygon{static isPolygon(e){return function(e){let r;return"vertices"in e&&Array.isArray(e.vertices)&&(r=e.vertices).length>=3&&r.every(e=>t.Point.isPoint(e))}(e)}static from(...t){return{vertices:Array.from(t)}}static contains(t,r){return e.Utils.inPolygon(r,t.vertices,12)}static centroid(t){const e=Polygon.boundingBox(t);return{x:e.x+e.width/2,y:e.y+e.height/2}}static boundingBox(t){let e=Number.MAX_VALUE,r=Number.MAX_VALUE,n=-Number.MAX_VALUE,s=-Number.MAX_VALUE;const{vertices:a}=t;a.length;for(let t of a)e=Math.min(e,t.x),r=Math.min(r,t.y),n=Math.max(n,t.x),s=Math.max(s,t.y);return{x:e,y:r,width:n-e,height:s-r}}static sides(t){const{vertices:e}=t,r=[];for(let t=1;t<=e.length;t++){const n=e[t%e.length],s=e[t-1];r.push([s,n])}return r}static isConvex(e){const{vertices:r}=e,n=r.length;if(n<=3)return!0;let s=0;for(let e=0;e<r.length;e++){const a=r[(e-1+n)%n],o=r[e],i=r[(e+1)%n],m=t.Angle.angleBetween(o,a,i);if(0!==s){if(s!=Math.sign(m))return!1}else s=Math.sign(m)}return!0}static isSelfIntersecting(r){const{vertices:n}=r;if(n.length<=3)return!1;const s=Polygon.sides(r);for(let r of s)for(let n of s){if(n===r||n[0]===r[1]||r[0]===n[1])continue;const s=e.Utils.intersect(n,r);if(!t.NullChecker.isNull(s))return!0}return!1}static isCounterClockwise(e){const{vertices:[r,n,s]}=e;return t.Angle.angleBetween(n,r,s)>0}static expand(r,n){const{vertices:s}=r,a=s.length,o=[];for(let r=0;r<s.length;r++){const i=s[(r-1+a)%a],m=s[r],c=s[(r+1)%a],f=t.Angle.angleBetween(m,i,c),u=-n/Math.sin(Math.abs(f)/2),l=t.Matrix2D.scale(t.Matrix2D.identity,u),h=t.Point.subtract(m,i);e.LinearAlgebra.Vector.normalize(h);const y=t.Point.subtract(m,c);e.LinearAlgebra.Vector.normalize(y);const x=t.Point.add(h,y);e.LinearAlgebra.Vector.normalize(x);const g=t.Matrix2D.multiply(x,l);o.push(t.Point.add(m,{x:g.x.roundoff(),y:g.y.roundoff()}))}return{vertices:o}}static area(t){return e.Utils.area(t.vertices)}static convexHull(t){return{vertices:e.Utils.convexHull(t.vertices)}}}e.Polygon=Polygon}(t.Geometry||(t.Geometry={}))}(Pacem||(Pacem={})),function(t){!function(t){function e(t){return"number"==typeof t&&(t={real:t,img:0}),t}var r;function n(t,e){const r={};return Object.defineProperty(r,"real",{value:t,writable:!1}),Object.defineProperty(r,"img",{value:e,writable:!1}),r}function s(){return r||(r=n(Number.NaN,Number.NaN))}t.Complex=class Complex{static build(t,e){return this.isComplex(t)?t:(e??=0,"number"!=typeof t||"number"!=typeof e?s():n(t,e||0))}static add(t,r){const s=e(t),a=e(r);return n(s.real+a.real,s.img+a.img)}static subtract(t,r){const s=e(t),a=e(r);return n(s.real-a.real,s.img-a.img)}static multiply(t,r){const s=e(t),a=e(r);return n(s.real*a.real-s.img*a.img,s.real*a.img+s.img*a.real)}static divide(t,r){const a=e(t),o=e(r),i=this.absSquare(o).roundoff();if(0===i)return s();const m=1/i;return n(m*(a.real*o.real+a.img*o.img),m*(a.img*o.real-a.real*o.img))}static absSquare(t){const r=e(t);return Math.pow(r.real,2)+Math.pow(r.img,2)}static modulus(t){return Math.sqrt(this.absSquare(t))}static isComplex(t){return null!=t&&"object"==typeof t&&"real"in t&&"img"in t&&"number"==typeof t.real&&"number"==typeof t.img}static conjugate(t){return n((t=e(t)).real,0==Math.abs(t.img)?0:-t.img)}static equals(t,e){const r=this.build(t),n=this.build(e);return!(!this.isComplex(t)||!this.isComplex(e))&&(r.real===n.real&&r.img===n.img)}static get NaC(){return s()}}}(t.Mathematics||(t.Mathematics={}))}(Pacem||(Pacem={})),function(t){!function(t){!function(e){const r={};function n(e,n){const s=r[n]=r[n]||{};return s[e]=s[e]||function(e,r){const n=2*Math.PI*e/r;return t.Complex.build(Math.cos(n),Math.sin(n))}(e,n)}function s(e){const r=[],a=e.length;if(1===a)return[t.Complex.build(e[0])];const o=s(e.filter((t,e)=>e%2==0)),i=s(e.filter((t,e)=>e%2==1));for(var m=0;m<a/2;m++){const e=o[m],s=t.Complex.multiply(n(m,a),i[m]);r[m]=t.Complex.add(e,s),r[m+a/2]=t.Complex.subtract(e,s)}return r}e.Fourier=class Fourier{static transform(t,e=!0){return(r=(t=t||[]).length)>0&&!(r&r-1)?this.fft(t,e):this.dft(t,e);var r}static invert(t,e=!0){return this.idft(t||[],e)}static dft(e,r=!0){const s=(e||[])?.length,a=r?1/Math.sqrt(s):1,o=[];for(let r=0;r<s;r++){o.push({real:0,img:0});for(let i=0;i<s;i++){const m=n(r*i,s),c=t.Complex.multiply(e[i],m),f=t.Complex.multiply(c,a);o[r]=t.Complex.add(o[r],f)}}return o}static idft(e,r=!0){const n=e.map(e=>t.Complex.build(e.img,e.real));return this.transform(n,r).map(e=>t.Complex.build(e.img,e.real))}static fft(e,r=!0){const n=s(e);if(!r)return n;const a=1/Math.sqrt(e.length);return n.map(e=>t.Complex.multiply(e,a))}}}(t.DataAnalysis||(t.DataAnalysis={}))}(t.Mathematics||(t.Mathematics={}))}(Pacem||(Pacem={})),function(t){!function(t){!function(t){const e=Math.sqrt(Math.PI);function r(t){const e=Math.abs(t),r=1/(1+.5*e),n=r*Math.exp(-e*e-1.26551223+r*(1.00002368+r*(.37409196+r*(.09678418+r*(r*(.27886807+r*(r*(1.48851587+r*(.17087277*r-.82215223))-1.13520398))-.18628806)))));return t>=0?n:2-n}class Gaussian{constructor(t,e){this.mean=t,this.stdev=Math.abs(e),this.variance=Math.pow(e,2)}mean;stdev;variance;static get normal(){return n}weight(t){return Math.exp(-.5*Math.pow(this._z(t),2))}probabilityDensity(t){const r=this.stdev*Math.SQRT2*e;return this.weight(t)/r}_z(t){return(t-this.mean)/this.stdev}probability(t){return.5*r(-this._z(t)/Math.SQRT2)}}t.Gaussian=Gaussian;const n=new Gaussian(0,1)}(t.DataAnalysis||(t.DataAnalysis={}))}(t.Mathematics||(t.Mathematics={}))}(Pacem||(Pacem={})),function(t){!function(t){!function(t){class Lagrangian{constructor(...t){this.#t=Array.from(t)||[]}#t;#e;_unsafeCreate(){const t=this.#t||[];let e,r="var ljs = [];\n";for(let n=0;n<t.length;n++){const s=t[n],a=s.x;if(null!=e&&e>=a)throw new Error("Invalid function provided.");e=a,r+=`ljs.push( ${s.y}`;for(let e=0;e<t.length;e++)if(e!==n){const n=t[e];r+=` * ((x - ${n.x})/${a-n.x})`}r+=");\n"}r+="return ljs.reduce((prev, next) => prev + next, 0);",this.#e=new Function("x",r)}_compute(t){const e=this.#t||[];let r;const n=[];for(let s=0;s<e.length;s++){const a=e[s].x;if(null!=r&&r>=a)throw new Error("Invalid function provided.");r=a;let o=e[s].y;for(let r=0;r<e.length;r++)if(r!==s){const n=e[r];o*=(t-n.x)/(a-n.x)}n.push(o)}return n.reduce((t,e)=>t+e,0)}interpolate(t){return"function"==typeof this.#e?this.#e.apply(null,[t]):this._compute(t)}static create(...t){const e=(arguments.length>0&&Array.isArray(arguments[0])?arguments[0]:Array.from(t)).map((t,e)=>"number"==typeof t?{x:e,y:t}:t),r=new(Function.prototype.bind.apply(Lagrangian,[null].concat(e)));try{r._unsafeCreate()}catch(t){}return r}}t.Lagrangian=Lagrangian}(t.DataAnalysis||(t.DataAnalysis={}))}(t.Mathematics||(t.Mathematics={}))}(Pacem||(Pacem={})),function(t){!function(e){!function(e){const r="0123456789abcdefghijklmnopqrstuvwxyz",n="Radix out of range: possible values go between positive 1 exclusive and 36 inclusive";class Utils{static lcd(...e){if(t.NullChecker.isNullOrEmpty(e)||e.length<=1)throw"Insufficient set of numbers.";function r(t,e){return e?r(e,t%e):0===e?t:NaN}function n(t,e){return t*e/r(t,e)}let s=Math.round(e[0]);for(let t=1;t<e.length;t++)s=n(s,Math.round(e[t]));return s}static gcd(t,e){return t=Math.round(t),e=Math.round(e),0===t?e:Utils.gcd(e%t,t)}static rebaseInt(e,r,n){return t.Numbers.rebase(e,r,n)}static rebaseFloat(t,e,r,n=12){const s=Utils.rebaseFloat10ToN,a=Utils.rebaseFloatNTo10;if(10===e){const e=parseFloat(t.toString());return r%1==0?Utils.rebaseFloat10ToNIntBase(e,r,n):s(e,r,n)}if(10===r)return a(t.toString(),e,n);return s(a(t.toString(),e,n+1),r,n)}static rebaseFloatNTo10(t,e,s=12){const a=r;if(e<=1||e>a.length)throw new Error(n);const o=(t??"0").toString().toLowerCase(),i=Number.NaN;if("0"===o)return 0;const m=/^([-+]?) *([\da-z]+)?(.[\da-z]+)?$/.exec(o);if(m.length<2)return i;const c="-"===m[1]?-1:1,f=m[2]||"0",u=m[3]||".0";let l=0,h=0;for(let t of f+u.substr(1)){const r=a.indexOf(t);if(-1===r||r>=e)return i;l+=r*Math.pow(e,f.length-h-1),h++}return c*l}static rebaseFloat10ToNIntBase(t,e,s=12){const a=r;if(e<=1||e>36)throw new Error(n);const o=e;let i=Math.abs(t??0);if(0===i||Number.isNaN(i))return t.toString();let m=(i%1).roundoff(),c="";for(;;){let t=i/o,e=Math.floor(t),r=(i-e*o).roundoff(),n=Math.floor(r);if(c=n>=36?`[${n}]`+c:a[n]+c,e<=0)break;i=e}if(c=c.replace(/^0+/,""),c||="0",0===m)return c;let f="";do{i=(m*o).roundoff();const t=Math.floor(i),e=(i-t).roundoff();t>=36?f=`[${t}]`:f+=a[t],m=e}while(!m.isCloseTo(0)&&f.length<s);return/^0*$/.test(f)?c:(Math.sign(t)<0?"-":"")+c+"."+f.replace(/0+$/,"")}static rebaseFloat10ToN(e,s,a=12){const o=r;if(s<=1||s>o.length)throw new Error(n);const i=s;let m=Math.abs(e??0);if(0===m||Number.isNaN(m))return e.toString();let c=Math.sign(e)<0?"-":"",f=[],u=[];for(let t=0;t<20;t++)f.push("0"),u.push("0");const l=i%1==0?i:Math.ceil(i);function h(t,e,r){const n=t?f:u,s=n[e]=n[e]||"0",a=o.indexOf(s)+r,i=a%l,m=Math.floor(a/l);return n[e]=o[i],m>0&&(t?h(t,e+1,m):0===e?h(!0,0,m):h(!1,e-1,m)),m}let y=0;for(;;){const e=Math.floor(t.Numbers.log(m,i)),r=e>=0;if(h(r,r?e:Math.abs(1+e),1),m=(m-Math.pow(i,e).roundoff()).roundoff(),r||y++,0===m||y>=100){const t=c+(f.reverse().map(t=>t||"0").join("").replace(/^0+/,"")||"0"),e=u.map(t=>t||"0").join("").substr(0,a).replace(/0+$/,"");return/^0*$/.test(e)?t:t+"."+e}}}}e.Utils=Utils}(e.NumberTheory||(e.NumberTheory={}))}(t.Mathematics||(t.Mathematics={}))}(Pacem||(Pacem={})),function(t){!function(t){!function(t){const e=(t,e)=>t;function r(t,r=e){return t.reduce((t,e,n)=>t+r(e,n),0)}function n(t,n=e){return r(t,n)/t.length}function s(t,r=e,s=!1){const a=n(t,r);return t.reduce((t,e)=>Math.pow(e-a,2)+t,0)/(t.length-(s?1:0))}function a(t,r=e,n=!1){const a=s(t,r,n);return Math.sqrt(a)}function o(t,e){return(r,n,s,a)=>{let o=r,i=n,m=t(o,i),c=e(o,i),f=s(m),u=s(c);for(;i-o>a;)f<u?(i=c,c=m,u=f,m=t(o,i),f=s(m)):(o=m,m=c,f=u,c=e(o,i),u=s(c));return.5*(m+c)}}t.Utils=class Utils{static sum(t,e){return r(t,e)}static mean(t,e){return n(t,e)}static median(t,r){return function(t,r=e){const n=t.slice(0),s=n.length;n.sort((t,e)=>r(t)-r(e));const a=Math.ceil(n.length/2)-1;return s%2==1?n[a]:.5*(n[a+1]+n[a])}(t,r)}static mode(t,r){return function(t,r=e){const n=Object.groupBy(t,r);let s,a=0;for(let t in n){const e=n[t].length;e>a&&(s=parseInt(t),a=e)}return s}(t,r)}static var(t,e){return s(t,e,!0)}static varp(t,e){return s(t,e,!1)}static stdevp(t,e){return a(t,e,!1)}static stdev(t,e){return a(t,e,!0)}static correlation(t,r,s,a){return function(t,r,s=e,a=e){const o=Array.isArray(r);if(o&&r.length!==t.length)throw new Error("Sets must be of the same length.");const i=t.length,m=t,c=o?r:t,f=o?s:r,u=o?a:s,l=n(m,f),h=n(c,u);let y=0,x=0,g=0;for(let t=0;t<i;t++){const e=m[t],r=c[t],n=f(e,t)-l,s=u(r,t)-h;y+=n*s,x+=n*n,g+=s*s}return y/Math.sqrt(x*g)}(t,r,s,a)}static linearRegression(t,r,n,s){return function(t,r,n=e,s=e){const a=Array.isArray(r);if(a&&r.length!==t.length)throw new Error("Sets must be of the same length.");const o=t,i=a?r:t,m=a?n:r,c=m??(t=>t.x),f=(a?s:m)??(t=>t.y),u=t.length;let l=0,h=0,y=0,x=0,g=0;for(let t=0;t<u;t++){const e=o[t],r=i[t],n=c(e,t),s=f(r,t);l+=n*s,h+=n,y+=s,x+=n*n,g+=s*s}const M=(u*l-h*y)/(u*x-Math.pow(h,2));return[M,(y-M*h)/u]}(t,r,n,s)}static gaussian(e,r){return new t.Gaussian(e,r)}};t.SearchFunctions={linear:(t=2)=>function(t){if(t<=1)throw new RangeError("segments must be a number grater than 1.");return(e,r,n,s=.001)=>o((e,r)=>e+(r-e)/t,(e,r)=>r-(r-e)/t)(e,r,n,s)}(t),goldenRatio:(t,e,r,n=.001)=>o((t,e)=>e-(e-t)/1.618,(t,e)=>t+(e-t)/1.618)(t,e,r,n),gaussian:(t,e,r,n=.001)=>{var s=null,a=null;const i=(t,e)=>(a??=e-t,s??=a/Math.sqrt(12),s*(e-t)/a);return o((t,e)=>Math.max(t,(e+t)/2-i(t,e)),(t,e)=>Math.min(e,(e+t)/2+i(t,e)))(t,e,r,n)}}}(t.DataAnalysis||(t.DataAnalysis={}))}(t.Mathematics||(t.Mathematics={}))}(Pacem||(Pacem={}));
|
|
6
|
+
"use strict";var Pacem;!function(t){!function(e){!function(e){class Vector{static unit(t){const e={x:t.x,y:t.y};return this.normalize(e),e}static magSqr(t){return t.x*t.x+t.y*t.y}static mag(t){return Math.sqrt(Vector.magSqr(t))}static normalize(t){const e=Vector.mag(t);if(e<=0)throw"Cannot normalize a vector of length 0.";const r=1/e;t.x*=r,t.y*=r}static from(e,r){return t.Point.subtract(e,r)}static dot(t,e){return t.x*e.x+t.y*e.y}static cross(t,e){return t.x*e.y-t.y*e.x}static areClose(t,e){return(e.x-t.x).isCloseTo(0)&&(e.y-t.y).isCloseTo(0)}}e.Vector=Vector}(e.LinearAlgebra||(e.LinearAlgebra={}))}(t.Geometry||(t.Geometry={}))}(Pacem||(Pacem={})),function(t){!function(t){class Vertex{x;y;index;constructor(t,e,r=-1){this.x=t,this.y=e,this.index=r}equals(t){return this.x===t.x&&this.y===t.y}}class Triangle{v0;v1;v2;circumCirc;constructor(t,e,r){this.v0=t,this.v1=e,this.v2=r,this.circumCirc=function(t,e,r){const n=t.x,s=t.y,o=e.x,i=e.y,a=r.x,m=r.y,c=2*(n*(i-m)+o*(m-s)+a*(s-i));if(Math.abs(c)<1e-12)return{c:{x:0,y:0},r:1/0};const l=((n*n+s*s)*(i-m)+(o*o+i*i)*(m-s)+(a*a+m*m)*(s-i))/c,u=((n*n+s*s)*(a-o)+(o*o+i*i)*(n-a)+(a*a+m*m)*(o-n))/c;return{c:{x:l,y:u},r:Math.hypot(l-n,u-s)}}(t,e,r)}inCircumcircle(t){const e=this.circumCirc.c.x-t.x,r=this.circumCirc.c.y-t.y;return Math.hypot(e,r)<=this.circumCirc.r+1e-9}}function e(t,e){const r=[];e=e.filter(e=>!e.inCircumcircle(t)||(r.push({v0:e.v0,v1:e.v1}),r.push({v0:e.v1,v1:e.v2}),r.push({v0:e.v2,v1:e.v0}),!1));const n=function(t){const e=[];for(let r=0;r<t.length;++r){let n=!0;for(let e=0;e<t.length;++e)if(r!==e){const s=t[r],o=t[e];if(s.v0.equals(o.v0)&&s.v1.equals(o.v1)||s.v0.equals(o.v1)&&s.v1.equals(o.v0)){n=!1;break}}n&&e.push(t[r])}return e}(r);for(const r of n)e.push(new Triangle(r.v0,r.v1,t));return e}function r(t){if(t.length<3)return[];const r=function(t){let e=1/0,r=1/0,n=-1/0,s=-1/0;for(const o of t)e=Math.min(e,o.x),r=Math.min(r,o.y),n=Math.max(n,o.x),s=Math.max(s,o.y);const o=10*(n-e),i=10*(s-r),a=new Vertex(e-o,r-3*i),m=new Vertex(e-o,s+i),c=new Vertex(n+3*o,s+i);return new Triangle(a,m,c)}(t);let n=[r];for(const r of t)n=e(r,n);return n=n.filter(t=>!(t.v0===r.v0||t.v0===r.v1||t.v0===r.v2||t.v1===r.v0||t.v1===r.v1||t.v1===r.v2||t.v2===r.v0||t.v2===r.v1||t.v2===r.v2)),n}t.Delaunay=class Delaunay{static triangulate(t){return function(t){if(t.length<3)return[];const e=r(t.map((t,e)=>new Vertex(t.x,t.y,e))),n=[];for(const t of e)n.push(t.v0.index,t.v1.index,t.v2.index);return n}(t)}}}(t.Geometry||(t.Geometry={}))}(Pacem||(Pacem={})),function(t){!function(e){const r=180/Math.PI,n=2*Math.PI,s=e.LinearAlgebra.Vector;function o(e){return t.Point.isPoint(e)}class Utils{static slopeRad(t,e){return Math.atan2(e.y-t.y,e.x-t.x)}static slopeRad2(t,e){return(n+Utils.slopeRad(t,e))%n}static slopeDeg(t,e){return Utils.slopeRad(t,e)*r}static slopeDeg2(t,e){return(360+Utils.slopeDeg(t,e))%360}static intersect(e,r,...n){return Array.isArray(e)&&Array.isArray(r)?Utils._intersectSegments(e,r,!0):t.Rect.isRect(e)?Utils._intersectRects(...arguments):"vertices"in e?Utils._mergePolygons(e,r,"intersect")?.polygons??[]:null}static combinePolygons(t,e,r){return Utils._mergePolygons(t,e,r)}static _mergePolygons(e,r,n){if(t.NullChecker.isNullOrEmpty(e?.vertices)||t.NullChecker.isNullOrEmpty(r?.vertices))return null;const{vertices:s}=e,{vertices:o}=r;if(s.length<3||o.length<3)return null;const i=(t,e,r)=>[t,r[(e+1)%r.length]],a=(t,e)=>t.x===e.x?t.y-e.y:t.x-e.x,m=s.map(i),c=o.map(i),l=s.concat(o),u=new Map,f=t=>{if(!u.has(t)){const e=[];u.set(t,e)}return u.get(t)};for(let e of m){const r=f(e);for(let n of c){const s=f(n),o=Utils.intersect(e,n);t.NullChecker.isNull(o)||(l.push(o),r.push(o),s.push(o))}}const h=[];for(let e of m.concat(c)){const r=f(e);if(t.NullChecker.isNullOrEmpty(r))h.push(e);else{const t=e.concat(r).sort(a);for(let e=0;e<t.length-1;e++)h.push([t[e],t[e+1]])}}var y,x=!1;do{l.sort(a),l.filter((t,e,r)=>0===e||!Utils.areClose(t,r[e-1])),y=Utils.mesh(l);const{vertices:e,triangleIndices:r}=y;x=!1;for(let n=0;n<r.length;n+=3){const s=r[n],o=r[n+1],i=r[n+2],a=e[s],m=e[o],c=e[i],u=[[a,m],[m,c],[c,a]];for(let e of h)for(let r of u){const n=Utils.areClose(r[0],e[0])||Utils.areClose(r[1],e[1])||Utils.areClose(r[0],e[1])||Utils.areClose(r[1],e[0])?null:Utils.intersect(r,e);t.NullChecker.isNull(n)||-1!==l.findIndex(t=>Utils.areClose(t,n,4))||(x=!0,l.push(n))}}}while(x);const{vertices:g,triangleIndices:p}=y,M=[];for(let t=0;t<p.length;t+=3){const e=g[p[t]],r=g[p[t+1]],i=g[p[t+2]],a={x:(e.x+r.x+i.x)/3,y:(e.y+r.y+i.y)/3},m=Utils.inPolygon(a,s),c=Utils.inPolygon(a,o);(m&&c&&"intersect"===n||(m||c)&&"union"===n||(m&&!c||!m&&c)&&"difference"===n)&&M.push([e,r,i])}const d=M.flatMap(([t,e,r])=>[[t,e],[e,r],[r,t]]),v=[];for(let t=0;t<d.length;t++){const e=d[t];if(0==t){v.push(e);continue}const r=v.findIndex(t=>Utils.areClose(t[0],e[0])&&Utils.areClose(t[1],e[1])||Utils.areClose(t[0],e[1])&&Utils.areClose(t[1],e[0]));-1===r?v.push(e):v.splice(r,1)}if(v.length<3)return null;const b=[],[z,w]=v.shift(),U=[z,w];for(;v.length>1;){const t=U[U.length-1],e=v.findIndex(e=>Utils.areClose(e[0],t)||Utils.areClose(e[1],t));if(-1===e){b.push({vertices:U.splice(0)});const[t,e]=v.shift();U.push(t,e)}else{const[r]=v.splice(e,1),n=Utils.areClose(r[0],t)?r[1]:Utils.areClose(r[1],t)?r[0]:null;U.push(n)}}return b.push({vertices:U}),{polygons:b,mesh:y}}static mesh(t,...r){const n=[].concat(t).concat(r);return{vertices:n,triangleIndices:e.Delaunay.triangulate(n)}}static intersectLines(t,e,r,n){let s,o;if(Array.isArray(t)&&Array.isArray(e)&&2===t.length&&2===e.length&&"number"==typeof t[0]&&"number"==typeof e[0]&&"number"==typeof t[1]&&"number"==typeof e[1]&&(r=e[0],n=e[1],e=t[1],t=t[0]),"number"==typeof t&&"number"==typeof e){s=[{x:0,y:e},{x:1,y:t+e}],o=[{x:0,y:n},{x:1,y:r+n}]}else s=t,o=e;return Utils._intersectSegments(s,o,!1)}static cramer(t,e){Array.isArray(t)&&(t={a:t[0],b:t[1],c:t[2]}),Array.isArray(e)&&(e={a:e[0],b:e[1],c:e[2]});let r=(t.b*e.c-t.c*e.b)/(t.b*e.a-t.a*e.b),n=(t.c*e.a-t.a*e.c)/(t.b*e.a-t.a*e.b);return{x:-r.roundoff(),y:-n.roundoff()}}static mq(t,e){let r;if(o(t)?r=t:(r=t[0],e=t[1]),r.x===e.x)return[Number.NaN,Number.NaN];const n=(e.y-r.y)/(e.x-r.x);return[n,r.y-n*r.x]}static _intersectSegments(t,e,r){const n=t[0],s=t[1],o=e[0],i=e[1],a=Math.min(n.x,s.x),m=Math.min(n.y,s.y),c=Math.max(n.x,s.x),l=c-a,u=Math.max(n.y,s.y),f=u-m,h=Math.min(o.x,i.x),y=Math.min(o.y,i.y),x=Math.max(o.x,i.x),g=x-h,p=Math.max(o.y,i.y),M=p-y;if(0===l&&0===g)return null;if(0===f&&0===M)return null;const d=t=>t.x<h||t.x>x||t.x<a||t.x>c,v=t=>t.y<y||t.y>p||t.y<m||t.y>u;var b=null;if(0===l){if(r&&(h>a||x<c))return null;const t=Utils.mq(o,i);b=Utils.cramer([1,0,-a],[t[0],-1,t[1]]),r&&v(b)&&(b=null)}else if(0===g){if(r&&(a>h||c<x))return null;const t=Utils.mq(n,s);b=Utils.cramer([t[0],-1,t[1]],[1,0,-h]),r&&v(b)&&(b=null)}else if(0===f){if(r&&(y>m||p<u))return null;const t=Utils.mq(o,i);b=Utils.cramer([0,1,-m],[t[0],-1,t[1]]),r&&d(b)&&(b=null)}else if(0===M){if(r&&(m>y||u<p))return null;const t=Utils.mq(n,s);b=Utils.cramer([t[0],-1,t[1]],[0,1,-y]),r&&d(b)&&(b=null)}else{let t;if(!r||(t=Utils._intersectRects({x:a,y:m,width:l,height:f},{x:h,y:y,width:g,height:M}))&&t.width>0&&t.height>0){const e=Utils.mq(n,s),a=Utils.mq(o,i),m=e[0],c=a[0],l=e[1],u=a[1];if(m!==c){let e=(b=Utils.cramer([m,-1,l],[c,-1,u])).x,n=b.y;r&&(e<t.x||e>t.x+t.width||n<t.y||n>t.y+t.height)&&(b=null)}}}return null===b?null:{x:b.x,y:b.y}}static _intersectRects(...e){return t.Rect.intersect(...e)}static _areClose(t,e,r=12){return Math.abs(t.x-e.x).isCloseTo(0,r)&&Math.abs(t.y-e.y).isCloseTo(0,r)}static areClose(t,e,r=12){return Utils._areClose(t,e,r)}static dot(t,e){return s.dot(t,e)}static cross(t,e){return s.cross(t,e)}static distance(e,r){if(null!=(n=e)&&Array.isArray(n)&&2===n.length&&o(n[0])&&o(n[1]))return t.Point.distance(e[0],e[1]);if(o(r))return t.Point.distance(e,r);{const t=r[0],n=r[1];return Math.abs(t*e.x-e.y+n)/Math.sqrt(Math.pow(t,2)+1)}var n}static _pointSegmentDistance(t,e){const r=s.from(e[0],e[1]),n=s.from(e[0],t);return Utils.cross(r,n)}static isWithin(t,e,r){const n=Utils._pointSegmentDistance(t,e);return!n.isCloseTo(0)&&(r?n<0:n>0)}static isBeyond(t,e,r){return Utils.isWithin(t,e,!r)}static inLine(t,e){return Utils._pointSegmentDistance(t,e).isCloseTo(0)}static inSegment(t,e){const r=Math.min(e[0].x,e[1].x),n=Math.max(e[0].x,e[1].x),s=Math.min(e[0].y,e[1].y),o=Math.max(e[0].y,e[1].y);return t.x>=r&&t.x<=n&&t.y>=s&&t.y<=o&&Utils.inLine(t,e)}static inTriangle(e,r){let n;for(let s=0;s<3;s++){const o=r[s],i=r[(s+1)%3],a=t.Point.subtract(i,e),m=t.Point.subtract(o,e),c=Utils.cross(a,m);if(s>0&&c*n<=0)return!1;n=c}return!0}static inPolygon(t,e,r=12){if(!(e?.length>=3))throw"Not enough vertices";const n=e.length;if(3===n)return Utils.inTriangle(t,[e[0],e[1],e[2]]);r>0&&(e=e.map(t=>({x:t.x.roundoff(r),y:t.y.roundoff(r)})),t={x:t.x.roundoff(r),y:t.y.roundoff(r)});let s=Number.MAX_VALUE,o=Number.MAX_VALUE,i=Number.MIN_VALUE,a=Number.MIN_VALUE;for(let t=0;t<n;t++){const r=e[t];s=Math.min(s,r.x),o=Math.min(o,r.y),i=Math.max(i,r.x),a=Math.max(a,r.y)}if(t.x<s||t.x>i||t.y<o||t.y>a)return!1;const m=[{x:s-1,y:t.y},t];let c=0;for(let r=0;r<n;r++){const s=e[r],o=e[(r+1)%n],i=[s,o];if(s.y===t.y){const i=e[(r-1+n)%n];t.x>s.x&&(i.y-t.y)*(o.y-t.y)<0&&c++}else{if(o.y===t.y)continue;null!=Utils.intersect(i,m)&&c++}}return c%2==1}static area(t,...e){const r=[].concat(t).concat(e);let n=0;const s=r.length;if(s>=3){for(let t=0;t<r.length;t++){const{x:e,y:o}=r[t],i=t===s-1?0:t+1,{x:a,y:m}=r[i];n+=e*m-o*a}n*=.5}return Math.abs(n.roundoff())}static convexHull(t,...e){const r=[].concat(t).concat(e);if(!(r?.length>1))return r?.slice()??[];const n=r.map(t=>({x:t.x,y:t.y})).sort((t,e)=>t.x===e.x?t.y-e.y:t.x-e.x),s=[];for(const t of n){const e=s[s.length-1];e&&e.x===t.x&&e.y===t.y||s.push(t)}if(s.length<=2)return s;const o=(t,e,r)=>(e.x-t.x)*(r.y-t.y)-(e.y-t.y)*(r.x-t.x),i=[];for(const t of s){for(;i.length>=2&&o(i[i.length-2],i[i.length-1],t)<=0;)i.pop();i.push(t)}const a=[];for(let t=s.length-1;t>=0;t--){const e=s[t];for(;a.length>=2&&o(a[a.length-2],a[a.length-1],e)<=0;)a.pop();a.push(e)}return i.pop(),a.pop(),i.concat(a)}}e.Utils=Utils}(t.Geometry||(t.Geometry={}))}(Pacem||(Pacem={})),function(t){!function(e){!function(e){const r=180/Math.PI,n=1/r;class Vector3D{static from(...t){if(3!==t.length)throw new RangeError("Must provide exactly 3 numbers");return{x:t[0],y:t[1],z:t[2]}}static parse(e){const r=t.parseAsNumericalArray(e);if(r&&3===r.length)return Vector3D.from.apply(null,r);throw new Error(`Cannot parse "${e}" as a valid Vector3D.`)}static i(){return{x:1,y:0,z:0}}static j(){return{x:0,y:1,z:0}}static k(){return{x:0,y:0,z:1}}static zero(){return{x:0,y:0,z:0}}static subtract(t,e){return{x:e.x-t.x,y:e.y-t.y,z:e.z-t.z}}static add(...t){var e={x:0,y:0,z:0};for(var r of t)e.x+=r.x,e.y+=r.y,e.z+=r.z;return e}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}static cross(t,e){return{x:t.y*e.z-t.z*e.y,y:t.z*e.x-t.x*e.z,z:t.x*e.y-t.y*e.x}}static scale(t,e,r=e,n=e){return{x:t.x*e,y:t.y*r,z:t.z*n}}static magSqr(t){return t.x*t.x+t.y*t.y+t.z*t.z}static areClose(t,e){return(e.x-t.x).isCloseTo(0)&&(e.y-t.y).isCloseTo(0)&&(e.z-t.z).isCloseTo(0)}static mag(t){return Math.sqrt(Vector3D.magSqr(t))}static negate(t){return{x:-t.x,y:-t.y,z:-t.z}}static unit(t){const e={x:t.x,y:t.y,z:t.z};return this.normalize(e),e}static normalize(t){const e=Vector3D.mag(t);if(e<=0)throw"Cannot normalize a vector of length 0.";const r=1/e;t.x*=r,t.y*=r,t.z*=r}static angleBetween(t,e){let n;const s=Vector3D.unit(t),o=Vector3D.unit(e);if(Vector3D.dot(s,o)<0){const t={x:-s.x-o.x,y:-s.y-o.y,z:-s.z-o.z},e=Vector3D.mag(t);n=Math.PI-2*Math.asin(e/2)}else{const t={x:s.x-o.x,y:s.y-o.y,z:s.z-o.z},e=Vector3D.mag(t);n=2*Math.asin(e/2)}return r*n}}e.Vector3D=Vector3D;class Spherical{static from(t,e,r){return{rho:t.clamp(0,1/0),theta:e.clamp(-180,180),phi:r.clamp(0,360)}}static fromVector(t,e,n){"number"==typeof t&&(t=Vector3D.from(t,e,n));const s=Vector3D.mag(t);if(s.isCloseTo(0))return Spherical.from(0,0,0);const o=Math.atan2(t.x,t.z),i=Math.acos((t.y/s).clamp(-1,1));return Spherical.from(s,o*r,i*r)}static toVector(t){const{rho:e,theta:r,phi:s}=t,o=s*n,i=r*n,a=Math.sin(o)*e;return{x:a*Math.sin(i),y:Math.cos(o)*e,z:a*Math.cos(i)}}static toRotationMatrix(t){const{theta:e,phi:r}=t,s=n*e,o=Math.sin(s),i=Math.cos(s),a=n*r,m=Math.sin(a),c=Math.cos(a);return Matrix3D.from(o*c,o*m,i,0,i*c,i*m,-o,0,-m,c,0,0,0,0,0,1)}}e.Spherical=Spherical;class Matrix3DUtils{static modify(t,e){const{m11:r,m12:n,m13:s,m14:o,m21:i,m22:a,m23:m,m24:c,m31:l,m32:u,m33:f,m34:h,offsetX:y,offsetY:x,offsetZ:g,m44:p}=t,M={m11:r,m12:n,m13:s,m14:o,m21:i,m22:a,m23:m,m24:c,m31:l,m32:u,m33:f,m34:h,offsetX:y,offsetY:x,offsetZ:g,m44:p};return e(M),M}static clone(t){return Matrix3DUtils.modify(t,t=>{})}static multiply(t,e){return Matrix3D.isIdentity(t)?e:Matrix3D.isIdentity(e)?t:Matrix3D.from(t.m11*e.m11+t.m12*e.m21+t.m13*e.m31+t.m14*e.offsetX,t.m11*e.m12+t.m12*e.m22+t.m13*e.m32+t.m14*e.offsetY,t.m11*e.m13+t.m12*e.m23+t.m13*e.m33+t.m14*e.offsetZ,t.m11*e.m14+t.m12*e.m24+t.m13*e.m34+t.m14*e.m44,t.m21*e.m11+t.m22*e.m21+t.m23*e.m31+t.m24*e.offsetX,t.m21*e.m12+t.m22*e.m22+t.m23*e.m32+t.m24*e.offsetY,t.m21*e.m13+t.m22*e.m23+t.m23*e.m33+t.m24*e.offsetZ,t.m21*e.m14+t.m22*e.m24+t.m23*e.m34+t.m24*e.m44,t.m31*e.m11+t.m32*e.m21+t.m33*e.m31+t.m34*e.offsetX,t.m31*e.m12+t.m32*e.m22+t.m33*e.m32+t.m34*e.offsetY,t.m31*e.m13+t.m32*e.m23+t.m33*e.m33+t.m34*e.offsetZ,t.m31*e.m14+t.m32*e.m24+t.m33*e.m34+t.m34*e.m44,t.offsetX*e.m11+t.offsetY*e.m21+t.offsetZ*e.m31+t.m44*e.offsetX,t.offsetX*e.m12+t.offsetY*e.m22+t.offsetZ*e.m32+t.m44*e.offsetY,t.offsetX*e.m13+t.offsetY*e.m23+t.offsetZ*e.m33+t.m44*e.offsetZ,t.offsetX*e.m14+t.offsetY*e.m24+t.offsetZ*e.m34+t.m44*e.m44)}}class Matrix3D{static identity(){return{m11:1,m12:0,m13:0,m14:0,m21:0,m22:1,m23:0,m24:0,m31:0,m32:0,m33:1,m34:0,offsetX:0,offsetY:0,offsetZ:0,m44:1}}static from(...t){if(16!==t.length)throw new RangeError("Must provide exactly 16 numbers");return{m11:t[0],m12:t[1],m13:t[2],m14:t[3],m21:t[4],m22:t[5],m23:t[6],m24:t[7],m31:t[8],m32:t[9],m33:t[10],m34:t[11],offsetX:t[12],offsetY:t[13],offsetZ:t[14],m44:t[15]}}static transpose(t){return Matrix3D.from(t.m11,t.m21,t.m31,t.offsetX,t.m12,t.m22,t.m32,t.offsetY,t.m13,t.m23,t.m33,t.offsetZ,t.m14,t.m24,t.m34,t.m44)}static toArray(t){return[t.m11,t.m12,t.m13,t.m14,t.m21,t.m22,t.m23,t.m24,t.m31,t.m32,t.m33,t.m34,t.offsetX,t.offsetY,t.offsetZ,t.m44]}static clone(t,e){return"function"==typeof e?Matrix3DUtils.modify(t,e):Matrix3DUtils.clone(t)}static scale(t,e,r,n){return"number"==typeof e?(r??=e,n??=e):(n=e.z,r=e.y,e=e.x),Matrix3DUtils.modify(t,t=>{t.m11*=e,t.m22*=r,t.m33*=n})}static translate(t,e){return Matrix3DUtils.modify(t,t=>{t.offsetX+=e.x,t.offsetY+=e.y,t.offsetZ+=e.z})}static parse(e){const r=t.parseAsNumericalArray(e);if(r&&16===r.length)return Matrix3D.from.apply(null,r);throw new Error(`Cannot parse "${e}" as a valid Matrix3D.`)}static isIdentity(t){return 1==t.m11&&0==t.m12&&0==t.m13&&0==t.m14&&0==t.m21&&1==t.m22&&0==t.m23&&0==t.m24&&0==t.m31&&0==t.m32&&1==t.m33&&0==t.m34&&0==t.offsetX&&0==t.offsetY&&0==t.offsetZ&&1==t.m44}static isAffine(t){return 0==t.m14&&0==t.m24&&0==t.m34&&1==t.m44}static determinant(t){if(Matrix3D.isIdentity(t))return 1;if(Matrix3D.isAffine(t))return t.m11*(t.m22*t.m33-t.m32*t.m23)-t.m12*(t.m21*t.m33-t.m31*t.m23)+t.m13*(t.m21*t.m32-t.m31*t.m22);{const e=t.m13*t.m24-t.m23*t.m14,r=t.m13*t.m34-t.m33*t.m14,n=t.m13*t.m44-t.offsetZ*t.m14,s=t.m23*t.m34-t.m33*t.m24,o=t.m23*t.m44-t.offsetZ*t.m24,i=t.m33*t.m44-t.offsetZ*t.m34,a=t.m22*r-t.m32*e-t.m12*s,m=t.m12*o-t.m22*n+t.offsetY*e,c=t.m32*n-t.offsetY*r-t.m12*i,l=t.m22*i-t.m32*o+t.offsetY*s;return t.offsetX*a+t.m31*m+t.m21*c+t.m11*l}}static multiply(...t){if(0===t.length)throw new ReferenceError("Matrix not provided.");const e=Array.from(t);let r=e[0];for(let t=1;t<e.length;t++)r=Matrix3DUtils.multiply(r,e[t]);return r}static invert(t){if(Matrix3D.isAffine(t)){const e=Matrix3D.determinant(t);if(0==e)return null;const r=t.m12*t.m23-t.m22*t.m13,n=t.m32*t.m13-t.m12*t.m33,s=t.m22*t.m33-t.m32*t.m23,o=t.m21*t.m13-t.m11*t.m23,i=t.m11*t.m33-t.m31*t.m13,a=t.m31*t.m23-t.m21*t.m33,m=t.m11*t.m22-t.m21*t.m12,c=t.m11*t.m32-t.m31*t.m12,l=t.m11*t.offsetY-t.offsetX*t.m12,u=t.m21*t.m32-t.m31*t.m22,f=t.m21*t.offsetY-t.offsetX*t.m22,h=t.m31*t.offsetY-t.offsetX*t.m32,y=t.m23*l-t.offsetZ*m-t.m13*f,x=t.m13*h-t.m33*l+t.offsetZ*c,g=t.m33*f-t.offsetZ*u-t.m23*h,p=m,M=-c,d=u,v=1/e;return Matrix3D.from(s*v,n*v,r*v,0,a*v,i*v,o*v,0,d*v,M*v,p*v,0,g*v,x*v,y*v,1)}{const e=Matrix3D.determinant(t);if(0==e)return null;const r=t.m33*t.m44-t.m34*t.offsetZ,n=t.m32*t.m44-t.m34*t.offsetY,s=t.m31*t.m44-t.m34*t.offsetX,o=t.m32*t.offsetZ-t.m33*t.offsetY,i=t.m31*t.offsetZ-t.m33*t.offsetX,a=t.m31*t.offsetY-t.m32*t.offsetX,m=t.m33*t.m44-t.m34*t.offsetZ,c=t.m32*t.m44-t.m34*t.offsetY,l=t.m31*t.m44-t.m34*t.offsetX,u=t.m32*t.offsetZ-t.m33*t.offsetY,f=t.m31*t.offsetZ-t.m33*t.offsetX,h=t.m31*t.offsetY-t.m32*t.offsetX,y=t.m23*t.m44-t.m24*t.offsetZ,x=t.m22*t.m44-t.m24*t.offsetY,g=t.m21*t.m44-t.m24*t.offsetX,p=t.m22*t.offsetZ-t.m23*t.offsetY,M=t.m21*t.offsetZ-t.m23*t.offsetX,d=t.m21*t.offsetY-t.m22*t.offsetX,v=t.m23*t.m34-t.m24*t.m33,b=t.m22*t.m34-t.m24*t.m32,z=t.m21*t.m34-t.m24*t.m31,w=t.m22*t.m33-t.m23*t.m32,U=t.m21*t.m33-t.m23*t.m31,C=t.m21*t.m32-t.m22*t.m31,A=t.m22*r-t.m23*n+t.m24*o,D=-(t.m21*r-t.m23*s+t.m24*i),N=t.m21*n-t.m22*s+t.m24*a,P=-(t.m21*o-t.m22*i+t.m23*a),V=-(t.m12*m-t.m13*c+t.m14*u),q=t.m11*m-t.m13*l+t.m14*f,X=-(t.m11*c-t.m12*l+t.m14*h),Y=t.m11*u-t.m12*f+t.m13*h,Z=t.m12*y-t.m13*x+t.m14*p,S=-(t.m11*y-t.m13*g+t.m14*M),_=t.m11*x-t.m12*g+t.m14*d,T=-(t.m11*p-t.m12*M+t.m13*d),E=-(t.m12*v-t.m13*b+t.m14*w),I=t.m11*v-t.m13*z+t.m14*U,L=-(t.m11*b-t.m12*z+t.m14*C),Q=t.m11*w-t.m12*U+t.m13*C,R=1/e;return Matrix3D.from(A*R,V*R,Z*R,E*R,D*R,q*R,S*R,I*R,N*R,X*R,_*R,L*R,P*R,Y*R,T*R,Q*R)}}static transform(t,e){var r={x:t.x,y:t.y,z:t.z};if(!Matrix3D.isIdentity(e)){var n=r.x,s=r.y,o=r.z;if(r.x=n*e.m11+s*e.m21+o*e.m31+e.offsetX,r.y=n*e.m12+s*e.m22+o*e.m32+e.offsetY,r.z=n*e.m13+s*e.m23+o*e.m33+e.offsetZ,!Matrix3D.isAffine(e)){var i=n*e.m14+s*e.m24+o*e.m34+e.m44;0!=i&&(r.x/=i,r.y/=i,r.z/=i)}}return r}}e.Matrix3D=Matrix3D;class Quaternion{static identity(){return Quaternion.from(0,0,0,1)}static from(...t){if(4!==t.length)throw new RangeError("Must provide exactly 4 numbers");return{x:t[0],y:t[1],z:t[2],w:t[3]}}static parse(e){const r=t.parseAsNumericalArray(e);if(r&&4===r.length)return Quaternion.from.apply(null,r);throw new Error(`Cannot parse "${e}" as a valid Quaternion.`)}static fromVectors(t,e){Vector3D.normalize(t),Vector3D.normalize(e);const r=(t,e,r,n)=>{const s=Quaternion.from(t,e,r,n);return Quaternion.normalize(s),s};let n=Vector3D.dot(t,e)+1;return n.isCloseTo(0)?Math.abs(t.x)>Math.abs(t.z)?r(-t.y,t.x,0,0):r(0,-t.z,t.y,0):r(t.y*e.z-t.z*e.y,t.z*e.x-t.x*e.z,t.x*e.y-t.y*e.x,n)}static normalize(t){const e=Quaternion.mag(t);if(e.isCloseTo(0))t.x=t.y=t.z=0,t.w=1;else{const r=1/e;t.x*=r,t.y*=r,t.z*=r,t.w*=r}}static unit(t){const e=Quaternion.from(t.x,t.y,t.z,t.w);return Quaternion.normalize(e),e}static fromAxisAngle(t,e){var r=n*(e%=360),s=Vector3D.mag(t);if(0==s)throw new RangeError("Invalid argument");var o=Math.sin(.5*r)/s,i=t.x*o,a=t.y*o,m=t.z*o;return Quaternion.from(i,a,m,Math.cos(.5*r))}static fromRotationMatrix(t){const e=t.m11+t.m22+t.m33+t.m44;if(e>0){const r=.5/Math.sqrt(e),n=.25/r,s=(t.m23-t.m32)*r,o=(t.m31-t.m13)*r,i=(t.m12-t.m21)*r;return Quaternion.from(s,o,i,n)}if(t.m11>t.m22&&t.m11>t.m22){const e=.5/Math.sqrt(t.m44+t.m11-t.m22-t.m33),r=(t.m23-t.m32)*e,n=.25/e,s=(t.m12+t.m21)*e,o=(t.m31+t.m13)*e;return Quaternion.from(n,s,o,r)}if(t.m22>t.m33){const e=.5/Math.sqrt(t.m44+t.m22-t.m11-t.m33),r=(t.m23+t.m32)*e,n=.25/e,s=(t.m12+t.m21)*e,o=(t.m31-t.m13)*e;return Quaternion.from(s,n,r,o)}{const e=.5/Math.sqrt(t.m44+t.m33-t.m11-t.m22),r=(t.m23+t.m32)*e,n=.25/e,s=(t.m12-t.m21)*e,o=(t.m31-t.m13)*e;return Quaternion.from(o,r,n,s)}}static conjugate(t){return Quaternion.from(-t.x,-t.y,-t.z,t.w)}static mag(t){return Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z+t.w*t.w)}static norm(t){return t.x*t.x+t.y*t.y+t.z*t.z}static axis(t){return 0==t.x&&0==t.y&&0==t.z?Vector3D.j():Vector3D.unit(t)}static transform(t,e){Quaternion.normalize(e);const r=Vector3D.cross(e,t),n=Vector3D.scale(r,2),s=Vector3D.cross(e,n);return{x:t.x+e.w*n.x+s.x,y:t.y+e.w*n.y+s.y,z:t.z+e.w*n.z+s.z}}static angle(t){let e=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z),r=t.w;if(e>Number.MAX_VALUE){const n=Math.max(Math.abs(t.x),Math.max(Math.abs(t.y),Math.abs(t.z))),s=t.x/n,o=t.y/n,i=t.z/n;e=Math.sqrt(s*s+o*o+i*i),r/=n}return 114.59155902616465*Math.atan2(e,r)}static toRotationMatrix(t){var e=Matrix3D.identity(),r=t.x,n=t.y,s=t.z,o=t.w;return e.m11=1-2*n*n-2*s*s,e.m12=2*r*n+2*o*s,e.m13=2*r*s-2*o*n,e.m21=2*r*n-2*o*s,e.m22=1-2*r*r-2*s*s,e.m23=2*n*s+2*o*r,e.m31=2*o*n+2*r*s,e.m32=2*n*s-2*o*r,e.m33=1-2*r*r-2*n*n,e}static invert(t){const e=Quaternion.unit(t);return Quaternion.conjugate(e)}static multiply(t,e){return Quaternion.from(t.w*e.x+t.x+e.w+t.y*e.z-t.z*e.y,t.w*e.y-t.x*e.z+t.y*e.w+t.z*e.x,t.w*e.z+t.x*e.y-t.y*e.x+t.z*e.w,t.w*e.w-t.x*e.x-t.y*e.y-t.z*e.z)}static dot(t,e){return Quaternion.multiply(t,Quaternion.conjugate(e)).w}}e.Quaternion=Quaternion}(e.LinearAlgebra||(e.LinearAlgebra={}))}(t.Geometry||(t.Geometry={}))}(Pacem||(Pacem={})),function(t){!function(e){const r=t.Geometry.LinearAlgebra.Vector3D;t.Geometry.LinearAlgebra.Matrix3D;e.Utils3D=class Utils3D{static intersect(t,e){const[n,s]=t,o=r.subtract(n,s),[i,a,m]=e,c=r.subtract(i,a),l=r.subtract(i,m),u=r.cross(o,l),f=r.dot(c,u);if(f.isCloseTo(0))return null;const h=1/f,y=r.subtract(n,i),x=h*r.dot(y,u);if(x<0||x>1)return null;const g=r.cross(y,c),p=h*r.dot(o,g);if(p<0||x+p>1)return null;const M=h*r.dot(l,g);return M<0||M.isCloseTo(0)?null:r.add(n,r.scale(o,M))}}}(t.Geometry||(t.Geometry={}))}(Pacem||(Pacem={})),function(t){!function(e){class Polygon{static _eps=1e-12;static isPolygon(e){return function(e){let r;return"vertices"in e&&Array.isArray(e.vertices)&&(r=e.vertices).length>=3&&r.every(e=>t.Point.isPoint(e))}(e)}static from(...t){return{vertices:Array.from(t)}}static contains(t,r){return e.Utils.inPolygon(r,t.vertices,12)}static centroid(t){const e=Polygon.boundingBox(t);return{x:e.x+e.width/2,y:e.y+e.height/2}}static boundingBox(t){let e=Number.MAX_VALUE,r=Number.MAX_VALUE,n=-Number.MAX_VALUE,s=-Number.MAX_VALUE;const{vertices:o}=t;o.length;for(let t of o)e=Math.min(e,t.x),r=Math.min(r,t.y),n=Math.max(n,t.x),s=Math.max(s,t.y);return{x:e,y:r,width:n-e,height:s-r}}static sides(t){const{vertices:e}=t,r=[];for(let t=1;t<=e.length;t++){const n=e[t%e.length],s=e[t-1];r.push([s,n])}return r}static isConvex(e){const{vertices:r}=e,n=r.length;if(n<=3)return!0;let s=0;for(let e=0;e<r.length;e++){const o=r[(e-1+n)%n],i=r[e],a=r[(e+1)%n],m=t.Angle.angleBetween(i,o,a);if(0!==s){if(s!=Math.sign(m))return!1}else s=Math.sign(m)}return!0}static isSelfIntersecting(r){const{vertices:n}=r;if(n.length<=3)return!1;const s=Polygon.sides(r);for(let r of s)for(let n of s){if(n===r||n[0]===r[1]||r[0]===n[1])continue;const s=e.Utils.intersect(n,r);if(!t.NullChecker.isNull(s))return!0}return!1}static isCounterClockwise(e){const{vertices:[r,n,s]}=e;return t.Angle.angleBetween(n,r,s)>0}static expand(r,n){const{vertices:s}=r,o=s.length,i=[];for(let r=0;r<s.length;r++){const a=s[(r-1+o)%o],m=s[r],c=s[(r+1)%o],l=t.Angle.angleBetween(m,a,c),u=-n/Math.sin(Math.abs(l)/2),f=t.Matrix2D.scale(t.Matrix2D.identity,u),h=t.Point.subtract(m,a);e.LinearAlgebra.Vector.normalize(h);const y=t.Point.subtract(m,c);e.LinearAlgebra.Vector.normalize(y);const x=t.Point.add(h,y);e.LinearAlgebra.Vector.normalize(x);const g=t.Matrix2D.multiply(x,f);i.push(t.Point.add(m,{x:g.x.roundoff(),y:g.y.roundoff()}))}return{vertices:i}}static area(t){return e.Utils.area(t.vertices)}static intersect(e,r){return t.Geometry.Utils.intersect(e,r)}static convexHull(t){return{vertices:e.Utils.convexHull(t.vertices)}}}e.Polygon=Polygon}(t.Geometry||(t.Geometry={}))}(Pacem||(Pacem={})),function(t){!function(t){function e(t){return"number"==typeof t&&(t={real:t,img:0}),t}var r;function n(t,e){const r={};return Object.defineProperty(r,"real",{value:t,writable:!1}),Object.defineProperty(r,"img",{value:e,writable:!1}),r}function s(){return r||(r=n(Number.NaN,Number.NaN))}t.Complex=class Complex{static build(t,e){return this.isComplex(t)?t:(e??=0,"number"!=typeof t||"number"!=typeof e?s():n(t,e||0))}static add(t,r){const s=e(t),o=e(r);return n(s.real+o.real,s.img+o.img)}static subtract(t,r){const s=e(t),o=e(r);return n(s.real-o.real,s.img-o.img)}static multiply(t,r){const s=e(t),o=e(r);return n(s.real*o.real-s.img*o.img,s.real*o.img+s.img*o.real)}static divide(t,r){const o=e(t),i=e(r),a=this.absSquare(i).roundoff();if(0===a)return s();const m=1/a;return n(m*(o.real*i.real+o.img*i.img),m*(o.img*i.real-o.real*i.img))}static absSquare(t){const r=e(t);return Math.pow(r.real,2)+Math.pow(r.img,2)}static modulus(t){return Math.sqrt(this.absSquare(t))}static isComplex(t){return null!=t&&"object"==typeof t&&"real"in t&&"img"in t&&"number"==typeof t.real&&"number"==typeof t.img}static conjugate(t){return n((t=e(t)).real,0==Math.abs(t.img)?0:-t.img)}static equals(t,e){const r=this.build(t),n=this.build(e);return!(!this.isComplex(t)||!this.isComplex(e))&&(r.real===n.real&&r.img===n.img)}static get NaC(){return s()}}}(t.Mathematics||(t.Mathematics={}))}(Pacem||(Pacem={})),function(t){!function(t){!function(e){const r={};function n(e,n){const s=r[n]=r[n]||{};return s[e]=s[e]||function(e,r){const n=2*Math.PI*e/r;return t.Complex.build(Math.cos(n),Math.sin(n))}(e,n)}function s(e){const r=[],o=e.length;if(1===o)return[t.Complex.build(e[0])];const i=s(e.filter((t,e)=>e%2==0)),a=s(e.filter((t,e)=>e%2==1));for(var m=0;m<o/2;m++){const e=i[m],s=t.Complex.multiply(n(m,o),a[m]);r[m]=t.Complex.add(e,s),r[m+o/2]=t.Complex.subtract(e,s)}return r}e.Fourier=class Fourier{static transform(t,e=!0){return(r=(t=t||[]).length)>0&&!(r&r-1)?this.fft(t,e):this.dft(t,e);var r}static invert(t,e=!0){return this.idft(t||[],e)}static dft(e,r=!0){const s=(e||[])?.length,o=r?1/Math.sqrt(s):1,i=[];for(let r=0;r<s;r++){i.push({real:0,img:0});for(let a=0;a<s;a++){const m=n(r*a,s),c=t.Complex.multiply(e[a],m),l=t.Complex.multiply(c,o);i[r]=t.Complex.add(i[r],l)}}return i}static idft(e,r=!0){const n=e.map(e=>t.Complex.build(e.img,e.real));return this.transform(n,r).map(e=>t.Complex.build(e.img,e.real))}static fft(e,r=!0){const n=s(e);if(!r)return n;const o=1/Math.sqrt(e.length);return n.map(e=>t.Complex.multiply(e,o))}}}(t.DataAnalysis||(t.DataAnalysis={}))}(t.Mathematics||(t.Mathematics={}))}(Pacem||(Pacem={})),function(t){!function(t){!function(t){const e=Math.sqrt(Math.PI);function r(t){const e=Math.abs(t),r=1/(1+.5*e),n=r*Math.exp(-e*e-1.26551223+r*(1.00002368+r*(.37409196+r*(.09678418+r*(r*(.27886807+r*(r*(1.48851587+r*(.17087277*r-.82215223))-1.13520398))-.18628806)))));return t>=0?n:2-n}class Gaussian{constructor(t,e){this.mean=t,this.stdev=Math.abs(e),this.variance=Math.pow(e,2)}mean;stdev;variance;static get normal(){return n}weight(t){return Math.exp(-.5*Math.pow(this._z(t),2))}probabilityDensity(t){const r=this.stdev*Math.SQRT2*e;return this.weight(t)/r}_z(t){return(t-this.mean)/this.stdev}probability(t){return.5*r(-this._z(t)/Math.SQRT2)}}t.Gaussian=Gaussian;const n=new Gaussian(0,1)}(t.DataAnalysis||(t.DataAnalysis={}))}(t.Mathematics||(t.Mathematics={}))}(Pacem||(Pacem={})),function(t){!function(t){!function(t){class Lagrangian{constructor(...t){this.#t=Array.from(t)||[]}#t;#e;_unsafeCreate(){const t=this.#t||[];let e,r="var ljs = [];\n";for(let n=0;n<t.length;n++){const s=t[n],o=s.x;if(null!=e&&e>=o)throw new Error("Invalid function provided.");e=o,r+=`ljs.push( ${s.y}`;for(let e=0;e<t.length;e++)if(e!==n){const n=t[e];r+=` * ((x - ${n.x})/${o-n.x})`}r+=");\n"}r+="return ljs.reduce((prev, next) => prev + next, 0);",this.#e=new Function("x",r)}_compute(t){const e=this.#t||[];let r;const n=[];for(let s=0;s<e.length;s++){const o=e[s].x;if(null!=r&&r>=o)throw new Error("Invalid function provided.");r=o;let i=e[s].y;for(let r=0;r<e.length;r++)if(r!==s){const n=e[r];i*=(t-n.x)/(o-n.x)}n.push(i)}return n.reduce((t,e)=>t+e,0)}interpolate(t){return"function"==typeof this.#e?this.#e.apply(null,[t]):this._compute(t)}static create(...t){const e=(arguments.length>0&&Array.isArray(arguments[0])?arguments[0]:Array.from(t)).map((t,e)=>"number"==typeof t?{x:e,y:t}:t),r=new(Function.prototype.bind.apply(Lagrangian,[null].concat(e)));try{r._unsafeCreate()}catch(t){}return r}}t.Lagrangian=Lagrangian}(t.DataAnalysis||(t.DataAnalysis={}))}(t.Mathematics||(t.Mathematics={}))}(Pacem||(Pacem={})),function(t){!function(e){!function(e){const r="0123456789abcdefghijklmnopqrstuvwxyz",n="Radix out of range: possible values go between positive 1 exclusive and 36 inclusive";class Utils{static lcd(...e){if(t.NullChecker.isNullOrEmpty(e)||e.length<=1)throw"Insufficient set of numbers.";function r(t,e){return e?r(e,t%e):0===e?t:NaN}function n(t,e){return t*e/r(t,e)}let s=Math.round(e[0]);for(let t=1;t<e.length;t++)s=n(s,Math.round(e[t]));return s}static gcd(t,e){return t=Math.round(t),e=Math.round(e),0===t?e:Utils.gcd(e%t,t)}static rebaseInt(e,r,n){return t.Numbers.rebase(e,r,n)}static rebaseFloat(t,e,r,n=12){const s=Utils.rebaseFloat10ToN,o=Utils.rebaseFloatNTo10;if(10===e){const e=parseFloat(t.toString());return r%1==0?Utils.rebaseFloat10ToNIntBase(e,r,n):s(e,r,n)}if(10===r)return o(t.toString(),e,n);return s(o(t.toString(),e,n+1),r,n)}static rebaseFloatNTo10(t,e,s=12){const o=r;if(e<=1||e>o.length)throw new Error(n);const i=(t??"0").toString().toLowerCase(),a=Number.NaN;if("0"===i)return 0;const m=/^([-+]?) *([\da-z]+)?(.[\da-z]+)?$/.exec(i);if(m.length<2)return a;const c="-"===m[1]?-1:1,l=m[2]||"0",u=m[3]||".0";let f=0,h=0;for(let t of l+u.substr(1)){const r=o.indexOf(t);if(-1===r||r>=e)return a;f+=r*Math.pow(e,l.length-h-1),h++}return c*f}static rebaseFloat10ToNIntBase(t,e,s=12){const o=r;if(e<=1||e>36)throw new Error(n);const i=e;let a=Math.abs(t??0);if(0===a||Number.isNaN(a))return t.toString();let m=(a%1).roundoff(),c="";for(;;){let t=a/i,e=Math.floor(t),r=(a-e*i).roundoff(),n=Math.floor(r);if(c=n>=36?`[${n}]`+c:o[n]+c,e<=0)break;a=e}if(c=c.replace(/^0+/,""),c||="0",0===m)return c;let l="";do{a=(m*i).roundoff();const t=Math.floor(a),e=(a-t).roundoff();t>=36?l=`[${t}]`:l+=o[t],m=e}while(!m.isCloseTo(0)&&l.length<s);return/^0*$/.test(l)?c:(Math.sign(t)<0?"-":"")+c+"."+l.replace(/0+$/,"")}static rebaseFloat10ToN(e,s,o=12){const i=r;if(s<=1||s>i.length)throw new Error(n);const a=s;let m=Math.abs(e??0);if(0===m||Number.isNaN(m))return e.toString();let c=Math.sign(e)<0?"-":"",l=[],u=[];for(let t=0;t<20;t++)l.push("0"),u.push("0");const f=a%1==0?a:Math.ceil(a);function h(t,e,r){const n=t?l:u,s=n[e]=n[e]||"0",o=i.indexOf(s)+r,a=o%f,m=Math.floor(o/f);return n[e]=i[a],m>0&&(t?h(t,e+1,m):0===e?h(!0,0,m):h(!1,e-1,m)),m}let y=0;for(;;){const e=Math.floor(t.Numbers.log(m,a)),r=e>=0;if(h(r,r?e:Math.abs(1+e),1),m=(m-Math.pow(a,e).roundoff()).roundoff(),r||y++,0===m||y>=100){const t=c+(l.reverse().map(t=>t||"0").join("").replace(/^0+/,"")||"0"),e=u.map(t=>t||"0").join("").substr(0,o).replace(/0+$/,"");return/^0*$/.test(e)?t:t+"."+e}}}}e.Utils=Utils}(e.NumberTheory||(e.NumberTheory={}))}(t.Mathematics||(t.Mathematics={}))}(Pacem||(Pacem={})),function(t){!function(t){!function(t){const e=(t,e)=>t;function r(t,r=e){return t.reduce((t,e,n)=>t+r(e,n),0)}function n(t,n=e){return r(t,n)/t.length}function s(t,r=e,s=!1){const o=n(t,r);return t.reduce((t,e)=>Math.pow(e-o,2)+t,0)/(t.length-(s?1:0))}function o(t,r=e,n=!1){const o=s(t,r,n);return Math.sqrt(o)}function i(t,e){return(r,n,s,o)=>{let i=r,a=n,m=t(i,a),c=e(i,a),l=s(m),u=s(c);for(;a-i>o;)l<u?(a=c,c=m,u=l,m=t(i,a),l=s(m)):(i=m,m=c,l=u,c=e(i,a),u=s(c));return.5*(m+c)}}t.Utils=class Utils{static sum(t,e){return r(t,e)}static mean(t,e){return n(t,e)}static median(t,r){return function(t,r=e){const n=t.slice(0),s=n.length;n.sort((t,e)=>r(t)-r(e));const o=Math.ceil(n.length/2)-1;return s%2==1?n[o]:.5*(n[o+1]+n[o])}(t,r)}static mode(t,r){return function(t,r=e){const n=Object.groupBy(t,r);let s,o=0;for(let t in n){const e=n[t].length;e>o&&(s=parseInt(t),o=e)}return s}(t,r)}static var(t,e){return s(t,e,!0)}static varp(t,e){return s(t,e,!1)}static stdevp(t,e){return o(t,e,!1)}static stdev(t,e){return o(t,e,!0)}static correlation(t,r,s,o){return function(t,r,s=e,o=e){const i=Array.isArray(r);if(i&&r.length!==t.length)throw new Error("Sets must be of the same length.");const a=t.length,m=t,c=i?r:t,l=i?s:r,u=i?o:s,f=n(m,l),h=n(c,u);let y=0,x=0,g=0;for(let t=0;t<a;t++){const e=m[t],r=c[t],n=l(e,t)-f,s=u(r,t)-h;y+=n*s,x+=n*n,g+=s*s}return y/Math.sqrt(x*g)}(t,r,s,o)}static linearRegression(t,r,n,s){return function(t,r,n=e,s=e){const o=Array.isArray(r);if(o&&r.length!==t.length)throw new Error("Sets must be of the same length.");const i=t,a=o?r:t,m=o?n:r,c=m??(t=>t.x),l=(o?s:m)??(t=>t.y),u=t.length;let f=0,h=0,y=0,x=0,g=0;for(let t=0;t<u;t++){const e=i[t],r=a[t],n=c(e,t),s=l(r,t);f+=n*s,h+=n,y+=s,x+=n*n,g+=s*s}const p=(u*f-h*y)/(u*x-Math.pow(h,2));return[p,(y-p*h)/u]}(t,r,n,s)}static gaussian(e,r){return new t.Gaussian(e,r)}};t.SearchFunctions={linear:(t=2)=>function(t){if(t<=1)throw new RangeError("segments must be a number grater than 1.");return(e,r,n,s=.001)=>i((e,r)=>e+(r-e)/t,(e,r)=>r-(r-e)/t)(e,r,n,s)}(t),goldenRatio:(t,e,r,n=.001)=>i((t,e)=>e-(e-t)/1.618,(t,e)=>t+(e-t)/1.618)(t,e,r,n),gaussian:(t,e,r,n=.001)=>{var s=null,o=null;const a=(t,e)=>(o??=e-t,s??=o/Math.sqrt(12),s*(e-t)/o);return i((t,e)=>Math.max(t,(e+t)/2-a(t,e)),(t,e)=>Math.min(e,(e+t)/2+a(t,e)))(t,e,r,n)}}}(t.DataAnalysis||(t.DataAnalysis={}))}(t.Mathematics||(t.Mathematics={}))}(Pacem||(Pacem={}));
|
package/dist/js/pacem-plus.d.ts
CHANGED
package/dist/js/pacem-plus.js
CHANGED
package/dist/js/pacem-ui.d.ts
CHANGED
package/dist/js/pacem-ui.js
CHANGED
package/dist/js/pacem-ui.min.js
CHANGED
package/package.json
CHANGED