@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.
Files changed (119) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +57 -2
  3. package/dist/addressing/index.d.ts +16 -0
  4. package/dist/addressing/index.js +4 -0
  5. package/dist/addressing/index.js.map +1 -0
  6. package/dist/bake/index.d.ts +91 -0
  7. package/dist/bake/index.js +3 -0
  8. package/dist/bake/index.js.map +1 -0
  9. package/dist/celestial-dataset-CUIsplKO.d.ts +99 -0
  10. package/dist/chunk-2HLQXRDD.js +246 -0
  11. package/dist/chunk-2HLQXRDD.js.map +1 -0
  12. package/dist/chunk-6YNCRDEE.js +170 -0
  13. package/dist/chunk-6YNCRDEE.js.map +1 -0
  14. package/dist/chunk-7AWV2IEK.js +79 -0
  15. package/dist/chunk-7AWV2IEK.js.map +1 -0
  16. package/dist/chunk-ESLGXWQR.js +219 -0
  17. package/dist/chunk-ESLGXWQR.js.map +1 -0
  18. package/dist/chunk-FB57CZDK.js +312 -0
  19. package/dist/chunk-FB57CZDK.js.map +1 -0
  20. package/dist/chunk-GRTG4WNA.js +44 -0
  21. package/dist/chunk-GRTG4WNA.js.map +1 -0
  22. package/dist/chunk-HVYN4AIT.js +45 -0
  23. package/dist/chunk-HVYN4AIT.js.map +1 -0
  24. package/dist/chunk-IGNRXAW3.js +77 -0
  25. package/dist/chunk-IGNRXAW3.js.map +1 -0
  26. package/dist/chunk-QGTREKHS.js +145 -0
  27. package/dist/chunk-QGTREKHS.js.map +1 -0
  28. package/dist/chunk-SPDRAY37.js +56 -0
  29. package/dist/chunk-SPDRAY37.js.map +1 -0
  30. package/dist/chunk-TA4BEVHL.js +81 -0
  31. package/dist/chunk-TA4BEVHL.js.map +1 -0
  32. package/dist/chunk-TGOB5HT5.js +149 -0
  33. package/dist/chunk-TGOB5HT5.js.map +1 -0
  34. package/dist/chunk-X6ZJ2PDY.js +104 -0
  35. package/dist/chunk-X6ZJ2PDY.js.map +1 -0
  36. package/dist/chunk-XTY4HCPY.js +22 -0
  37. package/dist/chunk-XTY4HCPY.js.map +1 -0
  38. package/dist/chunk-Y66PNDG2.js +107 -0
  39. package/dist/chunk-Y66PNDG2.js.map +1 -0
  40. package/dist/chunk-YEACOJOC.js +51 -0
  41. package/dist/chunk-YEACOJOC.js.map +1 -0
  42. package/dist/cube/index.d.ts +160 -0
  43. package/dist/cube/index.js +9 -0
  44. package/dist/cube/index.js.map +1 -0
  45. package/dist/datasets/index.d.ts +75 -0
  46. package/dist/datasets/index.js +11 -0
  47. package/dist/datasets/index.js.map +1 -0
  48. package/dist/index.d.ts +22 -0
  49. package/dist/index.js +18 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/mercator/index.d.ts +24 -0
  52. package/dist/mercator/index.js +8 -0
  53. package/dist/mercator/index.js.map +1 -0
  54. package/dist/metrics-HGbzqj6L.d.ts +45 -0
  55. package/dist/pyramid/index.d.ts +156 -0
  56. package/dist/pyramid/index.js +4 -0
  57. package/dist/pyramid/index.js.map +1 -0
  58. package/dist/raster-registration-CgBxrhDB.d.ts +19 -0
  59. package/dist/reference-surface-CsTtrNsc.d.ts +49 -0
  60. package/dist/reprojection/index.d.ts +255 -0
  61. package/dist/reprojection/index.js +6 -0
  62. package/dist/reprojection/index.js.map +1 -0
  63. package/dist/sources/index.d.ts +55 -0
  64. package/dist/sources/index.js +7 -0
  65. package/dist/sources/index.js.map +1 -0
  66. package/dist/surface/index.d.ts +15 -0
  67. package/dist/surface/index.js +4 -0
  68. package/dist/surface/index.js.map +1 -0
  69. package/dist/tile-D-jjIRRA.d.ts +53 -0
  70. package/dist/tile-address-BkfSftp6.d.ts +66 -0
  71. package/dist/tile-http-client-BHZOtGX7.d.ts +73 -0
  72. package/dist/tile-neighbors-LfvV7oiX.d.ts +48 -0
  73. package/dist/tile-surface-s9Zi6X9_.d.ts +40 -0
  74. package/dist/tile-topology-B6xHYqPb.d.ts +51 -0
  75. package/dist/web-mercator-dataset-Dmou8byO.d.ts +125 -0
  76. package/dist/web-tile-source-DrZDBIm6.d.ts +92 -0
  77. package/package.json +122 -5
  78. package/src/addressing/index.ts +8 -0
  79. package/src/addressing/metrics.ts +48 -0
  80. package/src/addressing/raster-registration.ts +22 -0
  81. package/src/addressing/tile-address.ts +130 -0
  82. package/src/addressing/tile-edge-rotation.ts +13 -0
  83. package/src/addressing/tile-neighbors.ts +73 -0
  84. package/src/addressing/tile-surface.ts +44 -0
  85. package/src/addressing/tile-topology.ts +86 -0
  86. package/src/addressing/tile.ts +73 -0
  87. package/src/bake/bake-pyramid.ts +106 -0
  88. package/src/bake/index.ts +2 -0
  89. package/src/bake/pyramid-levels.ts +63 -0
  90. package/src/cube/celestial-dataset.ts +182 -0
  91. package/src/cube/cube-face.ts +51 -0
  92. package/src/cube/cube-geometric-error.ts +30 -0
  93. package/src/cube/cube-mapping.ts +101 -0
  94. package/src/cube/cube-neighbors.ts +198 -0
  95. package/src/cube/cube-tile-surface.ts +30 -0
  96. package/src/cube/index.ts +6 -0
  97. package/src/datasets/index.ts +1 -0
  98. package/src/datasets/tile-dataset.ts +121 -0
  99. package/src/index.ts +9 -0
  100. package/src/mercator/index.ts +3 -0
  101. package/src/mercator/web-mercator-dataset.ts +215 -0
  102. package/src/mercator/web-mercator-tile-metrics.ts +119 -0
  103. package/src/mercator/web-mercator-tile-surface.ts +52 -0
  104. package/src/pyramid/index.ts +2 -0
  105. package/src/pyramid/resident-tiles.ts +81 -0
  106. package/src/pyramid/tile-pyramid.ts +285 -0
  107. package/src/reprojection/cube-resampling.ts +159 -0
  108. package/src/reprojection/index.ts +4 -0
  109. package/src/reprojection/source-projection.ts +196 -0
  110. package/src/reprojection/source-tile-matrix.ts +100 -0
  111. package/src/reprojection/wmts-capabilities.ts +112 -0
  112. package/src/sources/index.ts +4 -0
  113. package/src/sources/tile-http-client.ts +154 -0
  114. package/src/sources/tile-layer-changes.ts +88 -0
  115. package/src/sources/url-template.ts +96 -0
  116. package/src/sources/web-tile-source.ts +73 -0
  117. package/src/surface/directions.ts +27 -0
  118. package/src/surface/index.ts +2 -0
  119. package/src/surface/reference-surface.ts +88 -0
