@vizhub/quadstream 0.2.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +49 -323
- package/bin/quadstream.mjs +8 -6
- package/dist/blg.d.ts +3 -0
- package/dist/blg.js +14 -1
- package/dist/cooperative.d.ts +21 -0
- package/dist/cooperative.js +33 -0
- package/dist/dataset.d.ts +8 -4
- package/dist/dataset.js +51 -14
- package/dist/geometry-wire.d.ts +8 -0
- package/dist/geometry-wire.js +76 -0
- package/dist/geometry.d.ts +3 -1
- package/dist/geometry.js +115 -5
- package/dist/index.d.ts +20 -2
- package/dist/index.js +9 -1
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +1 -1
- package/dist/lod-scheduler.d.ts +15 -0
- package/dist/lod-scheduler.js +85 -0
- package/dist/progressive-map.d.ts +1 -1
- package/dist/progressive-map.js +12 -8
- package/dist/quadtree.d.ts +2 -0
- package/dist/quadtree.js +12 -0
- package/dist/reconstruct.d.ts +18 -1
- package/dist/reconstruct.js +94 -32
- package/dist/session.d.ts +12 -9
- package/dist/session.js +24 -7
- package/dist/spherical-clip.d.ts +95 -0
- package/dist/spherical-clip.js +557 -0
- package/dist/spherical-cull.d.ts +25 -0
- package/dist/spherical-cull.js +102 -0
- package/dist/spherical-dataset.d.ts +41 -9
- package/dist/spherical-dataset.js +221 -122
- package/dist/spherical-geometry.d.ts +2 -0
- package/dist/spherical-geometry.js +87 -44
- package/dist/spherical-line.d.ts +29 -0
- package/dist/spherical-line.js +221 -0
- package/dist/spherical-preprocess.d.ts +23 -0
- package/dist/spherical-preprocess.js +160 -0
- package/dist/spherical-repair.d.ts +17 -0
- package/dist/spherical-repair.js +100 -0
- package/dist/spherical-robust-dataset.d.ts +27 -0
- package/dist/spherical-robust-dataset.js +89 -0
- package/dist/spherical-view-clipper.d.ts +22 -0
- package/dist/spherical-view-clipper.js +85 -0
- package/dist/topology.d.ts +3 -0
- package/dist/topology.js +40 -9
- package/dist/types.d.ts +5 -1
- package/package.json +12 -7
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type CooperativeOptions } from "./cooperative.js";
|
|
2
|
+
import { type CollapsedRingPolicy } from "./reconstruct.js";
|
|
1
3
|
import type { SphericalPriorities } from "./spherical-geometry.js";
|
|
2
4
|
import type { FeatureCollection, QueryResult, Topology } from "./types.js";
|
|
3
5
|
import type { BlgTree } from "./blg.js";
|
|
@@ -5,27 +7,57 @@ import type { BlgTree } from "./blg.js";
|
|
|
5
7
|
export declare function importSphericalTopoJSON(input: unknown, objectName: string): FeatureCollection;
|
|
6
8
|
export interface SphericalQueryOptions {
|
|
7
9
|
level?: number;
|
|
10
|
+
/**
|
|
11
|
+
* "restore" (default) keeps every polygon. "drop" hides each polygon (and
|
|
12
|
+
* hole) whose ring has fewer than 3 distinct quadtree-activated vertices at
|
|
13
|
+
* the query level, except for explicitly retained polygon exteriors.
|
|
14
|
+
*/
|
|
15
|
+
collapsedRingPolicy?: CollapsedRingPolicy;
|
|
8
16
|
}
|
|
9
|
-
export interface SphericalInterruptOptions extends SphericalQueryOptions {
|
|
17
|
+
export interface SphericalInterruptOptions extends SphericalQueryOptions, CooperativeOptions {
|
|
10
18
|
shouldAbort?: () => boolean;
|
|
11
19
|
yieldTurn?: () => Promise<void>;
|
|
12
20
|
sliceMs?: number;
|
|
13
21
|
}
|
|
22
|
+
/** Optional preprocessing policy for explicitly retained polygon exteriors. */
|
|
23
|
+
export interface SphericalBuildOptions {
|
|
24
|
+
maxLevel?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Reuse the built topology and grow maxLevel on an explicit quadtree capacity
|
|
27
|
+
* failure, up to the supported maximum. Defaults to false so callers still
|
|
28
|
+
* observe the explicit failure.
|
|
29
|
+
*/
|
|
30
|
+
escalateCapacity?: boolean;
|
|
31
|
+
/** Feature ID to source polygon index; only the selected exterior is visible at level zero. */
|
|
32
|
+
alwaysVisiblePolygons?: ReadonlyMap<string, number>;
|
|
33
|
+
}
|
|
14
34
|
/** Geographic in-memory dataset. No planar viewport index or v1 partition serialization. */
|
|
15
35
|
export declare class SphericalQuadstreamDataset {
|
|
16
36
|
readonly coordinateMode: "spherical-d3";
|
|
17
37
|
readonly topology: Topology;
|
|
18
38
|
readonly priorities: SphericalPriorities;
|
|
19
39
|
readonly arcTrees: readonly BlgTree[];
|
|
40
|
+
/** Corrected global vertex thresholds, independent of query order. */
|
|
41
|
+
readonly activationLevels: readonly number[];
|
|
42
|
+
/** Vertices retained at all levels because a removal failed validation. */
|
|
43
|
+
readonly retainedVertices: number;
|
|
44
|
+
/**
|
|
45
|
+
* Per feature and path: the lowest level at which the closed ring has 3
|
|
46
|
+
* distinct vertices activated by the sparse quadtree (the third-smallest
|
|
47
|
+
* vertex activation level), or Infinity when it never does. Open paths and
|
|
48
|
+
* explicitly retained exteriors are 0.
|
|
49
|
+
*/
|
|
50
|
+
readonly ringActivation: readonly (readonly number[])[];
|
|
20
51
|
private readonly source;
|
|
21
52
|
private readonly signatures;
|
|
22
|
-
constructor(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
53
|
+
private constructor();
|
|
54
|
+
private pathActivation;
|
|
55
|
+
/** Nominal-level polygon eligibility, independent of corrected vertex thresholds. */
|
|
56
|
+
private visibility;
|
|
57
|
+
private session;
|
|
58
|
+
static create(input: FeatureCollection, options?: SphericalBuildOptions & CooperativeOptions): Promise<SphericalQuadstreamDataset>;
|
|
26
59
|
private formatResult;
|
|
27
|
-
|
|
60
|
+
query(options?: SphericalQueryOptions & CooperativeOptions): Promise<QueryResult>;
|
|
28
61
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}): SphericalQuadstreamDataset;
|
|
62
|
+
/** Cooperative construction with the same deterministic preparation algorithm. */
|
|
63
|
+
export declare function buildSphericalQuadstream(input: FeatureCollection, options?: SphericalBuildOptions & CooperativeOptions): Promise<SphericalQuadstreamDataset>;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { runSync, runCooperative, } from "./cooperative.js";
|
|
2
|
+
import { buildTopologyWithPolicy, buildTopologySteps } from "./topology.js";
|
|
2
3
|
import { decodeTopoJSON } from "./adapters.js";
|
|
3
|
-
import {
|
|
4
|
+
import { reconstructFeatureSteps, } from "./reconstruct.js";
|
|
5
|
+
import { stableBlgRandom } from "./blg.js";
|
|
6
|
+
import { buildTopologySafeArcTreeSteps } from "./spherical-preprocess.js";
|
|
4
7
|
import { signedArea } from "./geometry.js";
|
|
5
|
-
import { canonicalLonLat,
|
|
8
|
+
import { canonicalLonLat, buildSphericalPrioritiesSteps, projectSpherical, validGreatCirclePath, sphericalPolygonSignature, validSphericalPolygon, } from "./spherical-geometry.js";
|
|
6
9
|
function polygons(g) {
|
|
7
10
|
return g.type === "Polygon"
|
|
8
11
|
? [g.coordinates]
|
|
@@ -109,23 +112,155 @@ export function importSphericalTopoJSON(input, objectName) {
|
|
|
109
112
|
topology(decoded);
|
|
110
113
|
return decoded;
|
|
111
114
|
}
|
|
115
|
+
const ACTIVATION_EPSILON = 1e-9;
|
|
116
|
+
/**
|
|
117
|
+
* Level at which a vertex becomes selected in its arc's BLG tree. Selection at
|
|
118
|
+
* level L is `level <= floor(L)` or, for the next level, `random >= 1 - frac`,
|
|
119
|
+
* i.e. L >= level - random: a stable per-vertex threshold, so selections nest.
|
|
120
|
+
*/
|
|
121
|
+
function activationLevel(level, random) {
|
|
122
|
+
return level === 0
|
|
123
|
+
? 0
|
|
124
|
+
: level - random + (random === 1 ? ACTIVATION_EPSILON : 0);
|
|
125
|
+
}
|
|
126
|
+
function* buildSphericalPrioritiesWithEscalation(vertices, maxLevel, escalateCapacity) {
|
|
127
|
+
for (let level = maxLevel;; level++) {
|
|
128
|
+
try {
|
|
129
|
+
return yield* buildSphericalPrioritiesSteps(vertices, level);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
const message = String(error?.message ?? error);
|
|
133
|
+
if (!escalateCapacity ||
|
|
134
|
+
!message.includes("capacity exceeded") ||
|
|
135
|
+
level >= 26)
|
|
136
|
+
throw error;
|
|
137
|
+
yield {
|
|
138
|
+
stage: "Increase regional resolution",
|
|
139
|
+
completed: level - maxLevel + 1,
|
|
140
|
+
total: 26 - maxLevel,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function* prepareSpherical(input, maxLevel, escalateCapacity = false) {
|
|
146
|
+
yield { stage: "Normalize geometry" };
|
|
147
|
+
const source = sourceGeometry(input);
|
|
148
|
+
const signatures = [];
|
|
149
|
+
for (const f of source.features) {
|
|
150
|
+
if (signatures.length % 32 === 0)
|
|
151
|
+
yield {
|
|
152
|
+
stage: "Validate source",
|
|
153
|
+
completed: signatures.length,
|
|
154
|
+
total: source.features.length,
|
|
155
|
+
};
|
|
156
|
+
signatures.push(polygons(f.geometry).map((p) => sphericalPolygonSignature(p)));
|
|
157
|
+
}
|
|
158
|
+
yield { stage: "Construct topology" };
|
|
159
|
+
const topology = yield* buildTopologySteps(source, {
|
|
160
|
+
position: canonicalLonLat,
|
|
161
|
+
ring: (r) => validSphericalPolygon([[...r]]),
|
|
162
|
+
polygon: (r) => validSphericalPolygon(r),
|
|
163
|
+
line: validGreatCirclePath,
|
|
164
|
+
});
|
|
165
|
+
yield { stage: "Preserve spherical validity" };
|
|
166
|
+
preserveSphericalValidity(topology, source, signatures);
|
|
167
|
+
const priorities = yield* buildSphericalPrioritiesWithEscalation(topology.vertices, maxLevel, escalateCapacity);
|
|
168
|
+
const prepared = yield* buildTopologySafeArcTreeSteps(topology, topology.vertices.map((v) => activationLevel(priorities.levelByVertexId[v.id], v.critical ? 1 : stableBlgRandom(v.id))), signatures);
|
|
169
|
+
return { source, signatures, topology, priorities, prepared };
|
|
170
|
+
}
|
|
112
171
|
/** Geographic in-memory dataset. No planar viewport index or v1 partition serialization. */
|
|
113
172
|
export class SphericalQuadstreamDataset {
|
|
114
173
|
coordinateMode = "spherical-d3";
|
|
115
174
|
topology;
|
|
116
175
|
priorities;
|
|
117
176
|
arcTrees;
|
|
177
|
+
/** Corrected global vertex thresholds, independent of query order. */
|
|
178
|
+
activationLevels;
|
|
179
|
+
/** Vertices retained at all levels because a removal failed validation. */
|
|
180
|
+
retainedVertices;
|
|
181
|
+
/**
|
|
182
|
+
* Per feature and path: the lowest level at which the closed ring has 3
|
|
183
|
+
* distinct vertices activated by the sparse quadtree (the third-smallest
|
|
184
|
+
* vertex activation level), or Infinity when it never does. Open paths and
|
|
185
|
+
* explicitly retained exteriors are 0.
|
|
186
|
+
*/
|
|
187
|
+
ringActivation;
|
|
118
188
|
source;
|
|
119
189
|
signatures;
|
|
120
|
-
constructor(input, { maxLevel = 20 } = {}) {
|
|
121
|
-
|
|
122
|
-
this.
|
|
123
|
-
this.
|
|
124
|
-
|
|
125
|
-
this.priorities =
|
|
126
|
-
this.arcTrees =
|
|
190
|
+
constructor(input, { maxLevel = 20, escalateCapacity = false, alwaysVisiblePolygons, } = {}, prepared) {
|
|
191
|
+
const state = prepared ?? runSync(prepareSpherical(input, maxLevel, escalateCapacity));
|
|
192
|
+
this.source = state.source;
|
|
193
|
+
this.signatures = state.signatures;
|
|
194
|
+
this.topology = state.topology;
|
|
195
|
+
this.priorities = state.priorities;
|
|
196
|
+
this.arcTrees = state.prepared.trees;
|
|
197
|
+
this.activationLevels = state.prepared.activationLevels;
|
|
198
|
+
this.retainedVertices = state.prepared.retainedVertices;
|
|
199
|
+
this.ringActivation = this.topology.features.map((f) => {
|
|
200
|
+
const polygon = alwaysVisiblePolygons?.get(f.id);
|
|
201
|
+
const exterior = polygon !== undefined &&
|
|
202
|
+
(f.geometryType === "Polygon" || f.geometryType === "MultiPolygon")
|
|
203
|
+
? f.groups[polygon]?.[0]
|
|
204
|
+
: undefined;
|
|
205
|
+
return f.paths.map((path, i) => i === exterior ? 0 : this.pathActivation(path));
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
pathActivation(path) {
|
|
209
|
+
if (!path.closed)
|
|
210
|
+
return 0;
|
|
211
|
+
// Arc endpoints are always selected (topology anchors, three per closed
|
|
212
|
+
// ring), so they cannot define visibility: use each vertex's own priority.
|
|
213
|
+
const best = new Map();
|
|
214
|
+
for (const ref of path.arcs)
|
|
215
|
+
for (const id of this.topology.arcs[Math.abs(ref) - 1].vertexIds) {
|
|
216
|
+
const a = activationLevel(this.priorities.levelByVertexId[id], this.topology.vertices[id].critical ? 1 : stableBlgRandom(id));
|
|
217
|
+
if (a < (best.get(id) ?? Infinity))
|
|
218
|
+
best.set(id, a);
|
|
219
|
+
}
|
|
220
|
+
let m1 = Infinity, m2 = Infinity, m3 = Infinity;
|
|
221
|
+
for (const a of best.values()) {
|
|
222
|
+
if (a < m1)
|
|
223
|
+
[m1, m2, m3] = [a, m1, m2];
|
|
224
|
+
else if (a < m2)
|
|
225
|
+
[m2, m3] = [a, m2];
|
|
226
|
+
else if (a < m3)
|
|
227
|
+
m3 = a;
|
|
228
|
+
}
|
|
229
|
+
return m3;
|
|
230
|
+
}
|
|
231
|
+
/** Nominal-level polygon eligibility, independent of corrected vertex thresholds. */
|
|
232
|
+
visibility(level) {
|
|
233
|
+
let hiddenPolygons = 0;
|
|
234
|
+
const hidden = [], signatures = [];
|
|
235
|
+
this.topology.features.forEach((f, i) => {
|
|
236
|
+
const act = this.ringActivation[i], source = this.signatures[i];
|
|
237
|
+
let set;
|
|
238
|
+
const sigs = [];
|
|
239
|
+
if (f.geometryType === "Polygon" || f.geometryType === "MultiPolygon")
|
|
240
|
+
f.groups.forEach((group, j) => {
|
|
241
|
+
if (act[group[0]] > level) {
|
|
242
|
+
(set ??= new Set()).add(group[0]);
|
|
243
|
+
hiddenPolygons++;
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const shown = group.filter((p) => act[p] <= level);
|
|
247
|
+
for (const p of group)
|
|
248
|
+
if (!shown.includes(p))
|
|
249
|
+
(set ??= new Set()).add(p);
|
|
250
|
+
const sig = source[j];
|
|
251
|
+
sigs.push(shown.length === group.length
|
|
252
|
+
? sig
|
|
253
|
+
: {
|
|
254
|
+
chart: sig.chart,
|
|
255
|
+
signs: sig.signs.filter((_, k) => act[group[k]] <= level),
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
hidden.push(set);
|
|
259
|
+
signatures.push(sigs);
|
|
260
|
+
});
|
|
261
|
+
return { hidden, signatures, hiddenPolygons };
|
|
127
262
|
}
|
|
128
|
-
|
|
263
|
+
session(options) {
|
|
129
264
|
if ("bounds" in options || "validate" in options)
|
|
130
265
|
throw new Error("Spherical queries require global validated retrieval");
|
|
131
266
|
const level = options.level ?? this.priorities.maxLevel - 1;
|
|
@@ -133,54 +268,37 @@ export class SphericalQuadstreamDataset {
|
|
|
133
268
|
level < 0 ||
|
|
134
269
|
level >= this.priorities.maxLevel)
|
|
135
270
|
throw new Error("Invalid spherical query level");
|
|
136
|
-
const lookup = (id) => {
|
|
271
|
+
const drop = options.collapsedRingPolicy === "drop", vis = drop ? this.visibility(level) : undefined, lookup = (id) => {
|
|
137
272
|
const v = this.topology.vertices[id];
|
|
138
273
|
return v ? [v.x, v.y] : undefined;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const promoted = new Map();
|
|
142
|
-
let promotedArcs = 0;
|
|
143
|
-
const levelOf = (arcId) => promoted.get(arcId) ?? level;
|
|
144
|
-
const check = (i, r) => {
|
|
145
|
-
const p = polygons(r.feature.geometry), s = this.signatures[i];
|
|
274
|
+
}, check = (i, r) => {
|
|
275
|
+
const p = polygons(r.feature.geometry).filter((g) => g.length), s = vis ? vis.signatures[i] : this.signatures[i];
|
|
146
276
|
return (!r.missing &&
|
|
147
277
|
p.length === s.length &&
|
|
148
278
|
p.every((g, j) => validSphericalPolygon(g, s[j])) &&
|
|
149
279
|
lines(r.feature.geometry).every(validGreatCirclePath));
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const id = Math.abs(ref) - 1, cur = levelOf(id);
|
|
164
|
-
if (cur >= full)
|
|
165
|
-
continue;
|
|
166
|
-
promoted.set(id, Math.min(full, Math.floor(cur) + 1));
|
|
167
|
-
touched.add(id);
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
if (!touched.size)
|
|
171
|
-
break;
|
|
172
|
-
promotedArcs = promoted.size;
|
|
173
|
-
this.topology.features.forEach((f, i) => {
|
|
174
|
-
if (f.paths.some((p) => p.arcs.some((r) => touched.has(Math.abs(r) - 1)))) {
|
|
175
|
-
results[i] = run(f);
|
|
176
|
-
ok[i] = check(i, results[i]);
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
const valid = ok.every(Boolean);
|
|
181
|
-
return this.formatResult(level, results, valid, promotedArcs);
|
|
280
|
+
}, run = (f, i) => reconstructFeatureSteps(f, this.topology.arcs, this.arcTrees, level, lookup, false, drop
|
|
281
|
+
? { collapsed: "drop", hiddenPaths: vis.hidden[i] }
|
|
282
|
+
: { collapsed: "drop" });
|
|
283
|
+
return { level, check, run, vis };
|
|
284
|
+
}
|
|
285
|
+
static async create(input, options = {}) {
|
|
286
|
+
const prepared = await runCooperative(prepareSpherical(input, options.maxLevel ?? 20, options.escalateCapacity), options);
|
|
287
|
+
options.signal?.throwIfAborted();
|
|
288
|
+
return new SphericalQuadstreamDataset(input, options, prepared);
|
|
289
|
+
}
|
|
290
|
+
/** @internal Synchronous reference for algorithm parity tests. */
|
|
291
|
+
static createSync(input, options) {
|
|
292
|
+
return new SphericalQuadstreamDataset(input, options);
|
|
182
293
|
}
|
|
183
|
-
|
|
294
|
+
/** @internal Synchronous reference for algorithm parity tests. */
|
|
295
|
+
querySync(options = {}) {
|
|
296
|
+
const s = this.session(options);
|
|
297
|
+
const results = this.topology.features.map((f, i) => runSync(s.run(f, i)));
|
|
298
|
+
const valid = results.every((r, i) => s.check(i, r));
|
|
299
|
+
return this.formatResult(s, results, valid);
|
|
300
|
+
}
|
|
301
|
+
formatResult(s, results, valid) {
|
|
184
302
|
return {
|
|
185
303
|
geojson: {
|
|
186
304
|
type: "FeatureCollection",
|
|
@@ -194,91 +312,72 @@ export class SphericalQuadstreamDataset {
|
|
|
194
312
|
};
|
|
195
313
|
}),
|
|
196
314
|
},
|
|
197
|
-
level,
|
|
315
|
+
level: s.level,
|
|
198
316
|
valid,
|
|
199
|
-
promotedArcs,
|
|
317
|
+
promotedArcs: 0,
|
|
318
|
+
...(s.vis
|
|
319
|
+
? {
|
|
320
|
+
hiddenPolygons: s.vis.hiddenPolygons,
|
|
321
|
+
hiddenRings: results.reduce((n, r) => n + r.hiddenRings, 0),
|
|
322
|
+
}
|
|
323
|
+
: {}),
|
|
200
324
|
usedFallback: false,
|
|
201
325
|
selectedFeatures: results.length,
|
|
202
326
|
selectedVertices: results.reduce((n, r) => n + r.selectedVertices, 0),
|
|
203
327
|
};
|
|
204
328
|
}
|
|
329
|
+
async query(options = {}) {
|
|
330
|
+
const result = await this.queryInterruptible(options);
|
|
331
|
+
if (!result)
|
|
332
|
+
throw new DOMException("Aborted", "AbortError");
|
|
333
|
+
return result;
|
|
334
|
+
}
|
|
335
|
+
/** @internal Adapter for the demo's latest-view scheduler. */
|
|
205
336
|
async queryInterruptible(options = {}) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
level >= this.priorities.maxLevel)
|
|
213
|
-
throw new Error("Invalid spherical query level");
|
|
214
|
-
if (shouldAbort?.())
|
|
215
|
-
return null;
|
|
216
|
-
const lookup = (id) => {
|
|
217
|
-
const v = this.topology.vertices[id];
|
|
218
|
-
return v ? [v.x, v.y] : undefined;
|
|
219
|
-
};
|
|
220
|
-
const full = this.priorities.maxLevel - 1;
|
|
221
|
-
const promoted = new Map();
|
|
222
|
-
let promotedArcs = 0;
|
|
223
|
-
const levelOf = (arcId) => promoted.get(arcId) ?? level;
|
|
224
|
-
const check = (i, r) => {
|
|
225
|
-
const p = polygons(r.feature.geometry), s = this.signatures[i];
|
|
226
|
-
return (!r.missing &&
|
|
227
|
-
p.length === s.length &&
|
|
228
|
-
p.every((g, j) => validSphericalPolygon(g, s[j])) &&
|
|
229
|
-
lines(r.feature.geometry).every(validGreatCirclePath));
|
|
230
|
-
};
|
|
231
|
-
const run = (f) => reconstructFeature(f, this.topology.arcs, this.arcTrees, levelOf, lookup, false, false);
|
|
232
|
-
const results = [];
|
|
233
|
-
const ok = [];
|
|
234
|
-
let sliceStart = performance.now();
|
|
235
|
-
for (let i = 0; i < this.topology.features.length; i++) {
|
|
236
|
-
const r = run(this.topology.features[i]);
|
|
237
|
-
results.push(r);
|
|
238
|
-
ok.push(check(i, r));
|
|
239
|
-
if (yieldTurn && performance.now() - sliceStart >= sliceMs) {
|
|
240
|
-
await yieldTurn();
|
|
337
|
+
const { shouldAbort, yieldTurn, sliceMs = 4, signal, onProgress, onSlice, } = options;
|
|
338
|
+
const s = this.session(options), features = this.topology.features;
|
|
339
|
+
function* steps() {
|
|
340
|
+
const results = [];
|
|
341
|
+
let valid = true;
|
|
342
|
+
for (let i = 0; i < features.length; i++) {
|
|
241
343
|
if (shouldAbort?.())
|
|
242
344
|
return null;
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const touched = new Set();
|
|
248
|
-
ok.forEach((good, i) => {
|
|
249
|
-
if (good)
|
|
250
|
-
return;
|
|
251
|
-
for (const path of this.topology.features[i].paths)
|
|
252
|
-
for (const ref of path.arcs) {
|
|
253
|
-
const id = Math.abs(ref) - 1, cur = levelOf(id);
|
|
254
|
-
if (cur >= full)
|
|
255
|
-
continue;
|
|
256
|
-
promoted.set(id, Math.min(full, Math.floor(cur) + 1));
|
|
257
|
-
touched.add(id);
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
if (!touched.size)
|
|
261
|
-
break;
|
|
262
|
-
promotedArcs = promoted.size;
|
|
263
|
-
for (let i = 0; i < this.topology.features.length; i++) {
|
|
264
|
-
const f = this.topology.features[i];
|
|
265
|
-
if (f.paths.some((p) => p.arcs.some((r) => touched.has(Math.abs(r) - 1)))) {
|
|
266
|
-
results[i] = run(f);
|
|
267
|
-
ok[i] = check(i, results[i]);
|
|
268
|
-
if (yieldTurn && performance.now() - sliceStart >= sliceMs) {
|
|
269
|
-
await yieldTurn();
|
|
345
|
+
const work = s.run(features[i], i);
|
|
346
|
+
let step = work.next();
|
|
347
|
+
try {
|
|
348
|
+
while (!step.done) {
|
|
270
349
|
if (shouldAbort?.())
|
|
271
350
|
return null;
|
|
272
|
-
|
|
351
|
+
yield step.value;
|
|
352
|
+
step = work.next();
|
|
273
353
|
}
|
|
354
|
+
results.push(step.value);
|
|
355
|
+
if (!s.check(i, step.value))
|
|
356
|
+
valid = false;
|
|
357
|
+
}
|
|
358
|
+
finally {
|
|
359
|
+
work.return(undefined);
|
|
274
360
|
}
|
|
275
361
|
}
|
|
362
|
+
if (shouldAbort?.())
|
|
363
|
+
return null;
|
|
364
|
+
return finish(results, valid);
|
|
276
365
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
366
|
+
const finish = (results, valid) => this.formatResult(s, results, valid);
|
|
367
|
+
return runCooperative(steps(), {
|
|
368
|
+
yieldTurn,
|
|
369
|
+
sliceMs,
|
|
370
|
+
signal,
|
|
371
|
+
onProgress,
|
|
372
|
+
onSlice,
|
|
373
|
+
});
|
|
280
374
|
}
|
|
281
375
|
}
|
|
282
|
-
|
|
283
|
-
|
|
376
|
+
/** @internal Synchronous reference for algorithm parity tests. */
|
|
377
|
+
export function buildSphericalQuadstreamSync(input, options) {
|
|
378
|
+
return SphericalQuadstreamDataset.createSync(input, options);
|
|
379
|
+
}
|
|
380
|
+
/** Cooperative construction with the same deterministic preparation algorithm. */
|
|
381
|
+
export async function buildSphericalQuadstream(input, options = {}) {
|
|
382
|
+
return SphericalQuadstreamDataset.create(input, options);
|
|
284
383
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Work } from "./cooperative.js";
|
|
1
2
|
import type { Position, Vertex } from "./types.js";
|
|
2
3
|
export type UnitVector = readonly [number, number, number];
|
|
3
4
|
/** Exact seam aliases only; no near-coordinate snapping. */
|
|
@@ -21,6 +22,7 @@ export interface SphericalPriorities {
|
|
|
21
22
|
}
|
|
22
23
|
export declare function sphericalCellAddress(p: Position, level: number): Omit<SphericalCell, "vertexId">;
|
|
23
24
|
export declare function buildSphericalPriorities(vertices: readonly Vertex[], maxLevel?: number): SphericalPriorities;
|
|
25
|
+
export declare function buildSphericalPrioritiesSteps(vertices: readonly Vertex[], maxLevel?: number): Work<SphericalPriorities>;
|
|
24
26
|
/** Conservative reference chart: minor geodesics become straight segments in an open hemisphere. */
|
|
25
27
|
export interface SphericalChart {
|
|
26
28
|
center: UnitVector;
|