@vizhub/quadstream 0.0.0-stage → 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/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/README.md +396 -2
- package/bin/quadstream.mjs +240 -0
- package/dist/adapters.d.ts +26 -0
- package/dist/adapters.js +229 -0
- package/dist/blg.d.ts +17 -0
- package/dist/blg.js +83 -0
- package/dist/dataset.d.ts +16 -0
- package/dist/dataset.js +61 -0
- package/dist/geometry.d.ts +13 -0
- package/dist/geometry.js +126 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +15 -0
- package/dist/loader.d.ts +34 -0
- package/dist/loader.js +138 -0
- package/dist/manifest-schema.d.ts +4 -0
- package/dist/manifest-schema.js +141 -0
- package/dist/maplibre-adapter.d.ts +30 -0
- package/dist/maplibre-adapter.js +84 -0
- package/dist/partition.d.ts +13 -0
- package/dist/partition.js +124 -0
- package/dist/progressive-map.d.ts +28 -0
- package/dist/progressive-map.js +112 -0
- package/dist/quadtree.d.ts +8 -0
- package/dist/quadtree.js +50 -0
- package/dist/reconstruct.d.ts +13 -0
- package/dist/reconstruct.js +106 -0
- package/dist/session.d.ts +24 -0
- package/dist/session.js +116 -0
- package/dist/spatial-index.d.ts +9 -0
- package/dist/spatial-index.js +63 -0
- package/dist/spherical-dataset.d.ts +31 -0
- package/dist/spherical-dataset.js +284 -0
- package/dist/spherical-geometry.d.ts +39 -0
- package/dist/spherical-geometry.js +197 -0
- package/dist/topology.d.ts +11 -0
- package/dist/topology.js +229 -0
- package/dist/types.d.ts +119 -0
- package/dist/types.js +1 -0
- package/package.json +75 -4
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Bounds, SparseQuadtree, Vertex } from "./types.js";
|
|
2
|
+
export declare function cellKey(level: number, i: number, j: number): string;
|
|
3
|
+
export declare function cellAddress(x: number, y: number, bounds: Bounds, level: number): {
|
|
4
|
+
i: number;
|
|
5
|
+
j: number;
|
|
6
|
+
};
|
|
7
|
+
/** Assign each distinct vertex to the first unoccupied quadtree cell, coarse to fine. */
|
|
8
|
+
export declare function buildSparseQuadtree(vertices: readonly Vertex[], bounds: Bounds, maxLevel?: number): SparseQuadtree;
|
package/dist/quadtree.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { assertBounds } from "./geometry.js";
|
|
2
|
+
export function cellKey(level, i, j) {
|
|
3
|
+
return `${level}_${i}_${j}`;
|
|
4
|
+
}
|
|
5
|
+
export function cellAddress(x, y, bounds, level) {
|
|
6
|
+
assertBounds(bounds);
|
|
7
|
+
if (!Number.isInteger(level) || level < 0 || level > 25)
|
|
8
|
+
throw new Error("Quadtree level must be 0..25");
|
|
9
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
10
|
+
throw new Error("Nonfinite coordinate");
|
|
11
|
+
const [minX, minY, maxX, maxY] = bounds;
|
|
12
|
+
if (x < minX || x > maxX || y < minY || y > maxY)
|
|
13
|
+
throw new Error("Point outside quadtree bounds");
|
|
14
|
+
const side = 2 ** level;
|
|
15
|
+
const i = minX === maxX
|
|
16
|
+
? 0
|
|
17
|
+
: Math.min(side - 1, Math.floor(((x - minX) / (maxX - minX)) * side));
|
|
18
|
+
const j = minY === maxY
|
|
19
|
+
? 0
|
|
20
|
+
: Math.min(side - 1, Math.floor(((y - minY) / (maxY - minY)) * side));
|
|
21
|
+
return { i, j };
|
|
22
|
+
}
|
|
23
|
+
/** Assign each distinct vertex to the first unoccupied quadtree cell, coarse to fine. */
|
|
24
|
+
export function buildSparseQuadtree(vertices, bounds, maxLevel = 20) {
|
|
25
|
+
assertBounds(bounds);
|
|
26
|
+
if (!Number.isInteger(maxLevel) || maxLevel < 1 || maxLevel > 26)
|
|
27
|
+
throw new Error("maxLevel must be 1..26");
|
|
28
|
+
const sorted = [...vertices].sort((a, b) => Number(b.critical) - Number(a.critical) ||
|
|
29
|
+
a.x - b.x ||
|
|
30
|
+
a.y - b.y ||
|
|
31
|
+
a.id - b.id);
|
|
32
|
+
const occupied = new Set(), cells = [], levelByVertexId = [];
|
|
33
|
+
for (const v of sorted) {
|
|
34
|
+
let inserted = false;
|
|
35
|
+
for (let level = 0; level < maxLevel; level++) {
|
|
36
|
+
const { i, j } = cellAddress(v.x, v.y, bounds, level), key = cellKey(level, i, j);
|
|
37
|
+
if (occupied.has(key))
|
|
38
|
+
continue;
|
|
39
|
+
occupied.add(key);
|
|
40
|
+
cells.push({ vertexId: v.id, level, i, j, key });
|
|
41
|
+
levelByVertexId[v.id] = level;
|
|
42
|
+
inserted = true;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
if (!inserted)
|
|
46
|
+
throw new Error(`Quadtree capacity exceeded at vertex ${v.id}; increase maxLevel`);
|
|
47
|
+
}
|
|
48
|
+
cells.sort((a, b) => a.level - b.level || a.i - b.i || a.j - b.j || a.vertexId - b.vertexId);
|
|
49
|
+
return { bounds, maxLevel, cells, levelByVertexId };
|
|
50
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type BlgTree } from "./blg.js";
|
|
2
|
+
import type { Arc, Feature, Position, TopologyFeature } from "./types.js";
|
|
3
|
+
export interface CoordinateLookup {
|
|
4
|
+
(id: number): Position | undefined;
|
|
5
|
+
}
|
|
6
|
+
export interface ReconstructionResult {
|
|
7
|
+
feature: Feature;
|
|
8
|
+
missing: boolean;
|
|
9
|
+
valid: boolean;
|
|
10
|
+
selectedVertices: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function buildArcTrees(arcs: readonly Arc[], levels: readonly number[], critical?: readonly boolean[]): BlgTree[];
|
|
13
|
+
export declare function reconstructFeature(f: TopologyFeature, arcs: readonly Arc[], trees: readonly BlgTree[], level: number | ((arcId: number) => number), lookup: CoordinateLookup, includeMissing?: boolean, planarValidity?: boolean): ReconstructionResult;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { validPolygon, simpleClosedRing } from "./geometry.js";
|
|
2
|
+
import { buildBlgTree, selectBlgPositions, stableBlgRandom, } from "./blg.js";
|
|
3
|
+
export function buildArcTrees(arcs, levels, critical = []) {
|
|
4
|
+
return arcs.map((arc) => buildBlgTree(arc.vertexIds.map((id, i) => i === 0 || i === arc.vertexIds.length - 1 ? 0 : levels[id]), arc.vertexIds.map((id) => (critical[id] ? 1 : stableBlgRandom(id)))));
|
|
5
|
+
}
|
|
6
|
+
export function reconstructFeature(f, arcs, trees, level, lookup, includeMissing = false, planarValidity = true) {
|
|
7
|
+
let missing = false, selectedVertices = 0;
|
|
8
|
+
const paths = [];
|
|
9
|
+
for (const path of f.paths) {
|
|
10
|
+
const coords = [], allIds = [];
|
|
11
|
+
let pathSelectedVertices = 0;
|
|
12
|
+
for (const ref of path.arcs) {
|
|
13
|
+
const arcId = Math.abs(ref) - 1, arc = arcs[arcId], tree = trees[arcId];
|
|
14
|
+
const positions = selectBlgPositions(tree, typeof level === "number" ? level : level(arcId));
|
|
15
|
+
if (ref < 0)
|
|
16
|
+
positions.reverse();
|
|
17
|
+
const orderedIds = ref < 0 ? [...arc.vertexIds].reverse() : arc.vertexIds;
|
|
18
|
+
for (const id of orderedIds)
|
|
19
|
+
if (!allIds.length || allIds.at(-1) !== id)
|
|
20
|
+
allIds.push(id);
|
|
21
|
+
for (let i = 0; i < positions.length; i++) {
|
|
22
|
+
const id = arc.vertexIds[positions[i]], xy = lookup(id);
|
|
23
|
+
if (!xy) {
|
|
24
|
+
missing = true;
|
|
25
|
+
if (includeMissing)
|
|
26
|
+
continue;
|
|
27
|
+
else
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (coords.length &&
|
|
31
|
+
i === 0 &&
|
|
32
|
+
xy[0] === coords.at(-1)[0] &&
|
|
33
|
+
xy[1] === coords.at(-1)[1])
|
|
34
|
+
continue;
|
|
35
|
+
coords.push(xy);
|
|
36
|
+
pathSelectedVertices++;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (path.closed) {
|
|
40
|
+
const distinct = new Set(coords.slice(0, -1).map((p) => p.join(",")));
|
|
41
|
+
if (distinct.size < 3) {
|
|
42
|
+
coords.length = 0;
|
|
43
|
+
pathSelectedVertices = 0;
|
|
44
|
+
for (const id of allIds) {
|
|
45
|
+
const xy = lookup(id);
|
|
46
|
+
if (xy &&
|
|
47
|
+
(!coords.length ||
|
|
48
|
+
xy[0] !== coords.at(-1)[0] ||
|
|
49
|
+
xy[1] !== coords.at(-1)[1])) {
|
|
50
|
+
coords.push(xy);
|
|
51
|
+
pathSelectedVertices++;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Coordinate identity is maintained; close polygons explicitly if needed.
|
|
57
|
+
if (path.closed &&
|
|
58
|
+
coords.length &&
|
|
59
|
+
(coords[0][0] !== coords.at(-1)[0] ||
|
|
60
|
+
coords[0][1] !== coords.at(-1)[1]))
|
|
61
|
+
coords.push(coords[0]);
|
|
62
|
+
selectedVertices += pathSelectedVertices;
|
|
63
|
+
paths.push(coords);
|
|
64
|
+
}
|
|
65
|
+
const groups = f.groups.map((group) => group.map((i) => paths[i]));
|
|
66
|
+
let geometry;
|
|
67
|
+
let valid = true;
|
|
68
|
+
const checkPolygon = planarValidity ? validPolygon : () => true;
|
|
69
|
+
switch (f.geometryType) {
|
|
70
|
+
case "Polygon":
|
|
71
|
+
geometry = { type: "Polygon", coordinates: groups[0] };
|
|
72
|
+
valid = checkPolygon(groups[0]);
|
|
73
|
+
break;
|
|
74
|
+
case "MultiPolygon":
|
|
75
|
+
geometry = { type: "MultiPolygon", coordinates: groups };
|
|
76
|
+
valid = groups.every(checkPolygon);
|
|
77
|
+
break;
|
|
78
|
+
case "LineString":
|
|
79
|
+
geometry = { type: "LineString", coordinates: groups[0][0] };
|
|
80
|
+
valid = groups[0][0].length >= 2;
|
|
81
|
+
break;
|
|
82
|
+
case "MultiLineString":
|
|
83
|
+
geometry = {
|
|
84
|
+
type: "MultiLineString",
|
|
85
|
+
coordinates: groups.map((g) => g[0]),
|
|
86
|
+
};
|
|
87
|
+
valid = groups.every((g) => g[0].length >= 2);
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
// A closed ring whose last segment collapses must not be accepted by accident.
|
|
91
|
+
if (planarValidity &&
|
|
92
|
+
f.geometryType === "Polygon" &&
|
|
93
|
+
!groups[0].every(simpleClosedRing))
|
|
94
|
+
valid = false;
|
|
95
|
+
return {
|
|
96
|
+
feature: {
|
|
97
|
+
type: "Feature",
|
|
98
|
+
id: f.id,
|
|
99
|
+
properties: { ...f.properties },
|
|
100
|
+
geometry,
|
|
101
|
+
},
|
|
102
|
+
missing,
|
|
103
|
+
valid,
|
|
104
|
+
selectedVertices,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { FeatureCollection, QuadstreamManifest, QueryOptions } from "./types.js";
|
|
2
|
+
/** Progressive session: validates every partition before changing observable state. */
|
|
3
|
+
export declare class QuadstreamSession {
|
|
4
|
+
readonly manifest: QuadstreamManifest;
|
|
5
|
+
private readonly loaded;
|
|
6
|
+
private readonly vertices;
|
|
7
|
+
private readonly tree;
|
|
8
|
+
private readonly featureIndex;
|
|
9
|
+
private readonly partitionByKey;
|
|
10
|
+
private readonly validityCache;
|
|
11
|
+
constructor(manifest: QuadstreamManifest);
|
|
12
|
+
load(key: string, bytes: Uint8Array): boolean;
|
|
13
|
+
get loadedKeys(): string[];
|
|
14
|
+
missingKeys(level: number): string[];
|
|
15
|
+
query(options?: QueryOptions): {
|
|
16
|
+
geojson: FeatureCollection;
|
|
17
|
+
complete: boolean;
|
|
18
|
+
level: number;
|
|
19
|
+
missingKeys: string[];
|
|
20
|
+
omittedFeatures: number;
|
|
21
|
+
selectedVertices: number;
|
|
22
|
+
usedFallback: boolean;
|
|
23
|
+
};
|
|
24
|
+
}
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { assertBounds } from "./geometry.js";
|
|
2
|
+
import { buildArcTrees, reconstructFeature } from "./reconstruct.js";
|
|
3
|
+
import { createSpatialIndex } from "./spatial-index.js";
|
|
4
|
+
import { decodePartition, checksum, requiredPartitionKeys, } from "./partition.js";
|
|
5
|
+
/** Progressive session: validates every partition before changing observable state. */
|
|
6
|
+
export class QuadstreamSession {
|
|
7
|
+
manifest;
|
|
8
|
+
loaded = new Set();
|
|
9
|
+
vertices = new Map();
|
|
10
|
+
tree;
|
|
11
|
+
featureIndex;
|
|
12
|
+
partitionByKey;
|
|
13
|
+
validityCache = new Map();
|
|
14
|
+
constructor(manifest) {
|
|
15
|
+
if (manifest?.format !== "quadstream" ||
|
|
16
|
+
manifest.version !== 1 ||
|
|
17
|
+
!Array.isArray(manifest.partitions))
|
|
18
|
+
throw new Error("Unsupported Quadstream manifest");
|
|
19
|
+
this.manifest = manifest;
|
|
20
|
+
this.tree = buildArcTrees(manifest.arcs, manifest.vertices.map((v) => v.level));
|
|
21
|
+
this.featureIndex = createSpatialIndex(manifest.features.map((f, i) => ({ bounds: f.bounds, value: i })));
|
|
22
|
+
this.partitionByKey = new Map(manifest.partitions.map((p) => [p.key, p]));
|
|
23
|
+
if (this.partitionByKey.size !== manifest.partitions.length)
|
|
24
|
+
throw new Error("Duplicate partition keys");
|
|
25
|
+
const ids = new Set();
|
|
26
|
+
for (const p of manifest.partitions)
|
|
27
|
+
for (const id of p.vertexIds) {
|
|
28
|
+
if (ids.has(id))
|
|
29
|
+
throw new Error("Vertex assigned to multiple partitions");
|
|
30
|
+
ids.add(id);
|
|
31
|
+
}
|
|
32
|
+
if (ids.size !== manifest.vertices.length)
|
|
33
|
+
throw new Error("Manifest vertex accounting mismatch");
|
|
34
|
+
}
|
|
35
|
+
load(key, bytes) {
|
|
36
|
+
const info = this.partitionByKey.get(key);
|
|
37
|
+
if (!info)
|
|
38
|
+
throw new Error(`Unknown partition: ${key}`);
|
|
39
|
+
if (bytes.byteLength !== info.byteLength ||
|
|
40
|
+
checksum(bytes) !== info.checksum)
|
|
41
|
+
throw new Error(`Partition checksum or length mismatch: ${key}`);
|
|
42
|
+
if (this.loaded.has(key))
|
|
43
|
+
return false;
|
|
44
|
+
const records = decodePartition(bytes), expected = new Set(info.vertexIds), seen = new Set();
|
|
45
|
+
if (records.length !== expected.size)
|
|
46
|
+
throw new Error("Partition count mismatch");
|
|
47
|
+
for (const record of records) {
|
|
48
|
+
const meta = this.manifest.vertices[record.id];
|
|
49
|
+
if (!expected.has(record.id) ||
|
|
50
|
+
seen.has(record.id) ||
|
|
51
|
+
!meta ||
|
|
52
|
+
meta.id !== record.id ||
|
|
53
|
+
meta.level !== record.level ||
|
|
54
|
+
this.vertices.has(record.id))
|
|
55
|
+
throw new Error("Unexpected or duplicate partition vertex");
|
|
56
|
+
seen.add(record.id);
|
|
57
|
+
}
|
|
58
|
+
for (const record of records)
|
|
59
|
+
this.vertices.set(record.id, record);
|
|
60
|
+
this.loaded.add(key);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
get loadedKeys() {
|
|
64
|
+
return [...this.loaded].sort();
|
|
65
|
+
}
|
|
66
|
+
missingKeys(level) {
|
|
67
|
+
return requiredPartitionKeys(this.manifest, level).filter((k) => !this.loaded.has(k));
|
|
68
|
+
}
|
|
69
|
+
query(options = {}) {
|
|
70
|
+
const level = options.level ?? this.manifest.maxLevel - 1;
|
|
71
|
+
const missingKeys = this.missingKeys(level);
|
|
72
|
+
if (options.bounds)
|
|
73
|
+
assertBounds(options.bounds);
|
|
74
|
+
const ids = options.bounds
|
|
75
|
+
? this.featureIndex.query(options.bounds)
|
|
76
|
+
: this.manifest.features.map((_, i) => i);
|
|
77
|
+
const allLoaded = this.loaded.size === this.manifest.partitions.length;
|
|
78
|
+
let globallyInvalid = false;
|
|
79
|
+
if (allLoaded && options.validate !== false) {
|
|
80
|
+
const cached = this.validityCache.get(level);
|
|
81
|
+
if (cached !== undefined)
|
|
82
|
+
globallyInvalid = !cached;
|
|
83
|
+
else {
|
|
84
|
+
globallyInvalid = this.manifest.features.some((f) => !reconstructFeature(f, this.manifest.arcs, this.tree, level, (id) => {
|
|
85
|
+
const v = this.vertices.get(id);
|
|
86
|
+
return v ? [v.x, v.y] : undefined;
|
|
87
|
+
}).valid);
|
|
88
|
+
this.validityCache.set(level, !globallyInvalid);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
let omittedFeatures = 0, selectedVertices = 0;
|
|
92
|
+
const features = [];
|
|
93
|
+
for (const i of ids) {
|
|
94
|
+
const result = reconstructFeature(this.manifest.features[i], this.manifest.arcs, this.tree, globallyInvalid ? Infinity : level, (id) => {
|
|
95
|
+
const v = this.vertices.get(id);
|
|
96
|
+
return v ? [v.x, v.y] : undefined;
|
|
97
|
+
});
|
|
98
|
+
if (!result.valid || result.missing) {
|
|
99
|
+
omittedFeatures++;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
selectedVertices += result.selectedVertices;
|
|
103
|
+
features.push(result.feature);
|
|
104
|
+
}
|
|
105
|
+
const usedFallback = globallyInvalid;
|
|
106
|
+
return {
|
|
107
|
+
geojson: { type: "FeatureCollection", features },
|
|
108
|
+
complete: missingKeys.length === 0 && omittedFeatures === 0,
|
|
109
|
+
missingKeys,
|
|
110
|
+
level,
|
|
111
|
+
omittedFeatures,
|
|
112
|
+
selectedVertices,
|
|
113
|
+
usedFallback,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Bounds } from "./types.js";
|
|
2
|
+
/** Deterministic, immutable packed bounding-volume hierarchy for static geometry. */
|
|
3
|
+
export declare function createSpatialIndex<T>(items: readonly {
|
|
4
|
+
bounds: Bounds;
|
|
5
|
+
value: T;
|
|
6
|
+
}[], bucketSize?: number): {
|
|
7
|
+
query(bounds: Bounds): T[];
|
|
8
|
+
readonly size: number;
|
|
9
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { intersects, unionBounds } from "./geometry.js";
|
|
2
|
+
/** Deterministic, immutable packed bounding-volume hierarchy for static geometry. */
|
|
3
|
+
export function createSpatialIndex(items, bucketSize = 16) {
|
|
4
|
+
if (!Number.isInteger(bucketSize) || bucketSize < 2)
|
|
5
|
+
throw new Error("bucketSize must be >=2");
|
|
6
|
+
const entries = items.map((x, ordinal) => ({
|
|
7
|
+
bounds: x.bounds,
|
|
8
|
+
value: x.value,
|
|
9
|
+
ordinal,
|
|
10
|
+
}));
|
|
11
|
+
function box(nodes) {
|
|
12
|
+
return nodes
|
|
13
|
+
.slice(1)
|
|
14
|
+
.reduce((b, n) => unionBounds(b, n.bounds), nodes[0].bounds);
|
|
15
|
+
}
|
|
16
|
+
function leaf(chunks) {
|
|
17
|
+
return { bounds: box(chunks), entries: chunks };
|
|
18
|
+
}
|
|
19
|
+
function group(xs) {
|
|
20
|
+
const sorted = [...xs].sort((a, b) => a.bounds[0] + a.bounds[2] - (b.bounds[0] + b.bounds[2]) ||
|
|
21
|
+
a.bounds[1] + a.bounds[3] - (b.bounds[1] + b.bounds[3]));
|
|
22
|
+
const slices = Math.ceil(Math.sqrt(sorted.length / bucketSize)), perSlice = Math.ceil(sorted.length / slices);
|
|
23
|
+
const result = [];
|
|
24
|
+
for (let s = 0; s < sorted.length; s += perSlice) {
|
|
25
|
+
const stripe = sorted
|
|
26
|
+
.slice(s, s + perSlice)
|
|
27
|
+
.sort((a, b) => a.bounds[1] + a.bounds[3] - (b.bounds[1] + b.bounds[3]));
|
|
28
|
+
for (let j = 0; j < stripe.length; j += bucketSize)
|
|
29
|
+
result.push(stripe.slice(j, j + bucketSize));
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
let nodes = entries.length ? group(entries).map(leaf) : [];
|
|
34
|
+
while (nodes.length > 1)
|
|
35
|
+
nodes = group(nodes).map((children) => ({
|
|
36
|
+
bounds: box(children),
|
|
37
|
+
children,
|
|
38
|
+
}));
|
|
39
|
+
const root = nodes[0];
|
|
40
|
+
return {
|
|
41
|
+
query(bounds) {
|
|
42
|
+
if (!root)
|
|
43
|
+
return [];
|
|
44
|
+
const found = [], stack = [root];
|
|
45
|
+
while (stack.length) {
|
|
46
|
+
const node = stack.pop();
|
|
47
|
+
if (!intersects(node.bounds, bounds))
|
|
48
|
+
continue;
|
|
49
|
+
if (node.entries)
|
|
50
|
+
for (const entry of node.entries)
|
|
51
|
+
if (intersects(entry.bounds, bounds))
|
|
52
|
+
found.push(entry);
|
|
53
|
+
if (node.children)
|
|
54
|
+
stack.push(...node.children);
|
|
55
|
+
}
|
|
56
|
+
found.sort((a, b) => a.ordinal - b.ordinal);
|
|
57
|
+
return found.map((e) => e.value);
|
|
58
|
+
},
|
|
59
|
+
get size() {
|
|
60
|
+
return entries.length;
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SphericalPriorities } from "./spherical-geometry.js";
|
|
2
|
+
import type { FeatureCollection, QueryResult, Topology } from "./types.js";
|
|
3
|
+
import type { BlgTree } from "./blg.js";
|
|
4
|
+
/** Explicit geographic import: decode only the selected object and validate minor arcs. */
|
|
5
|
+
export declare function importSphericalTopoJSON(input: unknown, objectName: string): FeatureCollection;
|
|
6
|
+
export interface SphericalQueryOptions {
|
|
7
|
+
level?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface SphericalInterruptOptions extends SphericalQueryOptions {
|
|
10
|
+
shouldAbort?: () => boolean;
|
|
11
|
+
yieldTurn?: () => Promise<void>;
|
|
12
|
+
sliceMs?: number;
|
|
13
|
+
}
|
|
14
|
+
/** Geographic in-memory dataset. No planar viewport index or v1 partition serialization. */
|
|
15
|
+
export declare class SphericalQuadstreamDataset {
|
|
16
|
+
readonly coordinateMode: "spherical-d3";
|
|
17
|
+
readonly topology: Topology;
|
|
18
|
+
readonly priorities: SphericalPriorities;
|
|
19
|
+
readonly arcTrees: readonly BlgTree[];
|
|
20
|
+
private readonly source;
|
|
21
|
+
private readonly signatures;
|
|
22
|
+
constructor(input: FeatureCollection, { maxLevel }?: {
|
|
23
|
+
maxLevel?: number;
|
|
24
|
+
});
|
|
25
|
+
query(options?: SphericalQueryOptions): QueryResult;
|
|
26
|
+
private formatResult;
|
|
27
|
+
queryInterruptible(options?: SphericalInterruptOptions): Promise<QueryResult | null>;
|
|
28
|
+
}
|
|
29
|
+
export declare function buildSphericalQuadstream(input: FeatureCollection, options?: {
|
|
30
|
+
maxLevel?: number;
|
|
31
|
+
}): SphericalQuadstreamDataset;
|