@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
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,14 @@ First planned experimental npm release of the modern Quadstream library.
|
|
|
10
10
|
- CLI for build, inspect, validate, query and benchmark.
|
|
11
11
|
- MapLibre integration and experimental in-memory spherical reconstruction.
|
|
12
12
|
- Standalone map and globe demos with regression tests.
|
|
13
|
+
- Globe: spring-smoothed pointer navigation and continuous keyboard
|
|
14
|
+
"spaceship" flight (thrust + viscous drag) with tuning sliders.
|
|
15
|
+
- Globe: international ADM1 layers that exceed the source cache budget hand off
|
|
16
|
+
through a transient reservation, and dense datasets escalate spherical
|
|
17
|
+
quadtree resolution instead of failing to load.
|
|
18
|
+
- Globe: Settings → Rendering → Projection selects Equal Earth, Natural
|
|
19
|
+
Earth, Mercator, Equirectangular or Stereographic as well as the default
|
|
20
|
+
orthographic globe. View-layer only: no worker rebuild or refetch.
|
|
13
21
|
- MIT license for modern implementation; legacy license terms preserved.
|
|
14
22
|
- ESM package, TypeScript declarations and clean-install tarball validation.
|
|
15
23
|
|
package/README.md
CHANGED
|
@@ -2,68 +2,54 @@
|
|
|
2
2
|
|
|
3
3
|
**Progressive, topology-aware, multiresolution geometry for the web.**
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
sharing exactly matching boundaries. Build once, query a simpler representation
|
|
7
|
-
for a map or globe, or serialize planar geometry into independently loadable
|
|
8
|
-
binary partitions. The TypeScript-first core is ESM with no runtime dependencies,
|
|
9
|
-
and requires no VizHub account, map framework or server.
|
|
5
|
+
[Live globe demo](https://vizhub-studio.github.io/quadstream/) · [npm package](https://www.npmjs.com/package/@vizhub/quadstream)
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
> and remains private pending release sign-off. Reference validation can be
|
|
13
|
-
> expensive; do not use it for safety-critical geometry.
|
|
7
|
+
<img width="981" height="964" alt="Interactive Quadstream globe" src="https://github.com/user-attachments/assets/1b54d21a-ea13-4cdf-b88c-6048b3e009dc" />
|
|
14
8
|
|
|
15
|
-
|
|
9
|
+
Quadstream builds shared geographic topology once and reconstructs geometry at different levels of detail. The TypeScript ESM core has no runtime dependencies.
|
|
16
10
|
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
- Transport-independent progressive loading with cancellation and a bounded raw-byte cache.
|
|
21
|
-
- Experimental spherical geometry for D3 globes, including seam and pole aliases.
|
|
22
|
-
- Standalone CLI and local Canvas, MapLibre and D3 globe demos.
|
|
11
|
+
- Planar geometry: viewport selection, progressive binary partitions and cancellable loading.
|
|
12
|
+
- Spherical geometry: fractional detail, shared boundaries, visibility culling and clipping helpers for globe renderers.
|
|
13
|
+
- GeoJSON/TopoJSON adapters, a planar CLI and browser demos.
|
|
23
14
|
|
|
24
15
|
## Install
|
|
25
16
|
|
|
26
|
-
|
|
17
|
+
Node.js 20+ for the library.
|
|
27
18
|
|
|
28
19
|
```sh
|
|
29
20
|
npm install @vizhub/quadstream
|
|
30
21
|
```
|
|
31
22
|
|
|
32
|
-
Until then, use a checkout and build the package:
|
|
33
|
-
|
|
34
|
-
```sh
|
|
35
|
-
git clone https://github.com/vizhub-studio/quadstream.git
|
|
36
|
-
cd quadstream
|
|
37
|
-
npm ci
|
|
38
|
-
npm run build
|
|
39
|
-
node examples/hello.mjs
|
|
40
|
-
npm pack
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
The generated tarball can be installed into a separate project. The following
|
|
44
|
-
examples use the package's public import path. From a checkout, examples in
|
|
45
|
-
`examples/` instead import `../dist/index.js`.
|
|
46
|
-
|
|
47
23
|
## Quick start: planar geometry
|
|
48
24
|
|
|
49
25
|
```js
|
|
50
|
-
import { buildQuadstream } from
|
|
26
|
+
import { buildQuadstream } from "@vizhub/quadstream";
|
|
51
27
|
|
|
52
28
|
const source = {
|
|
53
|
-
type:
|
|
54
|
-
features: [
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
29
|
+
type: "FeatureCollection",
|
|
30
|
+
features: [
|
|
31
|
+
{
|
|
32
|
+
type: "Feature",
|
|
33
|
+
id: "square",
|
|
34
|
+
properties: { value: 42 },
|
|
35
|
+
geometry: {
|
|
36
|
+
type: "Polygon",
|
|
37
|
+
coordinates: [
|
|
38
|
+
[
|
|
39
|
+
[0, 0],
|
|
40
|
+
[10, 0],
|
|
41
|
+
[10, 10],
|
|
42
|
+
[0, 10],
|
|
43
|
+
[0, 0],
|
|
44
|
+
],
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
],
|
|
63
49
|
};
|
|
64
50
|
|
|
65
|
-
const dataset = buildQuadstream(source, { maxLevel: 12 });
|
|
66
|
-
const result = dataset.query({ level: 4, bounds: [0, 0, 10, 10] });
|
|
51
|
+
const dataset = await buildQuadstream(source, { maxLevel: 12 });
|
|
52
|
+
const result = await dataset.query({ level: 4, bounds: [0, 0, 10, 10] });
|
|
67
53
|
console.log(result.geojson, result.usedFallback);
|
|
68
54
|
```
|
|
69
55
|
|
|
@@ -76,275 +62,27 @@ The planar engine interprets coordinates as Cartesian numbers. Project or
|
|
|
76
62
|
split dateline-crossing geography upstream; use the spherical API for
|
|
77
63
|
great-circle globe geometry.
|
|
78
64
|
|
|
79
|
-
##
|
|
80
|
-
|
|
81
|
-
```js
|
|
82
|
-
import {
|
|
83
|
-
exportPartitions, QuadstreamSession, QuadstreamLoader, fetchFromBundle
|
|
84
|
-
} from '@vizhub/quadstream';
|
|
85
|
-
|
|
86
|
-
const bundle = exportPartitions(dataset, { fileDepth: 3 });
|
|
87
|
-
const session = new QuadstreamSession(bundle.manifest);
|
|
88
|
-
const loader = new QuadstreamLoader(session, fetchFromBundle(bundle), {
|
|
89
|
-
concurrency: 4,
|
|
90
|
-
cacheBytes: 1024 * 1024
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
const frame = await loader.loadLatest({ level: 4 });
|
|
94
|
-
console.log(frame.geojson, frame.complete, frame.usedFallback);
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
Replace `fetchFromBundle` with an async function accepting a partition key and
|
|
98
|
-
`{ signal }` to retrieve bytes from your own transport. The session validates
|
|
99
|
-
partition checksums, sizes and records before ingestion. A new latest-view
|
|
100
|
-
request cancels the preceding one. Partial session queries report incomplete
|
|
101
|
-
or omitted features until required partitions arrive.
|
|
65
|
+
## Run the globe
|
|
102
66
|
|
|
103
|
-
|
|
104
|
-
conservative: it may request partitions outside the viewport to reconstruct
|
|
105
|
-
segments that cross it. No production HTTP/CDN client is bundled.
|
|
106
|
-
|
|
107
|
-
## Spherical geometry and D3
|
|
108
|
-
|
|
109
|
-
Use the distinct spherical engine for longitude/latitude coordinates in
|
|
110
|
-
degrees with D3 spherical winding (clockwise small polygon interiors).
|
|
111
|
-
The following example assumes a TopoJSON atlas is already loaded:
|
|
112
|
-
|
|
113
|
-
```js
|
|
114
|
-
import { buildSphericalQuadstream, importSphericalTopoJSON } from '@vizhub/quadstream';
|
|
115
|
-
|
|
116
|
-
const countries = importSphericalTopoJSON(atlas, 'countries');
|
|
117
|
-
const globe = buildSphericalQuadstream(countries, { maxLevel: 20 });
|
|
118
|
-
const { geojson, valid, promotedArcs } = globe.query({ level: 8.5 });
|
|
119
|
-
// Supply geojson to your D3 geoPath renderer.
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Spherical queries reconstruct global geometry in memory. Fractional detail uses
|
|
123
|
-
stable vertex-ID hashing; shared-arc promotion repairs invalid features without
|
|
124
|
-
a global full-detail fallback. They do not support
|
|
125
|
-
planar viewport bounds, v1 partition serialization or network streaming.
|
|
126
|
-
They may reject inputs that cannot be validated in the reference hemisphere
|
|
127
|
-
chart. See [spherical semantics](https://github.com/vizhub-studio/quadstream/blob/master/docs/SPHERICAL.md).
|
|
128
|
-
|
|
129
|
-
## Interactive demos
|
|
130
|
-
|
|
131
|
-
From a checkout, install dependencies and build, then run either command:
|
|
132
|
-
|
|
133
|
-
| Demo | Command | What it demonstrates |
|
|
134
|
-
| --- | --- | --- |
|
|
135
|
-
| Progressive map | `npm run demo:map` | Canvas/MapLibre, detail levels, shared arcs, simulated partition latency |
|
|
136
|
-
| Orthographic globe | `npm run demo:globe` | D3 Canvas, real 110m/50m atlas inputs, pinch zoom, rotation, worker-based LOD and original/reconstructed comparison |
|
|
137
|
-
|
|
138
|
-
Open the local URL printed by the server (normally http://127.0.0.1:4173/).
|
|
139
|
-
The demos are not included in the npm artifact. The globe downloads the full
|
|
140
|
-
atlas up front; its LOD reduction is not a bandwidth-saving streaming protocol.
|
|
141
|
-
See [map demo](https://github.com/vizhub-studio/quadstream/blob/master/docs/PROGRESSIVE-MAP.md)
|
|
142
|
-
and [globe demo](https://github.com/vizhub-studio/quadstream/blob/master/docs/GLOBE.md).
|
|
143
|
-
|
|
144
|
-
## CLI
|
|
145
|
-
|
|
146
|
-
After installing the released package, run its executable with
|
|
147
|
-
`npx --no-install quadstream` (or use `node bin/quadstream.mjs` from a built checkout):
|
|
67
|
+
Use Node 26 for the React/Vite demo.
|
|
148
68
|
|
|
149
69
|
```sh
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
The CLI currently operates on planar coordinates. Query output and build
|
|
158
|
-
directories must not already exist. See [CLI and format policy](https://github.com/vizhub-studio/quadstream/blob/master/docs/CLI.md)
|
|
159
|
-
for input restrictions, bounds, exit codes and static staging.
|
|
160
|
-
|
|
161
|
-
## Public API guide
|
|
162
|
-
|
|
163
|
-
| API | Purpose |
|
|
164
|
-
| --- | --- |
|
|
165
|
-
| `buildQuadstream`, `QuadstreamDataset` | Build planar multiresolution geometry and query by detail/bounds |
|
|
166
|
-
| `buildSphericalQuadstream`, `SphericalQuadstreamDataset`, `importSphericalTopoJSON` | In-memory D3-style geographic reconstruction |
|
|
167
|
-
| `importGeoJSON`, `exportGeoJSON`, `importTopoJSON`, `exportTopoJSON` | Planar geographic interchange |
|
|
168
|
-
| `exportPartitions`, `validateManifest`, `MANIFEST_VERSION` | Versioned planar artifacts |
|
|
169
|
-
| `QuadstreamSession`, `QuadstreamLoader`, `fetchFromBundle` | Partial reconstruction and injected async delivery |
|
|
170
|
-
| `ProgressiveMap`, `attachMapLibre`, `mapLibreBounds` | Renderer-independent orchestration and MapLibre integration |
|
|
171
|
-
| `buildTopology`, `buildSparseQuadtree`, `buildBlgTree`, `createSpatialIndex` | Lower-level algorithm building blocks |
|
|
172
|
-
|
|
173
|
-
See the [export list](https://github.com/vizhub-studio/quadstream/blob/master/src/index.ts)
|
|
174
|
-
and included TypeScript declarations for complete signatures and utilities.
|
|
175
|
-
|
|
176
|
-
## Detailed API reference
|
|
177
|
-
|
|
178
|
-
The package exports its public API from `src/index.ts` and ships declarations
|
|
179
|
-
with the build. The signatures below describe the stable development-preview
|
|
180
|
-
surface; TypeScript is the authoritative source for exact structural types.
|
|
181
|
-
|
|
182
|
-
### Core planar dataset
|
|
183
|
-
|
|
184
|
-
```ts
|
|
185
|
-
buildQuadstream(
|
|
186
|
-
input: FeatureCollection,
|
|
187
|
-
options?: { maxLevel?: number },
|
|
188
|
-
): QuadstreamDataset
|
|
189
|
-
|
|
190
|
-
dataset.query(options?: {
|
|
191
|
-
level?: number;
|
|
192
|
-
bounds?: Bounds;
|
|
193
|
-
validate?: boolean;
|
|
194
|
-
}): QueryResult
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
`QuadstreamDataset` exposes `topology`, `quadtree`, and `arcTrees` for
|
|
198
|
-
inspection. `QueryResult` contains `geojson`, the requested `level`, `valid`,
|
|
199
|
-
`usedFallback`, `selectedFeatures`, and `selectedVertices`. `level` ranges
|
|
200
|
-
from `0` through `maxLevel - 1`; the default is the finest level. `bounds`
|
|
201
|
-
selects features by intersecting feature bounds and does not clip geometry.
|
|
202
|
-
Set `validate: false` only when the caller accepts unvalidated reconstructed
|
|
203
|
-
geometry.
|
|
204
|
-
|
|
205
|
-
The public planar model includes `Position`, `Bounds`, `Geometry`, `Feature`,
|
|
206
|
-
`FeatureCollection`, `Topology`, `TopologyFeature`, `Arc`, `TopologyPath`,
|
|
207
|
-
`Vertex`, `SparseQuadtree`, `QueryOptions`, and `QueryResult`. Supported
|
|
208
|
-
geometries are `Polygon`, `MultiPolygon`, `LineString`, and
|
|
209
|
-
`MultiLineString`.
|
|
210
|
-
|
|
211
|
-
### Topology, priorities, and geometry helpers
|
|
212
|
-
|
|
213
|
-
- `buildTopology(collection)` deduplicates exact coordinates, shared arcs, and
|
|
214
|
-
feature metadata.
|
|
215
|
-
- `buildSparseQuadtree(vertices, bounds, maxLevel)`, `cellKey(level, i, j)`,
|
|
216
|
-
and `cellAddress(key)` expose deterministic sparse spatial priorities.
|
|
217
|
-
- `buildBlgTree(levels)`, `selectBlgPositions(tree, maxLevel)`, and
|
|
218
|
-
`assertBlgInvariants(tree)` expose the ordered vertex-selection structure.
|
|
219
|
-
- `createSpatialIndex(items)` builds a packed bounds index whose `query(bounds)`
|
|
220
|
-
returns matching values.
|
|
221
|
-
- `boundsOf(points)`, `intersects(a, b)`, `simpleClosedRing(ring)`,
|
|
222
|
-
`segmentsIntersect(a, b, c, d)`, `pointInRing(point, ring)`, and
|
|
223
|
-
`validPolygon(rings)` provide the reference planar predicates.
|
|
224
|
-
|
|
225
|
-
These lower-level functions are useful for diagnostics, custom pipelines, and
|
|
226
|
-
tests. They enforce the same finite-coordinate and exact-coordinate policies as
|
|
227
|
-
the dataset builder.
|
|
228
|
-
|
|
229
|
-
### GeoJSON and TopoJSON
|
|
230
|
-
|
|
231
|
-
- `importGeoJSON(input)` validates and normalizes a GeoJSON
|
|
232
|
-
`FeatureCollection` or `Feature`.
|
|
233
|
-
- `exportGeoJSON(collection)` returns a serializable GeoJSON collection.
|
|
234
|
-
- `importTopoJSON(input)` decodes unquantized or quantized TopoJSON into a
|
|
235
|
-
feature collection.
|
|
236
|
-
- `exportTopoJSON(collection)` writes unquantized TopoJSON with shared arcs.
|
|
237
|
-
- `decodeTopoJSON(input, objectName, position?)` decodes one named TopoJSON
|
|
238
|
-
object with an optional coordinate normalizer.
|
|
239
|
-
|
|
240
|
-
`TopoJSONTopology` is exported for typed adapter integration. TopoJSON arc
|
|
241
|
-
references use standard zero-based indices and bitwise-complement reversal.
|
|
242
|
-
Feature IDs and properties are preserved by the adapters; the core normalizes
|
|
243
|
-
missing IDs and null properties during topology construction.
|
|
244
|
-
|
|
245
|
-
### Partitioned artifacts and progressive loading
|
|
246
|
-
|
|
247
|
-
```ts
|
|
248
|
-
exportPartitions(dataset, options?: { fileDepth?: number }): PartitionBundle
|
|
249
|
-
encodePartition(records): Uint8Array
|
|
250
|
-
decodePartition(bytes, maxRecords?): PartitionRecord[]
|
|
251
|
-
validateManifest(input): QuadstreamManifest
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
`exportPartitions` returns a manifest and `Map<string, Uint8Array>` containing
|
|
255
|
-
deterministic QSTR v1 partitions. `checksum(bytes)` computes the non-authenticating
|
|
256
|
-
FNV-1a corruption check. `requiredPartitionKeys(manifest, level)` returns all
|
|
257
|
-
partitions needed for a level, while `partitionsWithVerticesInBounds(manifest,
|
|
258
|
-
bounds)` is diagnostic vertex coverage and is not a safe request planner.
|
|
259
|
-
`MANIFEST_VERSION` is the current artifact version.
|
|
260
|
-
|
|
261
|
-
`QuadstreamSession` validates a manifest in its constructor, then accepts
|
|
262
|
-
partitions with `load(key, bytes)`. Its `loadedKeys`, `missingKeys(level)`, and
|
|
263
|
-
`query(options)` APIs report partial results through `complete`, `missingKeys`,
|
|
264
|
-
`omittedFeatures`, and `usedFallback`.
|
|
265
|
-
|
|
266
|
-
`QuadstreamLoader` wraps a session with an injected `PartitionFetcher`:
|
|
267
|
-
|
|
268
|
-
```ts
|
|
269
|
-
type PartitionFetcher = (
|
|
270
|
-
key: string,
|
|
271
|
-
context: { signal: AbortSignal },
|
|
272
|
-
) => Promise<Uint8Array>;
|
|
273
|
-
|
|
274
|
-
loader.ensureLevel(level, { signal? }): Promise<void>
|
|
275
|
-
loader.loadLatest(query?): Promise<SessionQueryResult>
|
|
276
|
-
loader.cancelLatest(): void
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
`LoaderOptions` limits per-request concurrency (default `4`, maximum `32`) and
|
|
280
|
-
the optional raw-byte LRU cache (default 16 MiB). `fetchFromBundle(bundle)`
|
|
281
|
-
provides an in-memory fetcher for tests and demos. Fetching, HTTP, retries,
|
|
282
|
-
persistent caching, and authentication remain application responsibilities.
|
|
283
|
-
|
|
284
|
-
### Progressive map client and MapLibre adapter
|
|
285
|
-
|
|
286
|
-
`ProgressiveMap` stages requests at coarse, intermediate, and target levels.
|
|
287
|
-
Implement `ProgressiveMapClient` with `request(query, onFrame)` and `cancel()`
|
|
288
|
-
when integrating another renderer. Each `MapFrame` reports the session result,
|
|
289
|
-
target level, whether it is final, and loaded/total partition counts.
|
|
290
|
-
|
|
291
|
-
`attachMapLibre(map, loader, options?)` connects the loader to a MapLibre-like
|
|
292
|
-
map interface, and `mapLibreBounds(bounds)` converts the current map bounds to
|
|
293
|
-
the planar query bounds. The adapter intentionally has no MapLibre runtime
|
|
294
|
-
dependency; `MapLibreLike` and `MapLibreAdapterOptions` describe the minimal
|
|
295
|
-
integration surface. See [the progressive map guide](docs/PROGRESSIVE-MAP.md).
|
|
296
|
-
|
|
297
|
-
### Spherical geographic API
|
|
298
|
-
|
|
299
|
-
```ts
|
|
300
|
-
importSphericalTopoJSON(input, objectName): FeatureCollection
|
|
301
|
-
buildSphericalQuadstream(
|
|
302
|
-
input: FeatureCollection,
|
|
303
|
-
options?: { maxLevel?: number },
|
|
304
|
-
): SphericalQuadstreamDataset
|
|
305
|
-
dataset.query(options?: { level?: number }): QueryResult
|
|
70
|
+
git clone https://github.com/vizhub-studio/quadstream.git
|
|
71
|
+
cd quadstream
|
|
72
|
+
npm ci
|
|
73
|
+
npm --prefix quadstream-globe ci
|
|
74
|
+
npm run dev
|
|
306
75
|
```
|
|
307
76
|
|
|
308
|
-
The
|
|
309
|
-
winding convention, minor great-circle arcs, and six cube-face sparse
|
|
310
|
-
priorities. It is intentionally separate from planar partitions and viewport
|
|
311
|
-
culling. Exported helpers include `canonicalLonLat`, `lonLatVector`,
|
|
312
|
-
`angularDistance`, `validGreatCirclePath`, `sphericalCellAddress`,
|
|
313
|
-
`buildSphericalPriorities`, `sphericalChart`, `projectSpherical`,
|
|
314
|
-
`sphericalPolygonSignature`, and `validSphericalPolygon`. Supporting types are
|
|
315
|
-
`UnitVector`, `CubeFace`, `SphericalCell`, `SphericalPriorities`,
|
|
316
|
-
`SphericalChart`, `SphericalPolygonSignature`, and `SphericalQueryOptions`.
|
|
317
|
-
Spherical queries support fractional levels. Invalid features are repaired by
|
|
318
|
-
promoting shared arcs to finer levels; `promotedArcs` reports the number of
|
|
319
|
-
promoted arcs. `valid: false` indicates geometry that remains invalid at full
|
|
320
|
-
detail. No global full-detail fallback is applied. See [spherical semantics](docs/SPHERICAL.md) for winding,
|
|
321
|
-
poles, seams, charts, and topology junctions.
|
|
322
|
-
|
|
323
|
-
Spherical reconstruction applies three additional safeguards:
|
|
77
|
+
The React globe is the GitHub Pages demo. It uses version-pinned CDN geometry sources, caches downloads and regional engines, and renders eligible administrative boundaries through Quadstream. Spherical simplification is in-memory, not network partition streaming. The legacy globe and progressive map remain available with `npm run dev:legacy` and `npm run demo:map`.
|
|
324
78
|
|
|
325
|
-
|
|
326
|
-
multi-shape junctions and shared topology;
|
|
327
|
-
- a vertex is promoted to critical when its removal would reverse a ring's
|
|
328
|
-
projected winding, collapse its area, or make a small ring fail the spherical
|
|
329
|
-
validity predicate;
|
|
330
|
-
- closed rings that would reconstruct with fewer than three distinct vertices
|
|
331
|
-
are restored from their source path rather than emitted as degenerate rings.
|
|
79
|
+
## Documentation
|
|
332
80
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
## How it works
|
|
340
|
-
|
|
341
|
-
Quadstream deduplicates exact shared vertices and arcs, assigns deterministic
|
|
342
|
-
spatial importance using a sparse hierarchy, and reconstructs source order
|
|
343
|
-
through Binary Line Generalization (BLG)-style priority trees. Planar geometry
|
|
344
|
-
uses a sparse quadtree, while spherical geometry uses hierarchical occupancy
|
|
345
|
-
on six cube faces. A packed planar spatial index selects viewport candidates.
|
|
346
|
-
The versioned planar binary format stores checksummed vertex batches separately
|
|
347
|
-
from topology metadata.
|
|
81
|
+
- [Usage and API guide](https://github.com/vizhub-studio/quadstream/blob/main/docs/USAGE.md) — progressive loading, spherical examples, CLI and API signatures.
|
|
82
|
+
- [Architecture](https://github.com/vizhub-studio/quadstream/blob/main/docs/ARCHITECTURE.md) · [Algorithmic complexity](https://github.com/vizhub-studio/quadstream/blob/main/docs/COMPLEXITY.md)
|
|
83
|
+
- [Spherical geometry](https://github.com/vizhub-studio/quadstream/blob/main/docs/SPHERICAL.md) · [Progressive map](https://github.com/vizhub-studio/quadstream/blob/main/docs/PROGRESSIVE-MAP.md) · [CLI](https://github.com/vizhub-studio/quadstream/blob/main/docs/CLI.md)
|
|
84
|
+
- [React globe setup and deployment](https://github.com/vizhub-studio/quadstream/blob/main/quadstream-globe/README.md) · [Globe controls and provenance](https://github.com/vizhub-studio/quadstream/blob/main/docs/GLOBE.md)
|
|
85
|
+
- [Roadmap](https://github.com/vizhub-studio/quadstream/blob/main/plans/PROJECT_ROADMAP.md) · [Contributing](https://github.com/vizhub-studio/quadstream/blob/main/CONTRIBUTING.md) · [History](https://github.com/vizhub-studio/quadstream/blob/main/docs/HISTORY.md)
|
|
348
86
|
|
|
349
87
|
## Geometry semantics and limitations
|
|
350
88
|
|
|
@@ -365,8 +103,8 @@ from topology metadata.
|
|
|
365
103
|
production resource hardening remain future work.
|
|
366
104
|
- Binary checksums detect accidental corruption, not malicious changes.
|
|
367
105
|
|
|
368
|
-
See the [architecture](https://github.com/vizhub-studio/quadstream/blob/
|
|
369
|
-
and [roadmap](https://github.com/vizhub-studio/quadstream/blob/
|
|
106
|
+
See the [architecture](https://github.com/vizhub-studio/quadstream/blob/main/docs/ARCHITECTURE.md)
|
|
107
|
+
and [roadmap](https://github.com/vizhub-studio/quadstream/blob/main/plans/PROJECT_ROADMAP.md)
|
|
370
108
|
for implementation details and planned work.
|
|
371
109
|
|
|
372
110
|
## Development
|
|
@@ -376,22 +114,10 @@ npm ci
|
|
|
376
114
|
npm run check
|
|
377
115
|
npm run lint
|
|
378
116
|
npm run test:package
|
|
379
|
-
npx playwright install --with-deps chromium webkit
|
|
380
|
-
npm run test:globe:browser
|
|
381
117
|
```
|
|
382
118
|
|
|
383
|
-
|
|
384
|
-
packed-package verification for Node 20 and 26. The real-atlas globe tests
|
|
385
|
-
compare original and full-resolution reconstruction across multiple views and
|
|
386
|
-
zoom levels. Physical mobile-device validation and production benchmarks remain
|
|
387
|
-
outstanding. See [contributing](https://github.com/vizhub-studio/quadstream/blob/master/CONTRIBUTING.md).
|
|
388
|
-
|
|
389
|
-
## History and license
|
|
119
|
+
See the [globe development guide](https://github.com/vizhub-studio/quadstream/blob/main/quadstream-globe/README.md) for browser tests. The modern implementation is MIT-licensed; historical code retains its existing license terms. See [LICENSE](https://github.com/vizhub-studio/quadstream/blob/main/LICENSE).
|
|
390
120
|
|
|
391
|
-
|
|
392
|
-
modern TypeScript implementation. See [historical provenance](https://github.com/vizhub-studio/quadstream/blob/master/docs/HISTORY.md).
|
|
121
|
+
### Cooperative computation
|
|
393
122
|
|
|
394
|
-
|
|
395
|
-
The modern implementation is MIT-licensed. Historical Java/browser code
|
|
396
|
-
retains its existing license terms.
|
|
397
|
-
See [LICENSE](https://github.com/vizhub-studio/quadstream/blob/master/LICENSE).
|
|
123
|
+
`buildQuadstream` and `buildSphericalQuadstream` return promises, as do dataset and session `query` methods. Pass `signal`, `onProgress`, `onSlice`, and `sliceMs` to cooperative operations as needed. The default build slice target is 4 ms; individual synchronous operations can exceed it. No `Async` suffix is needed. Cancellation rejects with the abort reason. Lightweight accessors, low-level geometry helpers, session construction, and atomic partition ingestion remain synchronous. Synchronous dataset reference methods are internal, not public TypeScript API.
|
package/bin/quadstream.mjs
CHANGED
|
@@ -148,7 +148,9 @@ async function main() {
|
|
|
148
148
|
"file-depth",
|
|
149
149
|
);
|
|
150
150
|
const bundle = exportPartitions(
|
|
151
|
-
buildQuadstream(asSource(json(await read(input))), {
|
|
151
|
+
await buildQuadstream(asSource(json(await read(input))), {
|
|
152
|
+
maxLevel: level,
|
|
153
|
+
}),
|
|
152
154
|
{ fileDepth: depth },
|
|
153
155
|
);
|
|
154
156
|
validateManifest(bundle.manifest);
|
|
@@ -175,7 +177,7 @@ async function main() {
|
|
|
175
177
|
if (cmd === "validate") {
|
|
176
178
|
if ((await lstat(input)).isDirectory()) {
|
|
177
179
|
const { m, session } = await load(input, read),
|
|
178
|
-
result = session.query({ level: m.maxLevel - 1 });
|
|
180
|
+
result = await session.query({ level: m.maxLevel - 1 });
|
|
179
181
|
if (!result.complete || result.omittedFeatures)
|
|
180
182
|
throw new Error("Incomplete full-detail reconstruction");
|
|
181
183
|
print({ valid: true, ...inspect(m) });
|
|
@@ -197,7 +199,7 @@ async function main() {
|
|
|
197
199
|
m.maxLevel - 1,
|
|
198
200
|
"level",
|
|
199
201
|
);
|
|
200
|
-
const result = session.query({ level, bounds });
|
|
202
|
+
const result = await session.query({ level, bounds });
|
|
201
203
|
if (!result.complete) throw new Error("Incomplete query result");
|
|
202
204
|
const data =
|
|
203
205
|
format === "topojson"
|
|
@@ -214,12 +216,12 @@ async function main() {
|
|
|
214
216
|
runs = [];
|
|
215
217
|
for (let i = 0; i < iterations; i++) {
|
|
216
218
|
const start = performance.now(),
|
|
217
|
-
dataset = buildQuadstream(data, { maxLevel: level }),
|
|
219
|
+
dataset = await buildQuadstream(data, { maxLevel: level }),
|
|
218
220
|
built = performance.now(),
|
|
219
221
|
bundle = exportPartitions(dataset, { fileDepth: Math.min(4, level) }),
|
|
220
222
|
packed = performance.now();
|
|
221
|
-
const coarse = dataset.query({ level: 0 }),
|
|
222
|
-
full = dataset.query({ level: level - 1 }),
|
|
223
|
+
const coarse = await dataset.query({ level: 0 }),
|
|
224
|
+
full = await dataset.query({ level: level - 1 }),
|
|
223
225
|
done = performance.now();
|
|
224
226
|
runs.push({
|
|
225
227
|
buildMs: built - start,
|
package/dist/blg.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Work } from "./cooperative.js";
|
|
1
2
|
/** Ordered min-Cartesian tree over vertex priorities; inorder restores exact input order. */
|
|
2
3
|
export interface BlgNode {
|
|
3
4
|
position: number;
|
|
@@ -12,6 +13,8 @@ export interface BlgTree {
|
|
|
12
13
|
}
|
|
13
14
|
export declare function stableBlgRandom(key: number): number;
|
|
14
15
|
export declare function buildBlgTree(levels: readonly number[], randomValues?: readonly number[]): BlgTree;
|
|
16
|
+
export declare function buildBlgTreeSteps(levels: readonly number[], randomValues?: readonly number[]): Work<BlgTree>;
|
|
15
17
|
/** Iterative inorder traversal: no recursion depth limitation. */
|
|
16
18
|
export declare function selectBlgPositions(tree: BlgTree, maxLevel: number): number[];
|
|
19
|
+
export declare function selectBlgPositionSteps(tree: BlgTree, maxLevel: number): Work<number[]>;
|
|
17
20
|
export declare function assertBlgInvariants(tree: BlgTree): void;
|
package/dist/blg.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { runSync } from "./cooperative.js";
|
|
1
2
|
export function stableBlgRandom(key) {
|
|
2
3
|
let hash = Math.imul(key + 1, 0x9e3779b1);
|
|
3
4
|
hash ^= hash >>> 16;
|
|
@@ -6,10 +7,15 @@ export function stableBlgRandom(key) {
|
|
|
6
7
|
return (hash >>> 0) / 0x100000000;
|
|
7
8
|
}
|
|
8
9
|
export function buildBlgTree(levels, randomValues) {
|
|
10
|
+
return runSync(buildBlgTreeSteps(levels, randomValues));
|
|
11
|
+
}
|
|
12
|
+
export function* buildBlgTreeSteps(levels, randomValues) {
|
|
9
13
|
if (randomValues && randomValues.length !== levels.length)
|
|
10
14
|
throw new Error("BLG random values must match priorities");
|
|
11
15
|
const stack = [];
|
|
12
16
|
for (let position = 0; position < levels.length; position++) {
|
|
17
|
+
if (position % 512 === 0)
|
|
18
|
+
yield undefined;
|
|
13
19
|
const level = levels[position];
|
|
14
20
|
if (!Number.isFinite(level) || level < 0)
|
|
15
21
|
throw new Error("BLG priorities must be nonnegative and finite");
|
|
@@ -32,6 +38,9 @@ export function buildBlgTree(levels, randomValues) {
|
|
|
32
38
|
}
|
|
33
39
|
/** Iterative inorder traversal: no recursion depth limitation. */
|
|
34
40
|
export function selectBlgPositions(tree, maxLevel) {
|
|
41
|
+
return runSync(selectBlgPositionSteps(tree, maxLevel));
|
|
42
|
+
}
|
|
43
|
+
export function* selectBlgPositionSteps(tree, maxLevel) {
|
|
35
44
|
if (!Number.isFinite(maxLevel) && maxLevel !== Infinity)
|
|
36
45
|
throw new Error("Invalid selection level");
|
|
37
46
|
if (maxLevel < 0)
|
|
@@ -40,14 +49,18 @@ export function selectBlgPositions(tree, maxLevel) {
|
|
|
40
49
|
maxLevel = Number.MAX_SAFE_INTEGER;
|
|
41
50
|
const wholeLevel = Math.floor(maxLevel), fraction = maxLevel - wholeLevel, partialLevel = wholeLevel + 1, traversalLevel = fraction === 0 ? wholeLevel : partialLevel;
|
|
42
51
|
const selected = [], stack = [];
|
|
43
|
-
let current = tree.root;
|
|
52
|
+
let current = tree.root, steps = 0;
|
|
44
53
|
while (current || stack.length) {
|
|
45
54
|
while (current && current.level <= traversalLevel) {
|
|
55
|
+
if (++steps % 512 === 0)
|
|
56
|
+
yield undefined;
|
|
46
57
|
stack.push(current);
|
|
47
58
|
current = current.left;
|
|
48
59
|
}
|
|
49
60
|
if (!stack.length)
|
|
50
61
|
break;
|
|
62
|
+
if (++steps % 512 === 0)
|
|
63
|
+
yield undefined;
|
|
51
64
|
const node = stack.pop();
|
|
52
65
|
if (node.level <= wholeLevel ||
|
|
53
66
|
(fraction > 0 &&
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Generator checkpoints are cooperative, not hard real-time deadlines. */
|
|
2
|
+
export interface CooperativeOptions {
|
|
3
|
+
signal?: AbortSignal;
|
|
4
|
+
sliceMs?: number;
|
|
5
|
+
yieldTurn?: () => Promise<void>;
|
|
6
|
+
/** Observed compute slice duration, excluding task-yield wait time. */
|
|
7
|
+
onSlice?: (elapsedMs: number) => void;
|
|
8
|
+
onProgress?: (progress: {
|
|
9
|
+
stage: string;
|
|
10
|
+
completed?: number;
|
|
11
|
+
total?: number;
|
|
12
|
+
}) => void;
|
|
13
|
+
}
|
|
14
|
+
export type WorkProgress = {
|
|
15
|
+
stage: string;
|
|
16
|
+
completed?: number;
|
|
17
|
+
total?: number;
|
|
18
|
+
};
|
|
19
|
+
export type Work<T> = Generator<WorkProgress | undefined, T, void>;
|
|
20
|
+
export declare function runSync<T>(work: Work<T>): T;
|
|
21
|
+
export declare function runCooperative<T>(work: Work<T>, { signal, sliceMs, yieldTurn, onProgress, onSlice, }?: CooperativeOptions): Promise<T>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function runSync(work) {
|
|
2
|
+
let step = work.next();
|
|
3
|
+
while (!step.done)
|
|
4
|
+
step = work.next();
|
|
5
|
+
return step.value;
|
|
6
|
+
}
|
|
7
|
+
export async function runCooperative(work, { signal, sliceMs = 4, yieldTurn = () => new Promise((resolve) => setTimeout(resolve, 0)), onProgress, onSlice, } = {}) {
|
|
8
|
+
if (!Number.isFinite(sliceMs) || sliceMs < 0)
|
|
9
|
+
throw new RangeError("Invalid slice budget");
|
|
10
|
+
let start = performance.now(), count = 0;
|
|
11
|
+
try {
|
|
12
|
+
for (;;) {
|
|
13
|
+
signal?.throwIfAborted();
|
|
14
|
+
const step = work.next();
|
|
15
|
+
if (step.done) {
|
|
16
|
+
onSlice?.(performance.now() - start);
|
|
17
|
+
signal?.throwIfAborted();
|
|
18
|
+
return step.value;
|
|
19
|
+
}
|
|
20
|
+
if (step.value)
|
|
21
|
+
onProgress?.(step.value);
|
|
22
|
+
if (++count >= 1024 || performance.now() - start >= sliceMs) {
|
|
23
|
+
onSlice?.(performance.now() - start);
|
|
24
|
+
await yieldTurn();
|
|
25
|
+
start = performance.now();
|
|
26
|
+
count = 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
work.return(undefined);
|
|
32
|
+
}
|
|
33
|
+
}
|
package/dist/dataset.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type CooperativeOptions } from "./cooperative.js";
|
|
1
2
|
import type { FeatureCollection, QueryOptions, QueryResult, SparseQuadtree, Topology } from "./types.js";
|
|
2
3
|
import type { BlgTree } from "./blg.js";
|
|
3
4
|
export declare class QuadstreamDataset {
|
|
@@ -6,11 +7,14 @@ export declare class QuadstreamDataset {
|
|
|
6
7
|
readonly arcTrees: readonly BlgTree[];
|
|
7
8
|
private readonly featureIndex;
|
|
8
9
|
private readonly validityCache;
|
|
9
|
-
constructor(
|
|
10
|
+
private constructor();
|
|
11
|
+
static create(input: FeatureCollection, options?: {
|
|
10
12
|
maxLevel?: number;
|
|
11
|
-
})
|
|
12
|
-
query(options?: QueryOptions): QueryResult
|
|
13
|
+
} & CooperativeOptions): Promise<QuadstreamDataset>;
|
|
14
|
+
query(options?: QueryOptions & CooperativeOptions): Promise<QueryResult>;
|
|
15
|
+
private querySteps;
|
|
13
16
|
}
|
|
17
|
+
/** Cooperative construction using the same topology and priority algorithms. */
|
|
14
18
|
export declare function buildQuadstream(input: FeatureCollection, options?: {
|
|
15
19
|
maxLevel?: number;
|
|
16
|
-
}): QuadstreamDataset
|
|
20
|
+
} & CooperativeOptions): Promise<QuadstreamDataset>;
|