@vizhub/quadstream 0.3.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 +6 -0
- package/README.md +28 -624
- 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/index.d.ts +5 -1
- package/dist/index.js +1 -0
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +1 -1
- 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 +3 -0
- package/dist/reconstruct.js +26 -3
- package/dist/session.d.ts +12 -9
- package/dist/session.js +24 -7
- package/dist/spherical-cull.js +15 -6
- package/dist/spherical-dataset.d.ts +13 -5
- package/dist/spherical-dataset.js +119 -41
- package/dist/spherical-geometry.d.ts +2 -0
- package/dist/spherical-geometry.js +11 -0
- package/dist/spherical-line.d.ts +29 -0
- package/dist/spherical-line.js +221 -0
- package/dist/spherical-preprocess.d.ts +6 -2
- package/dist/spherical-preprocess.js +34 -18
- package/dist/topology.d.ts +3 -0
- package/dist/topology.js +40 -9
- package/package.json +3 -2
package/dist/topology.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { type Work } from "./cooperative.js";
|
|
1
2
|
import type { FeatureCollection, Position, Topology } from "./types.js";
|
|
2
3
|
/** Exact coordinate topology: no implicit snapping, deduping almost-equal points, or antimeridian wrapping. */
|
|
3
4
|
export declare function buildTopology(input: FeatureCollection): Topology;
|
|
5
|
+
export declare function buildPlanarTopologySteps(input: FeatureCollection): Work<Topology>;
|
|
4
6
|
export interface TopologyPolicy {
|
|
5
7
|
position(value: unknown): Position;
|
|
6
8
|
ring(ring: readonly Position[]): boolean;
|
|
@@ -9,3 +11,4 @@ export interface TopologyPolicy {
|
|
|
9
11
|
}
|
|
10
12
|
/** Internal shared graph construction; coordinate semantics are provided by the caller. */
|
|
11
13
|
export declare function buildTopologyWithPolicy(input: FeatureCollection, policy: TopologyPolicy): Topology;
|
|
14
|
+
export declare function buildTopologySteps(input: FeatureCollection, policy: TopologyPolicy): Work<Topology>;
|
package/dist/topology.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { runSync } from "./cooperative.js";
|
|
1
2
|
import { assertPosition, boundsOf, simpleClosedRing, validPolygon, unionBounds, } from "./geometry.js";
|
|
2
3
|
/** Exact coordinate topology: no implicit snapping, deduping almost-equal points, or antimeridian wrapping. */
|
|
3
4
|
export function buildTopology(input) {
|
|
4
|
-
return
|
|
5
|
+
return runSync(buildPlanarTopologySteps(input));
|
|
6
|
+
}
|
|
7
|
+
export function* buildPlanarTopologySteps(input) {
|
|
8
|
+
return yield* buildTopologySteps(input, {
|
|
5
9
|
position: assertPosition,
|
|
6
10
|
ring: simpleClosedRing,
|
|
7
11
|
polygon: validPolygon,
|
|
@@ -9,6 +13,9 @@ export function buildTopology(input) {
|
|
|
9
13
|
}
|
|
10
14
|
/** Internal shared graph construction; coordinate semantics are provided by the caller. */
|
|
11
15
|
export function buildTopologyWithPolicy(input, policy) {
|
|
16
|
+
return runSync(buildTopologySteps(input, policy));
|
|
17
|
+
}
|
|
18
|
+
export function* buildTopologySteps(input, policy) {
|
|
12
19
|
if (!input ||
|
|
13
20
|
input.type !== "FeatureCollection" ||
|
|
14
21
|
!Array.isArray(input.features))
|
|
@@ -29,6 +36,12 @@ export function buildTopologyWithPolicy(input, policy) {
|
|
|
29
36
|
return id;
|
|
30
37
|
}
|
|
31
38
|
for (let f = 0; f < input.features.length; f++) {
|
|
39
|
+
if (f % 32 === 0)
|
|
40
|
+
yield {
|
|
41
|
+
stage: "Topology features",
|
|
42
|
+
completed: f,
|
|
43
|
+
total: input.features.length,
|
|
44
|
+
};
|
|
32
45
|
const feature = input.features[f];
|
|
33
46
|
if (!feature ||
|
|
34
47
|
feature.type !== "Feature" ||
|
|
@@ -43,10 +56,15 @@ export function buildTopologyWithPolicy(input, policy) {
|
|
|
43
56
|
if (!["Polygon", "MultiPolygon", "LineString", "MultiLineString"].includes(type))
|
|
44
57
|
throw new Error(`Unsupported geometry: ${type}`);
|
|
45
58
|
const paths = [], groups = [];
|
|
46
|
-
function append(coords, closed) {
|
|
59
|
+
function* append(coords, closed) {
|
|
47
60
|
if (!Array.isArray(coords))
|
|
48
61
|
throw new Error("Invalid coordinate path");
|
|
49
|
-
const pts =
|
|
62
|
+
const pts = [];
|
|
63
|
+
for (let i = 0; i < coords.length; i++) {
|
|
64
|
+
if (i % 512 === 0)
|
|
65
|
+
yield undefined;
|
|
66
|
+
pts.push(policy.position(coords[i]));
|
|
67
|
+
}
|
|
50
68
|
if (closed) {
|
|
51
69
|
if (pts.length >= 2 &&
|
|
52
70
|
pts[0][0] === pts.at(-1)[0] &&
|
|
@@ -60,8 +78,12 @@ export function buildTopologyWithPolicy(input, policy) {
|
|
|
60
78
|
new Set(pts.map((p) => JSON.stringify(p))).size < 2 ||
|
|
61
79
|
(policy.line && !policy.line(pts)))
|
|
62
80
|
throw new Error(`Line requires >=2 distinct coordinates in feature ${featureId}`);
|
|
63
|
-
const ids =
|
|
64
|
-
for (
|
|
81
|
+
const ids = [];
|
|
82
|
+
for (let i = 0; i < pts.length; i++) {
|
|
83
|
+
if (i % 512 === 0)
|
|
84
|
+
yield undefined;
|
|
85
|
+
const id = vertexId(pts[i]);
|
|
86
|
+
ids.push(id);
|
|
65
87
|
if (!featureIdsByVertex.has(id))
|
|
66
88
|
featureIdsByVertex.set(id, new Set());
|
|
67
89
|
featureIdsByVertex.get(id).add(featureId);
|
|
@@ -72,7 +94,7 @@ export function buildTopologyWithPolicy(input, policy) {
|
|
|
72
94
|
const group = [];
|
|
73
95
|
for (const ring of coordinates) {
|
|
74
96
|
group.push(paths.length);
|
|
75
|
-
append(ring, true);
|
|
97
|
+
yield* append(ring, true);
|
|
76
98
|
}
|
|
77
99
|
if (!group.length ||
|
|
78
100
|
!policy.polygon(coordinates.map((r) => {
|
|
@@ -90,7 +112,7 @@ export function buildTopologyWithPolicy(input, policy) {
|
|
|
90
112
|
const group = [];
|
|
91
113
|
for (const ring of polygon) {
|
|
92
114
|
group.push(paths.length);
|
|
93
|
-
append(ring, true);
|
|
115
|
+
yield* append(ring, true);
|
|
94
116
|
}
|
|
95
117
|
groups.push(group);
|
|
96
118
|
if (!policy.polygon(polygon.map((r) => {
|
|
@@ -106,13 +128,13 @@ export function buildTopologyWithPolicy(input, policy) {
|
|
|
106
128
|
throw new Error(`Empty multipolygon: ${featureId}`);
|
|
107
129
|
}
|
|
108
130
|
else if (type === "LineString") {
|
|
109
|
-
append(coordinates, false);
|
|
131
|
+
yield* append(coordinates, false);
|
|
110
132
|
groups.push([0]);
|
|
111
133
|
}
|
|
112
134
|
else {
|
|
113
135
|
for (const line of coordinates) {
|
|
114
136
|
const i = paths.length;
|
|
115
|
-
append(line, false);
|
|
137
|
+
yield* append(line, false);
|
|
116
138
|
groups.push([i]);
|
|
117
139
|
}
|
|
118
140
|
if (!groups.length)
|
|
@@ -146,6 +168,8 @@ export function buildTopologyWithPolicy(input, policy) {
|
|
|
146
168
|
vertices[path.ids[i]].critical = true;
|
|
147
169
|
}
|
|
148
170
|
for (let i = 0; i < limit; i++) {
|
|
171
|
+
if (i % 512 === 0)
|
|
172
|
+
yield undefined;
|
|
149
173
|
const a = path.ids[i], b = path.ids[(i + 1) % n];
|
|
150
174
|
if (a === b)
|
|
151
175
|
continue;
|
|
@@ -163,7 +187,10 @@ export function buildTopologyWithPolicy(input, policy) {
|
|
|
163
187
|
pathNumber++;
|
|
164
188
|
}
|
|
165
189
|
const incident = new Map();
|
|
190
|
+
let edgeCount = 0;
|
|
166
191
|
for (const [edge, owners] of edgeOwners) {
|
|
192
|
+
if (edgeCount++ % 512 === 0)
|
|
193
|
+
yield undefined;
|
|
167
194
|
const signature = [...owners].sort((a, b) => a - b).join(",");
|
|
168
195
|
const [a, b] = edge.split(":").map(Number);
|
|
169
196
|
for (const id of [a, b]) {
|
|
@@ -173,6 +200,8 @@ export function buildTopologyWithPolicy(input, policy) {
|
|
|
173
200
|
}
|
|
174
201
|
}
|
|
175
202
|
for (const v of vertices) {
|
|
203
|
+
if (v.id % 512 === 0)
|
|
204
|
+
yield undefined;
|
|
176
205
|
const shapeCount = featureIdsByVertex.get(v.id)?.size ?? 0;
|
|
177
206
|
if (shapeCount >= 3 ||
|
|
178
207
|
neighbors.get(v.id)?.size !== 2 ||
|
|
@@ -214,6 +243,8 @@ export function buildTopologyWithPolicy(input, policy) {
|
|
|
214
243
|
const refs = [], n = ids.length, total = raw.closed ? n : n - 1;
|
|
215
244
|
let current = [ids[0]];
|
|
216
245
|
for (let i = 1; i <= total; i++) {
|
|
246
|
+
if (i % 512 === 0)
|
|
247
|
+
yield undefined;
|
|
217
248
|
const next = ids[i % n];
|
|
218
249
|
current.push(next);
|
|
219
250
|
if (vertices[next].critical || i === total) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizhub/quadstream",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Deterministic, topology-aware progressive geographic geometry engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"bin"
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
|
-
"dev": "npm run build &&
|
|
24
|
+
"dev": "npm run build && npm --prefix quadstream-globe run dev",
|
|
25
|
+
"dev:legacy": "npm run build && node examples/progressive/server.mjs --globe",
|
|
25
26
|
"dev:restart": "node scripts/dev-restart.mjs",
|
|
26
27
|
"build": "tsc -p tsconfig.json",
|
|
27
28
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|