@vizhub/quadstream 0.0.0-stage → 0.3.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 +19 -0
- package/LICENSE +21 -0
- package/README.md +718 -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-wire.d.ts +8 -0
- package/dist/geometry-wire.js +76 -0
- package/dist/geometry.d.ts +15 -0
- package/dist/geometry.js +236 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +22 -0
- package/dist/loader.d.ts +34 -0
- package/dist/loader.js +138 -0
- package/dist/lod-scheduler.d.ts +15 -0
- package/dist/lod-scheduler.js +85 -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 +27 -0
- package/dist/reconstruct.js +145 -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-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 +93 -0
- package/dist/spherical-dataset.d.ts +55 -0
- package/dist/spherical-dataset.js +305 -0
- package/dist/spherical-geometry.d.ts +39 -0
- package/dist/spherical-geometry.js +229 -0
- package/dist/spherical-preprocess.d.ts +19 -0
- package/dist/spherical-preprocess.js +144 -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 +11 -0
- package/dist/topology.js +229 -0
- package/dist/types.d.ts +123 -0
- package/dist/types.js +1 -0
- package/package.json +79 -4
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { validPolygon } 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
|
+
/** True when fewer than 3 distinct positions precede the closing vertex. */
|
|
7
|
+
function distinctBelow3(coords) {
|
|
8
|
+
const n = coords.length - 1;
|
|
9
|
+
let first, second;
|
|
10
|
+
for (let i = 0; i < n; i++) {
|
|
11
|
+
const p = coords[i];
|
|
12
|
+
if (!first)
|
|
13
|
+
first = p;
|
|
14
|
+
else if (p[0] !== first[0] || p[1] !== first[1]) {
|
|
15
|
+
if (!second)
|
|
16
|
+
second = p;
|
|
17
|
+
else if ((p[0] !== second[0] || p[1] !== second[1]) &&
|
|
18
|
+
(first[0] !== second[0] || first[1] !== second[1]))
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
export function reconstructFeature(f, arcs, trees, level, lookup,
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
26
|
+
_includeMissing = false, planarValidity = true, options = {}) {
|
|
27
|
+
let missing = false, selectedVertices = 0;
|
|
28
|
+
const dropCollapsed = options.collapsed === "drop";
|
|
29
|
+
const hidden = new Set(options.hiddenPaths);
|
|
30
|
+
// Holes of a hidden exterior go with it, so they are never reconstructed.
|
|
31
|
+
const shellOf = [];
|
|
32
|
+
if (f.geometryType === "Polygon" || f.geometryType === "MultiPolygon")
|
|
33
|
+
for (const group of f.groups)
|
|
34
|
+
for (const p of group) {
|
|
35
|
+
shellOf[p] = group[0];
|
|
36
|
+
if (hidden.has(group[0]))
|
|
37
|
+
hidden.add(p);
|
|
38
|
+
}
|
|
39
|
+
const paths = [];
|
|
40
|
+
for (let pathIndex = 0; pathIndex < f.paths.length; pathIndex++) {
|
|
41
|
+
const path = f.paths[pathIndex];
|
|
42
|
+
if (hidden.has(pathIndex) || hidden.has(shellOf[pathIndex] ?? -1)) {
|
|
43
|
+
hidden.add(pathIndex);
|
|
44
|
+
paths.push([]);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const coords = [];
|
|
48
|
+
let pathSelectedVertices = 0;
|
|
49
|
+
for (const ref of path.arcs) {
|
|
50
|
+
const arcId = Math.abs(ref) - 1, arc = arcs[arcId], tree = trees[arcId];
|
|
51
|
+
const positions = selectBlgPositions(tree, typeof level === "number" ? level : level(arcId));
|
|
52
|
+
const last = positions.length - 1;
|
|
53
|
+
for (let i = 0; i < positions.length; i++) {
|
|
54
|
+
const id = arc.vertexIds[positions[ref < 0 ? last - i : i]], xy = lookup(id);
|
|
55
|
+
if (!xy) {
|
|
56
|
+
missing = true;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (coords.length &&
|
|
60
|
+
i === 0 &&
|
|
61
|
+
xy[0] === coords.at(-1)[0] &&
|
|
62
|
+
xy[1] === coords.at(-1)[1])
|
|
63
|
+
continue;
|
|
64
|
+
coords.push(xy);
|
|
65
|
+
pathSelectedVertices++;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (path.closed && dropCollapsed && distinctBelow3(coords)) {
|
|
69
|
+
hidden.add(pathIndex);
|
|
70
|
+
paths.push([]);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (path.closed && distinctBelow3(coords)) {
|
|
74
|
+
// Collapsed ring: restore every original vertex. Only this rare path
|
|
75
|
+
// pays for walking all arc positions.
|
|
76
|
+
coords.length = 0;
|
|
77
|
+
pathSelectedVertices = 0;
|
|
78
|
+
let lastId = -1;
|
|
79
|
+
for (const ref of path.arcs) {
|
|
80
|
+
const ids = arcs[Math.abs(ref) - 1].vertexIds;
|
|
81
|
+
for (let k = 0; k < ids.length; k++) {
|
|
82
|
+
const id = ids[ref < 0 ? ids.length - 1 - k : k];
|
|
83
|
+
if (id === lastId)
|
|
84
|
+
continue;
|
|
85
|
+
lastId = id;
|
|
86
|
+
const xy = lookup(id);
|
|
87
|
+
if (xy &&
|
|
88
|
+
(!coords.length ||
|
|
89
|
+
xy[0] !== coords.at(-1)[0] ||
|
|
90
|
+
xy[1] !== coords.at(-1)[1])) {
|
|
91
|
+
coords.push(xy);
|
|
92
|
+
pathSelectedVertices++;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Coordinate identity is maintained; close polygons explicitly if needed.
|
|
98
|
+
if (path.closed &&
|
|
99
|
+
coords.length &&
|
|
100
|
+
(coords[0][0] !== coords.at(-1)[0] ||
|
|
101
|
+
coords[0][1] !== coords.at(-1)[1]))
|
|
102
|
+
coords.push(coords[0]);
|
|
103
|
+
selectedVertices += pathSelectedVertices;
|
|
104
|
+
paths.push(coords);
|
|
105
|
+
}
|
|
106
|
+
const groups = f.groups
|
|
107
|
+
.filter((group) => !hidden.has(group[0]))
|
|
108
|
+
.map((group) => group.filter((i) => !hidden.has(i)).map((i) => paths[i]));
|
|
109
|
+
let geometry;
|
|
110
|
+
let valid = true;
|
|
111
|
+
const checkPolygon = planarValidity ? validPolygon : () => true;
|
|
112
|
+
switch (f.geometryType) {
|
|
113
|
+
case "Polygon":
|
|
114
|
+
geometry = { type: "Polygon", coordinates: groups[0] ?? [] };
|
|
115
|
+
valid = !groups[0] || checkPolygon(groups[0]);
|
|
116
|
+
break;
|
|
117
|
+
case "MultiPolygon":
|
|
118
|
+
geometry = { type: "MultiPolygon", coordinates: groups };
|
|
119
|
+
valid = groups.every(checkPolygon);
|
|
120
|
+
break;
|
|
121
|
+
case "LineString":
|
|
122
|
+
geometry = { type: "LineString", coordinates: groups[0][0] };
|
|
123
|
+
valid = groups[0][0].length >= 2;
|
|
124
|
+
break;
|
|
125
|
+
case "MultiLineString":
|
|
126
|
+
geometry = {
|
|
127
|
+
type: "MultiLineString",
|
|
128
|
+
coordinates: groups.map((g) => g[0]),
|
|
129
|
+
};
|
|
130
|
+
valid = groups.every((g) => g[0].length >= 2);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
feature: {
|
|
135
|
+
type: "Feature",
|
|
136
|
+
id: f.id,
|
|
137
|
+
properties: { ...f.properties },
|
|
138
|
+
geometry,
|
|
139
|
+
},
|
|
140
|
+
missing,
|
|
141
|
+
valid,
|
|
142
|
+
selectedVertices,
|
|
143
|
+
hiddenRings: hidden.size,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -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,95 @@
|
|
|
1
|
+
import type { SphericalCap, SphericalViewCone } from "./spherical-cull.js";
|
|
2
|
+
import type { Feature, FeatureCollection, Position } from "./types.js";
|
|
3
|
+
export interface SphericalClipWindow extends SphericalViewCone {
|
|
4
|
+
cx: number;
|
|
5
|
+
cy: number;
|
|
6
|
+
cz: number;
|
|
7
|
+
radius: number;
|
|
8
|
+
cosR: number;
|
|
9
|
+
sinR: number;
|
|
10
|
+
ux: number;
|
|
11
|
+
uy: number;
|
|
12
|
+
uz: number;
|
|
13
|
+
bx: number;
|
|
14
|
+
by: number;
|
|
15
|
+
bz: number;
|
|
16
|
+
}
|
|
17
|
+
interface RingInfo {
|
|
18
|
+
ring: Position[];
|
|
19
|
+
n: number;
|
|
20
|
+
xyz: Float64Array;
|
|
21
|
+
cap: SphericalCap;
|
|
22
|
+
}
|
|
23
|
+
interface Piece {
|
|
24
|
+
pts: Position[];
|
|
25
|
+
from: number;
|
|
26
|
+
to: number;
|
|
27
|
+
}
|
|
28
|
+
type RingResult = {
|
|
29
|
+
status: "away" | "wraps";
|
|
30
|
+
} | {
|
|
31
|
+
status: "inside";
|
|
32
|
+
ring: Position[];
|
|
33
|
+
} | {
|
|
34
|
+
status: "clipped";
|
|
35
|
+
rings: Position[][];
|
|
36
|
+
};
|
|
37
|
+
interface ClipWork {
|
|
38
|
+
classified: number;
|
|
39
|
+
inside: number;
|
|
40
|
+
outside: number;
|
|
41
|
+
}
|
|
42
|
+
interface FeatureInfo {
|
|
43
|
+
cap: SphericalCap;
|
|
44
|
+
ring: (pi: number, ri: number) => RingInfo;
|
|
45
|
+
}
|
|
46
|
+
export interface SphericalClipStats {
|
|
47
|
+
features: number;
|
|
48
|
+
rings: {
|
|
49
|
+
kept: number;
|
|
50
|
+
clipped: number;
|
|
51
|
+
wrapped: number;
|
|
52
|
+
dropped: number;
|
|
53
|
+
};
|
|
54
|
+
vertices: number;
|
|
55
|
+
stream: ClipWork;
|
|
56
|
+
}
|
|
57
|
+
export interface SphericalClipResult {
|
|
58
|
+
geojson: FeatureCollection;
|
|
59
|
+
stats: SphericalClipStats;
|
|
60
|
+
}
|
|
61
|
+
export declare function clipWindow(cx: number, cy: number, cz: number, radius: number): SphericalClipWindow;
|
|
62
|
+
export declare function circleRing(w: SphericalClipWindow, side?: number): Position[];
|
|
63
|
+
export declare function ringInfo(ring: Position[]): RingInfo;
|
|
64
|
+
/** Reference O(c^2) pairing: the first entry met walking from each exit. */
|
|
65
|
+
export declare function pairPiecesReference(pieces: Pick<Piece, "from" | "to">[], side?: number): number[];
|
|
66
|
+
/**
|
|
67
|
+
* Sorted-event pairing: entries are ordered by azimuth, each exit binary
|
|
68
|
+
* searches its neighbourhood and the exact reference delta rule decides among
|
|
69
|
+
* the few candidates, so ties, wraparound and epsilon behave identically.
|
|
70
|
+
*/
|
|
71
|
+
export declare function pairPieces(pieces: Pick<Piece, "from" | "to">[], side?: number): number[];
|
|
72
|
+
/**
|
|
73
|
+
* Clip one ring to the window. Status:
|
|
74
|
+
* - inside: every vertex inside, `ring` is the original array
|
|
75
|
+
* - clipped: `rings` are new closed rings (a ring that dips in and out of
|
|
76
|
+
* the window can split into several)
|
|
77
|
+
* - wraps: no crossing and the ring's material side (exterior) or enclosed
|
|
78
|
+
* region (hole) covers the whole window
|
|
79
|
+
* - away: no crossing and the window is on the other side
|
|
80
|
+
*/
|
|
81
|
+
export declare function clipRingReference(w: SphericalClipWindow, info: RingInfo, side?: number): RingResult;
|
|
82
|
+
/**
|
|
83
|
+
* Stream the ring in the reference's cyclic order, starting at the first
|
|
84
|
+
* exterior vertex. Classify each position exactly once; the initial inside
|
|
85
|
+
* prefix is known when the traversal wraps. No per-ring visibility bitmap.
|
|
86
|
+
* Keep outside endpoints only long enough to test their actual joining edge.
|
|
87
|
+
*/
|
|
88
|
+
export declare function clipRing(w: SphericalClipWindow, info: RingInfo, side?: number, work?: ClipWork): RingResult;
|
|
89
|
+
export declare function buildFeatureInfo(feature: Feature, cap?: SphericalCap): FeatureInfo;
|
|
90
|
+
/** Uncached clip of a collection to an explicit window. */
|
|
91
|
+
export declare function clipToWindow(geojson: FeatureCollection, w: SphericalClipWindow): SphericalClipResult;
|
|
92
|
+
export declare function countVertices(geojson: FeatureCollection | null | undefined): number;
|
|
93
|
+
/** Clip every feature to the window; unchanged features keep their identity. */
|
|
94
|
+
export declare function clipFeatureCollection(geojson: FeatureCollection, w: SphericalClipWindow, getInfo: (i: number, feature: Feature) => FeatureInfo): SphericalClipResult;
|
|
95
|
+
export {};
|