@@ -0,0 +1,88 @@
1
+ import type { Ellipsoid, ICartesian3 } from "@spacexr/geodesy";
2
+
3
+ /**
4
+ * Reference surface of a celestial body: a triaxial ellipsoid with radii `a`, `b`, `c` along the `X`, `Y` and `Z`
5
+ * axes of its body-fixed frame, in metres. Terrain heights are radial: the point of direction `d` and height `h` is
6
+ * `(radius(d) + h) * d`. No geodetic latitude is involved, so triaxial bodies need no special case.
7
+ */
8
+ export class ReferenceSurface {
9
+ public readonly radii: readonly [number, number, number];
10
+ private readonly inverseSquares: readonly [number, number, number];
11
+
12
+ /**
13
+ * @param a - Radius along `X`, in metres.
14
+ * @param b - Radius along `Y`, in metres.
15
+ * @param c - Radius along `Z`, the polar radius, in metres.
16
+ * @throws RangeError When a radius is not a positive finite number.
17
+ */
18
+ public constructor(a: number, b: number, c: number) {
19
+ for (const radius of [a, b, c]) {
20
+ if (!Number.isFinite(radius) || radius <= 0) throw new RangeError("The radii of a reference surface must be positive finite metres.");
21
+ }
22
+ this.radii = Object.freeze([a, b, c] as const);
23
+ this.inverseSquares = [1 / (a * a), 1 / (b * b), 1 / (c * c)];
24
+ }
25
+
26
+ /** A sphere of the given radius, in metres. */
27
+ public static sphere(radius: number): ReferenceSurface {
28
+ return new ReferenceSurface(radius, radius, radius);
29
+ }
30
+
31
+ /** The biaxial surface of an ellipsoid: its semi-major axis along `X` and `Y`, its semi-minor axis along `Z`. */
32
+ public static fromEllipsoid(ellipsoid: Ellipsoid): ReferenceSurface {
33
+ return new ReferenceSurface(ellipsoid.semiMajorAxis, ellipsoid.semiMajorAxis, ellipsoid.semiMinorAxis);
34
+ }
35
+
36
+ /**
37
+ * Distance from the centre to the surface along a unit direction: `1 / sqrt(x^2 / a^2 + y^2 / b^2 + z^2 / c^2)`.
38
+ */
39
+ public radius(direction: Readonly<ICartesian3>): number {
40
+ const [ia, ib, ic] = this.inverseSquares;
41
+ const { x, y, z } = direction;
42
+ return 1 / Math.sqrt(x * x * ia + y * y * ib + z * z * ic);
43
+ }
44
+
45
+ /**
46
+ * Point of a unit direction at a radial height: `(radius(direction) + height) * direction`.
47
+ *
48
+ * @param height - Radial height above the surface, in metres.
49
+ * @param target - Receives the point.
50
+ */
51
+ public point(direction: Readonly<ICartesian3>, height = 0, target: ICartesian3 = { x: 0, y: 0, z: 0 }): ICartesian3 {
52
+ const distance = this.radius(direction) + height;
53
+ target.x = direction.x * distance;
54
+ target.y = direction.y * distance;
55
+ target.z = direction.z * distance;
56
+ return target;
57
+ }
58
+
59
+ /**
60
+ * Radial height of a point above the surface: its distance to the centre minus the radius of its direction.
61
+ *
62
+ * @throws RangeError When the point is the centre or is not finite.
63
+ */
64
+ public height(point: Readonly<ICartesian3>): number {
65
+ const distance = Math.hypot(point.x, point.y, point.z);
66
+ if (!(distance > 0) || !Number.isFinite(distance)) throw new RangeError("The height of the centre is undefined.");
67
+ return distance - this.radius({ x: point.x / distance, y: point.y / distance, z: point.z / distance });
68
+ }
69
+
70
+ /**
71
+ * Unit normal of the surface at a point of it, `normalize(x / a^2, y / b^2, z / c^2)`. It differs from the radial
72
+ * direction on a non-spherical surface. For a point off the surface it is the normal of the scaled surface through
73
+ * that point.
74
+ *
75
+ * @param target - Receives the normal.
76
+ */
77
+ public normal(point: Readonly<ICartesian3>, target: ICartesian3 = { x: 0, y: 0, z: 0 }): ICartesian3 {
78
+ const [ia, ib, ic] = this.inverseSquares;
79
+ const x = point.x * ia;
80
+ const y = point.y * ib;
81
+ const z = point.z * ic;
82
+ const length = Math.hypot(x, y, z);
83
+ target.x = x / length;
84
+ target.y = y / length;
85
+ target.z = z / length;
86
+ return target;
87
+ }
88
+ }