msdfgen-ts 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -4
- package/dist/atlas-worker.js +1380 -1117
- package/dist/msdfgen-ts.iife.js +3 -2
- package/dist/msdfgen-ts.js +2020 -1402
- package/dist/types/atlas-gen.d.ts +51 -25
- package/dist/types/font/tables/glyf.d.ts +3 -1
- package/dist/types/index.d.ts +4 -0
- package/dist/types/msdf/shape-msdf.d.ts +51 -0
- package/dist/types/shape/normalize.d.ts +12 -1
- package/dist/types/shape/union.d.ts +58 -0
- package/dist/types/svg/svg.d.ts +78 -0
- package/package.json +38 -18
package/dist/atlas-worker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class wt {
|
|
2
2
|
/**
|
|
3
3
|
* @param buffer Source buffer (the full font file).
|
|
4
4
|
* @param byteOffset Starting position (default 0).
|
|
@@ -78,228 +78,228 @@ class Mt {
|
|
|
78
78
|
return this._view.getInt16(t, !1);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
function
|
|
82
|
-
const n = new
|
|
81
|
+
function Co(o, t) {
|
|
82
|
+
const n = new wt(o, t);
|
|
83
83
|
n.skip(2);
|
|
84
84
|
const s = n.u16();
|
|
85
|
-
let
|
|
86
|
-
for (let
|
|
87
|
-
const c = n.u16(), r = n.u16(), h = n.u32(),
|
|
85
|
+
let i = null;
|
|
86
|
+
for (let a = 0; a < s; a++) {
|
|
87
|
+
const c = n.u16(), r = n.u16(), h = n.u32(), p = t + h, l = n.peekU16(p);
|
|
88
88
|
let f = -1;
|
|
89
|
-
c === 3 && r === 10 &&
|
|
89
|
+
c === 3 && r === 10 && l === 12 ? f = 5 : c === 0 && r === 6 && l === 12 ? f = 4 : c === 0 && r === 4 && l === 12 ? f = 3 : c === 3 && r === 1 && l === 4 ? f = 2 : c === 0 && r <= 3 && l === 4 && (f = 1), f > ((i == null ? void 0 : i.priority) ?? -1) && (i = { priority: f, subtableAbsOffset: p });
|
|
90
90
|
}
|
|
91
|
-
if (!
|
|
92
|
-
const e = n.peekU16(
|
|
93
|
-
return e === 12 ?
|
|
91
|
+
if (!i) return () => 0;
|
|
92
|
+
const e = n.peekU16(i.subtableAbsOffset);
|
|
93
|
+
return e === 12 ? Fo(o, i.subtableAbsOffset) : e === 4 ? Ro(o, i.subtableAbsOffset) : () => 0;
|
|
94
94
|
}
|
|
95
|
-
function
|
|
96
|
-
const n = new
|
|
95
|
+
function Fo(o, t) {
|
|
96
|
+
const n = new wt(o, t);
|
|
97
97
|
n.skip(2), n.skip(2), n.skip(4), n.skip(4);
|
|
98
|
-
const s = n.u32(),
|
|
98
|
+
const s = n.u32(), i = new Uint32Array(s), e = new Uint32Array(s), a = new Uint32Array(s);
|
|
99
99
|
for (let c = 0; c < s; c++)
|
|
100
|
-
|
|
100
|
+
i[c] = n.u32(), e[c] = n.u32(), a[c] = n.u32();
|
|
101
101
|
return (c) => {
|
|
102
102
|
let r = 0, h = s - 1;
|
|
103
103
|
for (; r <= h; ) {
|
|
104
|
-
const
|
|
105
|
-
if (c <
|
|
106
|
-
else if (c > f) r =
|
|
107
|
-
else return (p
|
|
104
|
+
const p = r + h >>> 1, l = i[p] ?? 0, f = e[p] ?? 0;
|
|
105
|
+
if (c < l) h = p - 1;
|
|
106
|
+
else if (c > f) r = p + 1;
|
|
107
|
+
else return (a[p] ?? 0) + (c - l);
|
|
108
108
|
}
|
|
109
109
|
return 0;
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
|
-
function
|
|
113
|
-
const n = new
|
|
112
|
+
function Ro(o, t) {
|
|
113
|
+
const n = new wt(o, t);
|
|
114
114
|
n.skip(2), n.skip(2), n.skip(2);
|
|
115
|
-
const
|
|
115
|
+
const i = n.u16() >>> 1;
|
|
116
116
|
n.skip(6);
|
|
117
|
-
const e = new Uint16Array(
|
|
118
|
-
for (let
|
|
117
|
+
const e = new Uint16Array(i);
|
|
118
|
+
for (let l = 0; l < i; l++) e[l] = n.u16();
|
|
119
119
|
n.skip(2);
|
|
120
|
-
const
|
|
121
|
-
for (let
|
|
122
|
-
const c = new Int16Array(
|
|
123
|
-
for (let
|
|
124
|
-
const r = new Int32Array(
|
|
125
|
-
for (let
|
|
126
|
-
r[
|
|
127
|
-
const
|
|
128
|
-
return (
|
|
129
|
-
if (
|
|
130
|
-
let f = 0,
|
|
131
|
-
for (; f <=
|
|
132
|
-
const _ = f +
|
|
133
|
-
if (
|
|
120
|
+
const a = new Uint16Array(i);
|
|
121
|
+
for (let l = 0; l < i; l++) a[l] = n.u16();
|
|
122
|
+
const c = new Int16Array(i);
|
|
123
|
+
for (let l = 0; l < i; l++) c[l] = n.i16();
|
|
124
|
+
const r = new Int32Array(i), h = new Uint16Array(i);
|
|
125
|
+
for (let l = 0; l < i; l++)
|
|
126
|
+
r[l] = n.pos, h[l] = n.u16();
|
|
127
|
+
const p = new DataView(o);
|
|
128
|
+
return (l) => {
|
|
129
|
+
if (l > 65535) return 0;
|
|
130
|
+
let f = 0, u = i - 1;
|
|
131
|
+
for (; f <= u; ) {
|
|
132
|
+
const _ = f + u >>> 1, y = e[_] ?? 0;
|
|
133
|
+
if (l > y)
|
|
134
134
|
f = _ + 1;
|
|
135
|
-
else if (
|
|
136
|
-
|
|
135
|
+
else if (l < (a[_] ?? 0))
|
|
136
|
+
u = _ - 1;
|
|
137
137
|
else {
|
|
138
138
|
if ((e[_] ?? 0) === 65535) return 0;
|
|
139
|
-
const
|
|
140
|
-
if (
|
|
141
|
-
return
|
|
142
|
-
const
|
|
143
|
-
return
|
|
139
|
+
const M = h[_] ?? 0, I = c[_] ?? 0, q = a[_] ?? 0;
|
|
140
|
+
if (M === 0)
|
|
141
|
+
return l + I & 65535;
|
|
142
|
+
const T = (r[_] ?? 0) + M + (l - q) * 2, A = p.getUint16(T, !1);
|
|
143
|
+
return A === 0 ? 0 : A + I & 65535;
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
return 0;
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
|
-
function
|
|
150
|
-
const n = new
|
|
149
|
+
function To(o, t) {
|
|
150
|
+
const n = new wt(o, t);
|
|
151
151
|
n.skip(4), n.skip(4), n.skip(4), n.skip(4), n.skip(2);
|
|
152
152
|
const s = n.u16();
|
|
153
153
|
n.skip(16), n.skip(8), n.skip(2), n.skip(2), n.skip(2);
|
|
154
|
-
const
|
|
155
|
-
return { unitsPerEm: s, indexToLocFormat:
|
|
154
|
+
const i = n.i16();
|
|
155
|
+
return { unitsPerEm: s, indexToLocFormat: i };
|
|
156
156
|
}
|
|
157
|
-
function
|
|
158
|
-
const n = new
|
|
157
|
+
function So(o, t) {
|
|
158
|
+
const n = new wt(o, t);
|
|
159
159
|
n.skip(4);
|
|
160
|
-
const s = n.i16(),
|
|
160
|
+
const s = n.i16(), i = n.i16(), e = n.i16();
|
|
161
161
|
n.skip(2), n.skip(2), n.skip(2), n.skip(2), n.skip(2), n.skip(2), n.skip(2), n.skip(8), n.skip(2);
|
|
162
|
-
const
|
|
163
|
-
return { ascender: s, descender:
|
|
162
|
+
const a = n.u16();
|
|
163
|
+
return { ascender: s, descender: i, lineGap: e, numberOfHMetrics: a };
|
|
164
164
|
}
|
|
165
|
-
function
|
|
166
|
-
const
|
|
167
|
-
let
|
|
165
|
+
function Lo(o, t, n, s) {
|
|
166
|
+
const i = new wt(o, t), e = [];
|
|
167
|
+
let a = 0;
|
|
168
168
|
for (let c = 0; c < s; c++) {
|
|
169
|
-
const r =
|
|
170
|
-
e[c] = { advanceWidth: r, lsb: h },
|
|
169
|
+
const r = i.u16(), h = i.i16();
|
|
170
|
+
e[c] = { advanceWidth: r, lsb: h }, a = r;
|
|
171
171
|
}
|
|
172
172
|
for (let c = s; c < n; c++) {
|
|
173
|
-
const r =
|
|
174
|
-
e[c] = { advanceWidth:
|
|
173
|
+
const r = i.i16();
|
|
174
|
+
e[c] = { advanceWidth: a, lsb: r };
|
|
175
175
|
}
|
|
176
176
|
return e;
|
|
177
177
|
}
|
|
178
|
-
function
|
|
179
|
-
const
|
|
178
|
+
function Po(o, t, n, s) {
|
|
179
|
+
const i = new wt(o, t), e = n + 1, a = [];
|
|
180
180
|
if (s === 0)
|
|
181
|
-
for (let c = 0; c < e; c++)
|
|
181
|
+
for (let c = 0; c < e; c++) a[c] = i.u16() * 2;
|
|
182
182
|
else
|
|
183
|
-
for (let c = 0; c < e; c++)
|
|
184
|
-
return
|
|
183
|
+
for (let c = 0; c < e; c++) a[c] = i.u32();
|
|
184
|
+
return a;
|
|
185
185
|
}
|
|
186
|
-
function
|
|
187
|
-
const n = new
|
|
186
|
+
function Oo(o, t) {
|
|
187
|
+
const n = new wt(o, t);
|
|
188
188
|
return n.skip(4), { numGlyphs: n.u16() };
|
|
189
189
|
}
|
|
190
|
-
function
|
|
191
|
-
return
|
|
190
|
+
function No(o, t, n, s) {
|
|
191
|
+
return o * n + t * s;
|
|
192
192
|
}
|
|
193
|
-
function
|
|
194
|
-
return
|
|
193
|
+
function z(o, t, n, s) {
|
|
194
|
+
return o * s - t * n;
|
|
195
195
|
}
|
|
196
|
-
function
|
|
197
|
-
return (1 - n) *
|
|
196
|
+
function Go(o, t, n) {
|
|
197
|
+
return (1 - n) * o + n * t;
|
|
198
198
|
}
|
|
199
|
-
function
|
|
200
|
-
return +(
|
|
199
|
+
function pt(o) {
|
|
200
|
+
return +(o > 0) - +(o < 0);
|
|
201
201
|
}
|
|
202
|
-
function
|
|
203
|
-
return 2 * +(
|
|
202
|
+
function qt(o) {
|
|
203
|
+
return 2 * +(o > 0) - 1;
|
|
204
204
|
}
|
|
205
|
-
function
|
|
205
|
+
function bo(o, t, n, s) {
|
|
206
206
|
if (t === 0 || Math.abs(n) > 1e12 * Math.abs(t))
|
|
207
|
-
return n === 0 ? s === 0 ? -1 : 0 : (
|
|
208
|
-
const
|
|
209
|
-
if (
|
|
210
|
-
const e = Math.sqrt(
|
|
211
|
-
return
|
|
212
|
-
} else if (
|
|
213
|
-
return
|
|
207
|
+
return n === 0 ? s === 0 ? -1 : 0 : (o[0] = -s / n, 1);
|
|
208
|
+
const i = n * n - 4 * t * s;
|
|
209
|
+
if (i > 0) {
|
|
210
|
+
const e = Math.sqrt(i);
|
|
211
|
+
return o[0] = (-n + e) / (2 * t), o[1] = (-n - e) / (2 * t), 2;
|
|
212
|
+
} else if (i === 0)
|
|
213
|
+
return o[0] = -n / (2 * t), 1;
|
|
214
214
|
return 0;
|
|
215
215
|
}
|
|
216
|
-
function
|
|
217
|
-
const
|
|
216
|
+
function Uo(o, t, n, s) {
|
|
217
|
+
const i = t * t, e = 1 / 9 * (i - 3 * n), a = 1 / 54 * (t * (2 * i - 9 * n) + 27 * s), c = a * a, r = e * e * e, h = t * (1 / 3);
|
|
218
218
|
if (c < r) {
|
|
219
|
-
let
|
|
220
|
-
|
|
221
|
-
const
|
|
222
|
-
return
|
|
219
|
+
let p = a / Math.sqrt(r);
|
|
220
|
+
p < -1 && (p = -1), p > 1 && (p = 1), p = Math.acos(p);
|
|
221
|
+
const l = -2 * Math.sqrt(e);
|
|
222
|
+
return o[0] = l * Math.cos(1 / 3 * p) - h, o[1] = l * Math.cos(1 / 3 * (p + 2 * Math.PI)) - h, o[2] = l * Math.cos(1 / 3 * (p - 2 * Math.PI)) - h, 3;
|
|
223
223
|
} else {
|
|
224
|
-
const
|
|
225
|
-
return
|
|
224
|
+
const p = (a < 0 ? 1 : -1) * Math.pow(Math.abs(a) + Math.sqrt(c - r), 0.3333333333333333), l = p === 0 ? 0 : e / p;
|
|
225
|
+
return o[0] = p + l - h, p === l || Math.abs(p - l) < 1e-12 * Math.abs(p + l) ? (o[1] = -0.5 * (p + l) - h, 2) : 1;
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
-
function
|
|
228
|
+
function Yo(o, t, n, s, i) {
|
|
229
229
|
if (t !== 0) {
|
|
230
230
|
const e = n / t;
|
|
231
231
|
if (Math.abs(e) < 1e6)
|
|
232
|
-
return
|
|
232
|
+
return Uo(o, e, s / t, i / t);
|
|
233
233
|
}
|
|
234
|
-
return
|
|
234
|
+
return bo(o, n, s, i);
|
|
235
235
|
}
|
|
236
|
-
const
|
|
237
|
-
function
|
|
238
|
-
return ((s +
|
|
236
|
+
const Xo = 24;
|
|
237
|
+
function Bt(o, t, n, s) {
|
|
238
|
+
return ((s + o) * s + t) * s + n;
|
|
239
239
|
}
|
|
240
|
-
function
|
|
240
|
+
function Wo(o, t, n, s, i, e, a) {
|
|
241
241
|
const c = e < 0;
|
|
242
|
-
let r = s - e * (
|
|
243
|
-
r > s && r <
|
|
244
|
-
for (let h = 0; h <
|
|
245
|
-
const
|
|
246
|
-
if (
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
let f = r -
|
|
250
|
-
f > s && f <
|
|
251
|
-
const
|
|
252
|
-
if (r = f, (
|
|
242
|
+
let r = s - e * (i - s) / (a - e);
|
|
243
|
+
r > s && r < i || (r = 0.5 * (s + i));
|
|
244
|
+
for (let h = 0; h < Xo; h++) {
|
|
245
|
+
const p = Bt(o, t, n, r);
|
|
246
|
+
if (p === 0) return r;
|
|
247
|
+
p < 0 === c ? s = r : i = r;
|
|
248
|
+
const l = (3 * r + 2 * o) * r + t;
|
|
249
|
+
let f = r - p / l;
|
|
250
|
+
f > s && f < i || (f = 0.5 * (s + i));
|
|
251
|
+
const u = f - r;
|
|
252
|
+
if (r = f, (u < 0 ? -u : u) <= 1e-15 * (r < 0 ? -r : r)) break;
|
|
253
253
|
}
|
|
254
254
|
return r;
|
|
255
255
|
}
|
|
256
|
-
function
|
|
257
|
-
return e === 0 ? c[r++] = s : e < 0 !=
|
|
256
|
+
function rn(o, t, n, s, i, e, a, c, r) {
|
|
257
|
+
return e === 0 ? c[r++] = s : e < 0 != a < 0 && (c[r++] = Wo(o, t, n, s, i, e, a)), r;
|
|
258
258
|
}
|
|
259
|
-
function
|
|
260
|
-
let
|
|
261
|
-
if (
|
|
259
|
+
function Ho(o, t, n, s, i, e) {
|
|
260
|
+
let a = 0;
|
|
261
|
+
if (o === 0) {
|
|
262
262
|
if (t === 0) return 0;
|
|
263
263
|
const f = -n / t;
|
|
264
|
-
return f >= s && f <=
|
|
264
|
+
return f >= s && f <= i && (e[a++] = f), a;
|
|
265
265
|
}
|
|
266
|
-
const c = t * t - 4 *
|
|
266
|
+
const c = t * t - 4 * o * n;
|
|
267
267
|
if (c < 0) return 0;
|
|
268
268
|
const r = Math.sqrt(c), h = -0.5 * (t + (t < 0 ? -r : r));
|
|
269
|
-
let
|
|
269
|
+
let p, l;
|
|
270
270
|
if (h === 0)
|
|
271
|
-
|
|
272
|
-
else if (
|
|
273
|
-
const f =
|
|
274
|
-
|
|
271
|
+
p = 0, l = 0;
|
|
272
|
+
else if (p = h / o, l = n / h, p > l) {
|
|
273
|
+
const f = p;
|
|
274
|
+
p = l, l = f;
|
|
275
275
|
}
|
|
276
|
-
return
|
|
276
|
+
return p >= s && p <= i && (e[a++] = p), l !== p && l >= s && l <= i && (e[a++] = l), a;
|
|
277
277
|
}
|
|
278
|
-
function
|
|
279
|
-
if (
|
|
280
|
-
const c = 1 /
|
|
278
|
+
function Vo(o, t, n, s, i, e, a) {
|
|
279
|
+
if (o === 0) return Ho(t, n, s, i, e, a);
|
|
280
|
+
const c = 1 / o;
|
|
281
281
|
t *= c, n *= c, s *= c;
|
|
282
|
-
const r =
|
|
283
|
-
let
|
|
284
|
-
if (
|
|
285
|
-
|
|
282
|
+
const r = Bt(t, n, s, i), h = Bt(t, n, s, e), p = t * t - 3 * n;
|
|
283
|
+
let l = 0;
|
|
284
|
+
if (p <= 0)
|
|
285
|
+
l = rn(t, n, s, i, e, r, h, a, 0);
|
|
286
286
|
else {
|
|
287
|
-
const f = Math.sqrt(
|
|
288
|
-
let
|
|
289
|
-
if (_ >
|
|
290
|
-
const
|
|
291
|
-
|
|
287
|
+
const f = Math.sqrt(p) / 3, u = -t / 3, _ = u - f, y = u + f;
|
|
288
|
+
let g = i, M = r;
|
|
289
|
+
if (_ > i && _ < e) {
|
|
290
|
+
const I = Bt(t, n, s, _);
|
|
291
|
+
l = rn(t, n, s, g, _, M, I, a, l), g = _, M = I;
|
|
292
292
|
}
|
|
293
|
-
if (
|
|
294
|
-
const
|
|
295
|
-
|
|
293
|
+
if (y > i && y < e) {
|
|
294
|
+
const I = Bt(t, n, s, y);
|
|
295
|
+
l = rn(t, n, s, g, y, M, I, a, l), g = y, M = I;
|
|
296
296
|
}
|
|
297
|
-
|
|
297
|
+
l = rn(t, n, s, g, e, M, h, a, l);
|
|
298
298
|
}
|
|
299
|
-
return h === 0 && (
|
|
299
|
+
return h === 0 && (a[l++] = e), l;
|
|
300
300
|
}
|
|
301
|
-
const
|
|
302
|
-
class
|
|
301
|
+
const lt = 0, ct = 1, Gt = 2, $s = 4, Bo = 4, X = [0, 0, 0];
|
|
302
|
+
class et {
|
|
303
303
|
/**
|
|
304
304
|
* @param type Segment type (LINEAR=0, QUADRATIC=1, CUBIC=2).
|
|
305
305
|
* @param p0x Start x.
|
|
@@ -311,15 +311,15 @@ class it {
|
|
|
311
311
|
* @param p3x CUBIC: end x. Others: 0.
|
|
312
312
|
* @param p3y CUBIC: end y. Others: 0.
|
|
313
313
|
*/
|
|
314
|
-
constructor(t, n, s,
|
|
315
|
-
this.type = t, this.p0x = n, this.p0y = s, this.p1x =
|
|
314
|
+
constructor(t, n, s, i, e, a, c, r, h) {
|
|
315
|
+
this.type = t, this.p0x = n, this.p0y = s, this.p1x = i, this.p1y = e, this.p2x = a, this.p2y = c, this.p3x = r, this.p3y = h, this.color = 7;
|
|
316
316
|
}
|
|
317
317
|
/** Endpoint x (the on-curve destination of this segment). */
|
|
318
318
|
endX() {
|
|
319
319
|
switch (this.type) {
|
|
320
|
-
case
|
|
320
|
+
case lt:
|
|
321
321
|
return this.p1x;
|
|
322
|
-
case
|
|
322
|
+
case ct:
|
|
323
323
|
return this.p2x;
|
|
324
324
|
default:
|
|
325
325
|
return this.p3x;
|
|
@@ -328,9 +328,9 @@ class it {
|
|
|
328
328
|
/** Endpoint y. */
|
|
329
329
|
endY() {
|
|
330
330
|
switch (this.type) {
|
|
331
|
-
case
|
|
331
|
+
case lt:
|
|
332
332
|
return this.p1y;
|
|
333
|
-
case
|
|
333
|
+
case ct:
|
|
334
334
|
return this.p2y;
|
|
335
335
|
default:
|
|
336
336
|
return this.p3y;
|
|
@@ -346,18 +346,18 @@ class it {
|
|
|
346
346
|
point(t, n) {
|
|
347
347
|
const s = t;
|
|
348
348
|
switch (this.type) {
|
|
349
|
-
case
|
|
349
|
+
case lt: {
|
|
350
350
|
n[0] = this.p0x + s * (this.p1x - this.p0x), n[1] = this.p0y + s * (this.p1y - this.p0y);
|
|
351
351
|
return;
|
|
352
352
|
}
|
|
353
|
-
case
|
|
354
|
-
const
|
|
355
|
-
n[0] =
|
|
353
|
+
case ct: {
|
|
354
|
+
const i = this.p0x + s * (this.p1x - this.p0x), e = this.p0y + s * (this.p1y - this.p0y), a = this.p1x + s * (this.p2x - this.p1x), c = this.p1y + s * (this.p2y - this.p1y);
|
|
355
|
+
n[0] = i + s * (a - i), n[1] = e + s * (c - e);
|
|
356
356
|
return;
|
|
357
357
|
}
|
|
358
358
|
default: {
|
|
359
|
-
const
|
|
360
|
-
n[0] =
|
|
359
|
+
const i = this.p0x + s * (this.p1x - this.p0x), e = this.p0y + s * (this.p1y - this.p0y), a = this.p1x + s * (this.p2x - this.p1x), c = this.p1y + s * (this.p2y - this.p1y), r = this.p2x + s * (this.p3x - this.p2x), h = this.p2y + s * (this.p3y - this.p2y), p = i + s * (a - i), l = e + s * (c - e), f = a + s * (r - a), u = c + s * (h - c);
|
|
360
|
+
n[0] = p + s * (f - p), n[1] = l + s * (u - l);
|
|
361
361
|
return;
|
|
362
362
|
}
|
|
363
363
|
}
|
|
@@ -372,18 +372,18 @@ class it {
|
|
|
372
372
|
direction(t, n) {
|
|
373
373
|
const s = t;
|
|
374
374
|
switch (this.type) {
|
|
375
|
-
case
|
|
375
|
+
case lt: {
|
|
376
376
|
n[0] = this.p1x - this.p0x, n[1] = this.p1y - this.p0y;
|
|
377
377
|
return;
|
|
378
378
|
}
|
|
379
|
-
case
|
|
380
|
-
const
|
|
381
|
-
|
|
379
|
+
case ct: {
|
|
380
|
+
const i = this.p1x - this.p0x + s * (this.p2x - this.p1x - (this.p1x - this.p0x)), e = this.p1y - this.p0y + s * (this.p2y - this.p1y - (this.p1y - this.p0y));
|
|
381
|
+
i !== 0 || e !== 0 ? (n[0] = i, n[1] = e) : (n[0] = this.p2x - this.p0x, n[1] = this.p2y - this.p0y);
|
|
382
382
|
return;
|
|
383
383
|
}
|
|
384
384
|
default: {
|
|
385
|
-
const
|
|
386
|
-
|
|
385
|
+
const i = this.p1x - this.p0x, e = this.p1y - this.p0y, a = this.p2x - this.p1x, c = this.p2y - this.p1y, r = this.p3x - this.p2x, h = this.p3y - this.p2y, p = i + s * (a - i) + s * (a + s * (r - a) - (i + s * (a - i))), l = e + s * (c - e) + s * (c + s * (h - c) - (e + s * (c - e)));
|
|
386
|
+
p !== 0 || l !== 0 ? (n[0] = p, n[1] = l) : s === 0 ? (n[0] = this.p2x - this.p0x, n[1] = this.p2y - this.p0y) : s === 1 ? (n[0] = this.p3x - this.p1x, n[1] = this.p3y - this.p1y) : (n[0] = p, n[1] = l);
|
|
387
387
|
return;
|
|
388
388
|
}
|
|
389
389
|
}
|
|
@@ -398,80 +398,80 @@ class it {
|
|
|
398
398
|
splitInThirds() {
|
|
399
399
|
const t = [0, 0], n = [0, 0];
|
|
400
400
|
switch (this.type) {
|
|
401
|
-
case
|
|
401
|
+
case lt: {
|
|
402
402
|
this.point(1 / 3, t), this.point(2 / 3, n);
|
|
403
|
-
const s = new
|
|
404
|
-
return s.color =
|
|
403
|
+
const s = new et(lt, this.p0x, this.p0y, t[0], t[1], 0, 0, 0, 0), i = new et(lt, t[0], t[1], n[0], n[1], 0, 0, 0, 0), e = new et(lt, n[0], n[1], this.p1x, this.p1y, 0, 0, 0, 0);
|
|
404
|
+
return s.color = i.color = e.color = this.color, [s, i, e];
|
|
405
405
|
}
|
|
406
|
-
case
|
|
406
|
+
case ct: {
|
|
407
407
|
this.point(1 / 3, t), this.point(2 / 3, n);
|
|
408
|
-
const s = this.p0x + 1 / 3 * (this.p1x - this.p0x),
|
|
409
|
-
|
|
408
|
+
const s = this.p0x + 1 / 3 * (this.p1x - this.p0x), i = this.p0y + 1 / 3 * (this.p1y - this.p0y), e = this.p0x + 5 / 9 * (this.p1x - this.p0x), a = this.p0y + 5 / 9 * (this.p1y - this.p0y), c = this.p1x + 4 / 9 * (this.p2x - this.p1x), r = this.p1y + 4 / 9 * (this.p2y - this.p1y), h = e + 0.5 * (c - e), p = a + 0.5 * (r - a), l = this.p1x + 2 / 3 * (this.p2x - this.p1x), f = this.p1y + 2 / 3 * (this.p2y - this.p1y), u = new et(
|
|
409
|
+
ct,
|
|
410
410
|
this.p0x,
|
|
411
411
|
this.p0y,
|
|
412
412
|
s,
|
|
413
|
-
|
|
413
|
+
i,
|
|
414
414
|
t[0],
|
|
415
415
|
t[1],
|
|
416
416
|
0,
|
|
417
417
|
0
|
|
418
|
-
), _ = new
|
|
419
|
-
|
|
418
|
+
), _ = new et(
|
|
419
|
+
ct,
|
|
420
420
|
t[0],
|
|
421
421
|
t[1],
|
|
422
422
|
h,
|
|
423
|
-
|
|
423
|
+
p,
|
|
424
424
|
n[0],
|
|
425
425
|
n[1],
|
|
426
426
|
0,
|
|
427
427
|
0
|
|
428
|
-
),
|
|
429
|
-
|
|
428
|
+
), y = new et(
|
|
429
|
+
ct,
|
|
430
430
|
n[0],
|
|
431
431
|
n[1],
|
|
432
|
-
|
|
432
|
+
l,
|
|
433
433
|
f,
|
|
434
434
|
this.p2x,
|
|
435
435
|
this.p2y,
|
|
436
436
|
0,
|
|
437
437
|
0
|
|
438
438
|
);
|
|
439
|
-
return
|
|
439
|
+
return u.color = _.color = y.color = this.color, [u, _, y];
|
|
440
440
|
}
|
|
441
441
|
default: {
|
|
442
442
|
this.point(1 / 3, t), this.point(2 / 3, n);
|
|
443
|
-
const s = this.p0x === this.p1x && this.p0y === this.p1y ? this.p0x : this.p0x + 1 / 3 * (this.p1x - this.p0x),
|
|
443
|
+
const s = this.p0x === this.p1x && this.p0y === this.p1y ? this.p0x : this.p0x + 1 / 3 * (this.p1x - this.p0x), i = this.p0x === this.p1x && this.p0y === this.p1y ? this.p0y : this.p0y + 1 / 3 * (this.p1y - this.p0y), e = this.p0x + 1 / 3 * (this.p1x - this.p0x), a = this.p0y + 1 / 3 * (this.p1y - this.p0y), c = this.p1x + 1 / 3 * (this.p2x - this.p1x), r = this.p1y + 1 / 3 * (this.p2y - this.p1y), h = this.p2x + 1 / 3 * (this.p3x - this.p2x), p = this.p2y + 1 / 3 * (this.p3y - this.p2y), l = e + 1 / 3 * (c - e), f = a + 1 / 3 * (r - a), u = c + 1 / 3 * (h - c), _ = r + 1 / 3 * (p - r), y = l + 2 / 3 * (u - l), g = f + 2 / 3 * (_ - f), M = this.p0x + 2 / 3 * (this.p1x - this.p0x), I = this.p0y + 2 / 3 * (this.p1y - this.p0y), q = this.p1x + 2 / 3 * (this.p2x - this.p1x), T = this.p1y + 2 / 3 * (this.p2y - this.p1y), A = this.p2x + 2 / 3 * (this.p3x - this.p2x), D = this.p2y + 2 / 3 * (this.p3y - this.p2y), R = M + 2 / 3 * (q - M), m = I + 2 / 3 * (T - I), d = q + 2 / 3 * (A - q), x = T + 2 / 3 * (D - T), C = R + 1 / 3 * (d - R), v = m + 1 / 3 * (x - m), E = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3x : this.p2x + 2 / 3 * (this.p3x - this.p2x), k = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3y : this.p2y + 2 / 3 * (this.p3y - this.p2y), S = new et(
|
|
444
444
|
Gt,
|
|
445
445
|
this.p0x,
|
|
446
446
|
this.p0y,
|
|
447
447
|
s,
|
|
448
|
-
|
|
449
|
-
|
|
448
|
+
i,
|
|
449
|
+
l,
|
|
450
450
|
f,
|
|
451
451
|
t[0],
|
|
452
452
|
t[1]
|
|
453
|
-
),
|
|
453
|
+
), H = new et(
|
|
454
454
|
Gt,
|
|
455
455
|
t[0],
|
|
456
456
|
t[1],
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
457
|
+
y,
|
|
458
|
+
g,
|
|
459
|
+
C,
|
|
460
|
+
v,
|
|
461
461
|
n[0],
|
|
462
462
|
n[1]
|
|
463
|
-
),
|
|
463
|
+
), Y = new et(
|
|
464
464
|
Gt,
|
|
465
465
|
n[0],
|
|
466
466
|
n[1],
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
467
|
+
d,
|
|
468
|
+
x,
|
|
469
|
+
E,
|
|
470
|
+
k,
|
|
471
471
|
this.p3x,
|
|
472
472
|
this.p3y
|
|
473
473
|
);
|
|
474
|
-
return
|
|
474
|
+
return S.color = H.color = Y.color = this.color, [S, H, Y];
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
477
|
}
|
|
@@ -490,93 +490,93 @@ class it {
|
|
|
490
490
|
*/
|
|
491
491
|
signedDistance(t, n, s) {
|
|
492
492
|
switch (this.type) {
|
|
493
|
-
case
|
|
494
|
-
const
|
|
495
|
-
if (
|
|
496
|
-
const
|
|
497
|
-
if (Math.abs(
|
|
498
|
-
s.distance =
|
|
493
|
+
case lt: {
|
|
494
|
+
const i = this.p0x, e = this.p0y, a = this.p1x, c = this.p1y, r = t - i, h = n - e, p = a - i, l = c - e, f = p * p + l * l, u = (r * p + h * l) / f, _ = u > 0.5, y = (_ ? a : i) - t, g = (_ ? c : e) - n, M = Math.sqrt(y * y + g * g);
|
|
495
|
+
if (u > 0 && u < 1) {
|
|
496
|
+
const T = Math.sqrt(p * p + l * l), A = p / T, R = l / T * r - A * h;
|
|
497
|
+
if (Math.abs(R) < M) {
|
|
498
|
+
s.distance = R, s.dot = 0, s.param = u;
|
|
499
499
|
return;
|
|
500
500
|
}
|
|
501
501
|
}
|
|
502
|
-
const
|
|
503
|
-
s.distance =
|
|
504
|
-
const
|
|
505
|
-
s.dot =
|
|
502
|
+
const I = r * l - h * p;
|
|
503
|
+
s.distance = qt(I) * M;
|
|
504
|
+
const q = Math.sqrt(p * p + l * l);
|
|
505
|
+
s.dot = M === 0 || q === 0 ? 0 : Math.abs((p * y + l * g) / (q * M)), s.param = u;
|
|
506
506
|
return;
|
|
507
507
|
}
|
|
508
|
-
case
|
|
509
|
-
const
|
|
510
|
-
let
|
|
511
|
-
const
|
|
512
|
-
let
|
|
508
|
+
case ct: {
|
|
509
|
+
const i = this.p0x, e = this.p0y, a = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y, p = i - t, l = e - n, f = a - i, u = c - e, _ = r - a - f, y = h - c - u, g = _ * _ + y * y, M = 3 * (f * _ + u * y), I = 2 * (f * f + u * u) + (p * _ + l * y), q = p * f + l * u, T = Vo(g, M, I, q, 0, 1, X);
|
|
510
|
+
let A = f, D = u;
|
|
511
|
+
const R = p * p + l * l;
|
|
512
|
+
let m = qt(A * l - D * p), d = R, x = -(p * A + l * D) / (A * A + D * D);
|
|
513
513
|
{
|
|
514
|
-
const
|
|
515
|
-
|
|
514
|
+
const v = r - t, E = h - n, k = v * v + E * E;
|
|
515
|
+
k < d && (A = r - a, D = h - c, m = qt(A * E - D * v), d = k, x = ((t - a) * A + (n - c) * D) / (A * A + D * D));
|
|
516
516
|
}
|
|
517
|
-
for (let
|
|
518
|
-
const
|
|
519
|
-
if (
|
|
520
|
-
const
|
|
521
|
-
if (
|
|
522
|
-
const
|
|
523
|
-
|
|
517
|
+
for (let v = 0; v < T; ++v) {
|
|
518
|
+
const E = X[v];
|
|
519
|
+
if (E > 0 && E < 1) {
|
|
520
|
+
const k = p + 2 * E * f + E * E * _, S = l + 2 * E * u + E * E * y, H = k * k + S * S;
|
|
521
|
+
if (H <= d) {
|
|
522
|
+
const Y = f + E * _, tt = u + E * y;
|
|
523
|
+
m = qt(Y * S - tt * k), d = H, x = E;
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
526
|
}
|
|
527
|
-
const
|
|
528
|
-
if (
|
|
529
|
-
s.distance =
|
|
527
|
+
const C = m * Math.sqrt(d);
|
|
528
|
+
if (x >= 0 && x <= 1) {
|
|
529
|
+
s.distance = C, s.dot = 0, s.param = x;
|
|
530
530
|
return;
|
|
531
531
|
}
|
|
532
|
-
if (s.distance =
|
|
533
|
-
const
|
|
534
|
-
s.dot =
|
|
532
|
+
if (s.distance = C, s.param = x, x < 0.5) {
|
|
533
|
+
const v = Math.sqrt(f * f + u * u), E = Math.sqrt(R);
|
|
534
|
+
s.dot = E === 0 || v === 0 ? 0 : Math.abs((f * p + u * l) / (v * E));
|
|
535
535
|
} else {
|
|
536
|
-
const
|
|
537
|
-
s.dot =
|
|
536
|
+
const v = r - a, E = h - c, k = r - t, S = h - n, H = Math.sqrt(v * v + E * E), Y = Math.sqrt(k * k + S * S);
|
|
537
|
+
s.dot = H === 0 || Y === 0 ? 0 : Math.abs((v * k + E * S) / (H * Y));
|
|
538
538
|
}
|
|
539
539
|
return;
|
|
540
540
|
}
|
|
541
541
|
default: {
|
|
542
|
-
const
|
|
543
|
-
let
|
|
544
|
-
|
|
545
|
-
const
|
|
546
|
-
let
|
|
542
|
+
const i = this.p0x, e = this.p0y, a = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y, p = this.p3x, l = this.p3y, f = i - t, u = e - n, _ = a - i, y = c - e, g = r - a - _, M = h - c - y, I = p - r - (r - a) - g, q = l - h - (h - c) - M;
|
|
543
|
+
let T = _, A = y;
|
|
544
|
+
T === 0 && A === 0 && (T = r - i, A = h - e);
|
|
545
|
+
const D = Math.sqrt(f * f + u * u);
|
|
546
|
+
let R = qt(T * u - A * f) * D, m = -(f * T + u * A) / (T * T + A * A);
|
|
547
547
|
{
|
|
548
|
-
const
|
|
549
|
-
if (
|
|
550
|
-
let
|
|
551
|
-
|
|
548
|
+
const d = p - t, x = l - n, C = Math.sqrt(d * d + x * x);
|
|
549
|
+
if (C < Math.abs(R)) {
|
|
550
|
+
let v = p - r, E = l - h;
|
|
551
|
+
v === 0 && E === 0 && (v = p - a, E = l - c), T = v, A = E, R = qt(T * x - A * d) * C, m = ((T - d) * T + (A - x) * A) / (T * T + A * A);
|
|
552
552
|
}
|
|
553
553
|
}
|
|
554
|
-
for (let
|
|
555
|
-
let
|
|
556
|
-
if (
|
|
557
|
-
let
|
|
554
|
+
for (let d = 0; d <= $s; ++d) {
|
|
555
|
+
let x = 1 / $s * d, C = f + 3 * x * _ + 3 * x * x * g + x * x * x * I, v = u + 3 * x * y + 3 * x * x * M + x * x * x * q, E = 3 * _ + 6 * x * g + 3 * x * x * I, k = 3 * y + 6 * x * M + 3 * x * x * q, S = 6 * g + 6 * x * I, H = 6 * M + 6 * x * q, Y = x - (C * E + v * k) / (E * E + k * k + (C * S + v * H));
|
|
556
|
+
if (Y > 0 && Y < 1) {
|
|
557
|
+
let tt = Bo;
|
|
558
558
|
do {
|
|
559
|
-
if (
|
|
560
|
-
|
|
561
|
-
} while (
|
|
562
|
-
const
|
|
563
|
-
|
|
559
|
+
if (x = Y, C = f + 3 * x * _ + 3 * x * x * g + x * x * x * I, v = u + 3 * x * y + 3 * x * x * M + x * x * x * q, E = 3 * _ + 6 * x * g + 3 * x * x * I, k = 3 * y + 6 * x * M + 3 * x * x * q, !--tt) break;
|
|
560
|
+
S = 6 * g + 6 * x * I, H = 6 * M + 6 * x * q, Y = x - (C * E + v * k) / (E * E + k * k + (C * S + v * H));
|
|
561
|
+
} while (Y > 0 && Y < 1);
|
|
562
|
+
const V = Math.sqrt(C * C + v * v);
|
|
563
|
+
V < Math.abs(R) && (R = qt(E * v - k * C) * V, m = x);
|
|
564
564
|
}
|
|
565
565
|
}
|
|
566
|
-
if (
|
|
567
|
-
s.distance =
|
|
566
|
+
if (m >= 0 && m <= 1) {
|
|
567
|
+
s.distance = R, s.dot = 0, s.param = m;
|
|
568
568
|
return;
|
|
569
569
|
}
|
|
570
|
-
if (s.distance =
|
|
571
|
-
let
|
|
572
|
-
|
|
573
|
-
const
|
|
574
|
-
s.dot =
|
|
570
|
+
if (s.distance = R, s.param = m, m < 0.5) {
|
|
571
|
+
let d = _, x = y;
|
|
572
|
+
d === 0 && x === 0 && (d = r - i, x = h - e);
|
|
573
|
+
const C = Math.sqrt(d * d + x * x);
|
|
574
|
+
s.dot = D === 0 || C === 0 ? 0 : Math.abs((d * f + x * u) / (C * D));
|
|
575
575
|
} else {
|
|
576
|
-
let
|
|
577
|
-
|
|
578
|
-
const
|
|
579
|
-
s.dot =
|
|
576
|
+
let d = p - r, x = l - h;
|
|
577
|
+
d === 0 && x === 0 && (d = p - a, x = l - c);
|
|
578
|
+
const C = p - t, v = l - n, E = Math.sqrt(d * d + x * x), k = Math.sqrt(C * C + v * v);
|
|
579
|
+
s.dot = E === 0 || k === 0 ? 0 : Math.abs((d * C + x * v) / (E * k));
|
|
580
580
|
}
|
|
581
581
|
return;
|
|
582
582
|
}
|
|
@@ -595,56 +595,56 @@ class it {
|
|
|
595
595
|
*/
|
|
596
596
|
scanlineIntersections(t, n, s) {
|
|
597
597
|
switch (this.type) {
|
|
598
|
-
case
|
|
599
|
-
const
|
|
600
|
-
if (t >=
|
|
601
|
-
const
|
|
602
|
-
return n[0] =
|
|
598
|
+
case lt: {
|
|
599
|
+
const i = this.p0y, e = this.p1y;
|
|
600
|
+
if (t >= i && t < e || t >= e && t < i) {
|
|
601
|
+
const a = (t - i) / (e - i);
|
|
602
|
+
return n[0] = Go(this.p0x, this.p1x, a), s[0] = pt(e - i), 1;
|
|
603
603
|
}
|
|
604
604
|
return 0;
|
|
605
605
|
}
|
|
606
|
-
case
|
|
607
|
-
const
|
|
608
|
-
let
|
|
609
|
-
n[
|
|
606
|
+
case ct: {
|
|
607
|
+
const i = this.p0x, e = this.p0y, a = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y;
|
|
608
|
+
let p = 0, l = t > e ? 1 : -1;
|
|
609
|
+
n[p] = i, e === t && (e < c || e === c && e < h ? s[p++] = 1 : l = 1);
|
|
610
610
|
{
|
|
611
|
-
const f =
|
|
612
|
-
if (
|
|
613
|
-
const
|
|
614
|
-
|
|
611
|
+
const f = a - i, u = c - e, _ = r - a - f, y = h - c - u, g = bo(X, y, 2 * u, e - t);
|
|
612
|
+
if (g >= 2 && X[0] > X[1]) {
|
|
613
|
+
const M = X[0];
|
|
614
|
+
X[0] = X[1], X[1] = M;
|
|
615
615
|
}
|
|
616
|
-
for (let
|
|
617
|
-
const
|
|
618
|
-
|
|
616
|
+
for (let M = 0; M < g && p < 2; ++M) {
|
|
617
|
+
const I = X[M];
|
|
618
|
+
I >= 0 && I <= 1 && (n[p] = i + 2 * I * f + I * I * _, l * (u + I * y) >= 0 && (s[p++] = l, l = -l));
|
|
619
619
|
}
|
|
620
620
|
}
|
|
621
|
-
return h === t && (
|
|
621
|
+
return h === t && (l > 0 && p > 0 && (--p, l = -1), (h < c || h === c && h < e) && p < 2 && (n[p] = r, l < 0 && (s[p++] = -1, l = 1))), l !== (t >= h ? 1 : -1) && (p > 0 ? --p : (Math.abs(h - t) < Math.abs(e - t) && (n[p] = r), s[p++] = l)), p;
|
|
622
622
|
}
|
|
623
623
|
default: {
|
|
624
|
-
const
|
|
625
|
-
let f = 0,
|
|
626
|
-
n[f] =
|
|
624
|
+
const i = this.p0x, e = this.p0y, a = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y, p = this.p3x, l = this.p3y;
|
|
625
|
+
let f = 0, u = t > e ? 1 : -1;
|
|
626
|
+
n[f] = i, e === t && (e < c || e === c && (e < h || e === h && e < l) ? s[f++] = 1 : u = 1);
|
|
627
627
|
{
|
|
628
|
-
const _ =
|
|
629
|
-
if (
|
|
630
|
-
if (
|
|
631
|
-
const
|
|
632
|
-
|
|
628
|
+
const _ = p - 3 * r + 3 * a - i, y = l - 3 * h + 3 * c - e, g = 3 * r - 6 * a + 3 * i, M = 3 * h - 6 * c + 3 * e, I = 3 * a - 3 * i, q = 3 * c - 3 * e, T = Yo(X, y, M, q, e - t);
|
|
629
|
+
if (T >= 2) {
|
|
630
|
+
if (X[0] > X[1]) {
|
|
631
|
+
const A = X[0];
|
|
632
|
+
X[0] = X[1], X[1] = A;
|
|
633
633
|
}
|
|
634
|
-
if (
|
|
635
|
-
const
|
|
636
|
-
if (
|
|
637
|
-
const
|
|
638
|
-
|
|
634
|
+
if (T >= 3 && X[1] > X[2]) {
|
|
635
|
+
const A = X[1];
|
|
636
|
+
if (X[1] = X[2], X[2] = A, X[0] > X[1]) {
|
|
637
|
+
const D = X[0];
|
|
638
|
+
X[0] = X[1], X[1] = D;
|
|
639
639
|
}
|
|
640
640
|
}
|
|
641
641
|
}
|
|
642
|
-
for (let
|
|
643
|
-
const
|
|
644
|
-
|
|
642
|
+
for (let A = 0; A < T && f < 3; ++A) {
|
|
643
|
+
const D = X[A];
|
|
644
|
+
D >= 0 && D <= 1 && (n[f] = ((_ * D + g) * D + I) * D + i, u * ((3 * y * D + 2 * M) * D + q) >= 0 && (s[f++] = u, u = -u));
|
|
645
645
|
}
|
|
646
646
|
}
|
|
647
|
-
return
|
|
647
|
+
return l === t && (u > 0 && f > 0 && (--f, u = -1), (l < h || l === h && (l < c || l === c && l < e)) && f < 3 && (n[f] = p, u < 0 && (s[f++] = -1, u = 1))), u !== (t >= l ? 1 : -1) && (f > 0 ? --f : (Math.abs(l - t) < Math.abs(e - t) && (n[f] = p), s[f++] = u)), f;
|
|
648
648
|
}
|
|
649
649
|
}
|
|
650
650
|
}
|
|
@@ -656,92 +656,92 @@ class it {
|
|
|
656
656
|
* @returns A new CUBIC EdgeSegment with identical geometry.
|
|
657
657
|
*/
|
|
658
658
|
convertToCubic() {
|
|
659
|
-
const t = this.p0x + 0.6666666666666666 * (this.p1x - this.p0x), n = this.p0y + 2 / 3 * (this.p1y - this.p0y), s = this.p1x + 1 / 3 * (this.p2x - this.p1x),
|
|
659
|
+
const t = this.p0x + 0.6666666666666666 * (this.p1x - this.p0x), n = this.p0y + 2 / 3 * (this.p1y - this.p0y), s = this.p1x + 1 / 3 * (this.p2x - this.p1x), i = this.p1y + 1 / 3 * (this.p2y - this.p1y), e = new et(
|
|
660
660
|
Gt,
|
|
661
661
|
this.p0x,
|
|
662
662
|
this.p0y,
|
|
663
663
|
t,
|
|
664
664
|
n,
|
|
665
665
|
s,
|
|
666
|
-
|
|
666
|
+
i,
|
|
667
667
|
this.p2x,
|
|
668
668
|
this.p2y
|
|
669
669
|
);
|
|
670
670
|
return e.color = this.color, e;
|
|
671
671
|
}
|
|
672
672
|
}
|
|
673
|
-
const
|
|
674
|
-
function
|
|
675
|
-
const e =
|
|
673
|
+
const Ko = 1, zo = 2, $o = 4, jo = 8, js = 16, Qs = 32, Qo = 1, Zs = 2, Zo = 8, Jo = 32, te = 64, ne = 128;
|
|
674
|
+
function se(o, t, n, s, i) {
|
|
675
|
+
const e = Ao(o, t, n, s, i), a = [];
|
|
676
676
|
for (const c of e) {
|
|
677
|
-
const r =
|
|
678
|
-
r.length > 0 &&
|
|
677
|
+
const r = ie(c);
|
|
678
|
+
r.length > 0 && a.push(r);
|
|
679
679
|
}
|
|
680
|
-
return { contours:
|
|
680
|
+
return { contours: a, inverseYAxis: !1 };
|
|
681
681
|
}
|
|
682
|
-
function
|
|
682
|
+
function Ao(o, t, n, s, i) {
|
|
683
683
|
if (s === 0) return [];
|
|
684
|
-
const e = t + n,
|
|
685
|
-
return
|
|
684
|
+
const e = t + n, a = new wt(o, e), c = a.i16();
|
|
685
|
+
return a.skip(8), c >= 0 ? oe(a, c) : ce(o, a, t, i);
|
|
686
686
|
}
|
|
687
|
-
function
|
|
687
|
+
function oe(o, t) {
|
|
688
688
|
if (t === 0) return [];
|
|
689
|
-
const n =
|
|
690
|
-
for (let
|
|
691
|
-
const s = (n[t - 1] ?? 0) + 1,
|
|
692
|
-
|
|
689
|
+
const n = [];
|
|
690
|
+
for (let l = 0; l < t; l++) n[l] = o.u16();
|
|
691
|
+
const s = (n[t - 1] ?? 0) + 1, i = o.u16();
|
|
692
|
+
o.skip(i);
|
|
693
693
|
const e = new Uint8Array(s);
|
|
694
|
-
for (let
|
|
695
|
-
const f =
|
|
696
|
-
if (e[
|
|
697
|
-
let
|
|
698
|
-
for (;
|
|
694
|
+
for (let l = 0; l < s; ) {
|
|
695
|
+
const f = o.u8();
|
|
696
|
+
if (e[l++] = f, f & jo) {
|
|
697
|
+
let u = o.u8();
|
|
698
|
+
for (; u-- > 0; ) e[l++] = f;
|
|
699
699
|
}
|
|
700
700
|
}
|
|
701
|
-
const
|
|
701
|
+
const a = new Float64Array(s);
|
|
702
702
|
let c = 0;
|
|
703
|
-
for (let
|
|
704
|
-
const f = e[
|
|
705
|
-
if (f &
|
|
706
|
-
const
|
|
707
|
-
c += f &
|
|
708
|
-
} else f &
|
|
709
|
-
|
|
703
|
+
for (let l = 0; l < s; l++) {
|
|
704
|
+
const f = e[l] ?? 0;
|
|
705
|
+
if (f & zo) {
|
|
706
|
+
const u = o.u8();
|
|
707
|
+
c += f & js ? u : -u;
|
|
708
|
+
} else f & js || (c += o.i16());
|
|
709
|
+
a[l] = c;
|
|
710
710
|
}
|
|
711
711
|
const r = new Float64Array(s);
|
|
712
712
|
c = 0;
|
|
713
|
-
for (let
|
|
714
|
-
const f = e[
|
|
715
|
-
if (f &
|
|
716
|
-
const
|
|
717
|
-
c += f &
|
|
718
|
-
} else f &
|
|
719
|
-
r[
|
|
713
|
+
for (let l = 0; l < s; l++) {
|
|
714
|
+
const f = e[l] ?? 0;
|
|
715
|
+
if (f & $o) {
|
|
716
|
+
const u = o.u8();
|
|
717
|
+
c += f & Qs ? u : -u;
|
|
718
|
+
} else f & Qs || (c += o.i16());
|
|
719
|
+
r[l] = c;
|
|
720
720
|
}
|
|
721
721
|
const h = [];
|
|
722
|
-
let
|
|
723
|
-
for (let
|
|
724
|
-
const f = n[
|
|
725
|
-
|
|
722
|
+
let p = 0;
|
|
723
|
+
for (let l = 0; l < t; l++) {
|
|
724
|
+
const f = n[l] ?? 0, u = ee(e, a, r, p, f);
|
|
725
|
+
u.length > 0 && h.push(u), p = f + 1;
|
|
726
726
|
}
|
|
727
727
|
return h;
|
|
728
728
|
}
|
|
729
|
-
function
|
|
730
|
-
const e =
|
|
729
|
+
function ee(o, t, n, s, i) {
|
|
730
|
+
const e = i - s + 1;
|
|
731
731
|
if (e <= 0) return [];
|
|
732
|
-
const
|
|
732
|
+
const a = [];
|
|
733
733
|
for (let c = 0; c < e; c++) {
|
|
734
|
-
const r =
|
|
735
|
-
|
|
734
|
+
const r = o[s + c] ?? 0, h = t[s + c] ?? 0, p = n[s + c] ?? 0;
|
|
735
|
+
a.push({ x: h, y: p, onCurve: (r & Ko) !== 0 });
|
|
736
736
|
}
|
|
737
|
-
return
|
|
737
|
+
return a;
|
|
738
738
|
}
|
|
739
|
-
function
|
|
740
|
-
const t =
|
|
739
|
+
function ie(o) {
|
|
740
|
+
const t = o.length;
|
|
741
741
|
if (t <= 0) return [];
|
|
742
742
|
const n = [];
|
|
743
743
|
for (let c = 0; c < t; c++) {
|
|
744
|
-
const r =
|
|
744
|
+
const r = o[c], h = o[(c + 1) % t];
|
|
745
745
|
n.push(r), !r.onCurve && !h.onCurve && n.push({
|
|
746
746
|
x: Math.trunc((r.x + h.x) / 2),
|
|
747
747
|
y: Math.trunc((r.y + h.y) / 2),
|
|
@@ -749,109 +749,109 @@ function Lo(i) {
|
|
|
749
749
|
});
|
|
750
750
|
}
|
|
751
751
|
const s = n.length;
|
|
752
|
-
let
|
|
752
|
+
let i = 0;
|
|
753
753
|
if (!n[0].onCurve) {
|
|
754
754
|
for (let c = 1; c < s; c++)
|
|
755
755
|
if (n[c].onCurve) {
|
|
756
|
-
|
|
756
|
+
i = c;
|
|
757
757
|
break;
|
|
758
758
|
}
|
|
759
759
|
}
|
|
760
760
|
const e = [];
|
|
761
|
-
let
|
|
762
|
-
for (;
|
|
763
|
-
const c = n[(
|
|
761
|
+
let a = 0;
|
|
762
|
+
for (; a < s; ) {
|
|
763
|
+
const c = n[(i + a) % s], r = n[(i + a + 1) % s];
|
|
764
764
|
if (r.onCurve)
|
|
765
|
-
e.push(new
|
|
765
|
+
e.push(new et(lt, c.x, c.y, r.x, r.y, 0, 0, 0, 0)), a += 1;
|
|
766
766
|
else {
|
|
767
|
-
const h = n[(
|
|
768
|
-
e.push(new
|
|
767
|
+
const h = n[(i + a + 2) % s];
|
|
768
|
+
e.push(new et(ct, c.x, c.y, r.x, r.y, h.x, h.y, 0, 0)), a += 2;
|
|
769
769
|
}
|
|
770
770
|
}
|
|
771
771
|
return e;
|
|
772
772
|
}
|
|
773
|
-
function
|
|
774
|
-
const
|
|
773
|
+
function ce(o, t, n, s) {
|
|
774
|
+
const i = [];
|
|
775
775
|
let e = 0;
|
|
776
776
|
do {
|
|
777
777
|
e = t.u16();
|
|
778
|
-
const
|
|
778
|
+
const a = t.u16();
|
|
779
779
|
let c, r;
|
|
780
|
-
e &
|
|
781
|
-
let h = 0,
|
|
782
|
-
e &
|
|
783
|
-
let
|
|
784
|
-
e &
|
|
785
|
-
const
|
|
786
|
-
for (const
|
|
787
|
-
} while (e &
|
|
788
|
-
return
|
|
789
|
-
}
|
|
790
|
-
function
|
|
791
|
-
return
|
|
792
|
-
}
|
|
793
|
-
function
|
|
794
|
-
if (t === 1 && n === 0 && s === 0 &&
|
|
795
|
-
const r = t === 1 && n === 0 && s === 0 &&
|
|
796
|
-
return
|
|
797
|
-
(h) => h.map((
|
|
798
|
-
x:
|
|
799
|
-
y:
|
|
800
|
-
onCurve:
|
|
780
|
+
e & Qo ? (c = t.i16(), r = t.i16()) : (c = t.u8(), r = t.u8(), e & Zs && (c > 127 && (c -= 256), r > 127 && (r -= 256)));
|
|
781
|
+
let h = 0, p = 0;
|
|
782
|
+
e & Zs && (h = c, p = r);
|
|
783
|
+
let l = 1, f = 0, u = 0, _ = 1;
|
|
784
|
+
e & Zo ? l = _ = t.f2dot14() : e & te ? (l = t.f2dot14(), _ = t.f2dot14()) : e & ne && (l = t.f2dot14(), f = t.f2dot14(), u = t.f2dot14(), _ = t.f2dot14());
|
|
785
|
+
const y = s(a), g = re(y, l, f, u, _, h, p);
|
|
786
|
+
for (const M of g) i.push(M);
|
|
787
|
+
} while (e & Jo);
|
|
788
|
+
return i;
|
|
789
|
+
}
|
|
790
|
+
function Js(o) {
|
|
791
|
+
return o >= 0 ? Math.floor(o + 0.5) : Math.ceil(o - 0.5);
|
|
792
|
+
}
|
|
793
|
+
function re(o, t, n, s, i, e, a) {
|
|
794
|
+
if (t === 1 && n === 0 && s === 0 && i === 1 && e === 0 && a === 0) return o;
|
|
795
|
+
const r = t === 1 && n === 0 && s === 0 && i === 1;
|
|
796
|
+
return o.map(
|
|
797
|
+
(h) => h.map((p) => r ? { x: p.x + e, y: p.y + a, onCurve: p.onCurve } : {
|
|
798
|
+
x: Js(t * p.x + n * p.y + e),
|
|
799
|
+
y: Js(s * p.x + i * p.y + a),
|
|
800
|
+
onCurve: p.onCurve
|
|
801
801
|
})
|
|
802
802
|
);
|
|
803
803
|
}
|
|
804
|
-
function
|
|
805
|
-
const n = new
|
|
804
|
+
function ae(o, t) {
|
|
805
|
+
const n = new wt(o, t);
|
|
806
806
|
if (n.u16() !== 0)
|
|
807
|
-
return
|
|
808
|
-
const
|
|
809
|
-
for (let
|
|
807
|
+
return to;
|
|
808
|
+
const i = n.u16(), e = /* @__PURE__ */ new Map();
|
|
809
|
+
for (let a = 0; a < i; a++) {
|
|
810
810
|
const c = n.pos;
|
|
811
811
|
n.skip(2);
|
|
812
|
-
const r = n.u16(), h = n.u16(),
|
|
813
|
-
if (
|
|
812
|
+
const r = n.u16(), h = n.u16(), p = h >> 8 & 255, l = !(h & 2), f = !!(h & 4);
|
|
813
|
+
if (p !== 0 || !l || f) {
|
|
814
814
|
n.seek(c + r);
|
|
815
815
|
continue;
|
|
816
816
|
}
|
|
817
|
-
const
|
|
817
|
+
const u = n.u16();
|
|
818
818
|
n.skip(6);
|
|
819
|
-
for (let _ = 0; _ <
|
|
820
|
-
const
|
|
821
|
-
e.set(
|
|
819
|
+
for (let _ = 0; _ < u; _++) {
|
|
820
|
+
const y = n.u16(), g = n.u16(), M = n.i16(), I = (y & 65535) << 16 | g & 65535;
|
|
821
|
+
e.set(I, M);
|
|
822
822
|
}
|
|
823
823
|
n.seek(c + r);
|
|
824
824
|
}
|
|
825
|
-
return e.size === 0 ?
|
|
826
|
-
const r = (
|
|
825
|
+
return e.size === 0 ? to : (a, c) => {
|
|
826
|
+
const r = (a & 65535) << 16 | c & 65535;
|
|
827
827
|
return e.get(r) ?? 0;
|
|
828
828
|
};
|
|
829
829
|
}
|
|
830
|
-
const
|
|
831
|
-
function
|
|
832
|
-
const t = new
|
|
830
|
+
const to = () => 0;
|
|
831
|
+
function le(o) {
|
|
832
|
+
const t = new wt(o);
|
|
833
833
|
if (t.u32() === 1953784678) {
|
|
834
834
|
if (t.skip(4), t.u32() === 0) throw new Error("TTC contains no fonts");
|
|
835
|
-
const
|
|
836
|
-
t.seek(
|
|
835
|
+
const i = t.u32();
|
|
836
|
+
t.seek(i);
|
|
837
837
|
} else
|
|
838
838
|
t.seek(0);
|
|
839
|
-
return
|
|
839
|
+
return he(o, t);
|
|
840
840
|
}
|
|
841
|
-
function
|
|
841
|
+
function he(o, t) {
|
|
842
842
|
t.skip(4);
|
|
843
843
|
const n = t.u16();
|
|
844
844
|
t.skip(6);
|
|
845
845
|
const s = /* @__PURE__ */ new Map();
|
|
846
|
-
for (let
|
|
846
|
+
for (let i = 0; i < n; i++) {
|
|
847
847
|
const e = String.fromCharCode(t.u8(), t.u8(), t.u8(), t.u8());
|
|
848
848
|
t.skip(4);
|
|
849
|
-
const
|
|
850
|
-
s.set(e, { offset:
|
|
849
|
+
const a = t.u32(), c = t.u32();
|
|
850
|
+
s.set(e, { offset: a, length: c });
|
|
851
851
|
}
|
|
852
852
|
return s;
|
|
853
853
|
}
|
|
854
|
-
class
|
|
854
|
+
class pe {
|
|
855
855
|
/**
|
|
856
856
|
* Parses a TrueType font from an ArrayBuffer.
|
|
857
857
|
*
|
|
@@ -862,19 +862,19 @@ class Yo {
|
|
|
862
862
|
* @param buffer Raw font file bytes.
|
|
863
863
|
*/
|
|
864
864
|
constructor(t) {
|
|
865
|
-
this._buffer = t, this._tables =
|
|
866
|
-
const n = this._tables.get("head"), s = this._tables.get("maxp"),
|
|
865
|
+
this._buffer = t, this._tables = le(t);
|
|
866
|
+
const n = this._tables.get("head"), s = this._tables.get("maxp"), i = this._tables.get("hhea"), e = this._tables.get("hmtx"), a = this._tables.get("loca"), c = this._tables.get("cmap");
|
|
867
867
|
if (!n) throw new Error("Font missing required `head` table");
|
|
868
868
|
if (!s) throw new Error("Font missing required `maxp` table");
|
|
869
|
-
if (!
|
|
869
|
+
if (!i) throw new Error("Font missing required `hhea` table");
|
|
870
870
|
if (!e) throw new Error("Font missing required `hmtx` table");
|
|
871
|
-
if (!
|
|
871
|
+
if (!a) throw new Error("Font missing required `loca` table");
|
|
872
872
|
if (!c) throw new Error("Font missing required `cmap` table");
|
|
873
|
-
this._head =
|
|
874
|
-
const r =
|
|
875
|
-
this._hhea =
|
|
873
|
+
this._head = To(t, n.offset);
|
|
874
|
+
const r = Oo(t, s.offset);
|
|
875
|
+
this._hhea = So(t, i.offset), this._hmtx = Lo(t, e.offset, r.numGlyphs, this._hhea.numberOfHMetrics), this._loca = Po(t, a.offset, r.numGlyphs, this._head.indexToLocFormat), this._cmap = Co(t, c.offset);
|
|
876
876
|
const h = this._tables.get("kern");
|
|
877
|
-
this._kern = h ?
|
|
877
|
+
this._kern = h ? ae(t, h.offset) : () => 0, this.metrics = {
|
|
878
878
|
unitsPerEm: this._head.unitsPerEm,
|
|
879
879
|
ascender: this._hhea.ascender,
|
|
880
880
|
descender: this._hhea.descender,
|
|
@@ -942,12 +942,12 @@ class Yo {
|
|
|
942
942
|
shape(t) {
|
|
943
943
|
const n = this._tables.get("glyf");
|
|
944
944
|
if (!n) return { contours: [], inverseYAxis: !1 };
|
|
945
|
-
const s = this._loca,
|
|
946
|
-
return
|
|
945
|
+
const s = this._loca, i = s[t] ?? 0, a = (s[t + 1] ?? i) - i;
|
|
946
|
+
return se(
|
|
947
947
|
this._buffer,
|
|
948
948
|
n.offset,
|
|
949
|
-
|
|
950
|
-
|
|
949
|
+
i,
|
|
950
|
+
a,
|
|
951
951
|
(c) => this._glyphRaw(c)
|
|
952
952
|
);
|
|
953
953
|
}
|
|
@@ -960,583 +960,820 @@ class Yo {
|
|
|
960
960
|
_glyphRaw(t) {
|
|
961
961
|
const n = this._tables.get("glyf");
|
|
962
962
|
if (!n) return [];
|
|
963
|
-
const s = this._loca,
|
|
964
|
-
return
|
|
963
|
+
const s = this._loca, i = s[t] ?? 0, a = (s[t + 1] ?? i) - i;
|
|
964
|
+
return Ao(
|
|
965
965
|
this._buffer,
|
|
966
966
|
n.offset,
|
|
967
|
-
|
|
968
|
-
|
|
967
|
+
i,
|
|
968
|
+
a,
|
|
969
969
|
(c) => this._glyphRaw(c)
|
|
970
970
|
);
|
|
971
971
|
}
|
|
972
972
|
}
|
|
973
|
-
function
|
|
973
|
+
function fe(o, t) {
|
|
974
974
|
const n = 1 / t;
|
|
975
|
-
for (const s of
|
|
976
|
-
for (let
|
|
977
|
-
const e = s[
|
|
978
|
-
if (e.p0x *= n, e.p0y *= n, e.p1x *= n, e.p1y *= n, e.p2x *= n, e.p2y *= n, e.p3x *= n, e.p3y *= n, e.type ===
|
|
979
|
-
const
|
|
980
|
-
|
|
975
|
+
for (const s of o.contours)
|
|
976
|
+
for (let i = 0; i < s.length; i++) {
|
|
977
|
+
const e = s[i];
|
|
978
|
+
if (e.p0x *= n, e.p0y *= n, e.p1x *= n, e.p1y *= n, e.p2x *= n, e.p2y *= n, e.p3x *= n, e.p3y *= n, e.type === ct) {
|
|
979
|
+
const a = e.p1x - e.p0x, c = e.p1y - e.p0y, r = e.p2x - e.p1x, h = e.p2y - e.p1y;
|
|
980
|
+
z(a, c, r, h) === 0 && (s[i] = new et(lt, e.p0x, e.p0y, e.p2x, e.p2y, 0, 0, 0, 0));
|
|
981
|
+
} else if (e.type === Gt) {
|
|
982
|
+
const a = e.p2x - e.p1x, c = e.p2y - e.p1y, r = 1.5 * e.p1x - 0.5 * e.p0x, h = 1.5 * e.p1y - 0.5 * e.p0y;
|
|
983
|
+
z(e.p1x - e.p0x, e.p1y - e.p0y, a, c) === 0 && z(a, c, e.p3x - e.p2x, e.p3y - e.p2y) === 0 ? s[i] = new et(lt, e.p0x, e.p0y, e.p3x, e.p3y, 0, 0, 0, 0) : r === 1.5 * e.p2x - 0.5 * e.p3x && h === 1.5 * e.p2y - 0.5 * e.p3y && (s[i] = new et(ct, e.p0x, e.p0y, r, h, e.p3x, e.p3y, 0, 0));
|
|
981
984
|
}
|
|
982
985
|
}
|
|
983
986
|
}
|
|
984
|
-
const
|
|
985
|
-
function
|
|
986
|
-
switch (t[n] =
|
|
987
|
-
case
|
|
987
|
+
const no = 1e-6, ue = 1.1111111111111112, ye = new Float64Array(16);
|
|
988
|
+
function so(o, t, n) {
|
|
989
|
+
switch (t[n] = o.p0x, t[n + 1] = o.p0y, t[n + 2] = o.p1x, t[n + 3] = o.p1y, o.type) {
|
|
990
|
+
case lt:
|
|
988
991
|
return 1;
|
|
989
|
-
case
|
|
990
|
-
return t[n + 4] =
|
|
992
|
+
case ct:
|
|
993
|
+
return t[n + 4] = o.p2x, t[n + 5] = o.p2y, 2;
|
|
991
994
|
default:
|
|
992
|
-
return t[n + 4] =
|
|
995
|
+
return t[n + 4] = o.p2x, t[n + 5] = o.p2y, t[n + 6] = o.p3x, t[n + 7] = o.p3y, 3;
|
|
993
996
|
}
|
|
994
997
|
}
|
|
995
|
-
function
|
|
998
|
+
function oo(o, t, n) {
|
|
996
999
|
if (n === 3) {
|
|
997
|
-
const s =
|
|
998
|
-
(e === s &&
|
|
1000
|
+
const s = o[t], i = o[t + 1], e = o[t + 2], a = o[t + 3], c = o[t + 4], r = o[t + 5], h = o[t + 6], p = o[t + 7];
|
|
1001
|
+
(e === s && a === i || e === h && a === p) && (c === s && r === i || c === h && r === p) && (o[t + 2] = h, o[t + 3] = p, n = 1);
|
|
999
1002
|
}
|
|
1000
1003
|
if (n === 2) {
|
|
1001
|
-
const s =
|
|
1002
|
-
(e === s &&
|
|
1003
|
-
}
|
|
1004
|
-
return n === 1 &&
|
|
1005
|
-
}
|
|
1006
|
-
function
|
|
1007
|
-
const n =
|
|
1008
|
-
let s =
|
|
1009
|
-
if (!(s >= 1 && s <= 3 &&
|
|
1010
|
-
s =
|
|
1011
|
-
const e = n[s * 2],
|
|
1012
|
-
let c = 0, r = 0, h = 0,
|
|
1013
|
-
if (s >= 1 && (c = n[(s - 1) * 2] - e, r = n[(s - 1) * 2 + 1] -
|
|
1014
|
-
const
|
|
1015
|
-
h =
|
|
1004
|
+
const s = o[t], i = o[t + 1], e = o[t + 2], a = o[t + 3], c = o[t + 4], r = o[t + 5];
|
|
1005
|
+
(e === s && a === i || e === c && a === r) && (o[t + 2] = c, o[t + 3] = r, n = 1);
|
|
1006
|
+
}
|
|
1007
|
+
return n === 1 && o[t] === o[t + 2] && o[t + 1] === o[t + 3] && (n = 0), n;
|
|
1008
|
+
}
|
|
1009
|
+
function _e(o, t) {
|
|
1010
|
+
const n = ye;
|
|
1011
|
+
let s = so(o, n, 0), i = so(t, n, 8);
|
|
1012
|
+
if (!(s >= 1 && s <= 3 && i >= 1 && i <= 3) || n[s * 2] !== n[8] || n[s * 2 + 1] !== n[9]) return 0;
|
|
1013
|
+
s = oo(n, 0, s), i = oo(n, 8, i);
|
|
1014
|
+
const e = n[s * 2], a = n[s * 2 + 1];
|
|
1015
|
+
let c = 0, r = 0, h = 0, p = 0, l = 0, f = 0, u = 0, _ = 0, y = 0, g = 0, M = 0, I = 0;
|
|
1016
|
+
if (s >= 1 && (c = n[(s - 1) * 2] - e, r = n[(s - 1) * 2 + 1] - a), s >= 2) {
|
|
1017
|
+
const V = n[(s - 2) * 2] - n[(s - 1) * 2], K = n[(s - 2) * 2 + 1] - n[(s - 1) * 2 + 1];
|
|
1018
|
+
h = V - c, p = K - r;
|
|
1016
1019
|
}
|
|
1017
1020
|
if (s >= 3) {
|
|
1018
|
-
const
|
|
1019
|
-
|
|
1020
|
-
}
|
|
1021
|
-
if (
|
|
1022
|
-
const
|
|
1023
|
-
|
|
1024
|
-
}
|
|
1025
|
-
if (
|
|
1026
|
-
const
|
|
1027
|
-
|
|
1028
|
-
}
|
|
1029
|
-
c *= s, r *= s,
|
|
1030
|
-
const
|
|
1031
|
-
if (
|
|
1032
|
-
const
|
|
1033
|
-
if (
|
|
1034
|
-
const st =
|
|
1035
|
-
if (st) return
|
|
1036
|
-
const
|
|
1037
|
-
return
|
|
1038
|
-
}
|
|
1039
|
-
let
|
|
1040
|
-
if (
|
|
1041
|
-
const
|
|
1042
|
-
if (
|
|
1043
|
-
const
|
|
1044
|
-
if (
|
|
1045
|
-
const
|
|
1046
|
-
if (
|
|
1047
|
-
const st =
|
|
1048
|
-
return st ?
|
|
1049
|
-
}
|
|
1050
|
-
const
|
|
1051
|
-
return
|
|
1052
|
-
}
|
|
1053
|
-
function
|
|
1054
|
-
let e =
|
|
1055
|
-
if (e.type ===
|
|
1056
|
-
const
|
|
1057
|
-
|
|
1021
|
+
const V = n[(s - 3) * 2] - n[(s - 2) * 2], K = n[(s - 3) * 2 + 1] - n[(s - 2) * 2 + 1], nt = n[(s - 2) * 2] - n[(s - 1) * 2], st = n[(s - 2) * 2 + 1] - n[(s - 1) * 2 + 1];
|
|
1022
|
+
l = V - nt - h, f = K - st - p, h *= 3, p *= 3;
|
|
1023
|
+
}
|
|
1024
|
+
if (i >= 1 && (u = n[10] - e, _ = n[11] - a), i >= 2) {
|
|
1025
|
+
const V = n[12] - n[10], K = n[13] - n[11];
|
|
1026
|
+
y = V - u, g = K - _;
|
|
1027
|
+
}
|
|
1028
|
+
if (i >= 3) {
|
|
1029
|
+
const V = n[14] - n[12], K = n[15] - n[13], nt = n[12] - n[10], st = n[13] - n[11];
|
|
1030
|
+
M = V - nt - y, I = K - st - g, y *= 3, g *= 3;
|
|
1031
|
+
}
|
|
1032
|
+
c *= s, r *= s, u *= i, _ *= i;
|
|
1033
|
+
const q = c !== 0 || r !== 0;
|
|
1034
|
+
if (q && (u !== 0 || _ !== 0)) {
|
|
1035
|
+
const V = Math.sqrt(c * c + r * r), K = Math.sqrt(u * u + _ * _), nt = V * z(c, r, y, g) + K * z(h, p, u, _);
|
|
1036
|
+
if (nt) return pt(nt);
|
|
1037
|
+
const st = V * V * z(c, r, M, I) + V * K * z(h, p, y, g) + K * K * z(l, f, u, _);
|
|
1038
|
+
if (st) return pt(st);
|
|
1039
|
+
const Et = V * z(h, p, M, I) + K * z(l, f, y, g);
|
|
1040
|
+
return pt(Et || z(l, f, M, I));
|
|
1041
|
+
}
|
|
1042
|
+
let A = 1, D = h, R = p, m = l, d = f, x = u, C = _, v = y, E = g, k = M, S = I;
|
|
1043
|
+
if (q && (D = y, R = g, m = M, d = I, x = c, C = r, v = h, E = p, k = l, S = f, A = -1), x !== 0 || C !== 0) {
|
|
1044
|
+
const V = z(m, d, x, C);
|
|
1045
|
+
if (V) return A * pt(V);
|
|
1046
|
+
const K = z(D, R, v, E);
|
|
1047
|
+
if (K) return A * pt(K);
|
|
1048
|
+
const nt = z(m, d, v, E);
|
|
1049
|
+
if (nt) return A * pt(nt);
|
|
1050
|
+
const st = z(D, R, k, S);
|
|
1051
|
+
return st ? A * pt(st) : A * pt(z(m, d, k, S));
|
|
1052
|
+
}
|
|
1053
|
+
const H = Math.sqrt(D * D + R * R), Y = Math.sqrt(v * v + E * E), tt = Math.sqrt(H) * z(D, R, k, S) + Math.sqrt(Y) * z(m, d, v, E);
|
|
1054
|
+
return pt(tt || z(m, d, k, S));
|
|
1055
|
+
}
|
|
1056
|
+
function eo(o, t, n, s, i) {
|
|
1057
|
+
let e = o[t];
|
|
1058
|
+
if (e.type === ct) {
|
|
1059
|
+
const a = e.convertToCubic();
|
|
1060
|
+
o[t] = a, e = a;
|
|
1058
1061
|
}
|
|
1059
1062
|
if (e.type === Gt)
|
|
1060
1063
|
if (n === 0) {
|
|
1061
|
-
const
|
|
1062
|
-
e.p1x +=
|
|
1064
|
+
const a = Math.sqrt((e.p1x - e.p0x) ** 2 + (e.p1y - e.p0y) ** 2);
|
|
1065
|
+
e.p1x += a * s, e.p1y += a * i;
|
|
1063
1066
|
} else {
|
|
1064
|
-
const
|
|
1065
|
-
e.p2x +=
|
|
1067
|
+
const a = Math.sqrt((e.p2x - e.p3x) ** 2 + (e.p2y - e.p3y) ** 2);
|
|
1068
|
+
e.p2x += a * s, e.p2y += a * i;
|
|
1066
1069
|
}
|
|
1067
1070
|
}
|
|
1068
|
-
const
|
|
1069
|
-
function
|
|
1070
|
-
for (let t = 0; t <
|
|
1071
|
-
const n =
|
|
1071
|
+
const Xt = [0, 0], Wt = [0, 0];
|
|
1072
|
+
function xe(o) {
|
|
1073
|
+
for (let t = 0; t < o.contours.length; t++) {
|
|
1074
|
+
const n = o.contours[t];
|
|
1072
1075
|
let s = 0;
|
|
1073
|
-
for (let
|
|
1074
|
-
const e = n[
|
|
1076
|
+
for (let i = 0; i < n.length; i++) {
|
|
1077
|
+
const e = n[i];
|
|
1075
1078
|
(e.p0x !== e.endX() || e.p0y !== e.endY()) && (n[s++] = e);
|
|
1076
1079
|
}
|
|
1077
1080
|
n.length = s;
|
|
1078
1081
|
}
|
|
1079
|
-
for (const t of
|
|
1082
|
+
for (const t of o.contours)
|
|
1080
1083
|
if (t.length === 1) {
|
|
1081
|
-
const [n, s,
|
|
1082
|
-
t.length = 0, t.push(n, s,
|
|
1084
|
+
const [n, s, i] = t[0].splitInThirds();
|
|
1085
|
+
t.length = 0, t.push(n, s, i);
|
|
1083
1086
|
} else if (t.length > 0) {
|
|
1084
1087
|
const n = t.length;
|
|
1085
1088
|
for (let s = 0; s < n; s++) {
|
|
1086
|
-
const
|
|
1087
|
-
e.direction(1,
|
|
1088
|
-
const c = Math.sqrt(
|
|
1089
|
+
const i = (s + n - 1) % n, e = t[i], a = t[s];
|
|
1090
|
+
e.direction(1, Xt), a.direction(0, Wt);
|
|
1091
|
+
const c = Math.sqrt(Xt[0] ** 2 + Xt[1] ** 2), r = Math.sqrt(Wt[0] ** 2 + Wt[1] ** 2);
|
|
1089
1092
|
if (c === 0 || r === 0) continue;
|
|
1090
|
-
const h =
|
|
1091
|
-
if (
|
|
1092
|
-
const
|
|
1093
|
-
let
|
|
1094
|
-
const
|
|
1095
|
-
if (
|
|
1096
|
-
|
|
1093
|
+
const h = Xt[0] / c, p = Xt[1] / c, l = Wt[0] / r, f = Wt[1] / r;
|
|
1094
|
+
if (No(h, p, l, f) < no - 1) {
|
|
1095
|
+
const u = no - 1, _ = ue * Math.sqrt(1 - u * u) / u;
|
|
1096
|
+
let y = l - h, g = f - p;
|
|
1097
|
+
const M = Math.sqrt(y * y + g * g);
|
|
1098
|
+
if (M === 0) continue;
|
|
1099
|
+
y = _ * y / M, g = _ * g / M, _e(e, a) < 0 && (y = -y, g = -g), eo(t, i, 1, -g, y), eo(t, s, 0, g, -y);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
const io = 1e-5, ls = 1e-6, ge = 2e4, Me = 1e5;
|
|
1105
|
+
function de(o) {
|
|
1106
|
+
return [o.p0x, o.p0y, o.p1x, o.p1y, o.p2x, o.p2y, o.p3x, o.p3y].slice(0, 2 * o.type + 4);
|
|
1107
|
+
}
|
|
1108
|
+
function co(o) {
|
|
1109
|
+
const t = o.length / 2 - 2;
|
|
1110
|
+
return new et(
|
|
1111
|
+
t,
|
|
1112
|
+
o[0],
|
|
1113
|
+
o[1],
|
|
1114
|
+
o[2],
|
|
1115
|
+
o[3],
|
|
1116
|
+
o[4] ?? 0,
|
|
1117
|
+
o[5] ?? 0,
|
|
1118
|
+
o[6] ?? 0,
|
|
1119
|
+
o[7] ?? 0
|
|
1120
|
+
);
|
|
1121
|
+
}
|
|
1122
|
+
const ot = new Float64Array(8), it = new Float64Array(8), vt = new Float64Array(8);
|
|
1123
|
+
function hs(o, t, n, s) {
|
|
1124
|
+
const i = o.length, e = i / 2 - 1;
|
|
1125
|
+
for (let a = 0; a <= e; a++) {
|
|
1126
|
+
for (let c = 0; c < i; c++) vt[c] = o[c];
|
|
1127
|
+
for (let c = 0, r = i; c < e; c++, r -= 2) {
|
|
1128
|
+
const h = c < e - a ? t : n;
|
|
1129
|
+
for (let p = 0; p < r - 2; p++) vt[p] = vt[p] + h * (vt[p + 2] - vt[p]);
|
|
1130
|
+
}
|
|
1131
|
+
s[2 * a] = vt[0], s[2 * a + 1] = vt[1];
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
function we(o, t, n) {
|
|
1135
|
+
return hs(o, t, n, ot), Array.from(ot.subarray(0, o.length));
|
|
1136
|
+
}
|
|
1137
|
+
let ps = 0, fs = 0, mt = -1, $t = -1, jt = 0, Qt = 0, un = 0, yn = 0;
|
|
1138
|
+
function be(o, t) {
|
|
1139
|
+
mt = -1, $t = -1;
|
|
1140
|
+
let n = 0;
|
|
1141
|
+
for (let p = 0; p < 2; p++) {
|
|
1142
|
+
const l = p ? o.length - 2 : 0;
|
|
1143
|
+
for (let f = 0; f < 2; f++) {
|
|
1144
|
+
const u = f ? t.length - 2 : 0;
|
|
1145
|
+
o[l] === t[u] && o[l + 1] === t[u + 1] && (n++, mt = p, $t = f);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
if (n !== 1) {
|
|
1149
|
+
mt = -1;
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1152
|
+
const s = mt ? o.length - 2 : 0;
|
|
1153
|
+
jt = o[s], Qt = o[s + 1];
|
|
1154
|
+
let i = 0, e = 0;
|
|
1155
|
+
for (let p = 2; p < o.length && i === 0 && e === 0; p += 2) {
|
|
1156
|
+
const l = mt ? o.length - 2 - p : p;
|
|
1157
|
+
i = o[l] - jt, e = o[l + 1] - Qt;
|
|
1158
|
+
}
|
|
1159
|
+
let a = 0, c = 0;
|
|
1160
|
+
for (let p = 2; p < t.length && a === 0 && c === 0; p += 2) {
|
|
1161
|
+
const l = $t ? t.length - 2 - p : p;
|
|
1162
|
+
a = t[l] - jt, c = t[l + 1] - Qt;
|
|
1163
|
+
}
|
|
1164
|
+
const r = Math.hypot(i, e), h = Math.hypot(a, c);
|
|
1165
|
+
un = i / r - a / h, yn = e / r - c / h, Math.hypot(un, yn) > 1e-9 || (mt = -1);
|
|
1166
|
+
}
|
|
1167
|
+
function Ae(o, t) {
|
|
1168
|
+
const n = mt ? o - 2 : 0;
|
|
1169
|
+
for (let i = 0; i < o; i += 2)
|
|
1170
|
+
if (i !== n && (ot[i] - jt) * un + (ot[i + 1] - Qt) * yn <= 0) return !1;
|
|
1171
|
+
const s = $t ? t - 2 : 0;
|
|
1172
|
+
for (let i = 0; i < t; i += 2)
|
|
1173
|
+
if (i !== s && (it[i] - jt) * un + (it[i + 1] - Qt) * yn >= 0) return !1;
|
|
1174
|
+
return !0;
|
|
1175
|
+
}
|
|
1176
|
+
function Kt(o, t, n, s, i, e, a) {
|
|
1177
|
+
if (--ps < 0 || --fs < 0) return;
|
|
1178
|
+
const c = o.length, r = s.length;
|
|
1179
|
+
hs(o, t, n, ot), hs(s, i, e, it);
|
|
1180
|
+
let h = 1 / 0, p = 1 / 0, l = -1 / 0, f = -1 / 0;
|
|
1181
|
+
for (let q = 0; q < c; q += 2)
|
|
1182
|
+
h = Math.min(h, ot[q]), p = Math.min(p, ot[q + 1]), l = Math.max(l, ot[q]), f = Math.max(f, ot[q + 1]);
|
|
1183
|
+
let u = 1 / 0, _ = 1 / 0, y = -1 / 0, g = -1 / 0;
|
|
1184
|
+
for (let q = 0; q < r; q += 2)
|
|
1185
|
+
u = Math.min(u, it[q]), _ = Math.min(_, it[q + 1]), y = Math.max(y, it[q]), g = Math.max(g, it[q + 1]);
|
|
1186
|
+
if (h > y || u > l || p > g || _ > f || mt >= 0 && (mt ? n === 1 : t === 0) && ($t ? e === 1 : i === 0) && Ae(c, r))
|
|
1187
|
+
return;
|
|
1188
|
+
const M = Math.max(l - h, f - p), I = Math.max(y - u, g - _);
|
|
1189
|
+
if (c === 4 && r === 4 || M < io && I < io) {
|
|
1190
|
+
const q = ot[c - 2] - ot[0], T = ot[c - 1] - ot[1], A = it[r - 2] - it[0], D = it[r - 1] - it[1], R = z(q, T, A, D), m = z(it[0] - ot[0], it[1] - ot[1], A, D) / R, d = z(it[0] - ot[0], it[1] - ot[1], q, T) / R;
|
|
1191
|
+
m >= 0 && m <= 1 && d >= 0 && d <= 1 && a.push(t + m * (n - t), i + d * (e - i));
|
|
1192
|
+
} else M > I ? (Kt(o, t, (t + n) / 2, s, i, e, a), Kt(o, (t + n) / 2, n, s, i, e, a)) : (Kt(o, t, n, s, i, (i + e) / 2, a), Kt(o, t, n, s, (i + e) / 2, e, a));
|
|
1193
|
+
}
|
|
1194
|
+
function an(o, t, n) {
|
|
1195
|
+
const s = o[2] - o[0], i = o[3] - o[1];
|
|
1196
|
+
return ((t - o[0]) * s + (n - o[1]) * i) / (s * s + i * i);
|
|
1197
|
+
}
|
|
1198
|
+
function me(o, t, n) {
|
|
1199
|
+
if (o.length !== 4 || t.length !== 4) return !1;
|
|
1200
|
+
const s = o[2] - o[0], i = o[3] - o[1], e = 1e-9 * Math.hypot(s, i);
|
|
1201
|
+
return Math.abs(z(s, i, t[0] - o[0], t[1] - o[1])) > e || Math.abs(z(s, i, t[2] - o[0], t[3] - o[1])) > e ? !1 : (n.push(an(o, t[0], t[1]), 0, an(o, t[2], t[3]), 1), n.push(0, an(t, o[0], o[1]), 1, an(t, o[2], o[3])), !0);
|
|
1202
|
+
}
|
|
1203
|
+
function Ee(o) {
|
|
1204
|
+
const t = [];
|
|
1205
|
+
for (let n = o.length - 2; n >= 0; n -= 2) t.push(o[n], o[n + 1]);
|
|
1206
|
+
return t;
|
|
1207
|
+
}
|
|
1208
|
+
function Ie(o, t) {
|
|
1209
|
+
if (o.length !== t.length) return !1;
|
|
1210
|
+
for (let n = 0; n < o.length; n++) if (!(Math.abs(o[n] - t[n]) < ls)) return !1;
|
|
1211
|
+
return !0;
|
|
1212
|
+
}
|
|
1213
|
+
const Ht = [0, 0], kt = [0, 0], _n = [0, 0, 0], xn = [0, 0, 0];
|
|
1214
|
+
let Ut = new Int32Array(8);
|
|
1215
|
+
const De = 0, qe = 1;
|
|
1216
|
+
function ro(o, t, n, s) {
|
|
1217
|
+
let i = 0;
|
|
1218
|
+
for (let e = 0; e < o.length; e++) {
|
|
1219
|
+
if (s < t[4 * e + 1] - 1e-9 || s > t[4 * e + 3] + 1e-9) continue;
|
|
1220
|
+
const a = o[e].scanlineIntersections(s, _n, xn);
|
|
1221
|
+
for (let c = 0; c < a; c++) _n[c] <= n && (i += xn[c]);
|
|
1222
|
+
}
|
|
1223
|
+
return i !== 0;
|
|
1224
|
+
}
|
|
1225
|
+
function ao(o, t, n, s, i, e, a) {
|
|
1226
|
+
Ut.fill(0, 0, n);
|
|
1227
|
+
for (let r = 0; r < o.length; r++) {
|
|
1228
|
+
if (a < i[4 * r + 1] - 1e-9 || a > i[4 * r + 3] + 1e-9) continue;
|
|
1229
|
+
const h = o[r].scanlineIntersections(a, _n, xn);
|
|
1230
|
+
for (let p = 0; p < h; p++) _n[p] <= e && (Ut[t[r]] += xn[p]);
|
|
1231
|
+
}
|
|
1232
|
+
let c = !1;
|
|
1233
|
+
for (let r = 1; r < n && !c; r++) c = Ut[r] !== 0;
|
|
1234
|
+
return Ut[0] !== 0 && (s === qe ? c : !c);
|
|
1235
|
+
}
|
|
1236
|
+
function ve(o) {
|
|
1237
|
+
const t = ke([o.contours]);
|
|
1238
|
+
t && (o.contours = t);
|
|
1239
|
+
}
|
|
1240
|
+
function ke(o, t = De) {
|
|
1241
|
+
const n = o.flat(), s = n.flat(), i = s.map(de), e = i.length, a = o.length, c = a > 1;
|
|
1242
|
+
Ut.length < a && (Ut = new Int32Array(a));
|
|
1243
|
+
const r = new Float64Array(4 * e), h = new Int32Array(e), p = new Int32Array(e);
|
|
1244
|
+
let l = 0;
|
|
1245
|
+
for (let m = 0; m < a; m++)
|
|
1246
|
+
for (const d of o[m]) {
|
|
1247
|
+
for (let x = 0; x < d.length; x++)
|
|
1248
|
+
h[l + x] = l + (x + 1) % d.length, p[l + x] = m;
|
|
1249
|
+
l += d.length;
|
|
1250
|
+
}
|
|
1251
|
+
for (let m = 0; m < e; m++) {
|
|
1252
|
+
const d = i[m];
|
|
1253
|
+
let x = 1 / 0, C = 1 / 0, v = -1 / 0, E = -1 / 0;
|
|
1254
|
+
for (let k = 0; k < d.length; k += 2)
|
|
1255
|
+
x = Math.min(x, d[k]), C = Math.min(C, d[k + 1]), v = Math.max(v, d[k]), E = Math.max(E, d[k + 1]);
|
|
1256
|
+
r[4 * m] = x, r[4 * m + 1] = C, r[4 * m + 2] = v, r[4 * m + 3] = E;
|
|
1257
|
+
}
|
|
1258
|
+
const f = Array.from({ length: e }, (m, d) => d).sort((m, d) => r[4 * m] - r[4 * d]), u = i.map(() => []), _ = new Uint8Array(e);
|
|
1259
|
+
fs = Me;
|
|
1260
|
+
for (let m = 0; m < e; m++) {
|
|
1261
|
+
const d = f[m];
|
|
1262
|
+
for (let x = m + 1; x < e; x++) {
|
|
1263
|
+
const C = f[x];
|
|
1264
|
+
if (r[4 * C] > r[4 * d + 2]) break;
|
|
1265
|
+
if (r[4 * d + 1] > r[4 * C + 3] || r[4 * C + 1] > r[4 * d + 3]) continue;
|
|
1266
|
+
const v = Math.min(d, C), E = Math.max(d, C);
|
|
1267
|
+
h[v] !== E && h[E] !== v && (_[v] = _[E] = 1);
|
|
1268
|
+
const k = [];
|
|
1269
|
+
if (ps = ge, me(i[v], i[E], k) || (be(i[v], i[E]), Kt(i[v], 0, 1, i[E], 0, 1, k)), ps < 0 || fs < 0) return null;
|
|
1270
|
+
for (let S = 0; S < k.length; S += 2)
|
|
1271
|
+
u[v].push(k[S]), u[E].push(k[S + 1]);
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
const y = u.map((m) => {
|
|
1275
|
+
const d = [0];
|
|
1276
|
+
for (const x of m.sort((C, v) => C - v))
|
|
1277
|
+
x - d[d.length - 1] > 1e-7 && x < 1 - 1e-7 && d.push(x);
|
|
1278
|
+
return d.push(1), d;
|
|
1279
|
+
});
|
|
1280
|
+
let g = !1;
|
|
1281
|
+
const M = [], I = [];
|
|
1282
|
+
let q = 0;
|
|
1283
|
+
for (const m of n) {
|
|
1284
|
+
const d = q + m.length;
|
|
1285
|
+
let x = !0;
|
|
1286
|
+
for (let k = q; k < d; k++) (_[k] || y[k].length > 2) && (x = !1);
|
|
1287
|
+
let C = !1, v = !1, E = !1;
|
|
1288
|
+
for (let k = q; k < d; k++) {
|
|
1289
|
+
const S = y[k];
|
|
1290
|
+
for (let H = 1; H < S.length; H++) {
|
|
1291
|
+
const Y = we(i[k], S[H - 1], S[H]), tt = co(Y);
|
|
1292
|
+
tt.point(0.5, Ht), tt.direction(0.5, kt);
|
|
1293
|
+
const V = Math.hypot(kt[0], kt[1]), K = Math.hypot(Y[Y.length - 2] - Y[0], Y[Y.length - 1] - Y[1]);
|
|
1294
|
+
if (!(V === 0 || K === 0)) {
|
|
1295
|
+
if (!x || !C) {
|
|
1296
|
+
const nt = Math.min(1e-6, K * K / 64) / V, st = Ht[0] + kt[1] * nt, Et = Ht[1] - kt[0] * nt, Tt = Ht[0] - kt[1] * nt, St = Ht[1] + kt[0] * nt;
|
|
1297
|
+
v = c ? ao(s, p, a, t, r, st, Et) : ro(s, r, st, Et), E = c ? ao(s, p, a, t, r, Tt, St) : ro(s, r, Tt, St), C = !0;
|
|
1298
|
+
}
|
|
1299
|
+
v === E ? p[k] === 0 && (g = !0) : (M.push(Y), I.push(v), p[k] !== 0 && (g = !0));
|
|
1097
1300
|
}
|
|
1098
1301
|
}
|
|
1099
1302
|
}
|
|
1303
|
+
q = d;
|
|
1304
|
+
}
|
|
1305
|
+
const T = 2 * I.filter(Boolean).length >= I.length, A = [];
|
|
1306
|
+
for (let m = 0; m < M.length; m++) {
|
|
1307
|
+
let d = M[m];
|
|
1308
|
+
I[m] !== T && (d = Ee(d), g = !0);
|
|
1309
|
+
let x = !1;
|
|
1310
|
+
for (let C = 0; C < A.length && !x; C++) x = Ie(A[C], d);
|
|
1311
|
+
x ? g = !0 : A.push(d);
|
|
1312
|
+
}
|
|
1313
|
+
if (!g) return null;
|
|
1314
|
+
const D = new Uint8Array(A.length), R = [];
|
|
1315
|
+
for (let m = 0; m < A.length; m++) {
|
|
1316
|
+
if (D[m]) continue;
|
|
1317
|
+
D[m] = 1;
|
|
1318
|
+
const d = [A[m]];
|
|
1319
|
+
for (; ; ) {
|
|
1320
|
+
const x = d[d.length - 1], C = x[x.length - 2], v = x[x.length - 1];
|
|
1321
|
+
if (d.length > 1 && Math.hypot(C - d[0][0], v - d[0][1]) < ls) {
|
|
1322
|
+
d[0][0] = C, d[0][1] = v;
|
|
1323
|
+
break;
|
|
1324
|
+
}
|
|
1325
|
+
let E = -1, k = ls;
|
|
1326
|
+
for (let S = 0; S < A.length; S++) {
|
|
1327
|
+
if (D[S]) continue;
|
|
1328
|
+
const H = Math.hypot(A[S][0] - C, A[S][1] - v);
|
|
1329
|
+
H < k && (E = S, k = H);
|
|
1330
|
+
}
|
|
1331
|
+
if (E < 0) return null;
|
|
1332
|
+
D[E] = 1, A[E][0] = C, A[E][1] = v, d.push(A[E]);
|
|
1333
|
+
}
|
|
1334
|
+
R.push(d.map(co));
|
|
1335
|
+
}
|
|
1336
|
+
return R;
|
|
1100
1337
|
}
|
|
1101
|
-
const
|
|
1102
|
-
function
|
|
1103
|
-
return Math.trunc(3 + 2.875 *
|
|
1338
|
+
const Mn = 1, dn = 2, Ce = 3, wn = 4, Fe = 5, Re = 6, ys = 7, at = [0, 0], Ct = [0, 0];
|
|
1339
|
+
function Te(o, t) {
|
|
1340
|
+
return Math.trunc(3 + 2.875 * o / (t - 1) - 1.4375 + 0.5) - 3;
|
|
1104
1341
|
}
|
|
1105
|
-
function
|
|
1106
|
-
return
|
|
1342
|
+
function Se(o, t, n, s, i) {
|
|
1343
|
+
return o * n + t * s <= 0 || Math.abs(o * s - t * n) > i;
|
|
1107
1344
|
}
|
|
1108
|
-
function
|
|
1109
|
-
const t = Number(
|
|
1110
|
-
return
|
|
1345
|
+
function Le(o) {
|
|
1346
|
+
const t = Number(o.v & 1n);
|
|
1347
|
+
return o.v >>= 1n, t;
|
|
1111
1348
|
}
|
|
1112
|
-
function
|
|
1113
|
-
const t = Number(
|
|
1114
|
-
return
|
|
1349
|
+
function Pe(o) {
|
|
1350
|
+
const t = Number(o.v % 3n);
|
|
1351
|
+
return o.v /= 3n, t;
|
|
1115
1352
|
}
|
|
1116
|
-
function
|
|
1117
|
-
return [
|
|
1353
|
+
function lo(o) {
|
|
1354
|
+
return [Re, Fe, Ce][Pe(o)];
|
|
1118
1355
|
}
|
|
1119
|
-
function
|
|
1120
|
-
const n =
|
|
1121
|
-
|
|
1356
|
+
function zt(o, t) {
|
|
1357
|
+
const n = o.v << 1 + Le(t);
|
|
1358
|
+
o.v = (n | n >> 3) & ys;
|
|
1122
1359
|
}
|
|
1123
|
-
function
|
|
1124
|
-
const s =
|
|
1125
|
-
s ===
|
|
1360
|
+
function Oe(o, t, n) {
|
|
1361
|
+
const s = o.v & n;
|
|
1362
|
+
s === Mn || s === dn || s === wn ? o.v = s ^ ys : zt(o, t);
|
|
1126
1363
|
}
|
|
1127
|
-
function
|
|
1128
|
-
const s = Math.sin(t),
|
|
1129
|
-
e.v = n,
|
|
1130
|
-
const
|
|
1131
|
-
for (const c of
|
|
1364
|
+
function Ne(o, t, n = 0n) {
|
|
1365
|
+
const s = Math.sin(t), i = { v: lo({ v: n }) }, e = { v: n };
|
|
1366
|
+
e.v = n, i.v = lo(e);
|
|
1367
|
+
const a = [];
|
|
1368
|
+
for (const c of o.contours) {
|
|
1132
1369
|
if (c.length === 0) continue;
|
|
1133
|
-
|
|
1134
|
-
const h = Math.sqrt(
|
|
1135
|
-
let
|
|
1370
|
+
a.length = 0, c[c.length - 1].direction(1, at);
|
|
1371
|
+
const h = Math.sqrt(at[0] * at[0] + at[1] * at[1]);
|
|
1372
|
+
let p = h > 0 ? at[0] / h : 0, l = h > 0 ? at[1] / h : 0;
|
|
1136
1373
|
for (let f = 0; f < c.length; f++) {
|
|
1137
|
-
const
|
|
1138
|
-
|
|
1139
|
-
const _ = Math.sqrt(
|
|
1140
|
-
|
|
1141
|
-
const
|
|
1142
|
-
|
|
1374
|
+
const u = c[f];
|
|
1375
|
+
u.direction(0, Ct);
|
|
1376
|
+
const _ = Math.sqrt(Ct[0] * Ct[0] + Ct[1] * Ct[1]), y = _ > 0 ? Ct[0] / _ : 0, g = _ > 0 ? Ct[1] / _ : 0;
|
|
1377
|
+
Se(p, l, y, g, s) && a.push(f), u.direction(1, at);
|
|
1378
|
+
const M = Math.sqrt(at[0] * at[0] + at[1] * at[1]);
|
|
1379
|
+
p = M > 0 ? at[0] / M : 0, l = M > 0 ? at[1] / M : 0;
|
|
1143
1380
|
}
|
|
1144
|
-
if (
|
|
1145
|
-
|
|
1146
|
-
for (const f of c) f.color =
|
|
1147
|
-
} else if (
|
|
1148
|
-
const f = [0,
|
|
1149
|
-
|
|
1150
|
-
const
|
|
1381
|
+
if (a.length === 0) {
|
|
1382
|
+
zt(i, e);
|
|
1383
|
+
for (const f of c) f.color = i.v;
|
|
1384
|
+
} else if (a.length === 1) {
|
|
1385
|
+
const f = [0, ys, 0];
|
|
1386
|
+
zt(i, e), f[0] = i.v, zt(i, e), f[2] = i.v;
|
|
1387
|
+
const u = a[0], _ = c.length;
|
|
1151
1388
|
if (_ >= 3)
|
|
1152
|
-
for (let
|
|
1153
|
-
const
|
|
1154
|
-
c[(
|
|
1389
|
+
for (let y = 0; y < _; y++) {
|
|
1390
|
+
const g = Te(y, _);
|
|
1391
|
+
c[(u + y) % _].color = f[1 + g];
|
|
1155
1392
|
}
|
|
1156
1393
|
else if (_ >= 1) {
|
|
1157
|
-
const
|
|
1158
|
-
if (
|
|
1159
|
-
const
|
|
1160
|
-
|
|
1394
|
+
const y = [null, null, null, null, null, null, null], g = c[0].splitInThirds();
|
|
1395
|
+
if (y[0 + 3 * u] = g[0], y[1 + 3 * u] = g[1], y[2 + 3 * u] = g[2], _ >= 2) {
|
|
1396
|
+
const M = c[1].splitInThirds();
|
|
1397
|
+
y[3 - 3 * u] = M[0], y[4 - 3 * u] = M[1], y[5 - 3 * u] = M[2], y[0].color = y[1].color = f[0], y[2].color = y[3].color = f[1], y[4].color = y[5].color = f[2];
|
|
1161
1398
|
} else
|
|
1162
|
-
|
|
1399
|
+
y[0].color = f[0], y[1].color = f[1], y[2].color = f[2];
|
|
1163
1400
|
c.length = 0;
|
|
1164
|
-
for (const
|
|
1401
|
+
for (const M of y) M !== null && c.push(M);
|
|
1165
1402
|
}
|
|
1166
1403
|
} else {
|
|
1167
|
-
const f =
|
|
1168
|
-
let
|
|
1169
|
-
const _ =
|
|
1170
|
-
|
|
1171
|
-
const
|
|
1172
|
-
for (let
|
|
1173
|
-
const
|
|
1174
|
-
|
|
1404
|
+
const f = a.length;
|
|
1405
|
+
let u = 0;
|
|
1406
|
+
const _ = a[0], y = c.length;
|
|
1407
|
+
zt(i, e);
|
|
1408
|
+
const g = i.v;
|
|
1409
|
+
for (let M = 0; M < y; M++) {
|
|
1410
|
+
const I = (_ + M) % y;
|
|
1411
|
+
u + 1 < f && a[u + 1] === I && (++u, Oe(i, e, u === f - 1 ? g : 0)), c[I].color = i.v;
|
|
1175
1412
|
}
|
|
1176
1413
|
}
|
|
1177
1414
|
}
|
|
1178
1415
|
}
|
|
1179
|
-
const
|
|
1180
|
-
let
|
|
1181
|
-
const
|
|
1182
|
-
let
|
|
1183
|
-
function
|
|
1184
|
-
const t =
|
|
1416
|
+
const W = Number.MAX_VALUE, L = [0, 0], _t = [0, 0];
|
|
1417
|
+
let ho = 0, $ = new Float64Array(0), Q = new Float64Array(0), G = new Float64Array(0), U = new Float64Array(0), Z = new Int32Array(0), J = new Float64Array(0), Pt = new Float64Array(0), Ot = new Float64Array(0), Nt = new Float64Array(0), Ft = new Int32Array(0);
|
|
1418
|
+
const j = [0, 0];
|
|
1419
|
+
let po = 0, Vn = new Float64Array(0), Bn = new Float64Array(0), Kn = new Float64Array(0), zn = new Float64Array(0), $n = new Float64Array(0), jn = new Float64Array(0), Qn = new Float64Array(0), Zn = new Float64Array(0), Jn = new Float64Array(0), ts = new Float64Array(0), ns = new Float64Array(0), ss = new Float64Array(0), fo = 0, Vt = new Int32Array(0);
|
|
1420
|
+
function Ge(o) {
|
|
1421
|
+
const t = o.length;
|
|
1185
1422
|
if (t === 0) return 0;
|
|
1186
1423
|
let n = 0;
|
|
1187
1424
|
if (t === 1) {
|
|
1188
|
-
|
|
1189
|
-
const s =
|
|
1190
|
-
|
|
1191
|
-
const e =
|
|
1192
|
-
|
|
1193
|
-
const c =
|
|
1194
|
-
n += s *
|
|
1425
|
+
o[0].point(0, j);
|
|
1426
|
+
const s = j[0], i = j[1];
|
|
1427
|
+
o[0].point(1 / 3, j);
|
|
1428
|
+
const e = j[0], a = j[1];
|
|
1429
|
+
o[0].point(2 / 3, j);
|
|
1430
|
+
const c = j[0], r = j[1];
|
|
1431
|
+
n += s * a - i * e, n += e * r - a * c, n += c * i - r * s;
|
|
1195
1432
|
} else if (t === 2) {
|
|
1196
|
-
|
|
1197
|
-
const s =
|
|
1198
|
-
|
|
1199
|
-
const e =
|
|
1200
|
-
|
|
1201
|
-
const c =
|
|
1202
|
-
|
|
1203
|
-
const h =
|
|
1204
|
-
n += s *
|
|
1433
|
+
o[0].point(0, j);
|
|
1434
|
+
const s = j[0], i = j[1];
|
|
1435
|
+
o[0].point(0.5, j);
|
|
1436
|
+
const e = j[0], a = j[1];
|
|
1437
|
+
o[1].point(0, j);
|
|
1438
|
+
const c = j[0], r = j[1];
|
|
1439
|
+
o[1].point(0.5, j);
|
|
1440
|
+
const h = j[0], p = j[1];
|
|
1441
|
+
n += s * a - i * e, n += e * r - a * c, n += c * p - r * h, n += h * i - p * s;
|
|
1205
1442
|
} else {
|
|
1206
|
-
const s =
|
|
1207
|
-
let
|
|
1208
|
-
for (let
|
|
1209
|
-
const c =
|
|
1210
|
-
n +=
|
|
1443
|
+
const s = o[t - 1];
|
|
1444
|
+
let i = s.p0x, e = s.p0y;
|
|
1445
|
+
for (let a = 0; a < t; a++) {
|
|
1446
|
+
const c = o[a].p0x, r = o[a].p0y;
|
|
1447
|
+
n += i * r - e * c, i = c, e = r;
|
|
1211
1448
|
}
|
|
1212
1449
|
}
|
|
1213
1450
|
return n > 0 ? -1 : n < 0 ? 1 : 0;
|
|
1214
1451
|
}
|
|
1215
|
-
function
|
|
1216
|
-
const c =
|
|
1452
|
+
function Ue(o, t, n, s, i, e, a) {
|
|
1453
|
+
const c = a[o][t];
|
|
1217
1454
|
let r = n;
|
|
1218
1455
|
if (e < 0) {
|
|
1219
|
-
c.direction(0,
|
|
1220
|
-
const h = Math.sqrt(
|
|
1456
|
+
c.direction(0, L);
|
|
1457
|
+
const h = Math.sqrt(L[0] * L[0] + L[1] * L[1]);
|
|
1221
1458
|
if (h > 0) {
|
|
1222
|
-
const
|
|
1223
|
-
c.point(0,
|
|
1224
|
-
const f = s -
|
|
1225
|
-
if (f *
|
|
1226
|
-
const
|
|
1227
|
-
Math.abs(
|
|
1459
|
+
const p = L[0] / h, l = L[1] / h;
|
|
1460
|
+
c.point(0, _t);
|
|
1461
|
+
const f = s - _t[0], u = i - _t[1];
|
|
1462
|
+
if (f * p + u * l < 0) {
|
|
1463
|
+
const y = f * l - u * p;
|
|
1464
|
+
Math.abs(y) <= Math.abs(r) && (r = y);
|
|
1228
1465
|
}
|
|
1229
1466
|
}
|
|
1230
1467
|
}
|
|
1231
1468
|
if (e > 1) {
|
|
1232
|
-
c.direction(1,
|
|
1233
|
-
const h = Math.sqrt(
|
|
1469
|
+
c.direction(1, L);
|
|
1470
|
+
const h = Math.sqrt(L[0] * L[0] + L[1] * L[1]);
|
|
1234
1471
|
if (h > 0) {
|
|
1235
|
-
const
|
|
1236
|
-
c.point(1,
|
|
1237
|
-
const f = s -
|
|
1238
|
-
if (f *
|
|
1239
|
-
const
|
|
1240
|
-
Math.abs(
|
|
1472
|
+
const p = L[0] / h, l = L[1] / h;
|
|
1473
|
+
c.point(1, _t);
|
|
1474
|
+
const f = s - _t[0], u = i - _t[1];
|
|
1475
|
+
if (f * p + u * l > 0) {
|
|
1476
|
+
const y = f * l - u * p;
|
|
1477
|
+
Math.abs(y) <= Math.abs(r) && (r = y);
|
|
1241
1478
|
}
|
|
1242
1479
|
}
|
|
1243
1480
|
}
|
|
1244
1481
|
return r;
|
|
1245
1482
|
}
|
|
1246
|
-
function
|
|
1247
|
-
let h =
|
|
1248
|
-
if (
|
|
1249
|
-
const
|
|
1250
|
-
Math.abs(
|
|
1483
|
+
function ut(o, t, n, s, i, e, a, c, r) {
|
|
1484
|
+
let h = o < 0 ? t : n;
|
|
1485
|
+
if (i >= 0) {
|
|
1486
|
+
const p = Ue(s, i, o, a, c, e, r);
|
|
1487
|
+
Math.abs(p) < Math.abs(h) && (h = p);
|
|
1251
1488
|
}
|
|
1252
1489
|
return h;
|
|
1253
1490
|
}
|
|
1254
|
-
function
|
|
1255
|
-
return Math.max(Math.min(
|
|
1491
|
+
function dt(o, t, n) {
|
|
1492
|
+
return Math.max(Math.min(o, t), Math.min(Math.max(o, t), n));
|
|
1256
1493
|
}
|
|
1257
|
-
function
|
|
1494
|
+
function Ye(o, t, n, s, i, e, a, c) {
|
|
1258
1495
|
if (c.length !== t * n * 3)
|
|
1259
1496
|
throw new Error(`generateMSDF: out.length ${c.length} !== ${t * n * 3}`);
|
|
1260
|
-
const r =
|
|
1497
|
+
const r = o.contours, h = r.length;
|
|
1261
1498
|
if (h === 0) {
|
|
1262
1499
|
c.fill(0);
|
|
1263
1500
|
return;
|
|
1264
1501
|
}
|
|
1265
|
-
const
|
|
1266
|
-
|
|
1267
|
-
for (let
|
|
1268
|
-
|
|
1269
|
-
let
|
|
1270
|
-
for (let
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
for (let
|
|
1274
|
-
const _ = r[
|
|
1275
|
-
for (let
|
|
1276
|
-
const
|
|
1277
|
-
|
|
1278
|
-
let
|
|
1279
|
-
const
|
|
1280
|
-
|
|
1281
|
-
const
|
|
1282
|
-
|
|
1283
|
-
const
|
|
1284
|
-
|
|
1285
|
-
const
|
|
1286
|
-
|
|
1287
|
-
const
|
|
1288
|
-
|
|
1502
|
+
const p = s / a;
|
|
1503
|
+
Ft.length < h && (Ft = new Int32Array(h));
|
|
1504
|
+
for (let u = 0; u < h; u++) Ft[u] = Ge(r[u]);
|
|
1505
|
+
fo < h + 1 && (Vt = new Int32Array(h + 1), fo = h + 1);
|
|
1506
|
+
let l = 0;
|
|
1507
|
+
for (let u = 0; u < h; u++)
|
|
1508
|
+
Vt[u] = l, l += r[u].length;
|
|
1509
|
+
Vt[h] = l, po < l && (Vn = new Float64Array(l), Bn = new Float64Array(l), Kn = new Float64Array(l), zn = new Float64Array(l), $n = new Float64Array(l), jn = new Float64Array(l), Qn = new Float64Array(l), Zn = new Float64Array(l), Jn = new Float64Array(l), ts = new Float64Array(l), ns = new Float64Array(l), ss = new Float64Array(l), po = l);
|
|
1510
|
+
for (let u = 0; u < h; u++) {
|
|
1511
|
+
const _ = r[u], y = _.length, g = Vt[u];
|
|
1512
|
+
for (let M = 0; M < y; M++) {
|
|
1513
|
+
const I = _[M], q = _[(M + y - 1) % y], T = _[(M + 1) % y], A = g + M;
|
|
1514
|
+
I.point(0, _t), Vn[A] = _t[0], Bn[A] = _t[1], I.point(1, _t), Kn[A] = _t[0], zn[A] = _t[1], I.direction(0, L);
|
|
1515
|
+
let D = Math.sqrt(L[0] * L[0] + L[1] * L[1]);
|
|
1516
|
+
const R = D > 0 ? L[0] / D : 0, m = D > 0 ? L[1] / D : 0;
|
|
1517
|
+
$n[A] = R, jn[A] = m, I.direction(1, L), D = Math.sqrt(L[0] * L[0] + L[1] * L[1]);
|
|
1518
|
+
const d = D > 0 ? L[0] / D : 0, x = D > 0 ? L[1] / D : 0;
|
|
1519
|
+
Qn[A] = d, Zn[A] = x, q.direction(1, L), D = Math.sqrt(L[0] * L[0] + L[1] * L[1]);
|
|
1520
|
+
const C = D > 0 ? L[0] / D : 0, v = D > 0 ? L[1] / D : 0;
|
|
1521
|
+
T.direction(0, L), D = Math.sqrt(L[0] * L[0] + L[1] * L[1]);
|
|
1522
|
+
const E = D > 0 ? L[0] / D : 0, k = D > 0 ? L[1] / D : 0, S = C + R, H = v + m, Y = Math.sqrt(S * S + H * H);
|
|
1523
|
+
Jn[A] = Y > 0 ? S / Y : 0, ts[A] = Y > 0 ? H / Y : 0;
|
|
1524
|
+
const tt = d + E, V = x + k, K = Math.sqrt(tt * tt + V * V);
|
|
1525
|
+
ns[A] = K > 0 ? -(tt / K) : 0, ss[A] = K > 0 ? -(V / K) : 0;
|
|
1289
1526
|
}
|
|
1290
1527
|
}
|
|
1291
|
-
if (
|
|
1292
|
-
const
|
|
1293
|
-
|
|
1528
|
+
if (ho < h) {
|
|
1529
|
+
const u = h * 3;
|
|
1530
|
+
$ = new Float64Array(u), Q = new Float64Array(u), G = new Float64Array(u), U = new Float64Array(u), Z = new Int32Array(u), J = new Float64Array(u), Pt = new Float64Array(h), Ot = new Float64Array(h), Nt = new Float64Array(h), ho = h;
|
|
1294
1531
|
}
|
|
1295
1532
|
const f = { distance: 0, dot: 0, param: 0 };
|
|
1296
|
-
for (let
|
|
1533
|
+
for (let u = 0; u < n; u++)
|
|
1297
1534
|
for (let _ = 0; _ < t; _++) {
|
|
1298
|
-
const
|
|
1299
|
-
for (let
|
|
1300
|
-
const
|
|
1301
|
-
|
|
1302
|
-
for (let
|
|
1303
|
-
const
|
|
1304
|
-
|
|
1305
|
-
const
|
|
1306
|
-
if (
|
|
1307
|
-
const
|
|
1308
|
-
(
|
|
1535
|
+
const y = (_ + 0.5) / s - i, g = (u + 0.5) / s - e;
|
|
1536
|
+
for (let F = 0; F < h; F++) {
|
|
1537
|
+
const b = r[F], ht = b.length, w = F * 3, O = Vt[F];
|
|
1538
|
+
$[w] = $[w + 1] = $[w + 2] = -W, Q[w] = Q[w + 1] = Q[w + 2] = 0, G[w] = G[w + 1] = G[w + 2] = -W, U[w] = U[w + 1] = U[w + 2] = W, Z[w] = Z[w + 1] = Z[w + 2] = -1, J[w] = J[w + 1] = J[w + 2] = 0;
|
|
1539
|
+
for (let N = 0; N < ht; N++) {
|
|
1540
|
+
const B = b[N], Pn = B.color, On = (Pn & Mn) !== 0, Nn = (Pn & dn) !== 0, Gn = (Pn & wn) !== 0;
|
|
1541
|
+
B.signedDistance(y, g, f);
|
|
1542
|
+
const cn = f.distance, Lt = f.dot, Un = f.param, It = Math.abs(cn);
|
|
1543
|
+
if (On) {
|
|
1544
|
+
const bt = Math.abs($[w]);
|
|
1545
|
+
(It < bt || It === bt && Lt < Q[w]) && ($[w] = cn, Q[w] = Lt, Z[w] = N, J[w] = Un);
|
|
1309
1546
|
}
|
|
1310
|
-
if (
|
|
1311
|
-
const
|
|
1312
|
-
(
|
|
1547
|
+
if (Nn) {
|
|
1548
|
+
const bt = Math.abs($[w + 1]);
|
|
1549
|
+
(It < bt || It === bt && Lt < Q[w + 1]) && ($[w + 1] = cn, Q[w + 1] = Lt, Z[w + 1] = N, J[w + 1] = Un);
|
|
1313
1550
|
}
|
|
1314
|
-
if (
|
|
1315
|
-
const
|
|
1316
|
-
(
|
|
1551
|
+
if (Gn) {
|
|
1552
|
+
const bt = Math.abs($[w + 2]);
|
|
1553
|
+
(It < bt || It === bt && Lt < Q[w + 2]) && ($[w + 2] = cn, Q[w + 2] = Lt, Z[w + 2] = N, J[w + 2] = Un);
|
|
1317
1554
|
}
|
|
1318
|
-
const
|
|
1319
|
-
if (
|
|
1320
|
-
const
|
|
1321
|
-
Math.abs(
|
|
1555
|
+
const ft = O + N, Yn = y - Vn[ft], Xn = g - Bn[ft], Wn = y - Kn[ft], Hn = g - zn[ft], Vs = $n[ft], Bs = jn[ft], Ks = Qn[ft], zs = Zn[ft], vo = Yn * Jn[ft] + Xn * ts[ft], ko = Wn * ns[ft] + Hn * ss[ft];
|
|
1556
|
+
if (vo > 0 && -(Yn * Vs + Xn * Bs) > 0) {
|
|
1557
|
+
const P = Yn * Bs - Xn * Vs;
|
|
1558
|
+
Math.abs(P) < It && (On && (P <= 0 && P > G[w] ? G[w] = P : P > 0 && P < U[w] && (U[w] = P)), Nn && (P <= 0 && P > G[w + 1] ? G[w + 1] = P : P > 0 && P < U[w + 1] && (U[w + 1] = P)), Gn && (P <= 0 && P > G[w + 2] ? G[w + 2] = P : P > 0 && P < U[w + 2] && (U[w + 2] = P)));
|
|
1322
1559
|
}
|
|
1323
|
-
if (
|
|
1324
|
-
const
|
|
1325
|
-
Math.abs(
|
|
1560
|
+
if (ko > 0 && Wn * Ks + Hn * zs > 0) {
|
|
1561
|
+
const P = Wn * zs - Hn * Ks;
|
|
1562
|
+
Math.abs(P) < It && (On && (P <= 0 && P > G[w] ? G[w] = P : P > 0 && P < U[w] && (U[w] = P)), Nn && (P <= 0 && P > G[w + 1] ? G[w + 1] = P : P > 0 && P < U[w + 1] && (U[w + 1] = P)), Gn && (P <= 0 && P > G[w + 2] ? G[w + 2] = P : P > 0 && P < U[w + 2] && (U[w + 2] = P)));
|
|
1326
1563
|
}
|
|
1327
1564
|
}
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
Z[
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1565
|
+
Pt[F] = ut(
|
|
1566
|
+
$[w],
|
|
1567
|
+
G[w],
|
|
1568
|
+
U[w],
|
|
1569
|
+
F,
|
|
1570
|
+
Z[w],
|
|
1571
|
+
J[w],
|
|
1572
|
+
y,
|
|
1573
|
+
g,
|
|
1337
1574
|
r
|
|
1338
|
-
),
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
Z[
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1575
|
+
), Ot[F] = ut(
|
|
1576
|
+
$[w + 1],
|
|
1577
|
+
G[w + 1],
|
|
1578
|
+
U[w + 1],
|
|
1579
|
+
F,
|
|
1580
|
+
Z[w + 1],
|
|
1581
|
+
J[w + 1],
|
|
1582
|
+
y,
|
|
1583
|
+
g,
|
|
1347
1584
|
r
|
|
1348
|
-
),
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
Z[
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1585
|
+
), Nt[F] = ut(
|
|
1586
|
+
$[w + 2],
|
|
1587
|
+
G[w + 2],
|
|
1588
|
+
U[w + 2],
|
|
1589
|
+
F,
|
|
1590
|
+
Z[w + 2],
|
|
1591
|
+
J[w + 2],
|
|
1592
|
+
y,
|
|
1593
|
+
g,
|
|
1357
1594
|
r
|
|
1358
1595
|
);
|
|
1359
1596
|
}
|
|
1360
|
-
let
|
|
1361
|
-
for (let
|
|
1362
|
-
const
|
|
1597
|
+
let M = -W, I = 0, q = -W, T = W, A = -1, D = -1, R = 0, m = -W, d = 0, x = -W, C = W, v = -1, E = -1, k = 0, S = -W, H = 0, Y = -W, tt = W, V = -1, K = -1, nt = 0, st = -W, Et = 0, Tt = -W, St = W, xs = -1, gs = -1, Ms = 0, Zt = -W, ds = 0, bn = -W, An = W, ws = -1, bs = -1, As = 0, Jt = -W, ms = 0, mn = -W, En = W, Es = -1, Is = -1, Ds = 0, tn = -W, qs = 0, In = -W, Dn = W, vs = -1, ks = -1, Cs = 0, nn = -W, Fs = 0, qn = -W, vn = W, Rs = -1, Ts = -1, Ss = 0, sn = -W, Ls = 0, kn = -W, Cn = W, Ps = -1, Os = -1, Ns = 0;
|
|
1598
|
+
for (let F = 0; F < h; F++) {
|
|
1599
|
+
const b = F * 3, ht = Ft[F], w = dt(Pt[F], Ot[F], Nt[F]);
|
|
1363
1600
|
{
|
|
1364
|
-
const
|
|
1365
|
-
(
|
|
1601
|
+
const O = $[b], N = Q[b], B = Math.abs(O);
|
|
1602
|
+
(B < Math.abs(M) || B === Math.abs(M) && N < I) && (M = O, I = N, A = F, D = Z[b], R = J[b]), G[b] > q && (q = G[b]), U[b] < T && (T = U[b]);
|
|
1366
1603
|
}
|
|
1367
1604
|
{
|
|
1368
|
-
const
|
|
1369
|
-
(
|
|
1605
|
+
const O = $[b + 1], N = Q[b + 1], B = Math.abs(O);
|
|
1606
|
+
(B < Math.abs(m) || B === Math.abs(m) && N < d) && (m = O, d = N, v = F, E = Z[b + 1], k = J[b + 1]), G[b + 1] > x && (x = G[b + 1]), U[b + 1] < C && (C = U[b + 1]);
|
|
1370
1607
|
}
|
|
1371
1608
|
{
|
|
1372
|
-
const
|
|
1373
|
-
(
|
|
1609
|
+
const O = $[b + 2], N = Q[b + 2], B = Math.abs(O);
|
|
1610
|
+
(B < Math.abs(S) || B === Math.abs(S) && N < H) && (S = O, H = N, V = F, K = Z[b + 2], nt = J[b + 2]), G[b + 2] > Y && (Y = G[b + 2]), U[b + 2] < tt && (tt = U[b + 2]);
|
|
1374
1611
|
}
|
|
1375
|
-
if (
|
|
1612
|
+
if (ht > 0 && w >= 0) {
|
|
1376
1613
|
{
|
|
1377
|
-
const
|
|
1378
|
-
(
|
|
1614
|
+
const O = $[b], N = Q[b], B = Math.abs(O);
|
|
1615
|
+
(B < Math.abs(st) || B === Math.abs(st) && N < Et) && (st = O, Et = N, xs = F, gs = Z[b], Ms = J[b]), G[b] > Tt && (Tt = G[b]), U[b] < St && (St = U[b]);
|
|
1379
1616
|
}
|
|
1380
1617
|
{
|
|
1381
|
-
const
|
|
1382
|
-
(
|
|
1618
|
+
const O = $[b + 1], N = Q[b + 1], B = Math.abs(O);
|
|
1619
|
+
(B < Math.abs(Zt) || B === Math.abs(Zt) && N < ds) && (Zt = O, ds = N, ws = F, bs = Z[b + 1], As = J[b + 1]), G[b + 1] > bn && (bn = G[b + 1]), U[b + 1] < An && (An = U[b + 1]);
|
|
1383
1620
|
}
|
|
1384
1621
|
{
|
|
1385
|
-
const
|
|
1386
|
-
(
|
|
1622
|
+
const O = $[b + 2], N = Q[b + 2], B = Math.abs(O);
|
|
1623
|
+
(B < Math.abs(Jt) || B === Math.abs(Jt) && N < ms) && (Jt = O, ms = N, Es = F, Is = Z[b + 2], Ds = J[b + 2]), G[b + 2] > mn && (mn = G[b + 2]), U[b + 2] < En && (En = U[b + 2]);
|
|
1387
1624
|
}
|
|
1388
1625
|
}
|
|
1389
|
-
if (
|
|
1626
|
+
if (ht < 0 && w <= 0) {
|
|
1390
1627
|
{
|
|
1391
|
-
const
|
|
1392
|
-
(
|
|
1628
|
+
const O = $[b], N = Q[b], B = Math.abs(O);
|
|
1629
|
+
(B < Math.abs(tn) || B === Math.abs(tn) && N < qs) && (tn = O, qs = N, vs = F, ks = Z[b], Cs = J[b]), G[b] > In && (In = G[b]), U[b] < Dn && (Dn = U[b]);
|
|
1393
1630
|
}
|
|
1394
1631
|
{
|
|
1395
|
-
const
|
|
1396
|
-
(
|
|
1632
|
+
const O = $[b + 1], N = Q[b + 1], B = Math.abs(O);
|
|
1633
|
+
(B < Math.abs(nn) || B === Math.abs(nn) && N < Fs) && (nn = O, Fs = N, Rs = F, Ts = Z[b + 1], Ss = J[b + 1]), G[b + 1] > qn && (qn = G[b + 1]), U[b + 1] < vn && (vn = U[b + 1]);
|
|
1397
1634
|
}
|
|
1398
1635
|
{
|
|
1399
|
-
const
|
|
1400
|
-
(
|
|
1636
|
+
const O = $[b + 2], N = Q[b + 2], B = Math.abs(O);
|
|
1637
|
+
(B < Math.abs(sn) || B === Math.abs(sn) && N < Ls) && (sn = O, Ls = N, Ps = F, Os = Z[b + 2], Ns = J[b + 2]), G[b + 2] > kn && (kn = G[b + 2]), U[b + 2] < Cn && (Cn = U[b + 2]);
|
|
1401
1638
|
}
|
|
1402
1639
|
}
|
|
1403
1640
|
}
|
|
1404
|
-
const
|
|
1641
|
+
const Fn = ut(
|
|
1642
|
+
M,
|
|
1643
|
+
q,
|
|
1644
|
+
T,
|
|
1645
|
+
A,
|
|
1646
|
+
D,
|
|
1647
|
+
R,
|
|
1648
|
+
y,
|
|
1405
1649
|
g,
|
|
1650
|
+
r
|
|
1651
|
+
), Rn = ut(
|
|
1406
1652
|
m,
|
|
1653
|
+
x,
|
|
1654
|
+
C,
|
|
1407
1655
|
v,
|
|
1408
|
-
w,
|
|
1409
1656
|
E,
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
r
|
|
1414
|
-
), xn = lt(
|
|
1415
|
-
F,
|
|
1416
|
-
b,
|
|
1417
|
-
N,
|
|
1418
|
-
I,
|
|
1419
|
-
q,
|
|
1420
|
-
O,
|
|
1421
|
-
u,
|
|
1422
|
-
x,
|
|
1657
|
+
k,
|
|
1658
|
+
y,
|
|
1659
|
+
g,
|
|
1423
1660
|
r
|
|
1424
|
-
),
|
|
1425
|
-
|
|
1661
|
+
), Tn = ut(
|
|
1662
|
+
S,
|
|
1663
|
+
Y,
|
|
1664
|
+
tt,
|
|
1426
1665
|
V,
|
|
1666
|
+
K,
|
|
1427
1667
|
nt,
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
ht,
|
|
1431
|
-
u,
|
|
1432
|
-
x,
|
|
1668
|
+
y,
|
|
1669
|
+
g,
|
|
1433
1670
|
r
|
|
1434
|
-
),
|
|
1671
|
+
), qo = dt(Fn, Rn, Tn), Gs = ut(
|
|
1435
1672
|
st,
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1673
|
+
Tt,
|
|
1674
|
+
St,
|
|
1675
|
+
xs,
|
|
1676
|
+
gs,
|
|
1677
|
+
Ms,
|
|
1678
|
+
y,
|
|
1679
|
+
g,
|
|
1443
1680
|
r
|
|
1444
|
-
),
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1681
|
+
), Us = ut(
|
|
1682
|
+
Zt,
|
|
1683
|
+
bn,
|
|
1684
|
+
An,
|
|
1685
|
+
ws,
|
|
1686
|
+
bs,
|
|
1687
|
+
As,
|
|
1688
|
+
y,
|
|
1689
|
+
g,
|
|
1453
1690
|
r
|
|
1454
|
-
),
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1691
|
+
), Ys = ut(
|
|
1692
|
+
Jt,
|
|
1693
|
+
mn,
|
|
1694
|
+
En,
|
|
1695
|
+
Es,
|
|
1696
|
+
Is,
|
|
1697
|
+
Ds,
|
|
1698
|
+
y,
|
|
1699
|
+
g,
|
|
1463
1700
|
r
|
|
1464
|
-
),
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1701
|
+
), on = dt(Gs, Us, Ys), Xs = ut(
|
|
1702
|
+
tn,
|
|
1703
|
+
In,
|
|
1704
|
+
Dn,
|
|
1705
|
+
vs,
|
|
1706
|
+
ks,
|
|
1707
|
+
Cs,
|
|
1708
|
+
y,
|
|
1709
|
+
g,
|
|
1473
1710
|
r
|
|
1474
|
-
),
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1711
|
+
), Ws = ut(
|
|
1712
|
+
nn,
|
|
1713
|
+
qn,
|
|
1714
|
+
vn,
|
|
1715
|
+
Rs,
|
|
1716
|
+
Ts,
|
|
1717
|
+
Ss,
|
|
1718
|
+
y,
|
|
1719
|
+
g,
|
|
1483
1720
|
r
|
|
1484
|
-
),
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1721
|
+
), Hs = ut(
|
|
1722
|
+
sn,
|
|
1723
|
+
kn,
|
|
1724
|
+
Cn,
|
|
1725
|
+
Ps,
|
|
1726
|
+
Os,
|
|
1727
|
+
Ns,
|
|
1728
|
+
y,
|
|
1729
|
+
g,
|
|
1493
1730
|
r
|
|
1494
|
-
),
|
|
1495
|
-
let
|
|
1496
|
-
if (
|
|
1497
|
-
|
|
1498
|
-
for (let
|
|
1499
|
-
if (
|
|
1500
|
-
const
|
|
1501
|
-
Math.abs(
|
|
1731
|
+
), en = dt(Xs, Ws, Hs);
|
|
1732
|
+
let xt, gt, Mt, Sn = 0;
|
|
1733
|
+
if (on >= 0 && Math.abs(on) <= Math.abs(en)) {
|
|
1734
|
+
xt = Gs, gt = Us, Mt = Ys, Sn = 1;
|
|
1735
|
+
for (let F = 0; F < h; F++)
|
|
1736
|
+
if (Ft[F] > 0) {
|
|
1737
|
+
const b = Pt[F], ht = Ot[F], w = Nt[F], O = dt(b, ht, w);
|
|
1738
|
+
Math.abs(O) < Math.abs(en) && O > dt(xt, gt, Mt) && (xt = b, gt = ht, Mt = w);
|
|
1502
1739
|
}
|
|
1503
|
-
} else if (
|
|
1504
|
-
|
|
1505
|
-
for (let
|
|
1506
|
-
if (
|
|
1507
|
-
const
|
|
1508
|
-
Math.abs(
|
|
1740
|
+
} else if (en <= 0 && Math.abs(en) < Math.abs(on)) {
|
|
1741
|
+
xt = Xs, gt = Ws, Mt = Hs, Sn = -1;
|
|
1742
|
+
for (let F = 0; F < h; F++)
|
|
1743
|
+
if (Ft[F] < 0) {
|
|
1744
|
+
const b = Pt[F], ht = Ot[F], w = Nt[F], O = dt(b, ht, w);
|
|
1745
|
+
Math.abs(O) < Math.abs(on) && O < dt(xt, gt, Mt) && (xt = b, gt = ht, Mt = w);
|
|
1509
1746
|
}
|
|
1510
1747
|
} else {
|
|
1511
|
-
const
|
|
1512
|
-
c[
|
|
1748
|
+
const F = (u * t + _) * 3;
|
|
1749
|
+
c[F + 0] = Fn * p + 0.5, c[F + 1] = Rn * p + 0.5, c[F + 2] = Tn * p + 0.5;
|
|
1513
1750
|
continue;
|
|
1514
1751
|
}
|
|
1515
|
-
for (let
|
|
1516
|
-
if (
|
|
1517
|
-
const
|
|
1518
|
-
|
|
1752
|
+
for (let F = 0; F < h; F++)
|
|
1753
|
+
if (Ft[F] !== Sn) {
|
|
1754
|
+
const b = Pt[F], ht = Ot[F], w = Nt[F], O = dt(b, ht, w), N = dt(xt, gt, Mt);
|
|
1755
|
+
O * N >= 0 && Math.abs(O) < Math.abs(N) && (xt = b, gt = ht, Mt = w);
|
|
1519
1756
|
}
|
|
1520
|
-
|
|
1521
|
-
const
|
|
1522
|
-
c[
|
|
1757
|
+
dt(xt, gt, Mt) === qo && (xt = Fn, gt = Rn, Mt = Tn);
|
|
1758
|
+
const Ln = (u * t + _) * 3;
|
|
1759
|
+
c[Ln + 0] = xt * p + 0.5, c[Ln + 1] = gt * p + 0.5, c[Ln + 2] = Mt * p + 0.5;
|
|
1523
1760
|
}
|
|
1524
1761
|
}
|
|
1525
|
-
const
|
|
1526
|
-
function
|
|
1762
|
+
const mo = 0, Xe = 1, We = 2, He = 3;
|
|
1763
|
+
function Ve(o, t) {
|
|
1527
1764
|
switch (t) {
|
|
1528
|
-
case
|
|
1529
|
-
return
|
|
1530
|
-
case
|
|
1531
|
-
return (
|
|
1532
|
-
case
|
|
1533
|
-
return
|
|
1534
|
-
case
|
|
1535
|
-
return
|
|
1765
|
+
case mo:
|
|
1766
|
+
return o !== 0;
|
|
1767
|
+
case Xe:
|
|
1768
|
+
return (o & 1) !== 0;
|
|
1769
|
+
case We:
|
|
1770
|
+
return o > 0;
|
|
1771
|
+
case He:
|
|
1772
|
+
return o < 0;
|
|
1536
1773
|
}
|
|
1537
1774
|
return !1;
|
|
1538
1775
|
}
|
|
1539
|
-
class
|
|
1776
|
+
class Be {
|
|
1540
1777
|
constructor() {
|
|
1541
1778
|
this._intersections = [], this._lastIndex = 0;
|
|
1542
1779
|
}
|
|
@@ -1548,7 +1785,7 @@ class he {
|
|
|
1548
1785
|
*/
|
|
1549
1786
|
setIntersections(t) {
|
|
1550
1787
|
if (this._intersections = t, this._lastIndex = 0, t.length > 0) {
|
|
1551
|
-
t.sort((s,
|
|
1788
|
+
t.sort((s, i) => pt(s.x - i.x));
|
|
1552
1789
|
let n = 0;
|
|
1553
1790
|
for (let s = 0; s < t.length; s++)
|
|
1554
1791
|
n += t[s].direction, t[s].direction = n;
|
|
@@ -1592,298 +1829,326 @@ class he {
|
|
|
1592
1829
|
* @returns True when filled.
|
|
1593
1830
|
*/
|
|
1594
1831
|
filled(t, n) {
|
|
1595
|
-
return
|
|
1832
|
+
return Ve(this.sumIntersections(t), n);
|
|
1596
1833
|
}
|
|
1597
1834
|
}
|
|
1598
|
-
const
|
|
1599
|
-
function
|
|
1835
|
+
const uo = [0, 0, 0], yo = [0, 0, 0];
|
|
1836
|
+
function Ke(o, t, n) {
|
|
1600
1837
|
const s = [];
|
|
1601
|
-
for (const
|
|
1602
|
-
for (const e of
|
|
1603
|
-
const
|
|
1604
|
-
for (let c = 0; c <
|
|
1605
|
-
s.push({ x:
|
|
1838
|
+
for (const i of o.contours)
|
|
1839
|
+
for (const e of i) {
|
|
1840
|
+
const a = e.scanlineIntersections(t, uo, yo);
|
|
1841
|
+
for (let c = 0; c < a; c++)
|
|
1842
|
+
s.push({ x: uo[c], direction: yo[c] });
|
|
1606
1843
|
}
|
|
1607
1844
|
n.setIntersections(s);
|
|
1608
1845
|
}
|
|
1609
|
-
const
|
|
1610
|
-
function
|
|
1846
|
+
const Yt = 2, Eo = 1, os = 1.001, ze = 1.1111111111111112, gn = 0.01;
|
|
1847
|
+
function $e(o, t, n, s, i, e, a) {
|
|
1611
1848
|
if (n === 0 || s === 0) return;
|
|
1612
|
-
const c = new
|
|
1849
|
+
const c = new Be(), r = new Int8Array(n * s);
|
|
1613
1850
|
for (let h = 0; h < s; h++) {
|
|
1614
|
-
const
|
|
1615
|
-
|
|
1616
|
-
for (let
|
|
1617
|
-
const f = (
|
|
1618
|
-
|
|
1851
|
+
const p = (h + 0.5) / i - a;
|
|
1852
|
+
Ke(t, p, c);
|
|
1853
|
+
for (let l = 0; l < n; l++) {
|
|
1854
|
+
const f = (l + 0.5) / i - e, u = c.filled(f, mo), _ = (h * n + l) * 3, y = o[_], g = o[_ + 1], M = o[_ + 2], I = rt(y, g, M), q = h * n + l;
|
|
1855
|
+
I === 0.5 ? r[q] = 0 : I > 0.5 !== u ? (o[_] = 1 - y, o[_ + 1] = 1 - g, o[_ + 2] = 1 - M, r[q] = -1) : r[q] = 1;
|
|
1619
1856
|
}
|
|
1620
1857
|
}
|
|
1621
1858
|
for (let h = 0; h < s; h++)
|
|
1622
|
-
for (let
|
|
1623
|
-
const
|
|
1624
|
-
if (r[
|
|
1859
|
+
for (let p = 0; p < n; p++) {
|
|
1860
|
+
const l = h * n + p;
|
|
1861
|
+
if (r[l] !== 0) continue;
|
|
1625
1862
|
let f = 0;
|
|
1626
|
-
if (
|
|
1627
|
-
const
|
|
1628
|
-
|
|
1863
|
+
if (p > 0 && (f += r[l - 1]), p < n - 1 && (f += r[l + 1]), h > 0 && (f += r[l - n]), h < s - 1 && (f += r[l + n]), f < 0) {
|
|
1864
|
+
const u = (h * n + p) * 3;
|
|
1865
|
+
o[u] = 1 - o[u], o[u + 1] = 1 - o[u + 1], o[u + 2] = 1 - o[u + 2];
|
|
1629
1866
|
}
|
|
1630
1867
|
}
|
|
1631
1868
|
}
|
|
1632
|
-
const
|
|
1633
|
-
function
|
|
1869
|
+
const es = [0, 0];
|
|
1870
|
+
function je(o, t, n, s, i, e, a, c) {
|
|
1634
1871
|
const r = new Uint8Array(n * s);
|
|
1635
|
-
|
|
1872
|
+
Qe(r, t, n, s, i, e, a), Ze(r, o, n, s, i, c), si(r, o, n, s, c, ze), oi(r, o, n, s);
|
|
1636
1873
|
}
|
|
1637
|
-
function
|
|
1874
|
+
function Qe(o, t, n, s, i, e, a) {
|
|
1638
1875
|
for (const c of t.contours) {
|
|
1639
1876
|
if (c.length === 0) continue;
|
|
1640
1877
|
let r = c[c.length - 1];
|
|
1641
1878
|
for (const h of c) {
|
|
1642
|
-
const
|
|
1643
|
-
if (!(
|
|
1644
|
-
h.point(0,
|
|
1645
|
-
const
|
|
1646
|
-
|
|
1879
|
+
const p = r.color & h.color;
|
|
1880
|
+
if (!(p & p - 1)) {
|
|
1881
|
+
h.point(0, es);
|
|
1882
|
+
const l = i * (es[0] + e), f = i * (es[1] + a), u = Math.floor(l - 0.5) | 0, _ = Math.floor(f - 0.5) | 0, y = u + 1, g = _ + 1;
|
|
1883
|
+
u < n && _ < s && y >= 0 && g >= 0 && (u >= 0 && _ >= 0 && (o[_ * n + u] |= Yt), y < n && _ >= 0 && (o[_ * n + y] |= Yt), u >= 0 && g < s && (o[g * n + u] |= Yt), y < n && g < s && (o[g * n + y] |= Yt));
|
|
1647
1884
|
}
|
|
1648
1885
|
r = h;
|
|
1649
1886
|
}
|
|
1650
1887
|
}
|
|
1651
1888
|
}
|
|
1652
|
-
function
|
|
1889
|
+
function ln(o, t, n) {
|
|
1653
1890
|
let s = 0;
|
|
1654
|
-
for (let
|
|
1655
|
-
const e =
|
|
1891
|
+
for (let i = 0; i < 3; i++) {
|
|
1892
|
+
const e = o[t + i], a = o[n + i], c = e - a;
|
|
1656
1893
|
if (c === 0) continue;
|
|
1657
1894
|
const r = (e - 0.5) / c;
|
|
1658
1895
|
if (r > 0 && r < 1) {
|
|
1659
|
-
const h = 1 - r,
|
|
1660
|
-
|
|
1896
|
+
const h = 1 - r, p = h * o[t] + r * o[n], l = h * o[t + 1] + r * o[n + 1], f = h * o[t + 2] + r * o[n + 2], u = i === 0 ? p : i === 1 ? l : f;
|
|
1897
|
+
rt(p, l, f) === u && (s |= i === 0 ? Mn : i === 1 ? dn : wn);
|
|
1661
1898
|
}
|
|
1662
1899
|
}
|
|
1663
1900
|
return s;
|
|
1664
1901
|
}
|
|
1665
|
-
function
|
|
1666
|
-
(e &
|
|
1902
|
+
function Dt(o, t, n, s, i, e) {
|
|
1903
|
+
(e & Mn && n[s] !== i || e & dn && n[s + 1] !== i || e & wn && n[s + 2] !== i) && (o[t] |= Yt);
|
|
1667
1904
|
}
|
|
1668
|
-
function
|
|
1669
|
-
const
|
|
1905
|
+
function Ze(o, t, n, s, i, e) {
|
|
1906
|
+
const a = os / e, c = os / e, r = os * Math.SQRT2 / e;
|
|
1670
1907
|
for (let h = 0; h < s; h++)
|
|
1671
|
-
for (let
|
|
1672
|
-
const
|
|
1673
|
-
if (Math.abs(
|
|
1674
|
-
const
|
|
1675
|
-
|
|
1908
|
+
for (let p = 0; p < n - 1; p++) {
|
|
1909
|
+
const l = (h * n + p) * 3, f = l + 3, u = rt(t[l], t[l + 1], t[l + 2]), _ = rt(t[f], t[f + 1], t[f + 2]);
|
|
1910
|
+
if (Math.abs(u - 0.5) + Math.abs(_ - 0.5) < a) {
|
|
1911
|
+
const y = ln(t, l, f);
|
|
1912
|
+
Dt(o, h * n + p, t, l, u, y), Dt(o, h * n + p + 1, t, f, _, y);
|
|
1676
1913
|
}
|
|
1677
1914
|
}
|
|
1678
1915
|
for (let h = 0; h < s - 1; h++)
|
|
1679
|
-
for (let
|
|
1680
|
-
const
|
|
1681
|
-
if (Math.abs(
|
|
1682
|
-
const
|
|
1683
|
-
|
|
1916
|
+
for (let p = 0; p < n; p++) {
|
|
1917
|
+
const l = (h * n + p) * 3, f = ((h + 1) * n + p) * 3, u = rt(t[l], t[l + 1], t[l + 2]), _ = rt(t[f], t[f + 1], t[f + 2]);
|
|
1918
|
+
if (Math.abs(u - 0.5) + Math.abs(_ - 0.5) < c) {
|
|
1919
|
+
const y = ln(t, l, f);
|
|
1920
|
+
Dt(o, h * n + p, t, l, u, y), Dt(o, (h + 1) * n + p, t, f, _, y);
|
|
1684
1921
|
}
|
|
1685
1922
|
}
|
|
1686
1923
|
for (let h = 0; h < s - 1; h++)
|
|
1687
|
-
for (let
|
|
1688
|
-
const
|
|
1689
|
-
if (Math.abs(
|
|
1690
|
-
const
|
|
1691
|
-
|
|
1924
|
+
for (let p = 0; p < n - 1; p++) {
|
|
1925
|
+
const l = (h * n + p) * 3, f = (h * n + p + 1) * 3, u = ((h + 1) * n + p) * 3, _ = ((h + 1) * n + p + 1) * 3, y = rt(t[l], t[l + 1], t[l + 2]), g = rt(t[f], t[f + 1], t[f + 2]), M = rt(t[u], t[u + 1], t[u + 2]), I = rt(t[_], t[_ + 1], t[_ + 2]);
|
|
1926
|
+
if (Math.abs(y - 0.5) + Math.abs(I - 0.5) < r) {
|
|
1927
|
+
const q = ln(t, l, _);
|
|
1928
|
+
Dt(o, h * n + p, t, l, y, q), Dt(o, (h + 1) * n + p + 1, t, _, I, q);
|
|
1692
1929
|
}
|
|
1693
|
-
if (Math.abs(
|
|
1694
|
-
const
|
|
1695
|
-
|
|
1930
|
+
if (Math.abs(g - 0.5) + Math.abs(M - 0.5) < r) {
|
|
1931
|
+
const q = ln(t, f, u);
|
|
1932
|
+
Dt(o, h * n + p + 1, t, f, g, q), Dt(o, (h + 1) * n + p, t, u, M, q);
|
|
1696
1933
|
}
|
|
1697
1934
|
}
|
|
1698
1935
|
}
|
|
1699
|
-
function
|
|
1700
|
-
const s = t <
|
|
1936
|
+
function Je(o, t, n) {
|
|
1937
|
+
const s = t < o ? t : o, i = o < t ? t : o, e = n < i ? n : i;
|
|
1701
1938
|
return s < e ? e : s;
|
|
1702
1939
|
}
|
|
1703
|
-
function
|
|
1704
|
-
return
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1940
|
+
function ti(o, t, n, s) {
|
|
1941
|
+
return rt(
|
|
1942
|
+
o[t] + s * (o[n] - o[t]),
|
|
1943
|
+
o[t + 1] + s * (o[n + 1] - o[t + 1]),
|
|
1944
|
+
o[t + 2] + s * (o[n + 2] - o[t + 2])
|
|
1708
1945
|
);
|
|
1709
1946
|
}
|
|
1710
|
-
function
|
|
1711
|
-
return
|
|
1712
|
-
Math.fround(s * (s * n[0] + t[0]) +
|
|
1713
|
-
Math.fround(s * (s * n[1] + t[1]) +
|
|
1714
|
-
Math.fround(s * (s * n[2] + t[2]) +
|
|
1947
|
+
function us(o, t, n, s) {
|
|
1948
|
+
return Je(
|
|
1949
|
+
Math.fround(s * (s * n[0] + t[0]) + o[0]),
|
|
1950
|
+
Math.fround(s * (s * n[1] + t[1]) + o[1]),
|
|
1951
|
+
Math.fround(s * (s * n[2] + t[2]) + o[2])
|
|
1715
1952
|
);
|
|
1716
1953
|
}
|
|
1717
|
-
const
|
|
1718
|
-
function
|
|
1719
|
-
if (s > 0.5 &&
|
|
1720
|
-
const r = (n -
|
|
1721
|
-
return e >= s - r && e <= s + r && e >=
|
|
1954
|
+
const Rt = [0, 0, 0], At = [0, 0, 0], is = [0, 0, 0], yt = [0, 0, 0], _o = 1, Io = 2;
|
|
1955
|
+
function _s(o, t, n, s, i, e, a, c) {
|
|
1956
|
+
if (s > 0.5 && i > 0.5 && e <= 0.5 || s < 0.5 && i < 0.5 && e >= 0.5 || !c && ni(s, i, e) !== e) {
|
|
1957
|
+
const r = (n - o) * a, h = (t - n) * a;
|
|
1958
|
+
return e >= s - r && e <= s + r && e >= i - h && e <= i + h ? _o : _o | Io;
|
|
1722
1959
|
}
|
|
1723
1960
|
return 0;
|
|
1724
1961
|
}
|
|
1725
|
-
function
|
|
1726
|
-
return (
|
|
1962
|
+
function Do(o) {
|
|
1963
|
+
return (o & Io) !== 0;
|
|
1727
1964
|
}
|
|
1728
|
-
function
|
|
1729
|
-
return Math.max(Math.min(
|
|
1965
|
+
function ni(o, t, n) {
|
|
1966
|
+
return Math.max(Math.min(o, t), Math.min(Math.max(o, t), n));
|
|
1730
1967
|
}
|
|
1731
|
-
function
|
|
1732
|
-
const
|
|
1733
|
-
if (Math.abs(s - 0.5) < Math.abs(
|
|
1968
|
+
function hn(o, t, n, s, i, e) {
|
|
1969
|
+
const a = rt(o[n], o[n + 1], o[n + 2]);
|
|
1970
|
+
if (Math.abs(s - 0.5) < Math.abs(a - 0.5)) return !1;
|
|
1734
1971
|
for (let c = 0; c < 3; c++) {
|
|
1735
|
-
const r =
|
|
1736
|
-
if (
|
|
1737
|
-
const
|
|
1738
|
-
if (
|
|
1739
|
-
const f =
|
|
1740
|
-
if (
|
|
1972
|
+
const r = o[t + c] - o[t + (c + 1) % 3], h = o[n + c] - o[n + (c + 1) % 3], p = r - h;
|
|
1973
|
+
if (p === 0) continue;
|
|
1974
|
+
const l = r / p;
|
|
1975
|
+
if (l > gn && l < 1 - gn) {
|
|
1976
|
+
const f = ti(o, t, n, l), u = _s(0, 1, l, s, a, f, i, e);
|
|
1977
|
+
if (Do(u)) return !0;
|
|
1741
1978
|
}
|
|
1742
1979
|
}
|
|
1743
1980
|
return !1;
|
|
1744
1981
|
}
|
|
1745
|
-
function
|
|
1982
|
+
function xo(o, t, n, s, i, e, a, c, r) {
|
|
1746
1983
|
if (!(r > 0 && r < 1)) return 0;
|
|
1747
|
-
const h = r >
|
|
1748
|
-
|
|
1749
|
-
const
|
|
1750
|
-
|
|
1751
|
-
const f = r >
|
|
1752
|
-
return
|
|
1753
|
-
}
|
|
1754
|
-
function
|
|
1755
|
-
if (!(
|
|
1756
|
-
|
|
1757
|
-
const h =
|
|
1758
|
-
let
|
|
1759
|
-
return
|
|
1760
|
-
}
|
|
1761
|
-
function
|
|
1762
|
-
const
|
|
1763
|
-
Math.fround(
|
|
1764
|
-
),
|
|
1765
|
-
if (
|
|
1766
|
-
if (
|
|
1767
|
-
const
|
|
1768
|
-
if (
|
|
1984
|
+
const h = r > a ? 0 : r, p = r > a ? r : 1;
|
|
1985
|
+
yt[0] = o[t], yt[1] = o[t + 1], yt[2] = o[t + 2];
|
|
1986
|
+
const l = r > a ? n : us(yt, Rt, At, r);
|
|
1987
|
+
yt[0] = o[t], yt[1] = o[t + 1], yt[2] = o[t + 2];
|
|
1988
|
+
const f = r > a ? us(yt, Rt, At, r) : s;
|
|
1989
|
+
return _s(h, p, a, l, f, c, i, e);
|
|
1990
|
+
}
|
|
1991
|
+
function pn(o, t, n, s, i, e, a, c, r) {
|
|
1992
|
+
if (!(a > gn && a < 1 - gn)) return !1;
|
|
1993
|
+
yt[0] = o[t], yt[1] = o[t + 1], yt[2] = o[t + 2];
|
|
1994
|
+
const h = us(yt, Rt, At, a);
|
|
1995
|
+
let p = _s(0, 1, a, n, s, h, i, e);
|
|
1996
|
+
return p |= xo(o, t, n, s, i, e, a, h, c), p |= xo(o, t, n, s, i, e, a, h, r), Do(p);
|
|
1997
|
+
}
|
|
1998
|
+
function cs(o, t, n, s, i, e, a, c, r, h, p, l, f) {
|
|
1999
|
+
const u = Math.fround(o[t + h] - o[t + p]), _ = Math.fround(
|
|
2000
|
+
Math.fround(o[n + h] - o[n + p]) + Math.fround(o[s + h] - o[s + p])
|
|
2001
|
+
), y = Math.fround(o[i + h] - o[i + p]), g = Math.fround(Math.fround(y - _) + u), M = Math.fround(Math.fround(_ - u) - u), I = u;
|
|
2002
|
+
if (g === 0 || Math.abs(M) > 1e12 * Math.abs(g)) {
|
|
2003
|
+
if (M !== 0) {
|
|
2004
|
+
const T = -I / M;
|
|
2005
|
+
if (pn(o, t, e, a, c, r, T, l, f)) return !0;
|
|
1769
2006
|
}
|
|
1770
2007
|
return !1;
|
|
1771
2008
|
}
|
|
1772
|
-
const
|
|
1773
|
-
if (
|
|
1774
|
-
const
|
|
1775
|
-
if (
|
|
1776
|
-
const
|
|
1777
|
-
if (
|
|
1778
|
-
} else if (
|
|
1779
|
-
const
|
|
1780
|
-
if (
|
|
2009
|
+
const q = M * M - 4 * g * I;
|
|
2010
|
+
if (q > 0) {
|
|
2011
|
+
const T = Math.sqrt(q), A = (-M + T) / (2 * g);
|
|
2012
|
+
if (pn(o, t, e, a, c, r, A, l, f)) return !0;
|
|
2013
|
+
const D = (-M - T) / (2 * g);
|
|
2014
|
+
if (pn(o, t, e, a, c, r, D, l, f)) return !0;
|
|
2015
|
+
} else if (q === 0) {
|
|
2016
|
+
const T = -M / (2 * g);
|
|
2017
|
+
if (pn(o, t, e, a, c, r, T, l, f)) return !0;
|
|
1781
2018
|
}
|
|
1782
2019
|
return !1;
|
|
1783
2020
|
}
|
|
1784
|
-
function
|
|
1785
|
-
const r =
|
|
2021
|
+
function fn(o, t, n, s, i, e, a, c) {
|
|
2022
|
+
const r = rt(o[i], o[i + 1], o[i + 2]);
|
|
1786
2023
|
if (Math.abs(e - 0.5) < Math.abs(r - 0.5)) return !1;
|
|
1787
2024
|
for (let f = 0; f < 3; f++)
|
|
1788
|
-
|
|
1789
|
-
Math.fround(
|
|
1790
|
-
),
|
|
1791
|
-
const h =
|
|
1792
|
-
return !!(
|
|
1793
|
-
|
|
2025
|
+
is[f] = Math.fround(
|
|
2026
|
+
Math.fround(o[t + f] - o[n + f]) - o[s + f]
|
|
2027
|
+
), Rt[f] = Math.fround(-o[t + f] - is[f]), At[f] = Math.fround(o[i + f] + is[f]);
|
|
2028
|
+
const h = At[0] !== 0 ? -0.5 * Rt[0] / At[0] : -1, p = At[1] !== 0 ? -0.5 * Rt[1] / At[1] : -1, l = At[2] !== 0 ? -0.5 * Rt[2] / At[2] : -1;
|
|
2029
|
+
return !!(cs(
|
|
2030
|
+
o,
|
|
1794
2031
|
t,
|
|
1795
2032
|
n,
|
|
1796
2033
|
s,
|
|
1797
|
-
|
|
2034
|
+
i,
|
|
1798
2035
|
e,
|
|
1799
2036
|
r,
|
|
1800
|
-
|
|
2037
|
+
a,
|
|
1801
2038
|
c,
|
|
1802
2039
|
0,
|
|
1803
2040
|
1,
|
|
1804
2041
|
h,
|
|
1805
|
-
|
|
1806
|
-
) ||
|
|
1807
|
-
|
|
2042
|
+
p
|
|
2043
|
+
) || cs(
|
|
2044
|
+
o,
|
|
1808
2045
|
t,
|
|
1809
2046
|
n,
|
|
1810
2047
|
s,
|
|
1811
|
-
|
|
2048
|
+
i,
|
|
1812
2049
|
e,
|
|
1813
2050
|
r,
|
|
1814
|
-
|
|
2051
|
+
a,
|
|
1815
2052
|
c,
|
|
1816
2053
|
1,
|
|
1817
2054
|
2,
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
) ||
|
|
1821
|
-
|
|
2055
|
+
p,
|
|
2056
|
+
l
|
|
2057
|
+
) || cs(
|
|
2058
|
+
o,
|
|
1822
2059
|
t,
|
|
1823
2060
|
n,
|
|
1824
2061
|
s,
|
|
1825
|
-
|
|
2062
|
+
i,
|
|
1826
2063
|
e,
|
|
1827
2064
|
r,
|
|
1828
|
-
|
|
2065
|
+
a,
|
|
1829
2066
|
c,
|
|
1830
2067
|
2,
|
|
1831
2068
|
0,
|
|
1832
|
-
|
|
2069
|
+
l,
|
|
1833
2070
|
h
|
|
1834
2071
|
));
|
|
1835
2072
|
}
|
|
1836
|
-
function
|
|
1837
|
-
const
|
|
2073
|
+
function si(o, t, n, s, i, e) {
|
|
2074
|
+
const a = e / i, c = e / i, r = e * Math.SQRT2 / i;
|
|
1838
2075
|
for (let h = 0; h < s; h++)
|
|
1839
|
-
for (let
|
|
1840
|
-
const
|
|
1841
|
-
let
|
|
1842
|
-
if (
|
|
1843
|
-
const
|
|
1844
|
-
|
|
2076
|
+
for (let p = 0; p < n; p++) {
|
|
2077
|
+
const l = h * n + p, f = l * 3, u = rt(t[f], t[f + 1], t[f + 2]), _ = (o[l] & Yt) !== 0, y = p > 0, g = p < n - 1, M = h > 0, I = h < s - 1, q = y ? (l - 1) * 3 : -1, T = g ? (l + 1) * 3 : -1, A = M ? (l - n) * 3 : -1, D = I ? (l + n) * 3 : -1;
|
|
2078
|
+
let R = !1;
|
|
2079
|
+
if (y && hn(t, f, q, u, a, _) && (R = !0), !R && M && hn(t, f, A, u, c, _) && (R = !0), !R && g && hn(t, f, T, u, a, _) && (R = !0), !R && I && hn(t, f, D, u, c, _) && (R = !0), !R && y && M) {
|
|
2080
|
+
const m = (l - n - 1) * 3;
|
|
2081
|
+
fn(t, f, q, A, m, u, r, _) && (R = !0);
|
|
1845
2082
|
}
|
|
1846
|
-
if (!
|
|
1847
|
-
const
|
|
1848
|
-
|
|
2083
|
+
if (!R && g && M) {
|
|
2084
|
+
const m = (l - n + 1) * 3;
|
|
2085
|
+
fn(t, f, T, A, m, u, r, _) && (R = !0);
|
|
1849
2086
|
}
|
|
1850
|
-
if (!
|
|
1851
|
-
const
|
|
1852
|
-
|
|
2087
|
+
if (!R && y && I) {
|
|
2088
|
+
const m = (l + n - 1) * 3;
|
|
2089
|
+
fn(t, f, q, D, m, u, r, _) && (R = !0);
|
|
1853
2090
|
}
|
|
1854
|
-
if (!
|
|
1855
|
-
const
|
|
1856
|
-
|
|
2091
|
+
if (!R && g && I) {
|
|
2092
|
+
const m = (l + n + 1) * 3;
|
|
2093
|
+
fn(t, f, T, D, m, u, r, _) && (R = !0);
|
|
1857
2094
|
}
|
|
1858
|
-
|
|
2095
|
+
R && (o[l] |= Eo);
|
|
1859
2096
|
}
|
|
1860
2097
|
}
|
|
1861
|
-
function
|
|
1862
|
-
const
|
|
1863
|
-
for (let e = 0; e <
|
|
1864
|
-
if (
|
|
1865
|
-
const
|
|
1866
|
-
t[
|
|
2098
|
+
function oi(o, t, n, s) {
|
|
2099
|
+
const i = n * s;
|
|
2100
|
+
for (let e = 0; e < i; e++)
|
|
2101
|
+
if (o[e] & Eo) {
|
|
2102
|
+
const a = e * 3, c = rt(t[a], t[a + 1], t[a + 2]);
|
|
2103
|
+
t[a] = c, t[a + 1] = c, t[a + 2] = c;
|
|
1867
2104
|
}
|
|
1868
2105
|
}
|
|
1869
|
-
function
|
|
1870
|
-
return Math.max(Math.min(
|
|
2106
|
+
function rt(o, t, n) {
|
|
2107
|
+
return Math.max(Math.min(o, t), Math.min(Math.max(o, t), n));
|
|
2108
|
+
}
|
|
2109
|
+
const ei = 3, ii = 0n, go = 16;
|
|
2110
|
+
function ci(o, t, n, s = !0) {
|
|
2111
|
+
if (s && ve(o), o.contours.length === 0) return null;
|
|
2112
|
+
const i = ri(o), e = t, a = n, c = Math.max(1, Math.ceil((i.maxX - i.minX) * e)) + 2 * a, r = Math.max(1, Math.ceil((i.maxY - i.minY) * e)) + 2 * a, h = a / e - i.minX, p = a / e - i.minY;
|
|
2113
|
+
xe(o), Ne(o, ei, ii);
|
|
2114
|
+
const l = new Float32Array(c * r * 3);
|
|
2115
|
+
return Ye(o, c, r, e, h, p, a, l), $e(l, o, c, r, e, h, p), je(l, o, c, r, e, h, p, a), {
|
|
2116
|
+
msdf: l,
|
|
2117
|
+
w: c,
|
|
2118
|
+
h: r,
|
|
2119
|
+
planeLeft: -h,
|
|
2120
|
+
planeBottom: -p,
|
|
2121
|
+
planeRight: c / e - h,
|
|
2122
|
+
planeTop: r / e - p
|
|
2123
|
+
};
|
|
2124
|
+
}
|
|
2125
|
+
const rs = [0, 0];
|
|
2126
|
+
function ri(o) {
|
|
2127
|
+
let t = 1 / 0, n = 1 / 0, s = -1 / 0, i = -1 / 0;
|
|
2128
|
+
for (const e of o.contours)
|
|
2129
|
+
for (const a of e)
|
|
2130
|
+
for (let c = 0; c <= go; c++) {
|
|
2131
|
+
a.point(c / go, rs);
|
|
2132
|
+
const r = rs[0], h = rs[1];
|
|
2133
|
+
r < t && (t = r), h < n && (n = h), r > s && (s = r), h > i && (i = h);
|
|
2134
|
+
}
|
|
2135
|
+
return { minX: t, minY: n, maxX: s, maxY: i };
|
|
1871
2136
|
}
|
|
1872
|
-
function
|
|
2137
|
+
function ai(o) {
|
|
1873
2138
|
let t = 0, n = 0;
|
|
1874
|
-
for (const c of
|
|
2139
|
+
for (const c of o)
|
|
1875
2140
|
t += c.w * c.h, n = Math.max(n, c.w);
|
|
1876
|
-
|
|
1877
|
-
const
|
|
1878
|
-
let e = 0,
|
|
1879
|
-
for (const c of
|
|
1880
|
-
for (let r =
|
|
1881
|
-
const h =
|
|
2141
|
+
o.sort((c, r) => r.h - c.h);
|
|
2142
|
+
const i = [{ x: 0, y: 0, w: Math.max(Math.ceil(Math.sqrt(t / 0.95)), n), h: 1 / 0 }];
|
|
2143
|
+
let e = 0, a = 0;
|
|
2144
|
+
for (const c of o)
|
|
2145
|
+
for (let r = i.length - 1; r >= 0; r--) {
|
|
2146
|
+
const h = i[r];
|
|
1882
2147
|
if (!(c.w > h.w || c.h > h.h)) {
|
|
1883
|
-
if (c.x = h.x, c.y = h.y,
|
|
1884
|
-
const
|
|
1885
|
-
|
|
1886
|
-
} else c.h === h.h ? (h.x += c.w, h.w -= c.w) : c.w === h.w ? (h.y += c.h, h.h -= c.h) : (
|
|
2148
|
+
if (c.x = h.x, c.y = h.y, a = Math.max(a, c.y + c.h), e = Math.max(e, c.x + c.w), c.w === h.w && c.h === h.h) {
|
|
2149
|
+
const p = i.pop();
|
|
2150
|
+
p && r < i.length && (i[r] = p);
|
|
2151
|
+
} else c.h === h.h ? (h.x += c.w, h.w -= c.w) : c.w === h.w ? (h.y += c.h, h.h -= c.h) : (i.push({
|
|
1887
2152
|
x: h.x + c.w,
|
|
1888
2153
|
y: h.y,
|
|
1889
2154
|
w: h.w - c.w,
|
|
@@ -1895,20 +2160,24 @@ function we(i) {
|
|
|
1895
2160
|
return {
|
|
1896
2161
|
w: e,
|
|
1897
2162
|
// container width
|
|
1898
|
-
h:
|
|
2163
|
+
h: a,
|
|
1899
2164
|
// container height
|
|
1900
|
-
fill: t / (e *
|
|
2165
|
+
fill: t / (e * a) || 0
|
|
1901
2166
|
// space utilization
|
|
1902
2167
|
};
|
|
1903
2168
|
}
|
|
1904
|
-
const
|
|
1905
|
-
function
|
|
1906
|
-
const t =
|
|
2169
|
+
const Mo = 4;
|
|
2170
|
+
function as(o) {
|
|
2171
|
+
const t = o < 0 ? 0 : o > 1 ? 1 : o;
|
|
1907
2172
|
return ~Math.trunc(255.5 - 255 * t) & 255;
|
|
1908
2173
|
}
|
|
1909
|
-
class
|
|
2174
|
+
class li {
|
|
2175
|
+
/**
|
|
2176
|
+
* @param font Font for the glyph/layout methods; `null` for a shapes-only atlas.
|
|
2177
|
+
* @param opts Generation scale and distance range.
|
|
2178
|
+
*/
|
|
1910
2179
|
constructor(t, n = {}) {
|
|
1911
|
-
this._width = 0, this._height = 0, this._pixels = new Uint8Array(0), this._cache = /* @__PURE__ */ new Map(), this.
|
|
2180
|
+
this._width = 0, this._height = 0, this._pixels = new Uint8Array(0), this._cache = /* @__PURE__ */ new Map(), this._cacheByKey = /* @__PURE__ */ new Map(), this._font = t, this._pxPerEm = n.pixelsPerEm ?? 40, this._pxrange = n.pxrange ?? 4, this._floats = n.float ? new Float32Array(0) : null, this.pxrangeEm = this._pxrange / this._pxPerEm;
|
|
1912
2181
|
}
|
|
1913
2182
|
/** Packed atlas texture width in texels (chosen by potpack). */
|
|
1914
2183
|
get width() {
|
|
@@ -1922,24 +2191,19 @@ class De {
|
|
|
1922
2191
|
get texture() {
|
|
1923
2192
|
return this._pixels;
|
|
1924
2193
|
}
|
|
2194
|
+
/** {@link Atlas.texture} as raw float RGB, not clamped to [0, 1], for zoom that
|
|
2195
|
+
* outruns 8 bits; `null` without the `float` option. */
|
|
2196
|
+
get floatTexture() {
|
|
2197
|
+
return this._floats;
|
|
2198
|
+
}
|
|
1925
2199
|
/**
|
|
1926
2200
|
* Batched generate + pack. Generates MSDFs for any codepoints not
|
|
1927
2201
|
* already cached, then runs potpack **once** over the whole cache.
|
|
1928
2202
|
* Returns the `AtlasGlyph` for each requested codepoint, in order.
|
|
1929
2203
|
*/
|
|
1930
2204
|
glyphs(t) {
|
|
1931
|
-
const n =
|
|
1932
|
-
|
|
1933
|
-
for (const o of t) {
|
|
1934
|
-
const e = this._cache.get(o);
|
|
1935
|
-
if (e) {
|
|
1936
|
-
n.push(e.glyph);
|
|
1937
|
-
continue;
|
|
1938
|
-
}
|
|
1939
|
-
const p = this._generateForGlyphId(this._font.glyphId(o));
|
|
1940
|
-
this._cache.set(o, p), n.push(p.glyph), s++;
|
|
1941
|
-
}
|
|
1942
|
-
return s > 0 && this._repack(), n;
|
|
2205
|
+
const n = this._requireFont();
|
|
2206
|
+
return this.glyphsByIndex(Array.from(t, (s) => n.glyphId(s)));
|
|
1943
2207
|
}
|
|
1944
2208
|
/**
|
|
1945
2209
|
* Single-glyph convenience: generates + packs if missing. Repacks the
|
|
@@ -1954,23 +2218,20 @@ class De {
|
|
|
1954
2218
|
* Unicode codepoint — the {@link Atlas.glyphs} twin for glyphs with no
|
|
1955
2219
|
* reachable cmap entry. Icon fonts (e.g. Lucide) commonly have far more
|
|
1956
2220
|
* glyphs than mapped codepoints; this is how the rest of the set gets
|
|
1957
|
-
* generated. Shares one packed atlas texture with
|
|
1958
|
-
*
|
|
1959
|
-
* through either method. Cached separately from {@link Atlas.glyphs} (a
|
|
1960
|
-
* codepoint and a glyph index are different numbers in the same integer
|
|
1961
|
-
* space — sharing one cache would collide them).
|
|
2221
|
+
* generated. Shares one cache and one packed atlas texture with
|
|
2222
|
+
* {@link Atlas.glyphs}, which maps codepoints to glyph indices first.
|
|
1962
2223
|
*/
|
|
1963
2224
|
glyphsByIndex(t) {
|
|
1964
2225
|
const n = [];
|
|
1965
2226
|
let s = 0;
|
|
1966
|
-
for (const
|
|
1967
|
-
const e = this.
|
|
2227
|
+
for (const i of t) {
|
|
2228
|
+
const e = this._cache.get(i);
|
|
1968
2229
|
if (e) {
|
|
1969
2230
|
n.push(e.glyph);
|
|
1970
2231
|
continue;
|
|
1971
2232
|
}
|
|
1972
|
-
const
|
|
1973
|
-
this.
|
|
2233
|
+
const a = this._generateForGlyphId(i);
|
|
2234
|
+
this._cache.set(i, a), n.push(a.glyph), s++;
|
|
1974
2235
|
}
|
|
1975
2236
|
return s > 0 && this._repack(), n;
|
|
1976
2237
|
}
|
|
@@ -1981,38 +2242,46 @@ class De {
|
|
|
1981
2242
|
return this.glyphsByIndex([t])[0];
|
|
1982
2243
|
}
|
|
1983
2244
|
/**
|
|
1984
|
-
*
|
|
1985
|
-
*
|
|
1986
|
-
*
|
|
2245
|
+
* Batched generate + pack for arbitrary shapes (e.g. from `parseSvg`),
|
|
2246
|
+
* keyed by a caller-chosen string — the {@link Atlas.glyphs} twin for
|
|
2247
|
+
* non-font input. Shapes must be y-up, in the units `pixelsPerEm` scales
|
|
2248
|
+
* (`parseSvg` makes 1 unit = the viewBox height). A new shape is mutated
|
|
2249
|
+
* (overlaps merged, normalized + coloured); a cached key ignores the shape
|
|
2250
|
+
* passed. `advance` is 0. Shares the one packed texture with the glyph cache.
|
|
1987
2251
|
*/
|
|
2252
|
+
shapes(t) {
|
|
2253
|
+
const n = [];
|
|
2254
|
+
let s = 0;
|
|
2255
|
+
for (const [i, e] of t) {
|
|
2256
|
+
let a = this._cacheByKey.get(i);
|
|
2257
|
+
a || (a = this._generate(e, 0), this._cacheByKey.set(i, a), s++), n.push(a.glyph);
|
|
2258
|
+
}
|
|
2259
|
+
return s > 0 && this._repack(), n;
|
|
2260
|
+
}
|
|
2261
|
+
/** The font, or a clear error for glyph/layout calls on a shapes-only atlas. */
|
|
2262
|
+
_requireFont() {
|
|
2263
|
+
if (!this._font) throw new Error("Atlas: no font — this atlas only supports shapes()");
|
|
2264
|
+
return this._font;
|
|
2265
|
+
}
|
|
2266
|
+
/** Generates the MSDF for `glyphId`. Does not cache and does not pack. */
|
|
1988
2267
|
_generateForGlyphId(t) {
|
|
1989
|
-
const n = this.
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
advance: o,
|
|
1997
|
-
planeLeft: 0,
|
|
1998
|
-
planeBottom: 0,
|
|
1999
|
-
planeRight: 0,
|
|
2000
|
-
planeTop: 0
|
|
2001
|
-
}, msdf: null };
|
|
2002
|
-
const p = qe(e), c = this._pxPerEm, r = this._pxrange, h = Math.max(1, Math.ceil((p.maxX - p.minX) * c)) + 2 * r, l = Math.max(1, Math.ceil((p.maxY - p.minY) * c)) + 2 * r, a = r / c - p.minX, f = r / c - p.minY;
|
|
2003
|
-
zo(e), ne(e, Ae, Ee);
|
|
2004
|
-
const y = new Float32Array(h * l * 3);
|
|
2005
|
-
return ee(e, h, l, c, a, f, r, y), fe(y, e, h, l, c, a, f), ye(y, e, h, l, c, a, f, r), { glyph: {
|
|
2268
|
+
const n = this._requireFont(), s = n.metrics.unitsPerEm, i = n.shape(t);
|
|
2269
|
+
return fe(i, s), this._generate(i, n.advance(t) / s);
|
|
2270
|
+
}
|
|
2271
|
+
/** Generates one entry from an em-unit shape. Does not cache or pack. */
|
|
2272
|
+
_generate(t, n) {
|
|
2273
|
+
const s = ci(t, this._pxPerEm, this._pxrange);
|
|
2274
|
+
return { glyph: {
|
|
2006
2275
|
x: 0,
|
|
2007
2276
|
y: 0,
|
|
2008
|
-
w:
|
|
2009
|
-
h:
|
|
2010
|
-
advance:
|
|
2011
|
-
planeLeft:
|
|
2012
|
-
planeBottom:
|
|
2013
|
-
planeRight:
|
|
2014
|
-
planeTop:
|
|
2015
|
-
}, msdf:
|
|
2277
|
+
w: s ? s.w : 0,
|
|
2278
|
+
h: s ? s.h : 0,
|
|
2279
|
+
advance: n,
|
|
2280
|
+
planeLeft: s ? s.planeLeft : 0,
|
|
2281
|
+
planeBottom: s ? s.planeBottom : 0,
|
|
2282
|
+
planeRight: s ? s.planeRight : 0,
|
|
2283
|
+
planeTop: s ? s.planeTop : 0
|
|
2284
|
+
}, msdf: s ? s.msdf : null };
|
|
2016
2285
|
}
|
|
2017
2286
|
/**
|
|
2018
2287
|
* Lays out `text` left-to-right on a single line, applying kerning.
|
|
@@ -2025,15 +2294,15 @@ class De {
|
|
|
2025
2294
|
const n = [];
|
|
2026
2295
|
for (const r of t) n.push(r.codePointAt(0));
|
|
2027
2296
|
this.glyphs(n);
|
|
2028
|
-
const s = [],
|
|
2029
|
-
let
|
|
2297
|
+
const s = [], i = this._requireFont(), e = i.metrics.unitsPerEm;
|
|
2298
|
+
let a = 0, c = -1;
|
|
2030
2299
|
for (const r of n) {
|
|
2031
|
-
const h =
|
|
2032
|
-
c >= 0 && (
|
|
2033
|
-
const
|
|
2034
|
-
s.push({ glyph:
|
|
2300
|
+
const h = i.glyphId(r);
|
|
2301
|
+
c >= 0 && (a += i.kerning(c, h) / e);
|
|
2302
|
+
const p = this._cache.get(h).glyph;
|
|
2303
|
+
s.push({ glyph: p, penX: a, penY: 0 }), a += p.advance, c = h;
|
|
2035
2304
|
}
|
|
2036
|
-
return { glyphs: s, widthEm:
|
|
2305
|
+
return { glyphs: s, widthEm: a };
|
|
2037
2306
|
}
|
|
2038
2307
|
/**
|
|
2039
2308
|
* Lays out `text` as one or more `\n`-separated lines, each run through
|
|
@@ -2051,90 +2320,84 @@ class De {
|
|
|
2051
2320
|
* cropping.
|
|
2052
2321
|
*/
|
|
2053
2322
|
layoutMultiline(t) {
|
|
2054
|
-
const n = this.
|
|
2055
|
-
`),
|
|
2323
|
+
const n = this._requireFont(), s = n.metrics.unitsPerEm, i = (n.metrics.ascender - n.metrics.descender + n.metrics.lineGap) / s, e = t.split(`
|
|
2324
|
+
`), a = [];
|
|
2056
2325
|
let c = 0;
|
|
2057
2326
|
for (let r = 0; r < e.length; r++) {
|
|
2058
|
-
const { glyphs: h, widthEm:
|
|
2059
|
-
for (const f of h)
|
|
2060
|
-
|
|
2327
|
+
const { glyphs: h, widthEm: p } = this.layout(e[r]), l = -r * i;
|
|
2328
|
+
for (const f of h) a.push({ glyph: f.glyph, penX: f.penX, penY: l });
|
|
2329
|
+
p > c && (c = p);
|
|
2061
2330
|
}
|
|
2062
|
-
return { glyphs:
|
|
2331
|
+
return { glyphs: a, widthEm: c, heightEm: e.length * i };
|
|
2063
2332
|
}
|
|
2064
|
-
/** Repacks every cached
|
|
2065
|
-
*
|
|
2066
|
-
*
|
|
2067
|
-
*
|
|
2333
|
+
/** Repacks every cached entry (glyph-index- and string-keyed caches — one
|
|
2334
|
+
* shared texture) with potpack, reallocates the texture, and re-blits each
|
|
2335
|
+
* MSDF at its assigned rect. Called by `glyphsByIndex()`/`shapes()` after
|
|
2336
|
+
* any batch of new inserts — once per batch.
|
|
2337
|
+
*
|
|
2338
|
+
* Each cell gets a 1-texel gutter of zeros on its right and bottom, so a
|
|
2339
|
+
* quad covering the whole cell can sample its full rect: linear filtering
|
|
2340
|
+
* at the edge blends with zeros (further outside the glyph), never with a
|
|
2341
|
+
* neighbouring glyph's texels. */
|
|
2068
2342
|
_repack() {
|
|
2069
2343
|
const t = [];
|
|
2070
|
-
for (const
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
o.entry.glyph.x = o.x, o.entry.glyph.y = o.y, this._blit(o.entry.msdf, o.x, o.y, o.w, o.h);
|
|
2344
|
+
for (const i of [this._cache, this._cacheByKey])
|
|
2345
|
+
for (const { glyph: e, msdf: a } of i.values())
|
|
2346
|
+
a && t.push({ w: e.w + 1, h: e.h + 1, x: 0, y: 0, glyph: e, msdf: a });
|
|
2347
|
+
const { w: n, h: s } = ai(t);
|
|
2348
|
+
this._width = n, this._height = s, this._pixels = new Uint8Array(n * s * Mo), this._floats && (this._floats = new Float32Array(n * s * 3));
|
|
2349
|
+
for (const i of t)
|
|
2350
|
+
i.glyph.x = i.x, i.glyph.y = i.y, this._blit(i.msdf, i.x, i.y, i.glyph.w, i.glyph.h);
|
|
2078
2351
|
}
|
|
2079
2352
|
/**
|
|
2080
2353
|
* Quantise `msdf` (float, y-up, row 0 = bottom, w×h×3) into `_pixels` at
|
|
2081
2354
|
* atlas rect (`ax`, `ay`, `w`, `h`) — the single y-flip point.
|
|
2082
2355
|
*/
|
|
2083
|
-
_blit(t, n, s,
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2356
|
+
_blit(t, n, s, i, e) {
|
|
2357
|
+
var r;
|
|
2358
|
+
const a = this._width, c = this._pixels;
|
|
2359
|
+
for (let h = 0; h < e; h++) {
|
|
2360
|
+
const p = s + (e - 1 - h);
|
|
2361
|
+
(r = this._floats) == null || r.set(t.subarray(h * i * 3, (h + 1) * i * 3), (p * a + n) * 3);
|
|
2362
|
+
for (let l = 0; l < i; l++) {
|
|
2363
|
+
const f = (h * i + l) * 3, u = (p * a + (n + l)) * Mo;
|
|
2364
|
+
c[u] = as(t[f]), c[u + 1] = as(t[f + 1]), c[u + 2] = as(t[f + 2]), c[u + 3] = 255;
|
|
2090
2365
|
}
|
|
2091
2366
|
}
|
|
2092
2367
|
}
|
|
2093
2368
|
}
|
|
2094
|
-
const
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
for (const e of i.contours)
|
|
2098
|
-
for (const p of e)
|
|
2099
|
-
for (let c = 0; c <= Ks; c++) {
|
|
2100
|
-
p.point(c / Ks, zn);
|
|
2101
|
-
const r = zn[0], h = zn[1];
|
|
2102
|
-
r < t && (t = r), h < n && (n = h), r > s && (s = r), h > o && (o = h);
|
|
2103
|
-
}
|
|
2104
|
-
return { minX: t, minY: n, maxX: s, maxY: o };
|
|
2105
|
-
}
|
|
2106
|
-
const Qs = /* @__PURE__ */ new Map();
|
|
2107
|
-
self.onmessage = (i) => {
|
|
2108
|
-
const t = i.data;
|
|
2369
|
+
const wo = /* @__PURE__ */ new Map();
|
|
2370
|
+
self.onmessage = (o) => {
|
|
2371
|
+
const t = o.data;
|
|
2109
2372
|
if (t.type === "build")
|
|
2110
2373
|
try {
|
|
2111
|
-
let n =
|
|
2374
|
+
let n = wo.get(t.fontKey);
|
|
2112
2375
|
if (!n) {
|
|
2113
2376
|
if (!t.font)
|
|
2114
2377
|
throw new Error(
|
|
2115
2378
|
`atlas-worker: no cached font for fontKey "${t.fontKey}" and no \`font\` bytes provided on this request`
|
|
2116
2379
|
);
|
|
2117
|
-
n = new
|
|
2380
|
+
n = new pe(t.font), wo.set(t.fontKey, n);
|
|
2118
2381
|
}
|
|
2119
|
-
const s = performance.now(),
|
|
2382
|
+
const s = performance.now(), i = new li(n, { pixelsPerEm: t.pixelsPerEm, pxrange: t.pxrange }), { glyphs: e, widthEm: a, heightEm: c } = i.layoutMultiline(t.text), r = performance.now() - s, h = e.map(({ glyph: f, penX: u, penY: _ }) => ({
|
|
2120
2383
|
...f,
|
|
2121
|
-
penX:
|
|
2384
|
+
penX: u,
|
|
2122
2385
|
penY: _
|
|
2123
|
-
})),
|
|
2386
|
+
})), p = i.texture.slice().buffer, l = {
|
|
2124
2387
|
type: "built",
|
|
2125
2388
|
id: t.id,
|
|
2126
2389
|
pixelsPerEm: t.pixelsPerEm,
|
|
2127
2390
|
pxrange: t.pxrange,
|
|
2128
|
-
pxrangeEm:
|
|
2129
|
-
width:
|
|
2130
|
-
height:
|
|
2131
|
-
texture:
|
|
2391
|
+
pxrangeEm: i.pxrangeEm,
|
|
2392
|
+
width: i.width,
|
|
2393
|
+
height: i.height,
|
|
2394
|
+
texture: p,
|
|
2132
2395
|
glyphs: h,
|
|
2133
|
-
widthEm:
|
|
2396
|
+
widthEm: a,
|
|
2134
2397
|
heightEm: c,
|
|
2135
2398
|
genMs: r
|
|
2136
2399
|
};
|
|
2137
|
-
self.postMessage(
|
|
2400
|
+
self.postMessage(l, [p]);
|
|
2138
2401
|
} catch (n) {
|
|
2139
2402
|
const s = { type: "error", id: t.id, message: String(n) };
|
|
2140
2403
|
self.postMessage(s);
|