@spacexr/tiles 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/README.md +57 -2
- package/dist/addressing/index.d.ts +16 -0
- package/dist/addressing/index.js +4 -0
- package/dist/addressing/index.js.map +1 -0
- package/dist/bake/index.d.ts +91 -0
- package/dist/bake/index.js +3 -0
- package/dist/bake/index.js.map +1 -0
- package/dist/celestial-dataset-CUIsplKO.d.ts +99 -0
- package/dist/chunk-2HLQXRDD.js +246 -0
- package/dist/chunk-2HLQXRDD.js.map +1 -0
- package/dist/chunk-6YNCRDEE.js +170 -0
- package/dist/chunk-6YNCRDEE.js.map +1 -0
- package/dist/chunk-7AWV2IEK.js +79 -0
- package/dist/chunk-7AWV2IEK.js.map +1 -0
- package/dist/chunk-ESLGXWQR.js +219 -0
- package/dist/chunk-ESLGXWQR.js.map +1 -0
- package/dist/chunk-FB57CZDK.js +312 -0
- package/dist/chunk-FB57CZDK.js.map +1 -0
- package/dist/chunk-GRTG4WNA.js +44 -0
- package/dist/chunk-GRTG4WNA.js.map +1 -0
- package/dist/chunk-HVYN4AIT.js +45 -0
- package/dist/chunk-HVYN4AIT.js.map +1 -0
- package/dist/chunk-IGNRXAW3.js +77 -0
- package/dist/chunk-IGNRXAW3.js.map +1 -0
- package/dist/chunk-QGTREKHS.js +145 -0
- package/dist/chunk-QGTREKHS.js.map +1 -0
- package/dist/chunk-SPDRAY37.js +56 -0
- package/dist/chunk-SPDRAY37.js.map +1 -0
- package/dist/chunk-TA4BEVHL.js +81 -0
- package/dist/chunk-TA4BEVHL.js.map +1 -0
- package/dist/chunk-TGOB5HT5.js +149 -0
- package/dist/chunk-TGOB5HT5.js.map +1 -0
- package/dist/chunk-X6ZJ2PDY.js +104 -0
- package/dist/chunk-X6ZJ2PDY.js.map +1 -0
- package/dist/chunk-XTY4HCPY.js +22 -0
- package/dist/chunk-XTY4HCPY.js.map +1 -0
- package/dist/chunk-Y66PNDG2.js +107 -0
- package/dist/chunk-Y66PNDG2.js.map +1 -0
- package/dist/chunk-YEACOJOC.js +51 -0
- package/dist/chunk-YEACOJOC.js.map +1 -0
- package/dist/cube/index.d.ts +160 -0
- package/dist/cube/index.js +9 -0
- package/dist/cube/index.js.map +1 -0
- package/dist/datasets/index.d.ts +75 -0
- package/dist/datasets/index.js +11 -0
- package/dist/datasets/index.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/mercator/index.d.ts +24 -0
- package/dist/mercator/index.js +8 -0
- package/dist/mercator/index.js.map +1 -0
- package/dist/metrics-HGbzqj6L.d.ts +45 -0
- package/dist/pyramid/index.d.ts +156 -0
- package/dist/pyramid/index.js +4 -0
- package/dist/pyramid/index.js.map +1 -0
- package/dist/raster-registration-CgBxrhDB.d.ts +19 -0
- package/dist/reference-surface-CsTtrNsc.d.ts +49 -0
- package/dist/reprojection/index.d.ts +255 -0
- package/dist/reprojection/index.js +6 -0
- package/dist/reprojection/index.js.map +1 -0
- package/dist/sources/index.d.ts +55 -0
- package/dist/sources/index.js +7 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/surface/index.d.ts +15 -0
- package/dist/surface/index.js +4 -0
- package/dist/surface/index.js.map +1 -0
- package/dist/tile-D-jjIRRA.d.ts +53 -0
- package/dist/tile-address-BkfSftp6.d.ts +66 -0
- package/dist/tile-http-client-BHZOtGX7.d.ts +73 -0
- package/dist/tile-neighbors-LfvV7oiX.d.ts +48 -0
- package/dist/tile-surface-s9Zi6X9_.d.ts +40 -0
- package/dist/tile-topology-B6xHYqPb.d.ts +51 -0
- package/dist/web-mercator-dataset-Dmou8byO.d.ts +125 -0
- package/dist/web-tile-source-DrZDBIm6.d.ts +92 -0
- package/package.json +122 -5
- package/src/addressing/index.ts +8 -0
- package/src/addressing/metrics.ts +48 -0
- package/src/addressing/raster-registration.ts +22 -0
- package/src/addressing/tile-address.ts +130 -0
- package/src/addressing/tile-edge-rotation.ts +13 -0
- package/src/addressing/tile-neighbors.ts +73 -0
- package/src/addressing/tile-surface.ts +44 -0
- package/src/addressing/tile-topology.ts +86 -0
- package/src/addressing/tile.ts +73 -0
- package/src/bake/bake-pyramid.ts +106 -0
- package/src/bake/index.ts +2 -0
- package/src/bake/pyramid-levels.ts +63 -0
- package/src/cube/celestial-dataset.ts +182 -0
- package/src/cube/cube-face.ts +51 -0
- package/src/cube/cube-geometric-error.ts +30 -0
- package/src/cube/cube-mapping.ts +101 -0
- package/src/cube/cube-neighbors.ts +198 -0
- package/src/cube/cube-tile-surface.ts +30 -0
- package/src/cube/index.ts +6 -0
- package/src/datasets/index.ts +1 -0
- package/src/datasets/tile-dataset.ts +121 -0
- package/src/index.ts +9 -0
- package/src/mercator/index.ts +3 -0
- package/src/mercator/web-mercator-dataset.ts +215 -0
- package/src/mercator/web-mercator-tile-metrics.ts +119 -0
- package/src/mercator/web-mercator-tile-surface.ts +52 -0
- package/src/pyramid/index.ts +2 -0
- package/src/pyramid/resident-tiles.ts +81 -0
- package/src/pyramid/tile-pyramid.ts +285 -0
- package/src/reprojection/cube-resampling.ts +159 -0
- package/src/reprojection/index.ts +4 -0
- package/src/reprojection/source-projection.ts +196 -0
- package/src/reprojection/source-tile-matrix.ts +100 -0
- package/src/reprojection/wmts-capabilities.ts +112 -0
- package/src/sources/index.ts +4 -0
- package/src/sources/tile-http-client.ts +154 -0
- package/src/sources/tile-layer-changes.ts +88 -0
- package/src/sources/url-template.ts +96 -0
- package/src/sources/web-tile-source.ts +73 -0
- package/src/surface/directions.ts +27 -0
- package/src/surface/index.ts +2 -0
- package/src/surface/reference-surface.ts +88 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// src/bake/pyramid-levels.ts
|
|
2
|
+
function tileWidth(lod) {
|
|
3
|
+
return 360 / 2 ** lod;
|
|
4
|
+
}
|
|
5
|
+
function pyramidLevels(metrics, bounds, options) {
|
|
6
|
+
const { finest, coarsestTileRatio, pixelSize } = options;
|
|
7
|
+
if (!Number.isInteger(finest)) throw new RangeError("finest must be an integer level.");
|
|
8
|
+
if (!(coarsestTileRatio > 0)) throw new RangeError("coarsestTileRatio must be positive.");
|
|
9
|
+
const extent = Math.max(bounds.east - bounds.west, bounds.north - bounds.south);
|
|
10
|
+
if (!(extent > 0)) throw new RangeError("bounds must have an extent.");
|
|
11
|
+
let deepest = Math.min(finest, metrics.maxLOD);
|
|
12
|
+
if (pixelSize !== void 0) {
|
|
13
|
+
if (!(pixelSize > 0)) throw new RangeError("pixelSize must be a positive number of metres.");
|
|
14
|
+
const latitude = bounds.south > 0 ? bounds.south : bounds.north < 0 ? bounds.north : 0;
|
|
15
|
+
let lod = metrics.minLOD;
|
|
16
|
+
while (lod < deepest && metrics.groundResolution(latitude, lod) > pixelSize) lod++;
|
|
17
|
+
deepest = lod;
|
|
18
|
+
}
|
|
19
|
+
let coarsest = metrics.minLOD;
|
|
20
|
+
while (coarsest < deepest && tileWidth(coarsest) > coarsestTileRatio * extent) coarsest++;
|
|
21
|
+
return { minLOD: coarsest, maxLOD: deepest };
|
|
22
|
+
}
|
|
23
|
+
function* tilesInBounds(metrics, bounds, lod) {
|
|
24
|
+
const northWest = metrics.getLatLonToTileXY(bounds.north, bounds.west, lod);
|
|
25
|
+
const southEast = metrics.getLatLonToTileXY(bounds.south, bounds.east, lod);
|
|
26
|
+
for (let y = northWest.y; y <= southEast.y; y++) for (let x = northWest.x; x <= southEast.x; x++) yield { lod, x, y };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/bake/bake-pyramid.ts
|
|
30
|
+
function bakedTileTemplate(extension) {
|
|
31
|
+
return `./{z}/{x}/{y}.${extension}`;
|
|
32
|
+
}
|
|
33
|
+
function bakedTilePath(address, extension) {
|
|
34
|
+
return `${address.lod}/${address.x}/${address.y}.${extension}`;
|
|
35
|
+
}
|
|
36
|
+
function isTransparent(raster) {
|
|
37
|
+
if (raster.channels !== 4) return false;
|
|
38
|
+
const { data } = raster;
|
|
39
|
+
for (let i = 3; i < data.length; i += 4) if (data[i] !== 0) return false;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
function pyramidTileCount(metrics, bounds, levels) {
|
|
43
|
+
let count = 0;
|
|
44
|
+
for (let lod = levels.minLOD; lod <= levels.maxLOD; lod++) {
|
|
45
|
+
const northWest = metrics.getLatLonToTileXY(bounds.north, bounds.west, lod);
|
|
46
|
+
const southEast = metrics.getLatLonToTileXY(bounds.south, bounds.east, lod);
|
|
47
|
+
count += (southEast.x - northWest.x + 1) * (southEast.y - northWest.y + 1);
|
|
48
|
+
}
|
|
49
|
+
return count;
|
|
50
|
+
}
|
|
51
|
+
async function bakePyramid(options) {
|
|
52
|
+
const { metrics, bounds, levels, source, encode, write, extension, signal, onProgress } = options;
|
|
53
|
+
const concurrency = options.concurrency ?? 1;
|
|
54
|
+
if (!Number.isInteger(concurrency) || concurrency < 1) throw new RangeError("concurrency must be a positive integer.");
|
|
55
|
+
const total = pyramidTileCount(metrics, bounds, levels);
|
|
56
|
+
const result = { written: 0, empty: 0, total };
|
|
57
|
+
let done = 0;
|
|
58
|
+
function* addresses() {
|
|
59
|
+
for (let lod = levels.minLOD; lod <= levels.maxLOD; lod++) yield* tilesInBounds(metrics, bounds, lod);
|
|
60
|
+
}
|
|
61
|
+
const queue = addresses();
|
|
62
|
+
const bakeNext = async () => {
|
|
63
|
+
for (let next = queue.next(); !next.done; next = queue.next()) {
|
|
64
|
+
signal?.throwIfAborted();
|
|
65
|
+
const address = next.value;
|
|
66
|
+
const raster = await source(address, signal);
|
|
67
|
+
if (!raster || isTransparent(raster)) result.empty++;
|
|
68
|
+
else {
|
|
69
|
+
await write(bakedTilePath(address, extension), await encode(raster));
|
|
70
|
+
result.written++;
|
|
71
|
+
}
|
|
72
|
+
onProgress?.(++done, total);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
await Promise.all(Array.from({ length: concurrency }, () => bakeNext()));
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { bakePyramid, bakedTilePath, bakedTileTemplate, isTransparent, pyramidLevels, pyramidTileCount, tilesInBounds };
|
|
80
|
+
//# sourceMappingURL=chunk-TA4BEVHL.js.map
|
|
81
|
+
//# sourceMappingURL=chunk-TA4BEVHL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/bake/pyramid-levels.ts","../src/bake/bake-pyramid.ts"],"names":[],"mappings":";AA4BA,SAAS,UAAU,GAAA,EAAqB;AACpC,EAAA,OAAO,MAAM,CAAA,IAAK,GAAA;AACtB;AAOO,SAAS,aAAA,CAAc,OAAA,EAAiC,MAAA,EAAwB,OAAA,EAAgD;AACnI,EAAA,MAAM,EAAE,MAAA,EAAQ,iBAAA,EAAmB,SAAA,EAAU,GAAI,OAAA;AACjD,EAAA,IAAI,CAAC,OAAO,SAAA,CAAU,MAAM,GAAG,MAAM,IAAI,WAAW,kCAAkC,CAAA;AACtF,EAAA,IAAI,EAAE,iBAAA,GAAoB,CAAA,CAAA,EAAI,MAAM,IAAI,WAAW,qCAAqC,CAAA;AACxF,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,GAAA,CAAI,MAAA,CAAO,IAAA,GAAO,OAAO,IAAA,EAAM,MAAA,CAAO,KAAA,GAAQ,MAAA,CAAO,KAAK,CAAA;AAC9E,EAAA,IAAI,EAAE,MAAA,GAAS,CAAA,CAAA,EAAI,MAAM,IAAI,WAAW,6BAA6B,CAAA;AACrE,EAAA,IAAI,OAAA,GAAU,IAAA,CAAK,GAAA,CAAI,MAAA,EAAQ,QAAQ,MAAM,CAAA;AAC7C,EAAA,IAAI,cAAc,MAAA,EAAW;AACzB,IAAA,IAAI,EAAE,SAAA,GAAY,CAAA,CAAA,EAAI,MAAM,IAAI,WAAW,gDAAgD,CAAA;AAE3F,IAAA,MAAM,QAAA,GAAW,MAAA,CAAO,KAAA,GAAQ,CAAA,GAAI,MAAA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AI,KAAA,CAAM,IAAA,CAAK,EAAE,MAAA,EAAQ,WAAA,EAAY,EAAG,MAAM,QAAA,EAAU,CAAC,CAAA;AACvE,EAAA,OAAO,MAAA;AACX","file":"chunk-TA4BEVHL.js","sourcesContent":["import type { ITileAddress } from \"../addressing\";\nimport type { IDatasetBounds } from \"../mercator/web-mercator-dataset\";\nimport type { WebMercatorTileMetrics } from \"../mercator/web-mercator-tile-metrics\";\n\n/** Options of {@link pyramidLevels}. */\nexport interface IPyramidLevelsOptions {\n /** The deepest level wanted, such as the deepest level of the imagery the pyramid lies on. */\n finest: number;\n /**\n * How many times wider than the bounds a tile may be and still hold the pyramid: from higher up, its content would\n * be a patch of a few pixels. The coarsest level is the first whose tiles are no wider than that.\n */\n coarsestTileRatio: number;\n /**\n * Ground size of a sample of the source, in metres, for a raster: the pyramid stops at the first level whose pixels\n * are as fine as the source when that level is above `finest`. Absent for a source without a resolution of its own,\n * such as vectors.\n */\n pixelSize?: number;\n}\n\n/** The levels of a pyramid, from `minLOD` to `maxLOD`. */\nexport interface IPyramidLevels {\n readonly minLOD: number;\n readonly maxLOD: number;\n}\n\n/** Width in degrees of longitude of a tile of a level. */\nfunction tileWidth(lod: number): number {\n return 360 / 2 ** lod;\n}\n\n/**\n * The levels a pyramid over `bounds` is built for: from the first level whose tiles are at most `coarsestTileRatio`\n * times as wide as the bounds, down to `finest`, or to the level of the pixel size of a raster source when it is less\n * deep. The level range of `metrics` bounds both.\n */\nexport function pyramidLevels(metrics: WebMercatorTileMetrics, bounds: IDatasetBounds, options: IPyramidLevelsOptions): IPyramidLevels {\n const { finest, coarsestTileRatio, pixelSize } = options;\n if (!Number.isInteger(finest)) throw new RangeError(\"finest must be an integer level.\");\n if (!(coarsestTileRatio > 0)) throw new RangeError(\"coarsestTileRatio must be positive.\");\n const extent = Math.max(bounds.east - bounds.west, bounds.north - bounds.south);\n if (!(extent > 0)) throw new RangeError(\"bounds must have an extent.\");\n let deepest = Math.min(finest, metrics.maxLOD);\n if (pixelSize !== undefined) {\n if (!(pixelSize > 0)) throw new RangeError(\"pixelSize must be a positive number of metres.\");\n // The pixels of the source are finest where the bounds are nearest the equator, the case that sets the level.\n const latitude = bounds.south > 0 ? bounds.south : bounds.north < 0 ? bounds.north : 0;\n let lod = metrics.minLOD;\n while (lod < deepest && metrics.groundResolution(latitude, lod) > pixelSize) lod++;\n deepest = lod;\n }\n let coarsest = metrics.minLOD;\n while (coarsest < deepest && tileWidth(coarsest) > coarsestTileRatio * extent) coarsest++;\n return { minLOD: coarsest, maxLOD: deepest };\n}\n\n/** The tiles of a level that meet `bounds`, row by row from the north-west. */\nexport function* tilesInBounds(metrics: WebMercatorTileMetrics, bounds: IDatasetBounds, lod: number): Generator<ITileAddress> {\n const northWest = metrics.getLatLonToTileXY(bounds.north, bounds.west, lod);\n const southEast = metrics.getLatLonToTileXY(bounds.south, bounds.east, lod);\n for (let y = northWest.y; y <= southEast.y; y++) for (let x = northWest.x; x <= southEast.x; x++) yield { lod, x, y };\n}\n","import type { ITileAddress } from \"../addressing\";\nimport type { IDatasetBounds } from \"../mercator/web-mercator-dataset\";\nimport type { WebMercatorTileMetrics } from \"../mercator/web-mercator-tile-metrics\";\nimport { tilesInBounds, type IPyramidLevels } from \"./pyramid-levels\";\n\n/** An image of a tile: rows from the north, columns from the west, 8 bits per channel. */\nexport interface IBakedRaster {\n readonly width: number;\n readonly height: number;\n /** 3 for RGB, 4 for RGBA. */\n readonly channels: number;\n readonly data: Uint8Array | Uint8ClampedArray;\n}\n\n/** Options of {@link bakePyramid}. */\nexport interface IBakePyramidOptions {\n metrics: WebMercatorTileMetrics;\n bounds: IDatasetBounds;\n levels: IPyramidLevels;\n /** The image of a tile, or nothing where the source has none. */\n source(address: ITileAddress, signal?: AbortSignal): Promise<IBakedRaster | undefined>;\n /** The bytes of an image in the format of the pyramid, such as PNG. */\n encode(raster: IBakedRaster): Promise<Uint8Array>;\n /** Writes the file of a tile, at a path relative to the folder of the pyramid ({@link bakedTilePath}). */\n write(path: string, bytes: Uint8Array): Promise<void>;\n /** Extension of the files of the tiles, such as `png`. */\n extension: string;\n /** Tiles baked at once; one at a time by default. */\n concurrency?: number;\n signal?: AbortSignal;\n /** Called after each tile, baked or skipped. */\n onProgress?(done: number, total: number): void;\n}\n\n/** What a bake did. */\nexport interface IBakePyramidResult {\n /** Tiles written. */\n written: number;\n /** Tiles the source had nothing for, or only transparent texels: no file is written for them. */\n empty: number;\n total: number;\n}\n\n/** The URL template of the tiles of a baked pyramid, relative to its descriptor: `./{z}/{x}/{y}.<extension>`. */\nexport function bakedTileTemplate(extension: string): string {\n return `./{z}/{x}/{y}.${extension}`;\n}\n\n/** The path of the file of a tile of a baked pyramid, relative to its folder: `<lod>/<x>/<y>.<extension>`. */\nexport function bakedTilePath(address: ITileAddress, extension: string): string {\n return `${address.lod}/${address.x}/${address.y}.${extension}`;\n}\n\n/** Whether every texel of an image is transparent: an image without alpha never is. */\nexport function isTransparent(raster: IBakedRaster): boolean {\n if (raster.channels !== 4) return false;\n const { data } = raster;\n for (let i = 3; i < data.length; i += 4) if (data[i] !== 0) return false;\n return true;\n}\n\n/** The number of tiles of a pyramid over `bounds`, all its levels. */\nexport function pyramidTileCount(metrics: WebMercatorTileMetrics, bounds: IDatasetBounds, levels: IPyramidLevels): number {\n let count = 0;\n for (let lod = levels.minLOD; lod <= levels.maxLOD; lod++) {\n const northWest = metrics.getLatLonToTileXY(bounds.north, bounds.west, lod);\n const southEast = metrics.getLatLonToTileXY(bounds.south, bounds.east, lod);\n count += (southEast.x - northWest.x + 1) * (southEast.y - northWest.y + 1);\n }\n return count;\n}\n\n/**\n * Bakes a tile pyramid: asks the source for each tile of `bounds` at each level, encodes it and writes it. A tile the\n * source has nothing for, or only transparent texels, is not written: a reader takes an absent tile as empty. The bake\n * knows no canvas and no file system: the source, the encoder and the writer are given, so it runs in a browser as\n * under Node. Writing the descriptor of the pyramid is left to the caller, after the tiles, so that a pyramid without\n * its descriptor reads as unfinished.\n */\nexport async function bakePyramid(options: IBakePyramidOptions): Promise<IBakePyramidResult> {\n const { metrics, bounds, levels, source, encode, write, extension, signal, onProgress } = options;\n const concurrency = options.concurrency ?? 1;\n if (!Number.isInteger(concurrency) || concurrency < 1) throw new RangeError(\"concurrency must be a positive integer.\");\n const total = pyramidTileCount(metrics, bounds, levels);\n const result: IBakePyramidResult = { written: 0, empty: 0, total };\n let done = 0;\n function* addresses(): Generator<ITileAddress> {\n for (let lod = levels.minLOD; lod <= levels.maxLOD; lod++) yield* tilesInBounds(metrics, bounds, lod);\n }\n const queue = addresses();\n const bakeNext = async (): Promise<void> => {\n for (let next = queue.next(); !next.done; next = queue.next()) {\n signal?.throwIfAborted();\n const address = next.value;\n const raster = await source(address, signal);\n if (!raster || isTransparent(raster)) result.empty++;\n else {\n await write(bakedTilePath(address, extension), await encode(raster));\n result.written++;\n }\n onProgress?.(++done, total);\n }\n };\n await Promise.all(Array.from({ length: concurrency }, () => bakeNext()));\n return result;\n}\n"]}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { cubeTileDirection } from './chunk-IGNRXAW3.js';
|
|
2
|
+
import { oppositeTileEdge } from './chunk-X6ZJ2PDY.js';
|
|
3
|
+
import { TileNeighbor, TILE_EDGE_NEIGHBORS, assertValidTileAddress, tileCount, tileNeighborOffset, TILE_CORNER_EDGES } from './chunk-Y66PNDG2.js';
|
|
4
|
+
|
|
5
|
+
// src/cube/cube-geometric-error.ts
|
|
6
|
+
var CORNERS = [
|
|
7
|
+
[0, 0],
|
|
8
|
+
[1, 0],
|
|
9
|
+
[1, 1],
|
|
10
|
+
[0, 1]
|
|
11
|
+
];
|
|
12
|
+
function cubeTileGeometricError(address, surface, tileSize) {
|
|
13
|
+
if (!(tileSize > 0)) throw new RangeError("The tile size must be positive.");
|
|
14
|
+
const points = CORNERS.map(([s, t]) => surface.point(cubeTileDirection(address, s, t)));
|
|
15
|
+
let longest = 0;
|
|
16
|
+
for (let index = 0; index < 4; index++) {
|
|
17
|
+
const a = points[index];
|
|
18
|
+
const b = points[(index + 1) % 4];
|
|
19
|
+
longest = Math.max(longest, Math.hypot(a.x - b.x, a.y - b.y, a.z - b.z));
|
|
20
|
+
}
|
|
21
|
+
return longest / tileSize;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/cube/cube-neighbors.ts
|
|
25
|
+
var { N, E, S, W } = TileNeighbor;
|
|
26
|
+
var EDGE_TABLE = [
|
|
27
|
+
[
|
|
28
|
+
[4, S, false],
|
|
29
|
+
[1, W, false],
|
|
30
|
+
[5, N, false],
|
|
31
|
+
[3, E, false]
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
[4, E, true],
|
|
35
|
+
[2, W, false],
|
|
36
|
+
[5, E, false],
|
|
37
|
+
[0, E, false]
|
|
38
|
+
],
|
|
39
|
+
[
|
|
40
|
+
[4, N, true],
|
|
41
|
+
[3, W, false],
|
|
42
|
+
[5, S, true],
|
|
43
|
+
[1, E, false]
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
[4, W, false],
|
|
47
|
+
[0, W, false],
|
|
48
|
+
[5, W, true],
|
|
49
|
+
[2, E, false]
|
|
50
|
+
],
|
|
51
|
+
[
|
|
52
|
+
[2, N, true],
|
|
53
|
+
[1, N, true],
|
|
54
|
+
[0, N, false],
|
|
55
|
+
[3, N, false]
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
[0, S, false],
|
|
59
|
+
[1, S, false],
|
|
60
|
+
[2, S, true],
|
|
61
|
+
[3, S, true]
|
|
62
|
+
]
|
|
63
|
+
];
|
|
64
|
+
var CUBE_FACE_EDGES = Object.freeze(
|
|
65
|
+
EDGE_TABLE.map((row) => {
|
|
66
|
+
const junctions = {};
|
|
67
|
+
row.forEach(([face, edge, reversed], index) => {
|
|
68
|
+
const own = TILE_EDGE_NEIGHBORS[index];
|
|
69
|
+
const turns = (TILE_EDGE_NEIGHBORS.indexOf(oppositeTileEdge(edge)) - index + 4) % 4;
|
|
70
|
+
junctions[own] = Object.freeze({ face, edge, reversed, turns });
|
|
71
|
+
});
|
|
72
|
+
return Object.freeze(junctions);
|
|
73
|
+
})
|
|
74
|
+
);
|
|
75
|
+
function acrossFaceEdge(face, edge, k, lod, count) {
|
|
76
|
+
const junction = CUBE_FACE_EDGES[face][edge];
|
|
77
|
+
const along = junction.reversed ? count - 1 - k : k;
|
|
78
|
+
let x = along;
|
|
79
|
+
let y = along;
|
|
80
|
+
if (junction.edge === 1 /* N */) y = 0;
|
|
81
|
+
else if (junction.edge === 7 /* S */) y = count - 1;
|
|
82
|
+
else if (junction.edge === 3 /* W */) x = 0;
|
|
83
|
+
else x = count - 1;
|
|
84
|
+
return { address: { face: junction.face, lod, x, y }, turns: junction.turns };
|
|
85
|
+
}
|
|
86
|
+
function cubeTileNeighbor(address, neighbor) {
|
|
87
|
+
assertValidTileAddress(address);
|
|
88
|
+
const face = address.face ?? 0 /* PositiveX */;
|
|
89
|
+
const { lod } = address;
|
|
90
|
+
const count = tileCount(lod);
|
|
91
|
+
const [dx, dy] = tileNeighborOffset(neighbor);
|
|
92
|
+
const x = address.x + dx;
|
|
93
|
+
const y = address.y + dy;
|
|
94
|
+
const outX = x < 0 || x >= count;
|
|
95
|
+
const outY = y < 0 || y >= count;
|
|
96
|
+
if (outX && outY) return void 0;
|
|
97
|
+
if (!outX && !outY) return { address: { face, lod, x, y }, turns: 0 };
|
|
98
|
+
if (outY) return acrossFaceEdge(face, y < 0 ? 1 /* N */ : 7 /* S */, x, lod, count);
|
|
99
|
+
return acrossFaceEdge(face, x < 0 ? 3 /* W */ : 5 /* E */, y, lod, count);
|
|
100
|
+
}
|
|
101
|
+
function cubeTileNeighbors(address) {
|
|
102
|
+
return Array.from({ length: 9 }, (_, neighbor) => cubeTileNeighbor(address, neighbor));
|
|
103
|
+
}
|
|
104
|
+
function cubeCornerTileCount(address, corner) {
|
|
105
|
+
assertValidTileAddress(address);
|
|
106
|
+
const count = tileCount(address.lod);
|
|
107
|
+
const [vertical, horizontal] = TILE_CORNER_EDGES[corner];
|
|
108
|
+
const onRow = vertical === 1 /* N */ ? address.y === 0 : address.y === count - 1;
|
|
109
|
+
const onColumn = horizontal === 3 /* W */ ? address.x === 0 : address.x === count - 1;
|
|
110
|
+
return onRow && onColumn ? 3 : 4;
|
|
111
|
+
}
|
|
112
|
+
var TURNED_ORIGIN = [
|
|
113
|
+
[0, 0],
|
|
114
|
+
[0, 1],
|
|
115
|
+
[1, 1],
|
|
116
|
+
[1, 0]
|
|
117
|
+
];
|
|
118
|
+
function cubeTileAreaIn(address, other) {
|
|
119
|
+
assertValidTileAddress(address);
|
|
120
|
+
assertValidTileAddress(other);
|
|
121
|
+
const face = address.face ?? 0;
|
|
122
|
+
const otherFace = other.face ?? 0;
|
|
123
|
+
const scale = 2 ** (address.lod - other.lod);
|
|
124
|
+
const size = 1 / scale;
|
|
125
|
+
if (face === otherFace) return { west: address.x / scale - other.x, north: address.y / scale - other.y, size, turns: 0 };
|
|
126
|
+
const edge = TILE_EDGE_NEIGHBORS.find((candidate) => CUBE_FACE_EDGES[face][candidate].face === otherFace);
|
|
127
|
+
if (edge === void 0) throw new RangeError(`Faces ${face} and ${otherFace} are opposite: their tiles cannot touch.`);
|
|
128
|
+
const junction = CUBE_FACE_EDGES[face][edge];
|
|
129
|
+
const [cornerU, cornerV] = TURNED_ORIGIN[junction.turns];
|
|
130
|
+
const count = tileCount(address.lod);
|
|
131
|
+
const u = (address.x + cornerU) / count;
|
|
132
|
+
const v = (address.y + cornerV) / count;
|
|
133
|
+
const along = edge === 1 /* N */ || edge === 7 /* S */ ? u : v;
|
|
134
|
+
const beyond = edge === 1 /* N */ ? -v : edge === 7 /* S */ ? v - 1 : edge === 3 /* W */ ? -u : u - 1;
|
|
135
|
+
const alongOther = junction.reversed ? 1 - along : along;
|
|
136
|
+
let otherU = alongOther;
|
|
137
|
+
let otherV = alongOther;
|
|
138
|
+
if (junction.edge === 1 /* N */) otherV = beyond;
|
|
139
|
+
else if (junction.edge === 7 /* S */) otherV = 1 - beyond;
|
|
140
|
+
else if (junction.edge === 3 /* W */) otherU = beyond;
|
|
141
|
+
else otherU = 1 - beyond;
|
|
142
|
+
const otherCount = tileCount(other.lod);
|
|
143
|
+
return { west: otherU * otherCount - other.x, north: otherV * otherCount - other.y, size, turns: junction.turns };
|
|
144
|
+
}
|
|
145
|
+
var CUBE_TILE_TOPOLOGY = Object.freeze({ neighbor: cubeTileNeighbor, areaIn: cubeTileAreaIn });
|
|
146
|
+
|
|
147
|
+
export { CUBE_FACE_EDGES, CUBE_TILE_TOPOLOGY, cubeCornerTileCount, cubeTileAreaIn, cubeTileGeometricError, cubeTileNeighbor, cubeTileNeighbors };
|
|
148
|
+
//# sourceMappingURL=chunk-TGOB5HT5.js.map
|
|
149
|
+
//# sourceMappingURL=chunk-TGOB5HT5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cube/cube-geometric-error.ts","../src/cube/cube-neighbors.ts"],"names":[],"mappings":";;;;;AAIA,IAAM,OAAA,GAAoD;AAAA,EACtD,CAAC,GAAG,CAAC,CAAA;AAAA,EACL,CAAC,GAAG,CAAC,CAAA;AAAA,EACL,CAAC,GAAG,CAAC,CAAA;AAAA,EACL,CAAC,GAAG,CAAC;AACT,CAAA;AAUO,SAAS,sBAAA,CAAuB,OAAA,EAAuB,OAAA,EAA2B,QAAA,EAA0B;AAC/G,EAAA,IAAI,EAAE,QAAA,GAAW,CAAA,CAAA,EAAI,MAAM,IAAI,WAAW,iCAAiC,CAAA;AAC3E,EAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,GAAA,CAAI,CAAC,CAAC,CAAA,EAAG,CAAC,CAAA,KAAM,OAAA,CAAQ,MAAM,iBAAA,CAAkB,OAAA,EAAS,CAAA,EAAG,CAAC,CAAC,CAAC,CAAA;AACtF,EAAA,IAAI,OAAA,GAAU,CAAA;AACd,EAAA,KAAA,IAAS,KAAA,GAAQ,CAAA,EAAG,KAAA,GAAQ,C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AAA,EAAQ,gBAAgB","file":"chunk-TGOB5HT5.js","sourcesContent":["import type { ITileAddress } from \"../addressing/tile-address\";\nimport type { ReferenceSurface } from \"../surface/reference-surface\";\nimport { cubeTileDirection } from \"./cube-mapping\";\n\nconst CORNERS: ReadonlyArray<readonly [number, number]> = [\n [0, 0],\n [1, 0],\n [1, 1],\n [0, 1],\n];\n\n/**\n * Geometric error of a terrain tile of the cube index: the longest of its four edges, measured as the chord between\n * its corners on the reference surface, divided by the cells of a tile side. It follows the distortion of the cube\n * instead of assuming one size per level.\n *\n * @param tileSize - Cells per tile side.\n * @throws RangeError When the address is invalid or the tile size is not positive.\n */\nexport function cubeTileGeometricError(address: ITileAddress, surface: ReferenceSurface, tileSize: number): number {\n if (!(tileSize > 0)) throw new RangeError(\"The tile size must be positive.\");\n const points = CORNERS.map(([s, t]) => surface.point(cubeTileDirection(address, s, t)));\n let longest = 0;\n for (let index = 0; index < 4; index++) {\n const a = points[index]!;\n const b = points[(index + 1) % 4]!;\n longest = Math.max(longest, Math.hypot(a.x - b.x, a.y - b.y, a.z - b.z));\n }\n return longest / tileSize;\n}\n","import { assertValidTileAddress, tileCount, type ITileAddress } from \"../addressing/tile-address\";\nimport { TILE_CORNER_EDGES, TILE_EDGE_NEIGHBORS, TileNeighbor, tileNeighborOffset, type TileCornerNeighbor, type TileEdgeNeighbor } from \"../addressing/tile-neighbors\";\nimport { oppositeTileEdge } from \"../addressing/tile-edge-rotation\";\nimport type { ITileAreaAcross, ITileTopology } from \"../addressing/tile-topology\";\nimport { CubeFace } from \"./cube-face\";\n\n/** Edge of the neighbouring face met by an edge of a face. */\nexport interface ICubeEdgeJunction {\n /** Neighbouring face. */\n readonly face: CubeFace;\n /** Edge of the neighbouring face. */\n readonly edge: TileEdgeNeighbor;\n /** `true` when the coordinate along the edge runs the other way on the neighbouring face. */\n readonly reversed: boolean;\n /**\n * Quarter turns from the frame of the face to the frame of its neighbour: a direction `d` of the face is\n * `turnTileEdge(d, turns)` on the neighbour. Equatorial faces join with 0.\n */\n readonly turns: number;\n}\n\nconst { N, E, S, W } = TileNeighbor;\n/** Neighbouring face, its edge and the reversal, for the edges N, E, S, W of each face; see `docs/celestial-tiling.md`. */\nconst EDGE_TABLE: ReadonlyArray<\n readonly [\n readonly [CubeFace, TileEdgeNeighbor, boolean],\n readonly [CubeFace, TileEdgeNeighbor, boolean],\n readonly [CubeFace, TileEdgeNeighbor, boolean],\n readonly [CubeFace, TileEdgeNeighbor, boolean],\n ]\n> = [\n [\n [4, S, false],\n [1, W, false],\n [5, N, false],\n [3, E, false],\n ],\n [\n [4, E, true],\n [2, W, false],\n [5, E, false],\n [0, E, false],\n ],\n [\n [4, N, true],\n [3, W, false],\n [5, S, true],\n [1, E, false],\n ],\n [\n [4, W, false],\n [0, W, false],\n [5, W, true],\n [2, E, false],\n ],\n [\n [2, N, true],\n [1, N, true],\n [0, N, false],\n [3, N, false],\n ],\n [\n [0, S, false],\n [1, S, false],\n [2, S, true],\n [3, S, true],\n ],\n];\n\n/**\n * Junctions of the faces of the cube index, indexed by face then edge. The neighbour's edge is the opposite of the\n * face's edge turned by `turns`.\n */\nexport const CUBE_FACE_EDGES: ReadonlyArray<Readonly<Record<TileEdgeNeighbor, ICubeEdgeJunction>>> = Object.freeze(\n EDGE_TABLE.map((row) => {\n const junctions = {} as Record<TileEdgeNeighbor, ICubeEdgeJunction>;\n row.forEach(([face, edge, reversed], index) => {\n const own = TILE_EDGE_NEIGHBORS[index]!;\n const turns = (TILE_EDGE_NEIGHBORS.indexOf(oppositeTileEdge(edge)) - index + 4) % 4;\n junctions[own] = Object.freeze({ face, edge, reversed, turns });\n });\n return Object.freeze(junctions);\n })\n);\n\n/** Neighbour of a tile of the cube index, with the turns from the frame of the tile to the frame of the neighbour. */\nexport interface ICubeTileNeighbor {\n readonly address: ITileAddress;\n /** Quarter turns, as {@link ICubeEdgeJunction.turns}; 0 on the same face. */\n readonly turns: number;\n}\n\n/** Tile across an edge of the face at position `k` along that edge, at a level of `count` tiles per axis. */\nfunction acrossFaceEdge(face: CubeFace, edge: TileEdgeNeighbor, k: number, lod: number, count: number): ICubeTileNeighbor {\n const junction = CUBE_FACE_EDGES[face]![edge];\n const along = junction.reversed ? count - 1 - k : k;\n let x = along;\n let y = along;\n if (junction.edge === TileNeighbor.N) y = 0;\n else if (junction.edge === TileNeighbor.S) y = count - 1;\n else if (junction.edge === TileNeighbor.W) x = 0;\n else x = count - 1;\n return { address: { face: junction.face, lod, x, y }, turns: junction.turns };\n}\n\n/**\n * Neighbour of a tile of the cube index at the same level, across the faces when needed.\n *\n * A corner neighbour is reached by crossing one of its two edges. At the 8 vertices of the cube only 3 tiles meet:\n * the corner neighbour there does not exist and the result is `undefined`.\n *\n * @param address - Tile of the cube index; a missing face means face 0.\n * @param neighbor - Position around the tile; `C` returns the tile itself.\n * @throws RangeError When the address is invalid.\n */\nexport function cubeTileNeighbor(address: ITileAddress, neighbor: TileNeighbor): ICubeTileNeighbor | undefined {\n assertValidTileAddress(address);\n const face: CubeFace = address.face ?? CubeFace.PositiveX;\n const { lod } = address;\n const count = tileCount(lod);\n const [dx, dy] = tileNeighborOffset(neighbor);\n const x = address.x + dx;\n const y = address.y + dy;\n const outX = x < 0 || x >= count;\n const outY = y < 0 || y >= count;\n if (outX && outY) return undefined;\n if (!outX && !outY) return { address: { face, lod, x, y }, turns: 0 };\n if (outY) return acrossFaceEdge(face, y < 0 ? TileNeighbor.N : TileNeighbor.S, x, lod, count);\n return acrossFaceEdge(face, x < 0 ? TileNeighbor.W : TileNeighbor.E, y, lod, count);\n}\n\n/** Returns the nine neighbours in {@link TileNeighbor} order, the tile itself at `TileNeighbor.C`. */\nexport function cubeTileNeighbors(address: ITileAddress): Array<ICubeTileNeighbor | undefined> {\n return Array.from({ length: 9 }, (_, neighbor) => cubeTileNeighbor(address, neighbor));\n}\n\n/**\n * Number of tiles meeting at a corner of a tile: 3 at the vertices of the cube, 4 elsewhere.\n *\n * @throws RangeError When the address is invalid.\n */\nexport function cubeCornerTileCount(address: ITileAddress, corner: TileCornerNeighbor): 3 | 4 {\n assertValidTileAddress(address);\n const count = tileCount(address.lod);\n const [vertical, horizontal] = TILE_CORNER_EDGES[corner];\n const onRow = vertical === TileNeighbor.N ? address.y === 0 : address.y === count - 1;\n const onColumn = horizontal === TileNeighbor.W ? address.x === 0 : address.x === count - 1;\n return onRow && onColumn ? 3 : 4;\n}\n\n/** Corner of a tile that `turnedTileCoordinates` sends to `(0, 0)`, per number of quarter turns. */\nconst TURNED_ORIGIN: ReadonlyArray<readonly [number, number]> = [\n [0, 0],\n [0, 1],\n [1, 1],\n [1, 0],\n];\n\n/**\n * Area of a tile of the cube index in another tile, across at most one face edge; see {@link ITileAreaAcross}.\n *\n * The neighbouring face is unfolded around the edge the two faces share, a rigid motion, so the points of that edge\n * land exactly on the same directions.\n *\n * @throws RangeError When an address is invalid or the tiles lie on opposite faces.\n */\nexport function cubeTileAreaIn(address: ITileAddress, other: ITileAddress): ITileAreaAcross {\n assertValidTileAddress(address);\n assertValidTileAddress(other);\n const face: CubeFace = address.face ?? 0;\n const otherFace: CubeFace = other.face ?? 0;\n const scale = 2 ** (address.lod - other.lod);\n const size = 1 / scale;\n if (face === otherFace) return { west: address.x / scale - other.x, north: address.y / scale - other.y, size, turns: 0 };\n\n const edge = TILE_EDGE_NEIGHBORS.find((candidate) => CUBE_FACE_EDGES[face]![candidate].face === otherFace);\n if (edge === undefined) throw new RangeError(`Faces ${face} and ${otherFace} are opposite: their tiles cannot touch.`);\n const junction = CUBE_FACE_EDGES[face]![edge];\n // The corner of the tile at the origin of the turned frame.\n const [cornerU, cornerV] = TURNED_ORIGIN[junction.turns]!;\n const count = tileCount(address.lod);\n const u = (address.x + cornerU) / count;\n const v = (address.y + cornerV) / count;\n const along = edge === TileNeighbor.N || edge === TileNeighbor.S ? u : v;\n const beyond = edge === TileNeighbor.N ? -v : edge === TileNeighbor.S ? v - 1 : edge === TileNeighbor.W ? -u : u - 1;\n const alongOther = junction.reversed ? 1 - along : along;\n let otherU = alongOther;\n let otherV = alongOther;\n if (junction.edge === TileNeighbor.N) otherV = beyond;\n else if (junction.edge === TileNeighbor.S) otherV = 1 - beyond;\n else if (junction.edge === TileNeighbor.W) otherU = beyond;\n else otherU = 1 - beyond;\n const otherCount = tileCount(other.lod);\n return { west: otherU * otherCount - other.x, north: otherV * otherCount - other.y, size, turns: junction.turns };\n}\n\n/** Topology of the cube index: neighbours across faces, turned, and corners of 3 tiles. */\nexport const CUBE_TILE_TOPOLOGY: ITileTopology = Object.freeze({ neighbor: cubeTileNeighbor, areaIn: cubeTileAreaIn });\n"]}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { assertValidTileAddress, tileAddressToQuadkey, tileCount, tileNeighborAddress, TileNeighbor } from './chunk-Y66PNDG2.js';
|
|
2
|
+
|
|
3
|
+
// src/addressing/metrics.ts
|
|
4
|
+
var CellCoordinateReference = /* @__PURE__ */ ((CellCoordinateReference2) => {
|
|
5
|
+
CellCoordinateReference2[CellCoordinateReference2["Center"] = 0] = "Center";
|
|
6
|
+
CellCoordinateReference2[CellCoordinateReference2["NorthWest"] = 1] = "NorthWest";
|
|
7
|
+
CellCoordinateReference2[CellCoordinateReference2["NorthEast"] = 2] = "NorthEast";
|
|
8
|
+
CellCoordinateReference2[CellCoordinateReference2["SouthWest"] = 3] = "SouthWest";
|
|
9
|
+
CellCoordinateReference2[CellCoordinateReference2["SouthEast"] = 4] = "SouthEast";
|
|
10
|
+
return CellCoordinateReference2;
|
|
11
|
+
})(CellCoordinateReference || {});
|
|
12
|
+
|
|
13
|
+
// src/addressing/raster-registration.ts
|
|
14
|
+
function assertRasterRegistration(registration) {
|
|
15
|
+
if (registration !== "area" && registration !== "point") {
|
|
16
|
+
throw new TypeError(`A source declares its registration, "area" or "point", where its data is imported: got ${String(registration)}.`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/addressing/tile.ts
|
|
21
|
+
function tileGeoBounds(address, metrics) {
|
|
22
|
+
const northWest = metrics.getTileXYToLatLon(address.x, address.y, address.lod);
|
|
23
|
+
const southEast = metrics.getTileXYToLatLon(address.x + 1, address.y + 1, address.lod);
|
|
24
|
+
return { west: northWest.longitude, south: southEast.latitude, east: southEast.longitude, north: northWest.latitude };
|
|
25
|
+
}
|
|
26
|
+
function tilePixelBounds(address, metrics) {
|
|
27
|
+
const origin = metrics.getTileXYToPointXY(address.x, address.y);
|
|
28
|
+
return { x: origin.x, y: origin.y, width: metrics.tileSize, height: metrics.tileSize };
|
|
29
|
+
}
|
|
30
|
+
var Tile = class {
|
|
31
|
+
address;
|
|
32
|
+
quadkey;
|
|
33
|
+
namespace;
|
|
34
|
+
key;
|
|
35
|
+
geoBounds;
|
|
36
|
+
pixelBounds;
|
|
37
|
+
content;
|
|
38
|
+
/**
|
|
39
|
+
* @param address - XYZ address.
|
|
40
|
+
* @param metrics - Metrics of the pyramid, used to derive the bounds.
|
|
41
|
+
* @param content - Optional content.
|
|
42
|
+
* @param namespace - Pyramid identifier used in {@link key}.
|
|
43
|
+
* @throws RangeError When the address lies outside its pyramid level.
|
|
44
|
+
*/
|
|
45
|
+
constructor(address, metrics, content, namespace = "") {
|
|
46
|
+
assertValidTileAddress(address);
|
|
47
|
+
this.address = { lod: address.lod, x: address.x, y: address.y };
|
|
48
|
+
this.quadkey = tileAddressToQuadkey(this.address);
|
|
49
|
+
this.namespace = namespace;
|
|
50
|
+
this.key = `${namespace}:${this.quadkey}`;
|
|
51
|
+
this.geoBounds = tileGeoBounds(this.address, metrics);
|
|
52
|
+
this.pixelBounds = tilePixelBounds(this.address, metrics);
|
|
53
|
+
this.content = content;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/addressing/tile-topology.ts
|
|
58
|
+
function turnedTileCoordinates(u, v, turns) {
|
|
59
|
+
switch ((turns % 4 + 4) % 4) {
|
|
60
|
+
case 1:
|
|
61
|
+
return [1 - v, u];
|
|
62
|
+
case 2:
|
|
63
|
+
return [1 - u, 1 - v];
|
|
64
|
+
case 3:
|
|
65
|
+
return [v, 1 - u];
|
|
66
|
+
default:
|
|
67
|
+
return [u, v];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function flatTileTopology(options = {}) {
|
|
71
|
+
const wrapX = options.wrapX ?? false;
|
|
72
|
+
return {
|
|
73
|
+
neighbor: (address, position) => {
|
|
74
|
+
const neighbor = tileNeighborAddress(address, position, { wrapX });
|
|
75
|
+
return neighbor && { address: neighbor, turns: 0 };
|
|
76
|
+
},
|
|
77
|
+
areaIn: (address, other) => {
|
|
78
|
+
const scale = 2 ** (address.lod - other.lod);
|
|
79
|
+
const size = 1 / scale;
|
|
80
|
+
let west = address.x / scale - other.x;
|
|
81
|
+
if (wrapX) {
|
|
82
|
+
const count = tileCount(other.lod);
|
|
83
|
+
if (west > 1) west -= count;
|
|
84
|
+
else if (west + size < 0) west += count;
|
|
85
|
+
}
|
|
86
|
+
return { west, north: address.y / scale - other.y, size, turns: 0 };
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/addressing/tile-edge-rotation.ts
|
|
92
|
+
var EDGE_ORDER = [1 /* N */, 5 /* E */, 7 /* S */, 3 /* W */];
|
|
93
|
+
function turnTileEdge(edge, turns) {
|
|
94
|
+
const index = EDGE_ORDER.indexOf(edge);
|
|
95
|
+
if (index < 0) throw new RangeError(`${TileNeighbor[edge] ?? edge} is not an edge.`);
|
|
96
|
+
return EDGE_ORDER[((index + turns) % 4 + 4) % 4];
|
|
97
|
+
}
|
|
98
|
+
function oppositeTileEdge(edge) {
|
|
99
|
+
return turnTileEdge(edge, 2);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { CellCoordinateReference, Tile, assertRasterRegistration, flatTileTopology, oppositeTileEdge, tileGeoBounds, tilePixelBounds, turnTileEdge, turnedTileCoordinates };
|
|
103
|
+
//# sourceMappingURL=chunk-X6ZJ2PDY.js.map
|
|
104
|
+
//# sourceMappingURL=chunk-X6ZJ2PDY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/addressing/metrics.ts","../src/addressing/raster-registration.ts","../src/addressing/tile.ts","../src/addressing/tile-topology.ts","../src/addressing/tile-edge-rotation.ts"],"names":["CellCoordinateReference"],"mappings":";;;AAAO,IAAK,uBAAA,qBAAAA,wBAAAA,KAAL;AACH,EAAAA,wBAAAA,CAAAA,wBAAAA,CAAA,YAAS,CAAA,CAAA,GAAT,QAAA;AACA,EAAAA,wBAAAA,CAAAA,wBAAAA,CAAA,eAAY,CAAA,CAAA,GAAZ,WAAA;AACA,EAAAA,wBAAAA,CAAAA,wBAAAA,CAAA,eAAY,CAAA,CAAA,GAAZ,WAAA;AACA,EAAAA,wBAAAA,CAAAA,wBAAAA,CAAA,eAAY,CAAA,CAAA,GAAZ,WAAA;AACA,EAAAA,wBAAAA,CAAAA,wBAAAA,CAAA,eAAY,CAAA,CAAA,GAAZ,WAAA;AALQ,EAAA,OAAAA,wBAAAA;AAAA,CAAA,EAAA,uBAAA,IAAA,EAAA;;;ACiBL,SAAS,yBAAyB,YAAA,EAAmE;AACxG,EAAA,IAAI,YAAA,KAAiB,MAAA,IAAU,YAAA,KAAiB,OAAA,EAAS;AACrD,IAAA,MAAM,IAAI,SAAA,CAAU,CAAA,uFAAA,EAA0F,MAAA,CAAO,YAAY,CAAC,CAAA,CAAA,CAAG,CAAA;AAAA,EACzI;AACJ;;;ACYO,SAAS,aAAA,CAAc,SAAuB,OAAA,EAAmC;AACpF,EAAA,MAAM,SAAA,GAAY,QAAQ,iBAAA,CAAkB,OAAA,CAAQ,GAAG,OAAA,CAAQ,CAAA,EAAG,QAAQ,GAAG,CAAA;AAC7E,EAAA,MAAM,SAAA,GAAY,OAAA,CAAQ,iBAAA,CAAkB,OAAA,CAAQ,CAAA,GAAI,GAAG,OAAA,CAAQ,CAAA,GAAI,CAAA,EAAG,OAAA,CAAQ,GAA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AI,KAAA,GAAQ,KAAA,CAAM,CAAA;AACrC,MAAA,IAAI,KAAA,EAAO;AAEP,QAAA,MAAM,KAAA,GAAQ,SAAA,CAAU,KAAA,CAAM,GAAG,CAAA;AACjC,QAAA,IAAI,IAAA,GAAO,GAAG,IAAA,IAAQ,KAAA;AAAA,aAAA,IACb,IAAA,GAAO,IAAA,GAAO,CAAA,EAAG,IAAA,IAAQ,KAAA;AAAA,MACtC;AACA,MAAA,OAAO,EAAE,IAAA,EAAM,KAAA,EAAO,OAAA,CAAQ,CAAA,GAAI,QAAQ,KAAA,CAAM,CAAA,EAAG,IAAA,EAAM,KAAA,EAAO,CAAA,EAAE;AAAA,IACtE;AAAA,GACJ;AACJ;;;ACpFA,IAAM,aAA0C,CAAA,CAAA,UAAA,CAAA,UAAA,CAAA,UAAA,CAAA,SAA+D;AAExG,SAAS,YAAA,CAAa,MAAwB,KAAA,EAAiC;AAClF,EAAA,MAAM,KAAA,GAAQ,UAAA,CAAW,OAAA,CAAQ,IAAI,CAAA;AACrC,EAAA,IAAI,KAAA,GAAQ,CAAA,EAAG,MAAM,IAAI,UAAA,CAAW,GAAG,YAAA,CAAa,IAAI,CAAA,IAAK,IAAI,CAAA,gBAAA,CAAkB,CAAA;AACnF,EAAA,OAAO,UAAA,CAAA,CAAA,CAAc,KAAA,GAAQ,KAAA,IAAS,CAAA,GAAK,KAAK,CAAC,CAAA;AACrD;AAGO,SAAS,iBAAiB,IAAA,EAA0C;AACvE,EAAA,OAAO,YAAA,CAAa,MAAM,CAAC,CAAA;AAC/B","file":"chunk-X6ZJ2PDY.js","sourcesContent":["export enum CellCoordinateReference {\n Center = 0,\n NorthWest = 1,\n NorthEast = 2,\n SouthWest = 3,\n SouthEast = 4,\n}\n\nexport interface ICartesian2 {\n x: number;\n y: number;\n}\n\nexport interface IGeographic2 {\n latitude: number;\n longitude: number;\n}\n\n/**\n * Describes the addressing, resolution and valid LOD range of a tile source.\n *\n * This is the renderer-neutral counterpart of SpaceXR `ITileMetrics`. Angles\n * are expressed in degrees and sizes in pixels or metres as documented by\n * each method.\n */\nexport interface ITileMetrics {\n readonly minLOD: number;\n readonly maxLOD: number;\n readonly minLatitude: number;\n readonly maxLatitude: number;\n readonly minLongitude: number;\n readonly maxLongitude: number;\n readonly tileSize: number;\n readonly cellSize: number;\n readonly cellCoordinateReference: CellCoordinateReference;\n readonly overlap: number;\n\n mapSize(levelOfDetail: number): number;\n mapScale(latitudeDegrees: number, levelOfDetail: number, pixelsPerUnit: number): number;\n groundResolution(latitudeDegrees: number, levelOfDetail: number): number;\n\n getLatLonToTileXY(latitudeDegrees: number, longitudeDegrees: number, levelOfDetail: number): ICartesian2;\n getTileXYToLatLon(x: number, y: number, levelOfDetail: number): IGeographic2;\n getLatLonToPointXY(latitudeDegrees: number, longitudeDegrees: number, levelOfDetail: number): ICartesian2;\n getPointXYToLatLon(x: number, y: number, levelOfDetail: number): IGeographic2;\n getTileXYToPointXY(x: number, y: number): ICartesian2;\n getPointXYToTileXY(x: number, y: number): ICartesian2;\n}\n","/**\n * Location of the samples of a raster over the tile extent. It belongs to the data, so every source declares it where\n * its data is imported: there is no default.\n *\n * - `area`: each sample covers one pixel, so sample `i` is centred at `(i + 0.5) / size`. This is how web tiles are\n * published, elevation and imagery alike; two neighbouring tiles never share a sample.\n * - `point`: sample `i` lies at `i / (size - 1)`, so the first and last samples lie on the tile edges, as in the tiles of\n * a multi-root pyramid and in stitched rasters.\n */\nexport type RasterRegistration = \"area\" | \"point\";\n\n/**\n * Checks the registration a source declares, for callers the compiler does not reach: a raster read with the wrong one\n * moves half a pixel without any other sign.\n *\n * @throws TypeError When the registration is missing or unknown.\n */\nexport function assertRasterRegistration(registration: unknown): asserts registration is RasterRegistration {\n if (registration !== \"area\" && registration !== \"point\") {\n throw new TypeError(`A source declares its registration, \"area\" or \"point\", where its data is imported: got ${String(registration)}.`);\n }\n}\n","import type { ITileMetrics } from \"./metrics\";\nimport { assertValidTileAddress, tileAddressToQuadkey, type ITileAddress } from \"./tile-address\";\n\n/** Geographic extent in degrees. `west` may be greater than `east` only for extents crossing the antimeridian. */\nexport interface IGeoBounds {\n west: number;\n south: number;\n east: number;\n north: number;\n}\n\n/** Extent in map pixels at the tile level of detail, from the north-west corner of the map. */\nexport interface IPixelBounds {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/** Tile of a pyramid with its location and optional content. */\nexport interface ITile<T> {\n readonly address: ITileAddress;\n readonly quadkey: string;\n /** Identifies the pyramid, for example a source id. Empty by default. */\n readonly namespace: string;\n /** Unique key across pyramids: `namespace:quadkey`. */\n readonly key: string;\n readonly geoBounds: IGeoBounds;\n readonly pixelBounds: IPixelBounds;\n content: T | undefined;\n}\n\n/** Returns the geographic extent of a tile. */\nexport function tileGeoBounds(address: ITileAddress, metrics: ITileMetrics): IGeoBounds {\n const northWest = metrics.getTileXYToLatLon(address.x, address.y, address.lod);\n const southEast = metrics.getTileXYToLatLon(address.x + 1, address.y + 1, address.lod);\n return { west: northWest.longitude, south: southEast.latitude, east: southEast.longitude, north: northWest.latitude };\n}\n\n/** Returns the extent of a tile in map pixels. */\nexport function tilePixelBounds(address: ITileAddress, metrics: ITileMetrics): IPixelBounds {\n const origin = metrics.getTileXYToPointXY(address.x, address.y);\n return { x: origin.x, y: origin.y, width: metrics.tileSize, height: metrics.tileSize };\n}\n\n/** Immutable location of a tile with mutable content. */\nexport class Tile<T> implements ITile<T> {\n public readonly address: ITileAddress;\n public readonly quadkey: string;\n public readonly namespace: string;\n public readonly key: string;\n public readonly geoBounds: IGeoBounds;\n public readonly pixelBounds: IPixelBounds;\n public content: T | undefined;\n\n /**\n * @param address - XYZ address.\n * @param metrics - Metrics of the pyramid, used to derive the bounds.\n * @param content - Optional content.\n * @param namespace - Pyramid identifier used in {@link key}.\n * @throws RangeError When the address lies outside its pyramid level.\n */\n public constructor(address: ITileAddress, metrics: ITileMetrics, content?: T, namespace = \"\") {\n assertValidTileAddress(address);\n this.address = { lod: address.lod, x: address.x, y: address.y };\n this.quadkey = tileAddressToQuadkey(this.address);\n this.namespace = namespace;\n this.key = `${namespace}:${this.quadkey}`;\n this.geoBounds = tileGeoBounds(this.address, metrics);\n this.pixelBounds = tilePixelBounds(this.address, metrics);\n this.content = content;\n }\n}\n","import { tileCount, type ITileAddress } from \"./tile-address\";\nimport { TileNeighbor, tileNeighborAddress } from \"./tile-neighbors\";\n\n/** Neighbour of a tile, with the quarter turns from the frame of the tile to the frame of the neighbour. */\nexport interface ITileTopologyNeighbor {\n readonly address: ITileAddress;\n /** 0 when both tiles share a frame; within the pyramid root, 1 to 3 across some face edges. */\n readonly turns: number;\n}\n\n/**\n * Area of a tile in another tile, in coordinates of the other tile. A point `(u, v)` of the tile lies at\n * `(west + a * size, north + b * size)`, with `(a, b) = turnedTileCoordinates(u, v, turns)`. The area may lie outside\n * the other tile: only the points the two tiles share are inside it.\n */\nexport interface ITileAreaAcross {\n readonly west: number;\n readonly north: number;\n readonly size: number;\n /** Quarter turns from the frame of the tile to the frame of the other tile. */\n readonly turns: number;\n}\n\n/** How the tiles of a pyramid connect: the part of a tiling scheme that neighbours and junctions need. */\nexport interface ITileTopology {\n /**\n * Neighbour at the same level, or `undefined` beyond the pyramid or at a corner where only 3 tiles meet.\n *\n * @throws RangeError When the address is invalid.\n */\n neighbor(address: ITileAddress, position: TileNeighbor): ITileTopologyNeighbor | undefined;\n\n /**\n * Area of a tile in another tile that contains or touches it, for reading the data of a neighbour along a shared\n * edge or corner.\n *\n * @throws RangeError When the two tiles cannot touch.\n */\n areaIn(address: ITileAddress, other: ITileAddress): ITileAreaAcross;\n}\n\n/**\n * Coordinates of a point of a tile in a frame turned by quarter turns about the centre of the tile. One turn sends the\n * direction `N` to `E`, so `u`, which grows toward `E`, grows toward `S` in the turned frame.\n */\nexport function turnedTileCoordinates(u: number, v: number, turns: number): [number, number] {\n switch (((turns % 4) + 4) % 4) {\n case 1:\n return [1 - v, u];\n case 2:\n return [1 - u, 1 - v];\n case 3:\n return [v, 1 - u];\n default:\n return [u, v];\n }\n}\n\n/** Options of {@link flatTileTopology}. */\nexport interface IFlatTileTopologyOptions {\n /** Wraps columns around the antimeridian, for pyramids covering every longitude. Defaults to false. */\n wrapX?: boolean;\n}\n\n/** Topology of a pyramid with one root, such as Web Mercator: neighbours never turn. */\nexport function flatTileTopology(options: IFlatTileTopologyOptions = {}): ITileTopology {\n const wrapX = options.wrapX ?? false;\n return {\n neighbor: (address, position) => {\n const neighbor = tileNeighborAddress(address, position, { wrapX });\n return neighbor && { address: neighbor, turns: 0 };\n },\n areaIn: (address, other) => {\n const scale = 2 ** (address.lod - other.lod);\n const size = 1 / scale;\n let west = address.x / scale - other.x;\n if (wrapX) {\n // Take the side of the antimeridian on which the tiles touch.\n const count = tileCount(other.lod);\n if (west > 1) west -= count;\n else if (west + size < 0) west += count;\n }\n return { west, north: address.y / scale - other.y, size, turns: 0 };\n },\n };\n}\n","import { TileNeighbor, type TileEdgeNeighbor } from \"./tile-neighbors\";\nconst EDGE_ORDER: readonly TileEdgeNeighbor[] = [TileNeighbor.N, TileNeighbor.E, TileNeighbor.S, TileNeighbor.W];\n/** Rotate a tile edge in quarter turns within its local frame. */\nexport function turnTileEdge(edge: TileEdgeNeighbor, turns: number): TileEdgeNeighbor {\n const index = EDGE_ORDER.indexOf(edge);\n if (index < 0) throw new RangeError(`${TileNeighbor[edge] ?? edge} is not an edge.`);\n return EDGE_ORDER[(((index + turns) % 4) + 4) % 4]!;\n}\n\n/** Edge on the other side of a tile. */\nexport function oppositeTileEdge(edge: TileEdgeNeighbor): TileEdgeNeighbor {\n return turnTileEdge(edge, 2);\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/surface/directions.ts
|
|
2
|
+
var DEGREES = 180 / Math.PI;
|
|
3
|
+
function planetocentricDirection(latitudeDegrees, longitudeDegrees, target = { x: 0, y: 0, z: 0 }) {
|
|
4
|
+
const latitude = latitudeDegrees / DEGREES;
|
|
5
|
+
const longitude = longitudeDegrees / DEGREES;
|
|
6
|
+
const cosLatitude = Math.cos(latitude);
|
|
7
|
+
target.x = cosLatitude * Math.cos(longitude);
|
|
8
|
+
target.y = cosLatitude * Math.sin(longitude);
|
|
9
|
+
target.z = Math.sin(latitude);
|
|
10
|
+
return target;
|
|
11
|
+
}
|
|
12
|
+
function directionToPlanetocentric(direction) {
|
|
13
|
+
const { x, y, z } = direction;
|
|
14
|
+
const horizontal = Math.hypot(x, y);
|
|
15
|
+
if (!(horizontal + Math.abs(z) > 0) || !Number.isFinite(horizontal + z)) throw new RangeError("A direction must be finite and non-zero.");
|
|
16
|
+
const longitude = Math.atan2(y, x) * DEGREES;
|
|
17
|
+
return { latitude: Math.atan2(z, horizontal) * DEGREES, longitude: longitude === -180 ? 180 : longitude };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { directionToPlanetocentric, planetocentricDirection };
|
|
21
|
+
//# sourceMappingURL=chunk-XTY4HCPY.js.map
|
|
22
|
+
//# sourceMappingURL=chunk-XTY4HCPY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/surface/directions.ts"],"names":[],"mappings":";AAEA,IAAM,OAAA,GAAU,MAAM,IAAA,CAAK,EAAA;AAEpB,SAAS,uBAAA,CAAwB,eAAA,EAAyB,gBAAA,EAA0B,MAAA,GAAsB,EAAE,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAE,EAAgB;AAChJ,EAAA,MAAM,WAAW,eAAA,GAAkB,OAAA;AACnC,EAAA,MAAM,YAAY,gBAAA,GAAmB,OAAA;AACrC,EAAA,MAAM,WAAA,GAAc,IAAA,CAAK,GAAA,CAAI,QAAQ,CAAA;AACrC,EAAA,MAAA,CAAO,CAAA,GAAI,WAAA,GAAc,IAAA,CAAK,GAAA,CAAI,SAAS,CAAA;AAC3C,EAAA,MAAA,CAAO,CAAA,GAAI,WAAA,GAAc,IAAA,CAAK,GAAA,CAAI,SAAS,CAAA;AAC3C,EAAA,MAAA,CAAO,CAAA,GAAI,IAAA,CAAK,GAAA,CAAI,QAAQ,CAAA;AAC5B,EAAA,OAAO,MAAA;AACX;AAQO,SAAS,0BAA0B,SAAA,EAAgD;AACtF,EAAA,MAAM,EAAE,CAAA,EAAG,CAAA,EAAG,CAAA,EAAE,GAAI,SAAA;AACpB,EAAA,MAAM,UAAA,GAAa,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,CAAC,CAAA;AAClC,EAAA,IAAI,EAAE,UAAA,GAAa,IAAA,CAAK,GAAA,CAAI,CAAC,IAAI,CAAA,CAAA,IAAM,CAAC,MAAA,CAAO,QAAA,CAAS,aAAa,CAAC,CAAA,EAAG,MAAM,IAAI,WAAW,0CAA0C,CAAA;AACxI,EAAA,MAAM,SAAA,GAAY,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,CAAC,CAAA,GAAI,OAAA;AACrC,EAAA,OAAO,EAAE,QAAA,EAAU,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,UAAU,CAAA,GAAI,OAAA,EAAS,SAAA,EAAW,SAAA,KAAc,IAAA,GAAO,GAAA,GAAM,SAAA,EAAU;AAC5G","file":"chunk-XTY4HCPY.js","sourcesContent":["import type { ICartesian3 } from \"@spacexr/geodesy\";\nimport type { IGeographic2 } from \"../addressing/metrics\";\nconst DEGREES = 180 / Math.PI;\n/** Unit Cartesian direction from planetocentric angles in degrees. */\nexport function planetocentricDirection(latitudeDegrees: number, longitudeDegrees: number, target: ICartesian3 = { x: 0, y: 0, z: 0 }): ICartesian3 {\n const latitude = latitudeDegrees / DEGREES;\n const longitude = longitudeDegrees / DEGREES;\n const cosLatitude = Math.cos(latitude);\n target.x = cosLatitude * Math.cos(longitude);\n target.y = cosLatitude * Math.sin(longitude);\n target.z = Math.sin(latitude);\n return target;\n}\n\n/**\n * Planetocentric latitude and east-positive longitude of a direction, in degrees, longitudes in `(-180, 180]`. A\n * planetocentric latitude is not a geodetic one on a non-spherical body.\n *\n * @throws RangeError When the direction is zero or not finite.\n */\nexport function directionToPlanetocentric(direction: Readonly<ICartesian3>): IGeographic2 {\n const { x, y, z } = direction;\n const horizontal = Math.hypot(x, y);\n if (!(horizontal + Math.abs(z) > 0) || !Number.isFinite(horizontal + z)) throw new RangeError(\"A direction must be finite and non-zero.\");\n const longitude = Math.atan2(y, x) * DEGREES;\n return { latitude: Math.atan2(z, horizontal) * DEGREES, longitude: longitude === -180 ? 180 : longitude };\n}\n"]}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// src/addressing/tile-address.ts
|
|
2
|
+
var MAX_TILE_FACE = 5;
|
|
3
|
+
function withFace(source, lod, x, y) {
|
|
4
|
+
return source.face === void 0 ? { lod, x, y } : { face: source.face, lod, x, y };
|
|
5
|
+
}
|
|
6
|
+
function formatTileAddress(address) {
|
|
7
|
+
const path = `${address.lod}/${address.x}/${address.y}`;
|
|
8
|
+
return address.face === void 0 ? path : `${address.face}/${path}`;
|
|
9
|
+
}
|
|
10
|
+
function tileAddressKey(address) {
|
|
11
|
+
const path = `${address.lod}/${address.x}/${address.y}`;
|
|
12
|
+
return address.face ? `${address.face}/${path}` : path;
|
|
13
|
+
}
|
|
14
|
+
function tileCount(lod) {
|
|
15
|
+
return 2 ** lod;
|
|
16
|
+
}
|
|
17
|
+
function isValidTileAddress(address) {
|
|
18
|
+
const { face, lod, x, y } = address;
|
|
19
|
+
if (face !== void 0 && (!Number.isSafeInteger(face) || face < 0 || face > MAX_TILE_FACE)) return false;
|
|
20
|
+
if (!Number.isSafeInteger(lod) || lod < 0 || lod > 52) return false;
|
|
21
|
+
const count = tileCount(lod);
|
|
22
|
+
return Number.isSafeInteger(x) && Number.isSafeInteger(y) && x >= 0 && y >= 0 && x < count && y < count;
|
|
23
|
+
}
|
|
24
|
+
function assertValidTileAddress(address) {
|
|
25
|
+
if (!isValidTileAddress(address)) throw new RangeError(`Tile ${formatTileAddress(address)} lies outside its pyramid level.`);
|
|
26
|
+
}
|
|
27
|
+
function toTmsY(y, lod) {
|
|
28
|
+
return tileCount(lod) - 1 - y;
|
|
29
|
+
}
|
|
30
|
+
function tileAddressToQuadkey(address) {
|
|
31
|
+
assertValidTileAddress(address);
|
|
32
|
+
let quadkey = "";
|
|
33
|
+
for (let level = address.lod; level > 0; level--) {
|
|
34
|
+
const mask = 2 ** (level - 1);
|
|
35
|
+
const digit = Math.floor(address.x / mask) % 2 + 2 * (Math.floor(address.y / mask) % 2);
|
|
36
|
+
quadkey += String(digit);
|
|
37
|
+
}
|
|
38
|
+
return quadkey;
|
|
39
|
+
}
|
|
40
|
+
function quadkeyToTileAddress(quadkey) {
|
|
41
|
+
let x = 0;
|
|
42
|
+
let y = 0;
|
|
43
|
+
for (const character of quadkey) {
|
|
44
|
+
const digit = character.charCodeAt(0) - 48;
|
|
45
|
+
if (digit < 0 || digit > 3) throw new RangeError(`Invalid quadkey digit "${character}" in "${quadkey}".`);
|
|
46
|
+
x = x * 2 + digit % 2;
|
|
47
|
+
y = y * 2 + Math.floor(digit / 2);
|
|
48
|
+
}
|
|
49
|
+
return { lod: quadkey.length, x, y };
|
|
50
|
+
}
|
|
51
|
+
function parentTileAddress(address) {
|
|
52
|
+
if (address.lod === 0) return void 0;
|
|
53
|
+
return withFace(address, address.lod - 1, Math.floor(address.x / 2), Math.floor(address.y / 2));
|
|
54
|
+
}
|
|
55
|
+
function ancestorTileAddress(address, levels) {
|
|
56
|
+
const steps = Math.min(Math.max(0, Math.trunc(levels)), address.lod);
|
|
57
|
+
const scale = 2 ** steps;
|
|
58
|
+
return withFace(address, address.lod - steps, Math.floor(address.x / scale), Math.floor(address.y / scale));
|
|
59
|
+
}
|
|
60
|
+
function childTileAddresses(address) {
|
|
61
|
+
const lod = address.lod + 1;
|
|
62
|
+
const x = address.x * 2;
|
|
63
|
+
const y = address.y * 2;
|
|
64
|
+
return [withFace(address, lod, x, y), withFace(address, lod, x + 1, y), withFace(address, lod, x, y + 1), withFace(address, lod, x + 1, y + 1)];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/addressing/tile-neighbors.ts
|
|
68
|
+
var TileNeighbor = /* @__PURE__ */ ((TileNeighbor2) => {
|
|
69
|
+
TileNeighbor2[TileNeighbor2["NW"] = 0] = "NW";
|
|
70
|
+
TileNeighbor2[TileNeighbor2["N"] = 1] = "N";
|
|
71
|
+
TileNeighbor2[TileNeighbor2["NE"] = 2] = "NE";
|
|
72
|
+
TileNeighbor2[TileNeighbor2["W"] = 3] = "W";
|
|
73
|
+
TileNeighbor2[TileNeighbor2["C"] = 4] = "C";
|
|
74
|
+
TileNeighbor2[TileNeighbor2["E"] = 5] = "E";
|
|
75
|
+
TileNeighbor2[TileNeighbor2["SW"] = 6] = "SW";
|
|
76
|
+
TileNeighbor2[TileNeighbor2["S"] = 7] = "S";
|
|
77
|
+
TileNeighbor2[TileNeighbor2["SE"] = 8] = "SE";
|
|
78
|
+
return TileNeighbor2;
|
|
79
|
+
})(TileNeighbor || {});
|
|
80
|
+
var TILE_EDGE_NEIGHBORS = [1 /* N */, 5 /* E */, 7 /* S */, 3 /* W */];
|
|
81
|
+
var TILE_CORNER_NEIGHBORS = [0 /* NW */, 2 /* NE */, 8 /* SE */, 6 /* SW */];
|
|
82
|
+
var TILE_CORNER_EDGES = {
|
|
83
|
+
[0 /* NW */]: [1 /* N */, 3 /* W */],
|
|
84
|
+
[2 /* NE */]: [1 /* N */, 5 /* E */],
|
|
85
|
+
[8 /* SE */]: [7 /* S */, 5 /* E */],
|
|
86
|
+
[6 /* SW */]: [7 /* S */, 3 /* W */]
|
|
87
|
+
};
|
|
88
|
+
function tileNeighborOffset(neighbor) {
|
|
89
|
+
return [neighbor % 3 - 1, Math.floor(neighbor / 3) - 1];
|
|
90
|
+
}
|
|
91
|
+
function tileNeighborAddress(address, neighbor, options = {}) {
|
|
92
|
+
const [dx, dy] = tileNeighborOffset(neighbor);
|
|
93
|
+
const count = tileCount(address.lod);
|
|
94
|
+
let x = address.x + dx;
|
|
95
|
+
const y = address.y + dy;
|
|
96
|
+
if (y < 0 || y >= count) return void 0;
|
|
97
|
+
if (options.wrapX) x = (x % count + count) % count;
|
|
98
|
+
else if (x < 0 || x >= count) return void 0;
|
|
99
|
+
return address.face === void 0 ? { lod: address.lod, x, y } : { face: address.face, lod: address.lod, x, y };
|
|
100
|
+
}
|
|
101
|
+
function tileNeighborAddresses(address, options = {}) {
|
|
102
|
+
return Array.from({ length: 9 }, (_, neighbor) => tileNeighborAddress(address, neighbor, options));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { MAX_TILE_FACE, TILE_CORNER_EDGES, TILE_CORNER_NEIGHBORS, TILE_EDGE_NEIGHBORS, TileNeighbor, ancestorTileAddress, assertValidTileAddress, childTileAddresses, formatTileAddress, isValidTileAddress, parentTileAddress, quadkeyToTileAddress, tileAddressKey, tileAddressToQuadkey, tileCount, tileNeighborAddress, tileNeighborAddresses, tileNeighborOffset, toTmsY };
|
|
106
|
+
//# sourceMappingURL=chunk-Y66PNDG2.js.map
|
|
107
|
+
//# sourceMappingURL=chunk-Y66PNDG2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/addressing/tile-address.ts","../src/addressing/tile-neighbors.ts"],"names":["TileNeighbor"],"mappings":";AAoBO,IAAM,aAAA,GAAgB;AAG7B,SAAS,QAAA,CAAS,MAAA,EAAsB,GAAA,EAAa,CAAA,EAAW,CAAA,EAAyB;AACrF,EAAA,OAAO,MAAA,CAAO,IAAA,KAAS,MAAA,GAAY,EAAE,KAAK,CAAA,EAAG,CAAA,EAAE,GAAI,EAAE,IAAA,EAAM,MAAA,CAAO,IAAA,EAAM,GAAA,EAAK,GAAG,CAAA,EAAE;AACtF;AAGO,SAAS,kBAAkB,OAAA,EAA+B;AAC7D,EAAA,MAAM,IAAA,GAAO,GAAG,OAAA,CAAQ,GAAG,IAAI,OAAA,CAAQ,CAAC,CAAA,CAAA,EAAI,OAAA,CAAQ,CAAC,CAAA,CAAA;AACrD,E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QAAA,KAAa,mBAAA,CAAoB,OAAA,EAAS,QAAA,EAAU,OAAO,CAAC,CAAA;AACrG","file":"chunk-Y66PNDG2.js","sourcesContent":["/**\n * Address of a tile in a quadtree pyramid, in the XYZ convention.\n *\n * `x` grows eastward and `y` grows southward from the north-west corner, as in\n * Slippy Map, Google and Bing tiles. Use {@link toTmsY} for TMS sources, whose\n * `y` grows northward.\n *\n * A pyramid with several roots, such as a multi-root pyramid of a celestial body, has one quadtree per root, selected by\n * `face`. Single-root pyramids, such as Web Mercator, omit it, which means face 0.\n */\nexport interface ITileAddress {\n /** Root of the address, from 0 to {@link MAX_TILE_FACE}; omitted for face 0 of single-root pyramids. */\n face?: number;\n /** Level of detail, also called zoom. Level 0 has a single tile. */\n lod: number;\n x: number;\n y: number;\n}\n\n/** Highest root of a tile address: the six faces of a multi-root pyramid are 0 to 5. */\nexport const MAX_TILE_FACE = 5;\n\n/** Copies the face of `source` onto a new address, leaving it out when `source` has none. */\nfunction withFace(source: ITileAddress, lod: number, x: number, y: number): ITileAddress {\n return source.face === undefined ? { lod, x, y } : { face: source.face, lod, x, y };\n}\n\n/** Text of an address for messages and keys: `lod/x/y`, or `face/lod/x/y` when it has a face. */\nexport function formatTileAddress(address: ITileAddress): string {\n const path = `${address.lod}/${address.x}/${address.y}`;\n return address.face === undefined ? path : `${address.face}/${path}`;\n}\n\n/**\n * Key of a tile within a pyramid: `lod/x/y`, prefixed by the face when it is not 0, so that an address without a face\n * and an address on face 0 are the same tile. Keys are ephemeral: they are not stable identifiers.\n */\nexport function tileAddressKey(address: ITileAddress): string {\n const path = `${address.lod}/${address.x}/${address.y}`;\n return address.face ? `${address.face}/${path}` : path;\n}\n\n/** Number of tiles along one axis at a level of detail. */\nexport function tileCount(lod: number): number {\n return 2 ** lod;\n}\n\n/** Returns `true` when the address lies inside its pyramid level. */\nexport function isValidTileAddress(address: ITileAddress): boolean {\n const { face, lod, x, y } = address;\n if (face !== undefined && (!Number.isSafeInteger(face) || face < 0 || face > MAX_TILE_FACE)) return false;\n if (!Number.isSafeInteger(lod) || lod < 0 || lod > 52) return false;\n const count = tileCount(lod);\n return Number.isSafeInteger(x) && Number.isSafeInteger(y) && x >= 0 && y >= 0 && x < count && y < count;\n}\n\n/**\n * Throws when the address lies outside its pyramid level.\n *\n * @throws RangeError When the address is invalid.\n */\nexport function assertValidTileAddress(address: ITileAddress): void {\n if (!isValidTileAddress(address)) throw new RangeError(`Tile ${formatTileAddress(address)} lies outside its pyramid level.`);\n}\n\n/**\n * Converts between XYZ and TMS row numbers. The conversion is its own inverse.\n *\n * @param y - Row number in one convention.\n * @param lod - Level of detail.\n * @returns Row number in the other convention.\n */\nexport function toTmsY(y: number, lod: number): number {\n return tileCount(lod) - 1 - y;\n}\n\n/**\n * Encodes an address as a Bing Maps quadkey.\n *\n * Each digit encodes one level, from the coarsest: `x` bit plus twice the `y` bit.\n * Level 0 has the empty quadkey.\n */\nexport function tileAddressToQuadkey(address: ITileAddress): string {\n assertValidTileAddress(address);\n let quadkey = \"\";\n for (let level = address.lod; level > 0; level--) {\n const mask = 2 ** (level - 1);\n const digit = (Math.floor(address.x / mask) % 2) + 2 * (Math.floor(address.y / mask) % 2);\n quadkey += String(digit);\n }\n return quadkey;\n}\n\n/**\n * Decodes a Bing Maps quadkey.\n *\n * @throws RangeError When the quadkey contains a character other than 0 to 3.\n */\nexport function quadkeyToTileAddress(quadkey: string): ITileAddress {\n let x = 0;\n let y = 0;\n for (const character of quadkey) {\n const digit = character.charCodeAt(0) - 48;\n if (digit < 0 || digit > 3) throw new RangeError(`Invalid quadkey digit \"${character}\" in \"${quadkey}\".`);\n x = x * 2 + (digit % 2);\n y = y * 2 + Math.floor(digit / 2);\n }\n return { lod: quadkey.length, x, y };\n}\n\n/** Returns the parent address, or `undefined` at level 0. The face is kept. */\nexport function parentTileAddress(address: ITileAddress): ITileAddress | undefined {\n if (address.lod === 0) return undefined;\n return withFace(address, address.lod - 1, Math.floor(address.x / 2), Math.floor(address.y / 2));\n}\n\n/** Returns the ancestor `levels` levels above, clamped to level 0. The face is kept. */\nexport function ancestorTileAddress(address: ITileAddress, levels: number): ITileAddress {\n const steps = Math.min(Math.max(0, Math.trunc(levels)), address.lod);\n const scale = 2 ** steps;\n return withFace(address, address.lod - steps, Math.floor(address.x / scale), Math.floor(address.y / scale));\n}\n\n/** Returns the four children in north-west, north-east, south-west, south-east order. The face is kept. */\nexport function childTileAddresses(address: ITileAddress): [ITileAddress, ITileAddress, ITileAddress, ITileAddress] {\n const lod = address.lod + 1;\n const x = address.x * 2;\n const y = address.y * 2;\n return [withFace(address, lod, x, y), withFace(address, lod, x + 1, y), withFace(address, lod, x, y + 1), withFace(address, lod, x + 1, y + 1)];\n}\n","import { tileCount, type ITileAddress } from \"./tile-address\";\n\n/**\n * Position around a tile, as the SpaceXR `NeighborsIndex`. The values follow the 3 x 3 layout row-major from the\n * north-west, with the tile itself at the centre:\n *\n * ```text\n * NW N NE 0 1 2\n * W C E 3 4 5\n * SW S SE 6 7 8\n * ```\n */\nexport enum TileNeighbor {\n NW = 0,\n N = 1,\n NE = 2,\n W = 3,\n C = 4,\n E = 5,\n SW = 6,\n S = 7,\n SE = 8,\n}\n\n/** Neighbours sharing an edge with the tile. */\nexport type TileEdgeNeighbor = TileNeighbor.N | TileNeighbor.E | TileNeighbor.S | TileNeighbor.W;\n\n/** Neighbours sharing only a corner with the tile. */\nexport type TileCornerNeighbor = TileNeighbor.NW | TileNeighbor.NE | TileNeighbor.SE | TileNeighbor.SW;\n\n/** Edge neighbours, clockwise from the north. */\nexport const TILE_EDGE_NEIGHBORS: readonly TileEdgeNeighbor[] = [TileNeighbor.N, TileNeighbor.E, TileNeighbor.S, TileNeighbor.W];\n\n/** Corner neighbours, clockwise from the north-west. */\nexport const TILE_CORNER_NEIGHBORS: readonly TileCornerNeighbor[] = [TileNeighbor.NW, TileNeighbor.NE, TileNeighbor.SE, TileNeighbor.SW];\n\n/** The two edges meeting at each corner, north or south first. */\nexport const TILE_CORNER_EDGES: Readonly<Record<TileCornerNeighbor, readonly [TileEdgeNeighbor, TileEdgeNeighbor]>> = {\n [TileNeighbor.NW]: [TileNeighbor.N, TileNeighbor.W],\n [TileNeighbor.NE]: [TileNeighbor.N, TileNeighbor.E],\n [TileNeighbor.SE]: [TileNeighbor.S, TileNeighbor.E],\n [TileNeighbor.SW]: [TileNeighbor.S, TileNeighbor.W],\n};\n\n/** Column and row offsets of each neighbour, in XYZ axes: `x` eastward, `y` southward. */\nexport function tileNeighborOffset(neighbor: TileNeighbor): readonly [number, number] {\n return [(neighbor % 3) - 1, Math.floor(neighbor / 3) - 1];\n}\n\nexport interface ITileNeighborOptions {\n /** Wraps columns around the antimeridian, for pyramids covering every longitude. Defaults to false. */\n wrapX?: boolean;\n}\n\n/**\n * Returns the neighbour at the same level of detail, or `undefined` beyond the pyramid. Rows never wrap: there is no\n * tile north of the first row or south of the last one. The face is kept; neighbours across root boundaries are given by the supplied topology.\n */\nexport function tileNeighborAddress(address: ITileAddress, neighbor: TileNeighbor, options: ITileNeighborOptions = {}): ITileAddress | undefined {\n const [dx, dy] = tileNeighborOffset(neighbor);\n const count = tileCount(address.lod);\n let x = address.x + dx;\n const y = address.y + dy;\n if (y < 0 || y >= count) return undefined;\n if (options.wrapX) x = ((x % count) + count) % count;\n else if (x < 0 || x >= count) return undefined;\n return address.face === undefined ? { lod: address.lod, x, y } : { face: address.face, lod: address.lod, x, y };\n}\n\n/** Returns the nine addresses of {@link TileNeighbor} order, the tile itself at `TileNeighbor.C`. */\nexport function tileNeighborAddresses(address: ITileAddress, options: ITileNeighborOptions = {}): Array<ITileAddress | undefined> {\n return Array.from({ length: 9 }, (_, neighbor) => tileNeighborAddress(address, neighbor, options));\n}\n"]}
|