@tachyon-charts/geo 0.0.0-stage → 1.1.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/dist/tiles.js ADDED
@@ -0,0 +1,338 @@
1
+ // Tiles of a server of the application's choice over a map in Web Mercator, as TileSource, TileLayerSeries and
2
+ // AttributionOverlay of the .NET version. The library names no server: the application gives the address and the
3
+ // notice of its source, and keeps to the rules of that server.
4
+ import { ChartOverlay, ChartSeries, DoubleRange, } from '@tachyon-charts/core';
5
+ /** Where the tiles of a map come from: the address of a server with `{z}`, `{x}` and `{y}`, and the notice of its source. */
6
+ export class TileSource {
7
+ urlTemplate;
8
+ attribution;
9
+ /** The finest level the server has. */
10
+ maxZoom;
11
+ /** The tiles kept in memory. */
12
+ memoryTiles;
13
+ /** The name of the cache of the browser that keeps tiles, if any. */
14
+ cacheName;
15
+ fetcher;
16
+ decoder;
17
+ painter;
18
+ /**
19
+ * @param urlTemplate - The address of a tile, with `{z}`, `{x}` and `{y}`.
20
+ * @param attribution - The notice of the source the server asks for, shown in the corner of the map.
21
+ * @param options - Levels, memory, cache, fetching and decoding.
22
+ * @throws RangeError when the address lacks `{z}`, `{x}` or `{y}`, or the notice is empty.
23
+ */
24
+ constructor(
25
+ /** The address of a tile, with `{z}`, `{x}` and `{y}`. */
26
+ urlTemplate,
27
+ /** The notice of the source, shown in the corner of the map. */
28
+ attribution, options = {}) {
29
+ this.urlTemplate = urlTemplate;
30
+ this.attribution = attribution;
31
+ if (!['{z}', '{x}', '{y}'].every((part) => urlTemplate.includes(part))) {
32
+ throw new RangeError('The address needs {z}, {x} and {y}.');
33
+ }
34
+ if (attribution.trim().length === 0) {
35
+ throw new RangeError('Tiles need the notice of their source.');
36
+ }
37
+ this.maxZoom = options.maxZoom ?? 19;
38
+ this.memoryTiles = options.memoryTiles ?? 512;
39
+ this.cacheName = options.cacheName;
40
+ this.fetcher = options.fetch;
41
+ this.decoder = options.decode ?? decodeImage;
42
+ }
43
+ /** A grid of tiles drawn on the spot, without a server: it shows how the levels stack. */
44
+ static grid() {
45
+ const source = new TileSource('{z}/{x}/{y}', 'Grid of tiles drawn locally');
46
+ source.painter = paintGrid;
47
+ return source;
48
+ }
49
+ /** The address of a tile. */
50
+ addressOf(z, x, y) {
51
+ return this.urlTemplate.replaceAll('{z}', String(z)).replaceAll('{x}', String(x)).replaceAll('{y}', String(y));
52
+ }
53
+ /** @internal Brings a tile: drawn, from the cache of the browser, or from the server. */
54
+ async load(z, x, y, signal) {
55
+ if (this.painter) {
56
+ return this.painter(z, x, y);
57
+ }
58
+ const address = this.addressOf(z, x, y);
59
+ const cache = this.cacheName !== undefined && typeof caches !== 'undefined' ? await caches.open(this.cacheName) : undefined;
60
+ const kept = await cache?.match(address);
61
+ if (kept) {
62
+ return this.decoder(await kept.arrayBuffer());
63
+ }
64
+ let bytes;
65
+ if (this.fetcher) {
66
+ bytes = await this.fetcher(address, signal);
67
+ }
68
+ else {
69
+ const response = await fetch(address, { signal });
70
+ if (!response.ok) {
71
+ throw new Error(`The tile ${address} came with ${String(response.status)}.`);
72
+ }
73
+ bytes = await response.arrayBuffer();
74
+ }
75
+ await cache?.put(address, new Response(bytes.slice(0)));
76
+ return this.decoder(bytes);
77
+ }
78
+ }
79
+ async function decodeImage(bytes) {
80
+ const bitmap = await createImageBitmap(new Blob([bytes]));
81
+ const canvas = new OffscreenCanvas(bitmap.width, bitmap.height);
82
+ const context = canvas.getContext('2d');
83
+ if (!context) {
84
+ bitmap.close();
85
+ return undefined;
86
+ }
87
+ context.drawImage(bitmap, 0, 0);
88
+ bitmap.close();
89
+ const data = context.getImageData(0, 0, canvas.width, canvas.height);
90
+ return { pixels: data.data, width: data.width, height: data.height };
91
+ }
92
+ // A tile mostly clear, with its border and a soft tint that changes with the level, so the stacking shows.
93
+ function paintGrid(z, x, y) {
94
+ const size = 256;
95
+ const pixels = new Uint8Array(size * size * 4);
96
+ const tint = [60 + ((z * 37) % 120), 90 + ((x * 23) % 100), 140 + ((y * 41) % 100), 40];
97
+ const edge = [40, 60, 90, 200];
98
+ for (let row = 0; row < size; row++) {
99
+ for (let column = 0; column < size; column++) {
100
+ pixels.set(row < 2 || column < 2 ? edge : tint, (row * size + column) * 4);
101
+ }
102
+ }
103
+ return { pixels, width: size, height: size };
104
+ }
105
+ const workers = 6;
106
+ const coarser = 6;
107
+ const retryMilliseconds = 30_000;
108
+ const keyOf = (z, x, y) => (z * 2 ** 20 + y) * 2 ** 20 + x;
109
+ /**
110
+ * The tiles of a server below the series of a map in Web Mercator: they arrive in the background, the newest view
111
+ * first, and where a tile is missing a coarser one stands in, or the map below shows.
112
+ */
113
+ export class TileLayerSeries extends ChartSeries {
114
+ source;
115
+ tiles = new Map();
116
+ failed = new Map();
117
+ pending = new Set();
118
+ wanted = [];
119
+ stop = new AbortController();
120
+ texture;
121
+ device;
122
+ pixels = new Uint8Array(0);
123
+ arrived = 0;
124
+ built = -1;
125
+ builtFrame;
126
+ running = 0;
127
+ zoomLevel = 0;
128
+ /**
129
+ * @param source - Where the tiles come from.
130
+ * @param xAxis - The X axis of the map.
131
+ * @param yAxis - The Y axis of the map.
132
+ */
133
+ constructor(
134
+ /** Where the tiles come from. */
135
+ source, xAxis, yAxis) {
136
+ super(xAxis, yAxis);
137
+ this.source = source;
138
+ }
139
+ /** The level of the tiles of the last frame. */
140
+ get zoom() {
141
+ return this.zoomLevel;
142
+ }
143
+ /** The tiles in memory. */
144
+ get tileCount() {
145
+ return this.tiles.size;
146
+ }
147
+ /** {@inheritDoc @tachyon-charts/core#ChartSeries.version} */
148
+ get version() {
149
+ return this.arrived;
150
+ }
151
+ /** {@inheritDoc @tachyon-charts/core#ChartSeries.dataRange} */
152
+ dataRange() {
153
+ return new DoubleRange(-Math.PI, Math.PI);
154
+ }
155
+ /** Stops the tiles on their way and frees the texture. */
156
+ dispose() {
157
+ this.stop.abort();
158
+ this.releaseResources();
159
+ }
160
+ /** {@inheritDoc @tachyon-charts/core#ChartSeries.releaseResources} */
161
+ releaseResources() {
162
+ this.texture?.dispose();
163
+ this.texture = undefined;
164
+ this.device = undefined;
165
+ this.built = -1;
166
+ }
167
+ /** {@inheritDoc @tachyon-charts/core#ChartSeries.prepare} */
168
+ prepare(device, frame) {
169
+ const width = Math.max(Math.trunc(frame.bounds.width), 1);
170
+ const height = Math.max(Math.trunc(frame.bounds.height), 1);
171
+ if (this.device !== device || this.texture?.size.width !== width || this.texture.size.height !== height) {
172
+ this.texture?.dispose();
173
+ this.texture = device.createTexture({ size: { width, height }, format: 'rgba8unorm' });
174
+ this.device = device;
175
+ this.built = -1;
176
+ }
177
+ if (this.arrived === this.built && frame === this.builtFrame) {
178
+ return;
179
+ }
180
+ this.built = this.arrived;
181
+ this.builtFrame = frame;
182
+ if (this.pixels.length !== width * height * 4) {
183
+ this.pixels = new Uint8Array(width * height * 4);
184
+ }
185
+ // The level whose tiles come closest to 256 pixels; a tile spans 2π / 2^z of the plane.
186
+ const bounds = frame.bounds;
187
+ const unitsPerPixel = Math.abs(frame.x.toData(bounds.x + 1) - frame.x.toData(bounds.x));
188
+ const zoom = Math.min(Math.max(Math.ceil(Math.log2((2 * Math.PI) / (256 * unitsPerPixel))), 0), this.source.maxZoom);
189
+ this.zoomLevel = zoom;
190
+ const x0 = frame.x.toData(bounds.x + 0.5);
191
+ const y0 = frame.y.toData(bounds.y + 0.5);
192
+ const dx = frame.x.toData(bounds.x + 1.5) - x0;
193
+ const dy = frame.y.toData(bounds.y + 1.5) - y0;
194
+ this.want(zoom, x0, y0, x0 + dx * width, y0 + dy * height);
195
+ this.fill(zoom, width, height, x0, y0, dx, dy);
196
+ this.texture.write(this.pixels);
197
+ }
198
+ /** {@inheritDoc @tachyon-charts/core#ChartSeries.draw} */
199
+ draw(commands, frame) {
200
+ if (this.texture) {
201
+ commands.drawImage(this.texture, frame.bounds);
202
+ }
203
+ }
204
+ // The tiles of the view at its level, asked for when they are neither here, on their way, nor failed a short while ago.
205
+ want(zoom, left, top, right, bottom) {
206
+ const count = 2 ** zoom;
207
+ const tx0 = column(Math.min(left, right), zoom);
208
+ const tx1 = column(Math.max(left, right), zoom);
209
+ const ty0 = row(Math.max(top, bottom), zoom);
210
+ const ty1 = row(Math.min(top, bottom), zoom);
211
+ const now = performance.now();
212
+ for (let ty = Math.max(0, ty0); ty <= Math.min(count - 1, ty1); ty++) {
213
+ for (let tx = tx0; tx <= tx1; tx++) {
214
+ const x = ((tx % count) + count) % count;
215
+ const key = keyOf(zoom, x, ty);
216
+ const failedAt = this.failed.get(key);
217
+ if (this.tiles.has(key) ||
218
+ this.pending.has(key) ||
219
+ (failedAt !== undefined && now - failedAt < retryMilliseconds)) {
220
+ continue;
221
+ }
222
+ this.pending.add(key);
223
+ this.wanted.push([zoom, x, ty]);
224
+ }
225
+ }
226
+ while (this.running < workers && this.wanted.length > 0) {
227
+ this.running++;
228
+ void this.work();
229
+ }
230
+ }
231
+ // A worker takes the newest wish first, so that the tiles of the current view come before older ones.
232
+ async work() {
233
+ try {
234
+ for (let next = this.wanted.pop(); next && !this.stop.signal.aborted; next = this.wanted.pop()) {
235
+ const [z, x, y] = next;
236
+ const key = keyOf(z, x, y);
237
+ try {
238
+ const image = await this.source.load(z, x, y, this.stop.signal);
239
+ if (image) {
240
+ this.keep(key, image);
241
+ }
242
+ else {
243
+ this.failed.set(key, performance.now());
244
+ }
245
+ }
246
+ catch {
247
+ // Without a network the map below shows; the tile is asked for again after a while.
248
+ this.failed.set(key, performance.now());
249
+ }
250
+ finally {
251
+ this.pending.delete(key);
252
+ }
253
+ }
254
+ }
255
+ finally {
256
+ this.running--;
257
+ }
258
+ }
259
+ keep(key, image) {
260
+ this.tiles.set(key, image);
261
+ // A map keeps the order of arrival: the oldest tile leaves first.
262
+ while (this.tiles.size > this.source.memoryTiles) {
263
+ const oldest = this.tiles.keys().next().value;
264
+ this.tiles.delete(oldest);
265
+ }
266
+ this.arrived++;
267
+ }
268
+ // Each pixel takes the finest tile there is at its place, from the level of the view up to six coarser ones.
269
+ fill(zoom, width, height, x0, y0, dx, dy) {
270
+ const pixels = this.pixels;
271
+ for (let line = 0; line < height; line++) {
272
+ const y = y0 + dy * line;
273
+ const start = line * width * 4;
274
+ if (Math.abs(y) > Math.PI) {
275
+ pixels.fill(0, start, start + width * 4);
276
+ continue;
277
+ }
278
+ const ty = (Math.PI - y) / (2 * Math.PI);
279
+ for (let column = 0; column < width; column++) {
280
+ let tx = (x0 + dx * column + Math.PI) / (2 * Math.PI);
281
+ tx -= Math.floor(tx);
282
+ this.sample(zoom, tx, ty, start + column * 4);
283
+ }
284
+ }
285
+ }
286
+ sample(zoom, tx, ty, at) {
287
+ const pixels = this.pixels;
288
+ for (let z = zoom; z >= Math.max(0, zoom - coarser); z--) {
289
+ const count = 2 ** z;
290
+ const fx = tx * count;
291
+ const fy = ty * count;
292
+ const x = Math.trunc(fx);
293
+ const y = Math.trunc(fy);
294
+ const tile = y >= 0 && y < count ? this.tiles.get(keyOf(z, Math.min(x, count - 1), y)) : undefined;
295
+ if (!tile) {
296
+ continue;
297
+ }
298
+ const px = Math.min(tile.width - 1, Math.trunc((fx - x) * tile.width));
299
+ const py = Math.min(tile.height - 1, Math.trunc((fy - y) * tile.height));
300
+ const from = (py * tile.width + px) * 4;
301
+ pixels[at] = tile.pixels[from];
302
+ pixels[at + 1] = tile.pixels[from + 1];
303
+ pixels[at + 2] = tile.pixels[from + 2];
304
+ pixels[at + 3] = tile.pixels[from + 3];
305
+ return;
306
+ }
307
+ pixels[at] = 0;
308
+ pixels[at + 1] = 0;
309
+ pixels[at + 2] = 0;
310
+ pixels[at + 3] = 0;
311
+ }
312
+ }
313
+ function column(x, zoom) {
314
+ return Math.floor(((x + Math.PI) / (2 * Math.PI)) * 2 ** zoom);
315
+ }
316
+ function row(y, zoom) {
317
+ return Math.floor(((Math.PI - y) / (2 * Math.PI)) * 2 ** zoom);
318
+ }
319
+ /** The notice of the source of tiles or of a map, in the lower right corner of the plot. */
320
+ export class AttributionOverlay extends ChartOverlay {
321
+ text;
322
+ /** @param text - The notice. */
323
+ constructor(
324
+ /** The notice. */
325
+ text) {
326
+ super();
327
+ this.text = text;
328
+ }
329
+ /** {@inheritDoc @tachyon-charts/core#ChartOverlay.draw} */
330
+ draw(canvas) {
331
+ const margin = 4;
332
+ const plot = canvas.layout.plotArea;
333
+ const width = canvas.measureWidth(this.text, canvas.labelSize) + 8;
334
+ const height = canvas.lineHeight(canvas.labelSize) + 8;
335
+ canvas.drawLabel(this.text, plot.right - width - margin, plot.bottom - height - margin, { ...canvas.colors.background, a: 200 }, canvas.colors.text);
336
+ }
337
+ }
338
+ //# sourceMappingURL=tiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiles.js","sourceRoot":"","sources":["../src/tiles.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,iHAAiH;AACjH,+DAA+D;AAC/D,OAAO,EACL,YAAY,EACZ,WAAW,EACX,WAAW,GAOZ,MAAM,sBAAsB,CAAC;AA4B9B,6HAA6H;AAC7H,MAAM,OAAO,UAAU;IAmBV;IAEA;IApBX,uCAAuC;IAC9B,OAAO,CAAS;IACzB,gCAAgC;IACvB,WAAW,CAAS;IAC7B,qEAAqE;IAC5D,SAAS,CAAqB;IACtB,OAAO,CAA+E;IACtF,OAAO,CAAyD;IACzE,OAAO,CAAsB;IAErC;;;;;OAKG;IACH;IACE,0DAA0D;IACjD,WAAmB;IAC5B,gEAAgE;IACvD,WAAmB,EAC5B,UAA6B,EAAE;QAHtB,gBAAW,GAAX,WAAW,CAAQ;QAEnB,gBAAW,GAAX,WAAW,CAAQ;QAG5B,IAAI,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;YACvE,MAAM,IAAI,UAAU,CAAC,qCAAqC,CAAC,CAAC;QAC9D,CAAC;QACD,IAAI,WAAW,CAAC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AK,GAAG,KAAK,GAAG,MAAM,EAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAC7B,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,EAAE,GAAG,EAAE,EACvC,MAAM,CAAC,MAAM,CAAC,IAAI,CACnB,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ /** An area cut into triangles: its corners (outer ring, then holes), the triangles and the corners of each ring. */
2
+ export interface GeoTriangles {
3
+ /** The X of the corners: the outer ring, then each hole. */
4
+ readonly x: Float64Array;
5
+ /** The Y of the corners. */
6
+ readonly y: Float64Array;
7
+ /** Three corners per triangle. */
8
+ readonly triangles: Int32Array;
9
+ /** The number of corners of each ring, the outer one first. */
10
+ readonly rings: Int32Array;
11
+ }
12
+ /** @internal Cuts an outer ring with its holes into triangles. */
13
+ export declare function triangulateArea(outer: {
14
+ readonly x: ArrayLike<number>;
15
+ readonly y: ArrayLike<number>;
16
+ }, holes: readonly {
17
+ readonly x: ArrayLike<number>;
18
+ readonly y: ArrayLike<number>;
19
+ }[]): GeoTriangles;
20
+ //# sourceMappingURL=triangulator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"triangulator.d.ts","sourceRoot":"","sources":["../src/triangulator.ts"],"names":[],"mappings":"AAGA,oHAAoH;AACpH,MAAM,WAAW,YAAY;IAC3B,4DAA4D;IAC5D,QAAQ,CAAC,CAAC,EAAE,YAAY,CAAC;IACzB,4BAA4B;IAC5B,QAAQ,CAAC,CAAC,EAAE,YAAY,CAAC;IACzB,kCAAkC;IAClC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,+DAA+D;IAC/D,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;CAC5B;AAkBD,kEAAkE;AAClE,wBAAgB,eAAe,CAC7B,KAAK,EAAE;IAAE,QAAQ,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAA;CAAE,EACvE,KAAK,EAAE,SAAS;IAAE,QAAQ,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAA;CAAE,EAAE,GACjF,YAAY,CA8Bd"}
@@ -0,0 +1,270 @@
1
+ // Cuts areas of a map into triangles, as GeoTriangulator of the .NET version: ear cutting on a linked ring, holes joined
2
+ // by bridges (Eberly), and a grid of the corners, so that countries with many thousand corners cut quickly.
3
+ function node(index, x, y) {
4
+ const created = { index, x, y, isRemoved: false };
5
+ created.prev = created;
6
+ created.next = created;
7
+ return created;
8
+ }
9
+ /** @internal Cuts an outer ring with its holes into triangles. */
10
+ export function triangulateArea(outer, holes) {
11
+ const xs = [];
12
+ const ys = [];
13
+ const start = addRing(xs, ys, outer.x, outer.y, true);
14
+ if (!start) {
15
+ return { x: new Float64Array(0), y: new Float64Array(0), triangles: new Int32Array(0), rings: new Int32Array(0) };
16
+ }
17
+ const rings = [xs.length];
18
+ // The holes from the one reaching farthest east, each joined by a bridge to the ring so far.
19
+ const holeStarts = [];
20
+ for (const hole of holes) {
21
+ const before = xs.length;
22
+ const first = addRing(xs, ys, hole.x, hole.y, false);
23
+ if (first) {
24
+ holeStarts.push(rightmost(first));
25
+ rings.push(xs.length - before);
26
+ }
27
+ }
28
+ holeStarts.sort((a, b) => b.x - a.x);
29
+ for (const hole of holeStarts) {
30
+ bridge(start, hole);
31
+ }
32
+ const triangles = [];
33
+ cut(start, triangles);
34
+ return {
35
+ x: Float64Array.from(xs),
36
+ y: Float64Array.from(ys),
37
+ triangles: Int32Array.from(triangles),
38
+ rings: Int32Array.from(rings),
39
+ };
40
+ }
41
+ // A ring as a linked list, turned positively (counterclockwise) for an outer ring and negatively for a hole.
42
+ function addRing(xs, ys, x, y, positive) {
43
+ let count = Math.min(x.length, y.length);
44
+ if (count > 1 && x[0] === x[count - 1] && y[0] === y[count - 1]) {
45
+ count--;
46
+ }
47
+ if (count < 3) {
48
+ return undefined;
49
+ }
50
+ let area = 0;
51
+ for (let i = 0, j = count - 1; i < count; j = i++) {
52
+ area += (x[j] - x[i]) * (y[j] + y[i]);
53
+ }
54
+ // The sum is positive for a counterclockwise ring.
55
+ const reverse = area > 0 !== positive;
56
+ let first;
57
+ let last;
58
+ for (let k = 0; k < count; k++) {
59
+ const i = reverse ? count - 1 - k : k;
60
+ const created = node(xs.length, x[i], y[i]);
61
+ xs.push(created.x);
62
+ ys.push(created.y);
63
+ if (last) {
64
+ last.next = created;
65
+ created.prev = last;
66
+ }
67
+ else {
68
+ first = created;
69
+ }
70
+ last = created;
71
+ }
72
+ const head = first;
73
+ const tail = last;
74
+ tail.next = head;
75
+ head.prev = tail;
76
+ return head;
77
+ }
78
+ function rightmost(start) {
79
+ let best = start;
80
+ let current = start.next;
81
+ while (current !== start) {
82
+ if (current.x > best.x || (current.x === best.x && current.y < best.y)) {
83
+ best = current;
84
+ }
85
+ current = current.next;
86
+ }
87
+ return best;
88
+ }
89
+ // Eberly: a ray from the hole east meets an edge; the bridge goes to the end of that edge, or to the corner within the
90
+ // triangle of hole, meeting point and edge end that lies at the smallest angle.
91
+ function bridge(outer, hole) {
92
+ const hit = rayHit(outer, hole.x, hole.y);
93
+ if (!hit) {
94
+ return;
95
+ }
96
+ const target = visible(outer, hit.edge, hole.x, hole.y, hit.x);
97
+ // Two copies of each end close the bridge: target → hole → around the hole → hole' → target' → on.
98
+ const targetCopy = node(target.index, target.x, target.y);
99
+ const holeCopy = node(hole.index, hole.x, hole.y);
100
+ const afterTarget = target.next;
101
+ const beforeHole = hole.prev;
102
+ target.next = hole;
103
+ hole.prev = target;
104
+ beforeHole.next = holeCopy;
105
+ holeCopy.prev = beforeHole;
106
+ holeCopy.next = targetCopy;
107
+ targetCopy.prev = holeCopy;
108
+ targetCopy.next = afterTarget;
109
+ afterTarget.prev = targetCopy;
110
+ }
111
+ // The edge the ray from the hole east meets first, and its end further east.
112
+ function rayHit(outer, hx, hy) {
113
+ let edge;
114
+ let nearest = Number.POSITIVE_INFINITY;
115
+ let current = outer;
116
+ do {
117
+ const next = current.next;
118
+ const crosses = (current.y <= hy && next.y >= hy) || (next.y <= hy && current.y >= hy);
119
+ if (crosses && next.y !== current.y) {
120
+ const x = current.x + ((hy - current.y) * (next.x - current.x)) / (next.y - current.y);
121
+ if (x >= hx && x < nearest) {
122
+ nearest = x;
123
+ edge = current.x > next.x ? current : next;
124
+ }
125
+ }
126
+ current = next;
127
+ } while (current !== outer);
128
+ return edge ? { edge, x: nearest } : undefined;
129
+ }
130
+ // Corners inside the triangle could block the bridge: the one at the smallest angle to the ray is visible.
131
+ function visible(outer, edge, hx, hy, mx) {
132
+ let target = edge;
133
+ let smallest = Number.POSITIVE_INFINITY;
134
+ let current = outer;
135
+ do {
136
+ if (current !== edge && current.x >= hx && inTriangle(hx, hy, mx, hy, edge.x, edge.y, current.x, current.y)) {
137
+ const angle = Math.abs(current.y - hy) / Math.max(current.x - hx, 1e-300);
138
+ if (angle < smallest || (angle === smallest && current.x > target.x)) {
139
+ smallest = angle;
140
+ target = current;
141
+ }
142
+ }
143
+ current = current.next;
144
+ } while (current !== outer);
145
+ return target;
146
+ }
147
+ // Cuts ears along the ring; a grid over the corners finds those that could lie inside an ear.
148
+ function cut(start, triangles) {
149
+ const all = [];
150
+ let current = start;
151
+ do {
152
+ all.push(current);
153
+ current = current.next;
154
+ } while (current !== start);
155
+ const grid = new CornerGrid(all);
156
+ let left = all.length;
157
+ let stall = 0;
158
+ current = start;
159
+ while (left > 3) {
160
+ const prev = current.prev;
161
+ const next = current.next;
162
+ if (isEar(prev, current, next, grid) || stall > left) {
163
+ triangles.push(prev.index, current.index, next.index);
164
+ prev.next = next;
165
+ next.prev = prev;
166
+ current.isRemoved = true;
167
+ left--;
168
+ stall = 0;
169
+ // Back one, as the corner before may have become an ear.
170
+ current = prev;
171
+ continue;
172
+ }
173
+ current = next;
174
+ stall++;
175
+ }
176
+ if (left === 3) {
177
+ triangles.push(current.prev.index, current.index, current.next.index);
178
+ }
179
+ }
180
+ function isEar(a, b, c, grid) {
181
+ // Convex: the corner turns left on a counterclockwise ring.
182
+ if (cross(a, b, c) <= 0) {
183
+ return false;
184
+ }
185
+ const found = grid.within(Math.min(a.x, b.x, c.x), Math.min(a.y, b.y, c.y), Math.max(a.x, b.x, c.x), Math.max(a.y, b.y, c.y));
186
+ for (const other of found) {
187
+ if (other.isRemoved ||
188
+ other === a ||
189
+ other === b ||
190
+ other === c ||
191
+ (other.x === a.x && other.y === a.y) ||
192
+ (other.x === b.x && other.y === b.y) ||
193
+ (other.x === c.x && other.y === c.y)) {
194
+ continue;
195
+ }
196
+ // Only a corner that turns right (a reflex one) can lie inside an ear.
197
+ if (cross(other.prev, other, other.next) <= 0 && inTriangle(a.x, a.y, b.x, b.y, c.x, c.y, other.x, other.y)) {
198
+ return false;
199
+ }
200
+ }
201
+ return true;
202
+ }
203
+ function cross(a, b, c) {
204
+ return (b.x - a.x) * (c.y - b.y) - (b.y - a.y) * (c.x - b.x);
205
+ }
206
+ function inTriangle(ax, ay, bx, by, cx, cy, px, py) {
207
+ const first = (cx - px) * (ay - py) - (ax - px) * (cy - py);
208
+ const second = (ax - px) * (by - py) - (bx - px) * (ay - py);
209
+ const third = (bx - px) * (cy - py) - (cx - px) * (by - py);
210
+ return (first >= 0 && second >= 0 && third >= 0) || (first <= 0 && second <= 0 && third <= 0);
211
+ }
212
+ // A grid of about one corner per cell over the box of the ring.
213
+ class CornerGrid {
214
+ cells;
215
+ side;
216
+ minX;
217
+ minY;
218
+ cellWidth;
219
+ cellHeight;
220
+ found = [];
221
+ constructor(nodes) {
222
+ this.side = Math.min(Math.max(Math.trunc(Math.sqrt(nodes.length)), 1), 1024);
223
+ let minX = Infinity;
224
+ let minY = Infinity;
225
+ let maxX = -Infinity;
226
+ let maxY = -Infinity;
227
+ for (const each of nodes) {
228
+ minX = Math.min(minX, each.x);
229
+ minY = Math.min(minY, each.y);
230
+ maxX = Math.max(maxX, each.x);
231
+ maxY = Math.max(maxY, each.y);
232
+ }
233
+ this.minX = minX;
234
+ this.minY = minY;
235
+ this.cellWidth = Math.max((maxX - minX) / this.side, 1e-12);
236
+ this.cellHeight = Math.max((maxY - minY) / this.side, 1e-12);
237
+ this.cells = new Array(this.side * this.side);
238
+ for (const each of nodes) {
239
+ const at = this.row(each.y) * this.side + this.column(each.x);
240
+ const cell = this.cells[at] ?? [];
241
+ this.cells[at] = cell;
242
+ cell.push(each);
243
+ }
244
+ }
245
+ within(minX, minY, maxX, maxY) {
246
+ this.found.length = 0;
247
+ const x0 = this.column(minX);
248
+ const y0 = this.row(minY);
249
+ const x1 = this.column(maxX);
250
+ const y1 = this.row(maxY);
251
+ for (let row = y0; row <= y1; row++) {
252
+ for (let column = x0; column <= x1; column++) {
253
+ const cell = this.cells[row * this.side + column];
254
+ if (cell) {
255
+ for (const each of cell) {
256
+ this.found.push(each);
257
+ }
258
+ }
259
+ }
260
+ }
261
+ return this.found;
262
+ }
263
+ column(x) {
264
+ return Math.min(Math.max(Math.trunc((x - this.minX) / this.cellWidth), 0), this.side - 1);
265
+ }
266
+ row(y) {
267
+ return Math.min(Math.max(Math.trunc((y - this.minY) / this.cellHeight), 0), this.side - 1);
268
+ }
269
+ }
270
+ //# sourceMappingURL=triangulator.js.map