@ac-kit/math-geometry 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +177 -0
- package/README.md +76 -5
- package/dist/_polygon3-cross.d.ts +23 -0
- package/dist/_polygon3-cross.d.ts.map +1 -0
- package/dist/_polygon3-cross.js +418 -0
- package/dist/_polygon3-cross.js.map +1 -0
- package/dist/_polyline-simplify.d.ts +11 -0
- package/dist/_polyline-simplify.d.ts.map +1 -0
- package/dist/_polyline-simplify.js +92 -0
- package/dist/_polyline-simplify.js.map +1 -0
- package/dist/_triangle3-cross.d.ts +66 -0
- package/dist/_triangle3-cross.d.ts.map +1 -0
- package/dist/_triangle3-cross.js +405 -0
- package/dist/_triangle3-cross.js.map +1 -0
- package/dist/convex-hull2.d.ts +26 -0
- package/dist/convex-hull2.d.ts.map +1 -0
- package/dist/convex-hull2.js +88 -0
- package/dist/convex-hull2.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/line2.d.ts +4 -0
- package/dist/line2.d.ts.map +1 -1
- package/dist/line2.js +26 -5
- package/dist/line2.js.map +1 -1
- package/dist/mesh/_index-kernels-u16.d.ts +46 -11
- package/dist/mesh/_index-kernels-u16.d.ts.map +1 -1
- package/dist/mesh/_index-kernels-u16.js +1442 -132
- package/dist/mesh/_index-kernels-u16.js.map +1 -1
- package/dist/mesh/_index-kernels-u32.d.ts +46 -11
- package/dist/mesh/_index-kernels-u32.d.ts.map +1 -1
- package/dist/mesh/_index-kernels-u32.js +1442 -132
- package/dist/mesh/_index-kernels-u32.js.map +1 -1
- package/dist/mesh/mesh3-kernels.d.ts +104 -20
- package/dist/mesh/mesh3-kernels.d.ts.map +1 -1
- package/dist/mesh/mesh3-kernels.js +123 -25
- package/dist/mesh/mesh3-kernels.js.map +1 -1
- package/dist/plane3.d.ts +4 -3
- package/dist/plane3.d.ts.map +1 -1
- package/dist/plane3.js +18 -35
- package/dist/plane3.js.map +1 -1
- package/dist/polygon2.d.ts +76 -4
- package/dist/polygon2.d.ts.map +1 -1
- package/dist/polygon2.js +366 -7
- package/dist/polygon2.js.map +1 -1
- package/dist/polygon3.d.ts +19 -3
- package/dist/polygon3.d.ts.map +1 -1
- package/dist/polygon3.js +40 -16
- package/dist/polygon3.js.map +1 -1
- package/dist/polyline2.d.ts +20 -0
- package/dist/polyline2.d.ts.map +1 -1
- package/dist/polyline2.js +25 -0
- package/dist/polyline2.js.map +1 -1
- package/dist/polyline3.d.ts +17 -0
- package/dist/polyline3.d.ts.map +1 -1
- package/dist/polyline3.js +22 -0
- package/dist/polyline3.js.map +1 -1
- package/dist/predicates2.d.ts +51 -0
- package/dist/predicates2.d.ts.map +1 -0
- package/dist/predicates2.js +172 -0
- package/dist/predicates2.js.map +1 -0
- package/dist/quadtree.d.ts +40 -23
- package/dist/quadtree.d.ts.map +1 -1
- package/dist/quadtree.js +196 -119
- package/dist/quadtree.js.map +1 -1
- package/dist/segment2.d.ts +6 -1
- package/dist/segment2.d.ts.map +1 -1
- package/dist/segment2.js +20 -4
- package/dist/segment2.js.map +1 -1
- package/dist/triangle3.d.ts +20 -1
- package/dist/triangle3.d.ts.map +1 -1
- package/dist/triangle3.js +38 -18
- package/dist/triangle3.js.map +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
import { binaryExponent, scaleByPowerOfTwoInPlace } from "@ac-kit/core";
|
|
2
|
+
import { DotExactAccumulator, twoProductInRangeInPlace, twoSumInPlace, } from "@ac-kit/math-scalar";
|
|
3
|
+
import { NONE_, PLAIN_ACCURACY_, PLAIN_BOUND_, PLAIN_EDGE_MAX_, PLAIN_EDGE_MIN_, PLAIN_MAX_, PLAIN_MIN_, PLAIN_UNDERFLOW_, UNDERFLOW_BOUND_, UNIT_ROUNDOFF_, writeScaledComponents_, } from "./_triangle3-cross.js";
|
|
4
|
+
// Newell's vector of a polygon in space, `Σ (vᵢ − v₀) × (vᵢ₊₁ − v₀)` over the
|
|
5
|
+
// fan from its first vertex (twice its area times its unit normal), with the
|
|
6
|
+
// guarantees and the three paths of `triangle3Cross_`, which this is the sum of
|
|
7
|
+
// such products of: plain arithmetic, then doubled precision, then exact sums,
|
|
8
|
+
// each with a rigorous error bound settling the result before the next is
|
|
9
|
+
// tried.
|
|
10
|
+
/**
|
|
11
|
+
* The fans the plain and doubled paths take: their bounds grow with the number
|
|
12
|
+
* of terms and are stated for fewer than 2^24 of them per part; a polygon with
|
|
13
|
+
* more triangles goes to the exact path.
|
|
14
|
+
*/
|
|
15
|
+
const MAX_TRIANGLES_ = 2 ** 24;
|
|
16
|
+
/**
|
|
17
|
+
* The doubled path's bound on a product of two parts it rounds: within u of the
|
|
18
|
+
* exact one, so within u / (1 − u) of the rounded one.
|
|
19
|
+
*/
|
|
20
|
+
const ROUNDED_PRODUCT_BOUND_ = 1.01 * UNIT_ROUNDOFF_;
|
|
21
|
+
/** The exact path's products per call to the accumulator. */
|
|
22
|
+
const CHUNK_ = 32;
|
|
23
|
+
/**
|
|
24
|
+
* Per axis, the edges `vᵢ − v₀` and `vᵢ₊₁ − v₀` of one fan triangle as TwoSum
|
|
25
|
+
* leaves them, the rounded difference then its exact error (0–3 for x, 4–7 for
|
|
26
|
+
* y, 8–11 for z), then scaled by the axis's power of two.
|
|
27
|
+
*/
|
|
28
|
+
const EDGES_ = new Float64Array(12);
|
|
29
|
+
/** Per axis, the power of two its scaled edges are to be multiplied by. */
|
|
30
|
+
const AXIS_EXPONENTS_ = new Int32Array(3);
|
|
31
|
+
/** Per edge component (`vᵢ` then `vᵢ₊₁`, per axis), 1 when it is exactly 0. */
|
|
32
|
+
const ZEROS_ = new Uint8Array(6);
|
|
33
|
+
/** A fan triangle's two products per component, as TwoProduct leaves them. */
|
|
34
|
+
const PRODUCTS_ = new Float64Array(4);
|
|
35
|
+
/** One component's eight parts in a fan triangle, summed as they come. */
|
|
36
|
+
const PARTS_ = new Float64Array(8);
|
|
37
|
+
/** Per component, the doubled path's running sum and its compensation. */
|
|
38
|
+
const SUMS_ = new Float64Array(6);
|
|
39
|
+
/** Per component, the sum of the magnitudes of the parts summed. */
|
|
40
|
+
const MAGNITUDES_ = new Float64Array(3);
|
|
41
|
+
/** Per component, the bound on what the parts lost before summing. */
|
|
42
|
+
const LOSSES_ = new Float64Array(3);
|
|
43
|
+
/** Per component, 1 while every fan triangle's component is exactly 0. */
|
|
44
|
+
const IS_ZERO_ = new Uint8Array(3);
|
|
45
|
+
/** Per component, the bound the doubled path settled it with. */
|
|
46
|
+
const BOUNDS_ = new Float64Array(3);
|
|
47
|
+
/** The components, each `COMPONENTS_[i] · 2^EXPONENTS_[i]`. */
|
|
48
|
+
const COMPONENTS_ = new Float64Array(3);
|
|
49
|
+
const EXPONENTS_ = new Int32Array(3);
|
|
50
|
+
/** The exact path's factors, a chunk of products at a time. */
|
|
51
|
+
const LEFT_ = new Float64Array(CHUNK_);
|
|
52
|
+
const RIGHT_ = new Float64Array(CHUNK_);
|
|
53
|
+
/** An exact component, as significand and exponent. */
|
|
54
|
+
const SCALED_ = new Float64Array(2);
|
|
55
|
+
const EXACT_ = new DotExactAccumulator();
|
|
56
|
+
/**
|
|
57
|
+
* Writes Newell's vector of the ring of the first `count` (at least 3) vertices
|
|
58
|
+
* of `coordinates` into `out` as `[x, y, z, k]`, the vector being `(x, y, z) ·
|
|
59
|
+
* 2^k`, with `triangle3Cross_`'s guarantees: every component within 2^−49 of
|
|
60
|
+
* the largest component of the exact vector, for any finite coordinates; `[0,
|
|
61
|
+
* 0, 0, 0]` exactly when the exact vector is zero, a component +0 where the
|
|
62
|
+
* exact one is 0, and one with the exact one's sign wherever that bound cannot
|
|
63
|
+
* reach 0; k = 0 when the largest component lies in `[2^−400, 2^402)`,
|
|
64
|
+
* otherwise the largest lies in `[1, 2)`. A coordinate that is not finite gives
|
|
65
|
+
* `NaN`s. Allocates nothing.
|
|
66
|
+
*
|
|
67
|
+
* The plain fan sum where its rigorous bound settles every component (edges up
|
|
68
|
+
* to 2^200, no cancellation between the fan triangles beyond about 2^−50 of the
|
|
69
|
+
* largest component); then the same sum in doubled precision (each edge split
|
|
70
|
+
* exactly by TwoSum and scaled per axis as `triangle3Cross_` scales a
|
|
71
|
+
* triangle's, each product of high parts by TwoProduct, every part summed by
|
|
72
|
+
* Ogita, Rump & Oishi's `Sum2`, with a rigorous bound on what is lost); last,
|
|
73
|
+
* each component as the exact sum `Σ vᵢ × vᵢ₊₁` around the ring (the fan's sum
|
|
74
|
+
* expanded, the first vertex's terms cancelling) by Kulisch's long accumulator,
|
|
75
|
+
* rounded once at any exponent.
|
|
76
|
+
*/
|
|
77
|
+
export function polygon3Cross_(out, coordinates, count) {
|
|
78
|
+
for (let index = 0; index < 3 * count; index++) {
|
|
79
|
+
const value = coordinates[index];
|
|
80
|
+
if (value - value !== 0) {
|
|
81
|
+
out[0] = Number.NaN;
|
|
82
|
+
out[1] = Number.NaN;
|
|
83
|
+
out[2] = Number.NaN;
|
|
84
|
+
out[3] = 0;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (count - 2 <= MAX_TRIANGLES_) {
|
|
89
|
+
if (plainNewell_(out, coordinates, count)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const scaling = axisScaling_(coordinates, count);
|
|
93
|
+
if (scaling !== SCALING_WIDE_ &&
|
|
94
|
+
doubledNewell_(coordinates, count, scaling)) {
|
|
95
|
+
writeScaledComponents_(out, COMPONENTS_, EXPONENTS_);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exactNewell_(coordinates, count);
|
|
100
|
+
writeScaledComponents_(out, COMPONENTS_, EXPONENTS_);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The plain path of {@link polygon3Cross_}: the fan sum in plain arithmetic,
|
|
104
|
+
* written into `out` with k = 0 when a rigorous bound settles every sign and
|
|
105
|
+
* puts every component within 2^−50 of the largest (and the largest in the
|
|
106
|
+
* unscaled range). Returns whether it did.
|
|
107
|
+
*
|
|
108
|
+
* Each fan triangle's component is within `triangle3Cross_`'s plain bound of
|
|
109
|
+
* its exact value: 3.001u of its two products, u of itself, and 2^−1070 per
|
|
110
|
+
* product that underflows (u = 2^−53). The recursive sum of T of them adds
|
|
111
|
+
* γ_{T−1} of the sum of their magnitudes (Higham, "Accuracy and Stability of
|
|
112
|
+
* Numerical Algorithms", §4.2); the bound, itself a sum of T positive terms, is
|
|
113
|
+
* widened by 2(T + 2)u for its own roundings.
|
|
114
|
+
*/
|
|
115
|
+
function plainNewell_(out, coordinates, count) {
|
|
116
|
+
const originX = coordinates[0];
|
|
117
|
+
const originY = coordinates[1];
|
|
118
|
+
const originZ = coordinates[2];
|
|
119
|
+
let sumX = 0;
|
|
120
|
+
let sumY = 0;
|
|
121
|
+
let sumZ = 0;
|
|
122
|
+
let productsX = 0;
|
|
123
|
+
let productsY = 0;
|
|
124
|
+
let productsZ = 0;
|
|
125
|
+
let termsX = 0;
|
|
126
|
+
let termsY = 0;
|
|
127
|
+
let termsZ = 0;
|
|
128
|
+
let isZeroX = true;
|
|
129
|
+
let isZeroY = true;
|
|
130
|
+
let isZeroZ = true;
|
|
131
|
+
let longest = 0;
|
|
132
|
+
let abX = coordinates[3] - originX;
|
|
133
|
+
let abY = coordinates[4] - originY;
|
|
134
|
+
let abZ = coordinates[5] - originZ;
|
|
135
|
+
for (let vertex = 2; vertex < count; vertex++) {
|
|
136
|
+
const acX = coordinates[3 * vertex] - originX;
|
|
137
|
+
const acY = coordinates[3 * vertex + 1] - originY;
|
|
138
|
+
const acZ = coordinates[3 * vertex + 2] - originZ;
|
|
139
|
+
longest = Math.max(longest, Math.abs(abX), Math.abs(abY), Math.abs(abZ), Math.abs(acX), Math.abs(acY), Math.abs(acZ));
|
|
140
|
+
const p0 = abY * acZ;
|
|
141
|
+
const q0 = abZ * acY;
|
|
142
|
+
const p1 = abZ * acX;
|
|
143
|
+
const q1 = abX * acZ;
|
|
144
|
+
const p2 = abX * acY;
|
|
145
|
+
const q2 = abY * acX;
|
|
146
|
+
const crossX = p0 - q0;
|
|
147
|
+
const crossY = p1 - q1;
|
|
148
|
+
const crossZ = p2 - q2;
|
|
149
|
+
sumX += crossX;
|
|
150
|
+
sumY += crossY;
|
|
151
|
+
sumZ += crossZ;
|
|
152
|
+
productsX += Math.abs(p0) + Math.abs(q0);
|
|
153
|
+
productsY += Math.abs(p1) + Math.abs(q1);
|
|
154
|
+
productsZ += Math.abs(p2) + Math.abs(q2);
|
|
155
|
+
termsX += Math.abs(crossX);
|
|
156
|
+
termsY += Math.abs(crossY);
|
|
157
|
+
termsZ += Math.abs(crossZ);
|
|
158
|
+
// An edge component 0 in each product: exactly 0, as is its product.
|
|
159
|
+
isZeroX &&= (abY === 0 || acZ === 0) && (abZ === 0 || acY === 0);
|
|
160
|
+
isZeroY &&= (abZ === 0 || acX === 0) && (abX === 0 || acZ === 0);
|
|
161
|
+
isZeroZ &&= (abX === 0 || acY === 0) && (abY === 0 || acX === 0);
|
|
162
|
+
abX = acX;
|
|
163
|
+
abY = acY;
|
|
164
|
+
abZ = acZ;
|
|
165
|
+
}
|
|
166
|
+
if (!(longest <= PLAIN_EDGE_MAX_)) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
const largest = Math.max(Math.abs(sumX), Math.abs(sumY), Math.abs(sumZ));
|
|
170
|
+
if (!(largest >= PLAIN_MIN_ && largest < PLAIN_MAX_)) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
const triangles = count - 2;
|
|
174
|
+
const termsFactor = (triangles + 1) * 1.0001 * UNIT_ROUNDOFF_;
|
|
175
|
+
const underflow = 2 * triangles * PLAIN_UNDERFLOW_;
|
|
176
|
+
const widening = 1 + 2 * (triangles + 2) * UNIT_ROUNDOFF_;
|
|
177
|
+
const boundX = (PLAIN_BOUND_ * productsX + termsFactor * termsX + underflow) * widening;
|
|
178
|
+
const boundY = (PLAIN_BOUND_ * productsY + termsFactor * termsY + underflow) * widening;
|
|
179
|
+
const boundZ = (PLAIN_BOUND_ * productsZ + termsFactor * termsZ + underflow) * widening;
|
|
180
|
+
const limit = largest * PLAIN_ACCURACY_;
|
|
181
|
+
if ((isZeroX
|
|
182
|
+
? sumX === 0
|
|
183
|
+
: Math.abs(sumX) * (1 - 2 * UNIT_ROUNDOFF_) > boundX &&
|
|
184
|
+
boundX <= limit) &&
|
|
185
|
+
(isZeroY
|
|
186
|
+
? sumY === 0
|
|
187
|
+
: Math.abs(sumY) * (1 - 2 * UNIT_ROUNDOFF_) > boundY &&
|
|
188
|
+
boundY <= limit) &&
|
|
189
|
+
(isZeroZ
|
|
190
|
+
? sumZ === 0
|
|
191
|
+
: Math.abs(sumZ) * (1 - 2 * UNIT_ROUNDOFF_) > boundZ && boundZ <= limit)) {
|
|
192
|
+
// A zero component is +0, whatever the signs of the zeros summed.
|
|
193
|
+
out[0] = sumX + 0;
|
|
194
|
+
out[1] = sumY + 0;
|
|
195
|
+
out[2] = sumZ + 0;
|
|
196
|
+
out[3] = 0;
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
/** {@link axisScaling_}'s answers. */
|
|
202
|
+
const SCALING_PLAIN_ = 0;
|
|
203
|
+
const SCALING_SCALED_ = 1;
|
|
204
|
+
const SCALING_WIDE_ = 2;
|
|
205
|
+
/**
|
|
206
|
+
* Sets `AXIS_EXPONENTS_` for the doubled path, as `triangle3Cross_` does over
|
|
207
|
+
* one triangle's edges, over every edge `vᵢ − v₀`: 0 on every axis when each
|
|
208
|
+
* axis's longest edge component is 0 or in `[2^−200, 2^200]`
|
|
209
|
+
* (`SCALING_PLAIN_`), otherwise the exponent that brings it to `[1, 2)`
|
|
210
|
+
* (`SCALING_SCALED_`); `SCALING_WIDE_` when a difference overflows, which
|
|
211
|
+
* leaves the polygon to the exact path.
|
|
212
|
+
*/
|
|
213
|
+
function axisScaling_(coordinates, count) {
|
|
214
|
+
let isPlain = true;
|
|
215
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
216
|
+
const origin = coordinates[axis];
|
|
217
|
+
let longest = 0;
|
|
218
|
+
for (let vertex = 1; vertex < count; vertex++) {
|
|
219
|
+
longest = Math.max(longest, Math.abs(coordinates[3 * vertex + axis] - origin));
|
|
220
|
+
}
|
|
221
|
+
if (longest === Number.POSITIVE_INFINITY) {
|
|
222
|
+
return SCALING_WIDE_;
|
|
223
|
+
}
|
|
224
|
+
isPlain &&=
|
|
225
|
+
longest === 0 ||
|
|
226
|
+
(longest >= PLAIN_EDGE_MIN_ && longest <= PLAIN_EDGE_MAX_);
|
|
227
|
+
AXIS_EXPONENTS_[axis] = longest > 0 ? binaryExponent(longest) : 0;
|
|
228
|
+
}
|
|
229
|
+
if (isPlain) {
|
|
230
|
+
AXIS_EXPONENTS_.fill(0);
|
|
231
|
+
return SCALING_PLAIN_;
|
|
232
|
+
}
|
|
233
|
+
return SCALING_SCALED_;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* The doubled-precision path of {@link polygon3Cross_}: writes each component
|
|
237
|
+
* into `COMPONENTS_` and its exponent into `EXPONENTS_` and returns whether its
|
|
238
|
+
* bound settles them.
|
|
239
|
+
*
|
|
240
|
+
* In a fan triangle, with the edges split exactly (`a + a′`, `c + c′`, scaled
|
|
241
|
+
* per axis), a component is `(a₁ + a₁′)(c₂ + c₂′) − (a₂ + a₂′)(c₁ + c₁′)`: the
|
|
242
|
+
* products of high parts by TwoProduct (exact, but for products below 2^−969,
|
|
243
|
+
* which `UNDERFLOW_BOUND_` covers), the four products of a high part and a low
|
|
244
|
+
* one rounded (each within 1.01u of itself), the two of low parts dropped
|
|
245
|
+
* (bounded by themselves, widened by 1%). The eight parts of every triangle are
|
|
246
|
+
* summed by `Sum2` (Ogita, Rump & Oishi, "Accurate sum and dot product", SIAM
|
|
247
|
+
* J. Sci. Comput. 26, 2005, Proposition 4.5): within u of the exact sum plus
|
|
248
|
+
* γ²_{N−1} of the sum of the parts' magnitudes, for N parts; the final rounding
|
|
249
|
+
* is the u, kept out of the bound as in `triangle3Cross_`. The bound, a sum of
|
|
250
|
+
* positive terms, is widened by 2(N + 4)u for its own roundings.
|
|
251
|
+
*/
|
|
252
|
+
function doubledNewell_(coordinates, count, scaling) {
|
|
253
|
+
const edges = EDGES_;
|
|
254
|
+
const products = PRODUCTS_;
|
|
255
|
+
const parts = PARTS_;
|
|
256
|
+
const sums = SUMS_;
|
|
257
|
+
SUMS_.fill(0);
|
|
258
|
+
MAGNITUDES_.fill(0);
|
|
259
|
+
LOSSES_.fill(0);
|
|
260
|
+
IS_ZERO_.fill(1);
|
|
261
|
+
for (let vertex = 1; vertex + 1 < count; vertex++) {
|
|
262
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
263
|
+
const at = 4 * axis;
|
|
264
|
+
const origin = -coordinates[axis];
|
|
265
|
+
edges[at] = coordinates[3 * vertex + axis];
|
|
266
|
+
edges[at + 1] = origin;
|
|
267
|
+
twoSumInPlace(edges, at);
|
|
268
|
+
edges[at + 2] = coordinates[3 * vertex + 3 + axis];
|
|
269
|
+
edges[at + 3] = origin;
|
|
270
|
+
twoSumInPlace(edges, at + 2);
|
|
271
|
+
// Zero before scaling, where a component far below the longest flushes.
|
|
272
|
+
ZEROS_[2 * axis] = edges[at] === 0 ? 1 : 0;
|
|
273
|
+
ZEROS_[2 * axis + 1] = edges[at + 2] === 0 ? 1 : 0;
|
|
274
|
+
if (scaling === SCALING_SCALED_) {
|
|
275
|
+
for (let part = at; part < at + 4; part++) {
|
|
276
|
+
scaleByPowerOfTwoInPlace(edges, part, -AXIS_EXPONENTS_[axis]);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
for (let component = 0; component < 3; component++) {
|
|
281
|
+
const firstAxis = (component + 1) % 3;
|
|
282
|
+
const secondAxis = (component + 2) % 3;
|
|
283
|
+
if ((ZEROS_[2 * firstAxis] === 1 || ZEROS_[2 * secondAxis + 1] === 1) &&
|
|
284
|
+
(ZEROS_[2 * secondAxis] === 1 || ZEROS_[2 * firstAxis + 1] === 1)) {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
IS_ZERO_[component] = 0;
|
|
288
|
+
const first = 4 * firstAxis;
|
|
289
|
+
const second = 4 * secondAxis;
|
|
290
|
+
const abFirst = edges[first];
|
|
291
|
+
const abFirstLow = edges[first + 1];
|
|
292
|
+
const acFirst = edges[first + 2];
|
|
293
|
+
const acFirstLow = edges[first + 3];
|
|
294
|
+
const abSecond = edges[second];
|
|
295
|
+
const abSecondLow = edges[second + 1];
|
|
296
|
+
const acSecond = edges[second + 2];
|
|
297
|
+
const acSecondLow = edges[second + 3];
|
|
298
|
+
products[0] = abFirst;
|
|
299
|
+
products[1] = acSecond;
|
|
300
|
+
twoProductInRangeInPlace(products, 0);
|
|
301
|
+
products[2] = abSecond;
|
|
302
|
+
products[3] = acFirst;
|
|
303
|
+
twoProductInRangeInPlace(products, 2);
|
|
304
|
+
parts[0] = products[0];
|
|
305
|
+
parts[1] = -products[2];
|
|
306
|
+
parts[2] = products[1];
|
|
307
|
+
parts[3] = -products[3];
|
|
308
|
+
parts[4] = abFirst * acSecondLow;
|
|
309
|
+
parts[5] = abFirstLow * acSecond;
|
|
310
|
+
parts[6] = -(abSecond * acFirstLow);
|
|
311
|
+
parts[7] = -(abSecondLow * acFirst);
|
|
312
|
+
LOSSES_[component] =
|
|
313
|
+
LOSSES_[component] +
|
|
314
|
+
ROUNDED_PRODUCT_BOUND_ *
|
|
315
|
+
(Math.abs(parts[4]) +
|
|
316
|
+
Math.abs(parts[5]) +
|
|
317
|
+
Math.abs(parts[6]) +
|
|
318
|
+
Math.abs(parts[7])) +
|
|
319
|
+
1.01 *
|
|
320
|
+
(Math.abs(abFirstLow * acSecondLow) +
|
|
321
|
+
Math.abs(abSecondLow * acFirstLow)) +
|
|
322
|
+
UNDERFLOW_BOUND_;
|
|
323
|
+
// Sum2: each part added by TwoSum, the errors summed plainly.
|
|
324
|
+
const at = 2 * component;
|
|
325
|
+
for (let index = 0; index < 8; index++) {
|
|
326
|
+
const part = parts[index];
|
|
327
|
+
const sum = sums[at];
|
|
328
|
+
const next = sum + part;
|
|
329
|
+
const partRounded = next - sum;
|
|
330
|
+
sums[at] = next;
|
|
331
|
+
sums[at + 1] =
|
|
332
|
+
sums[at + 1] + (sum - (next - partRounded) + (part - partRounded));
|
|
333
|
+
MAGNITUDES_[component] = MAGNITUDES_[component] + Math.abs(part);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
const partCount = 8 * (count - 2);
|
|
338
|
+
return settleDoubled_(partCount);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* The end of {@link doubledNewell_}, kept apart so that `binaryExponent` is
|
|
342
|
+
* inlined here whatever budget the accumulation spent (a double passed to a
|
|
343
|
+
* call the engine does not inline is boxed): each component and its bound from
|
|
344
|
+
* the sums, and whether they settle it.
|
|
345
|
+
*/
|
|
346
|
+
function settleDoubled_(partCount) {
|
|
347
|
+
const sums = SUMS_;
|
|
348
|
+
const gamma = (partCount * UNIT_ROUNDOFF_) / (1 - partCount * UNIT_ROUNDOFF_);
|
|
349
|
+
const widening = 1 + 2 * (partCount + 4) * UNIT_ROUNDOFF_;
|
|
350
|
+
let top = NONE_;
|
|
351
|
+
for (let component = 0; component < 3; component++) {
|
|
352
|
+
const firstAxis = (component + 1) % 3;
|
|
353
|
+
const secondAxis = (component + 2) % 3;
|
|
354
|
+
EXPONENTS_[component] =
|
|
355
|
+
AXIS_EXPONENTS_[firstAxis] + AXIS_EXPONENTS_[secondAxis];
|
|
356
|
+
if (IS_ZERO_[component] === 1) {
|
|
357
|
+
COMPONENTS_[component] = 0;
|
|
358
|
+
BOUNDS_[component] = 0;
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
const value = sums[2 * component] + sums[2 * component + 1];
|
|
362
|
+
const bound = (LOSSES_[component] + gamma * gamma * MAGNITUDES_[component]) *
|
|
363
|
+
widening;
|
|
364
|
+
// The sign is settled when the bound, and the last rounding, cannot
|
|
365
|
+
// reach 0.
|
|
366
|
+
if (!(Math.abs(value) * (1 - 4 * UNIT_ROUNDOFF_) > bound)) {
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
COMPONENTS_[component] = value;
|
|
370
|
+
BOUNDS_[component] = bound;
|
|
371
|
+
top = Math.max(top, binaryExponent(value) + EXPONENTS_[component]);
|
|
372
|
+
}
|
|
373
|
+
// Every bound below 2^−54 of the largest component, and the rounding of the
|
|
374
|
+
// sum below 2^−53 of the component itself.
|
|
375
|
+
for (let component = 0; component < 3; component++) {
|
|
376
|
+
if (COMPONENTS_[component] !== 0 &&
|
|
377
|
+
binaryExponent(BOUNDS_[component]) + EXPONENTS_[component] > top - 54) {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return true;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* The exact path of {@link polygon3Cross_}: each component as the exact sum of
|
|
385
|
+
* `Σ vᵢ × vᵢ₊₁` around the ring (`x = Σ yᵢ zᵢ₊₁ − zᵢ yᵢ₊₁`, cyclically), which
|
|
386
|
+
* the fan's sum is, rounded once to 53 bits at any exponent.
|
|
387
|
+
*/
|
|
388
|
+
function exactNewell_(coordinates, count) {
|
|
389
|
+
const left = LEFT_;
|
|
390
|
+
const right = RIGHT_;
|
|
391
|
+
for (let component = 0; component < 3; component++) {
|
|
392
|
+
const first = (component + 1) % 3;
|
|
393
|
+
const second = (component + 2) % 3;
|
|
394
|
+
EXACT_.reset();
|
|
395
|
+
let filled = 0;
|
|
396
|
+
for (let vertex = 0; vertex < count; vertex++) {
|
|
397
|
+
const next = vertex + 1 === count ? 0 : vertex + 1;
|
|
398
|
+
left[filled] = coordinates[3 * vertex + first];
|
|
399
|
+
right[filled] = coordinates[3 * next + second];
|
|
400
|
+
left[filled + 1] = -coordinates[3 * vertex + second];
|
|
401
|
+
right[filled + 1] = coordinates[3 * next + first];
|
|
402
|
+
filled += 2;
|
|
403
|
+
if (filled === CHUNK_) {
|
|
404
|
+
EXACT_.addProducts(left, right);
|
|
405
|
+
filled = 0;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (filled > 0) {
|
|
409
|
+
left.fill(0, filled);
|
|
410
|
+
right.fill(0, filled);
|
|
411
|
+
EXACT_.addProducts(left, right);
|
|
412
|
+
}
|
|
413
|
+
EXACT_.writeScaled(SCALED_, 0);
|
|
414
|
+
COMPONENTS_[component] = SCALED_[0];
|
|
415
|
+
EXPONENTS_[component] = SCALED_[1];
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
//# sourceMappingURL=_polygon3-cross.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_polygon3-cross.js","sourceRoot":"","sources":["../src/_polygon3-cross.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EACN,mBAAmB,EACnB,wBAAwB,EACxB,aAAa,GACb,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACN,KAAK,EACL,eAAe,EACf,YAAY,EACZ,eAAe,EACf,eAAe,EACf,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,GACtB,MAAM,uBAAuB,CAAC;AAE/B,8EAA8E;AAC9E,6EAA6E;AAC7E,gFAAgF;AAChF,+EAA+E;AAC/E,0EAA0E;AAC1E,SAAS;AAET;;;;GAIG;AACH,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,CAAC;AAE/B;;;GAGG;AACH,MAAM,sBAAsB,GAAG,IAAI,GAAG,cAAc,CAAC;AAErD,6DAA6D;AAC7D,MAAM,MAAM,GAAG,EAAE,CA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+
* Ramer–Douglas–Peucker over a chain packed as `dimension` numbers per vertex:
|
|
3
|
+
* the indices of the vertices kept, ascending, the ends always among them.
|
|
4
|
+
* Distances are to the segment (not its line), so a spike doubling back past an
|
|
5
|
+
* end is kept. Iterative, O(n log n) typical and O(n²) worst case time, O(n)
|
|
6
|
+
* memory.
|
|
7
|
+
*/
|
|
8
|
+
export declare function polylineSimplifyIndices_(name: string, coordinates: Float64Array, dimension: number, tolerance: number): Uint32Array;
|
|
9
|
+
/** The coordinates of the vertices at `indices`. */
|
|
10
|
+
export declare function polylineGather_(coordinates: Float64Array, dimension: number, indices: Uint32Array): Float64Array;
|
|
11
|
+
//# sourceMappingURL=_polyline-simplify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_polyline-simplify.d.ts","sourceRoot":"","sources":["../src/_polyline-simplify.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACvC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,YAAY,EACzB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GACf,WAAW,CA4Eb;AAED,oDAAoD;AACpD,wBAAgB,eAAe,CAC9B,WAAW,EAAE,YAAY,EACzB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,WAAW,GAClB,YAAY,CASd"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { describeValue } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* Ramer–Douglas–Peucker over a chain packed as `dimension` numbers per vertex:
|
|
4
|
+
* the indices of the vertices kept, ascending, the ends always among them.
|
|
5
|
+
* Distances are to the segment (not its line), so a spike doubling back past an
|
|
6
|
+
* end is kept. Iterative, O(n log n) typical and O(n²) worst case time, O(n)
|
|
7
|
+
* memory.
|
|
8
|
+
*/
|
|
9
|
+
export function polylineSimplifyIndices_(name, coordinates, dimension, tolerance) {
|
|
10
|
+
if (coordinates.length % dimension !== 0) {
|
|
11
|
+
throw new RangeError(`${name}: coordinates has ${coordinates.length} numbers, not a multiple of ${dimension}.`);
|
|
12
|
+
}
|
|
13
|
+
if (!(tolerance >= 0)) {
|
|
14
|
+
throw new RangeError(`${name}: tolerance must be a non-negative number, got ${describeValue(tolerance)}.`);
|
|
15
|
+
}
|
|
16
|
+
const count = coordinates.length / dimension;
|
|
17
|
+
if (count <= 2) {
|
|
18
|
+
return Uint32Array.from({ length: count }, (_, index) => index);
|
|
19
|
+
}
|
|
20
|
+
const keep = new Uint8Array(count);
|
|
21
|
+
keep[0] = 1;
|
|
22
|
+
keep[count - 1] = 1;
|
|
23
|
+
const stack = new Int32Array(2 * count);
|
|
24
|
+
let top = 0;
|
|
25
|
+
stack[top++] = 0;
|
|
26
|
+
stack[top++] = count - 1;
|
|
27
|
+
const limit = tolerance * tolerance;
|
|
28
|
+
let kept = 2;
|
|
29
|
+
while (top > 0) {
|
|
30
|
+
const last = stack[--top];
|
|
31
|
+
const first = stack[--top];
|
|
32
|
+
const start = first * dimension;
|
|
33
|
+
const end = last * dimension;
|
|
34
|
+
let along = 0;
|
|
35
|
+
for (let axis = 0; axis < dimension; axis++) {
|
|
36
|
+
const step = coordinates[end + axis] - coordinates[start + axis];
|
|
37
|
+
along += step * step;
|
|
38
|
+
}
|
|
39
|
+
let farthest = -1;
|
|
40
|
+
let largest = limit;
|
|
41
|
+
for (let index = first + 1; index < last; index++) {
|
|
42
|
+
const offset = index * dimension;
|
|
43
|
+
let projection = 0;
|
|
44
|
+
for (let axis = 0; axis < dimension; axis++) {
|
|
45
|
+
projection +=
|
|
46
|
+
(coordinates[offset + axis] - coordinates[start + axis]) *
|
|
47
|
+
(coordinates[end + axis] - coordinates[start + axis]);
|
|
48
|
+
}
|
|
49
|
+
const t = along > 0 ? Math.min(1, Math.max(0, projection / along)) : 0;
|
|
50
|
+
let squared = 0;
|
|
51
|
+
for (let axis = 0; axis < dimension; axis++) {
|
|
52
|
+
const from = coordinates[start + axis];
|
|
53
|
+
const deviation = coordinates[offset + axis] -
|
|
54
|
+
(from + t * (coordinates[end + axis] - from));
|
|
55
|
+
squared += deviation * deviation;
|
|
56
|
+
}
|
|
57
|
+
// A vertex at a NaN distance is kept rather than silently dropped.
|
|
58
|
+
if (squared > largest || (squared !== squared && largest === largest)) {
|
|
59
|
+
largest = squared;
|
|
60
|
+
farthest = index;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (farthest >= 0) {
|
|
64
|
+
keep[farthest] = 1;
|
|
65
|
+
kept++;
|
|
66
|
+
stack[top++] = first;
|
|
67
|
+
stack[top++] = farthest;
|
|
68
|
+
stack[top++] = farthest;
|
|
69
|
+
stack[top++] = last;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const indices = new Uint32Array(kept);
|
|
73
|
+
let position = 0;
|
|
74
|
+
for (let index = 0; index < count; index++) {
|
|
75
|
+
if (keep[index] === 1) {
|
|
76
|
+
indices[position++] = index;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return indices;
|
|
80
|
+
}
|
|
81
|
+
/** The coordinates of the vertices at `indices`. */
|
|
82
|
+
export function polylineGather_(coordinates, dimension, indices) {
|
|
83
|
+
const out = new Float64Array(indices.length * dimension);
|
|
84
|
+
for (let position = 0; position < indices.length; position++) {
|
|
85
|
+
const source = indices[position] * dimension;
|
|
86
|
+
for (let axis = 0; axis < dimension; axis++) {
|
|
87
|
+
out[position * dimension + axis] = coordinates[source + axis];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=_polyline-simplify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_polyline-simplify.js","sourceRoot":"","sources":["../src/_polyline-simplify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACvC,IAAY,EACZ,WAAyB,EAC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AAC;QAC7B,CAAC;IACF,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,eAAe,CAC9B,WAAyB,EACzB,SAAiB,EACjB,OAAoB;IAEpB,MAAM,GAAG,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACzD,KAAK,IAAI,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC;QAC9D,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAE,GAAG,SAAS,CAAC;QAC9C,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC;YAC7C,GAAG,CAAC,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,WAAW,CAAC,MAAM,GAAG,IAAI,CAAE,CAAC;QAChE,CAAC;IACF,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** The unit roundoff, 2^−53. */
|
|
2
|
+
export declare const UNIT_ROUNDOFF_: number;
|
|
3
|
+
/**
|
|
4
|
+
* An absolute bound, far above them, on what the doubled-precision path loses,
|
|
5
|
+
* in its scaled units, where a scaled edge component falls below 2^−1022 or a
|
|
6
|
+
* product below 2^−969, so that its error is no longer exact or underflows:
|
|
7
|
+
* every product there is below 4, so a component this small beside them goes to
|
|
8
|
+
* the exact path.
|
|
9
|
+
*/
|
|
10
|
+
export declare const UNDERFLOW_BOUND_: number;
|
|
11
|
+
/** An exponent below every one a component can have: "no component". */
|
|
12
|
+
export declare const NONE_ = -8192;
|
|
13
|
+
/**
|
|
14
|
+
* The edge components the doubled-precision path takes unscaled: products of
|
|
15
|
+
* them lie below 2^402, and their bounds hold in absolute terms.
|
|
16
|
+
*/
|
|
17
|
+
export declare const PLAIN_EDGE_MIN_: number;
|
|
18
|
+
export declare const PLAIN_EDGE_MAX_: number;
|
|
19
|
+
export declare const PLAIN_MIN_: number;
|
|
20
|
+
export declare const PLAIN_MAX_: number;
|
|
21
|
+
/** {@link plainCross_}'s bound per unit of its products, 3.001u. */
|
|
22
|
+
export declare const PLAIN_BOUND_: number;
|
|
23
|
+
/** {@link plainCross_}'s absolute bound on what products lose underflowing. */
|
|
24
|
+
export declare const PLAIN_UNDERFLOW_: number;
|
|
25
|
+
/**
|
|
26
|
+
* {@link plainCross_}'s accuracy: every bound within 2^−50 of the largest
|
|
27
|
+
* component, so that the unit normal stays within 2^−48 of the exact one.
|
|
28
|
+
*/
|
|
29
|
+
export declare const PLAIN_ACCURACY_: number;
|
|
30
|
+
/**
|
|
31
|
+
* Writes the cross product `(b − a) × (c − a)` of the triangle whose corners
|
|
32
|
+
* `a`, `b` and `c` are `corners[0–2]`, `[3–5]` and `[6–8]` into `out` as `[x,
|
|
33
|
+
* y, z, k]`, the product being `(x, y, z) · 2^k`. Every component lies within
|
|
34
|
+
* 2^−49 of the largest component of the exact value, for any finite corners:
|
|
35
|
+
* `[0, 0, 0, 0]` exactly when the exact product is zero (a degenerate
|
|
36
|
+
* triangle), a component +0 where the exact one is 0, and one with the exact
|
|
37
|
+
* one's sign wherever that bound cannot reach 0. A component nonzero but within
|
|
38
|
+
* the bound may round to a zero of either sign (the k = 0 form flushes whatever
|
|
39
|
+
* lies below the smallest double, however large its ratio to the largest
|
|
40
|
+
* component). k is 0 when the largest component lies in `[2^−400, 2^402)`;
|
|
41
|
+
* otherwise the largest lies in `[1, 2)`. A corner that is not finite gives
|
|
42
|
+
* `NaN`s.
|
|
43
|
+
*
|
|
44
|
+
* Three paths, each taken only where the one before cannot settle every
|
|
45
|
+
* component. The plain cross product, with a rigorous bound (a triangle not far
|
|
46
|
+
* from right-angled at `a`, edges up to 2^200). Then doubled precision: the
|
|
47
|
+
* edges split exactly by TwoSum and scaled per axis by the power of two that
|
|
48
|
+
* brings the axis's longest to [1, 2) where an edge leaves [2^−200, 2^200] (the
|
|
49
|
+
* product is bilinear: component x takes the scales of y and z), each product
|
|
50
|
+
* of their high parts by TwoProduct, the rest summed, with a rigorous bound on
|
|
51
|
+
* what is lost. Last, where that bound leaves a sign or the last bits of the
|
|
52
|
+
* largest component in doubt (a triangle almost degenerate, a component almost
|
|
53
|
+
* 0 or below 2^−1000 of the products it is the difference of, or an edge whose
|
|
54
|
+
* difference overflows), each component summed exactly (Kulisch's long
|
|
55
|
+
* accumulator, over the six products of coordinates it expands to) and rounded
|
|
56
|
+
* once, at any exponent. Allocates nothing.
|
|
57
|
+
*/
|
|
58
|
+
export declare function triangle3Cross_(out: Float64Array, corners: Float64Array): void;
|
|
59
|
+
/**
|
|
60
|
+
* Writes the product `components[i] · 2^exponents[i]` into `out` as `[x, y, z,
|
|
61
|
+
* k]`: k = 0, the components unscaled, when the largest lies in `[2^−400,
|
|
62
|
+
* 2^402)`; otherwise the components scaled so that the largest lies in `[1,
|
|
63
|
+
* 2)`, and k the power of two that undoes it. Zeros for a zero product.
|
|
64
|
+
*/
|
|
65
|
+
export declare function writeScaledComponents_(out: Float64Array, components: Float64Array, exponents: Int32Array): void;
|
|
66
|
+
//# sourceMappingURL=_triangle3-cross.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_triangle3-cross.d.ts","sourceRoot":"","sources":["../src/_triangle3-cross.ts"],"names":[],"mappings":"AAOA,gCAAgC;AAChC,eAAO,MAAM,cAAc,QAAW,CAAC;AAWvC;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,QAAa,CAAC;AAE3C,wEAAwE;AACxE,eAAO,MAAM,KAAK,QAAQ,CAAC;AAQ3B;;;GAGG;AACH,eAAO,MAAM,eAAe,QAAY,CAAC;AACzC,eAAO,MAAM,eAAe,QAAW,CAAC;AASxC,eAAO,MAAM,UAAU,QAA2B,CAAC;AACnD,eAAO,MAAM,UAAU,QAAiC,CAAC;AAEzD,oEAAoE;AACpE,eAAO,MAAM,YAAY,QAAyB,CAAC;AACnD,+EAA+E;AAC/E,eAAO,MAAM,gBAAgB,QAAa,CAAC;AAC3C;;;GAGG;AACH,eAAO,MAAM,eAAe,QAAW,CAAC;AAgCxC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,eAAe,CAC9B,GAAG,EAAE,YAAY,EACjB,OAAO,EAAE,YAAY,GACnB,IAAI,CA6EN;AAqOD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACrC,GAAG,EAAE,YAAY,EACjB,UAAU,EAAE,YAAY,EACxB,SAAS,EAAE,UAAU,GACnB,IAAI,CAuBN"}
|