@itowns/geographic 2.46.1-next.6 → 2.46.1-next.60

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.
@@ -0,0 +1,77 @@
1
+ import { Vector3, type Vector3Like, type Ray } from 'three';
2
+ import Coordinates from './Coordinates';
3
+ /**
4
+ * Length of the semi-axes of the WGS84 ellipsoid.
5
+ * @internal
6
+ */
7
+ export declare const ellipsoidSizes: Vector3;
8
+ declare class Ellipsoid {
9
+ /**
10
+ * Length of the semi-axes of the ellipsoid.
11
+ */
12
+ size: Vector3;
13
+ /**
14
+ * Eccentricity of the ellipsoid.
15
+ */
16
+ eccentricity: number;
17
+ private _radiiSquared;
18
+ private _invRadiiSquared;
19
+ /**
20
+ * @param size - Length of the semi-axes of the ellipsoid. Defaults to those
21
+ * defined by the WGS84 ellipsoid.
22
+ */
23
+ constructor(size?: Vector3);
24
+ /**
25
+ * Computes the normal vector to an ellipsoid at the given cartesian
26
+ * coordinate `(x, y, z)`.
27
+ *
28
+ * @param cartesian - The given cartesian coordinate.
29
+ * @param target - An object to store this vector to. If this is not
30
+ * specified, a new vector will be created.
31
+ * @returns
32
+ */
33
+ geodeticSurfaceNormal(cartesian: Coordinates, target?: Vector3): Vector3;
34
+ /**
35
+ * Computes the normal vector to an ellipsoid at the given geographic
36
+ * coordinate `(longitude, latitude, altitude)`.
37
+ *
38
+ * @param coordCarto - The given geographic coordinate.
39
+ * @param target - An object to store this vector to. If this is not
40
+ * specified, a new vector will be created.
41
+ * @returns
42
+ */
43
+ geodeticSurfaceNormalCartographic(coordCarto: Coordinates, target?: Vector3): Vector3;
44
+ /**
45
+ * Sets the length of the semi-axes of this ellipsoid from a 3-dimensional
46
+ * vector-like object. The object shall have both `x`, `y` and `z`
47
+ * properties.
48
+ *
49
+ * @param size - The source vector.
50
+ * @returns
51
+ */
52
+ setSize(size: Vector3Like): this;
53
+ cartographicToCartesian(coordCarto: Coordinates, target?: Vector3): Vector3;
54
+ /**
55
+ * Convert cartesian coordinates to geographic according to the current
56
+ * ellipsoid of revolution.
57
+ * @param position - The coordinate to convert
58
+ * @param target - coordinate to copy result
59
+ * @returns an object describing the coordinates on the reference ellipsoid,
60
+ * angles are in degree
61
+ */
62
+ cartesianToCartographic(position: Vector3Like, target?: Coordinates): Coordinates;
63
+ cartographicToCartesianArray(coordCartoArray: Coordinates[]): Vector3[];
64
+ intersection(ray: Ray): Vector3 | false;
65
+ /**
66
+ * Calculate the geodesic distance, between coordCarto1 and coordCarto2.
67
+ * It's most short distance on ellipsoid surface between coordCarto1 and
68
+ * coordCarto2.
69
+ * It's called orthodromy.
70
+ *
71
+ * @param coordCarto1 - The coordinate carto 1
72
+ * @param coordCarto2 - The coordinate carto 2
73
+ * @returns The orthodromic distance between the two given coordinates.
74
+ */
75
+ geodesicDistance(coordCarto1: Coordinates, coordCarto2: Coordinates): number;
76
+ }
77
+ export default Ellipsoid;
package/lib/Ellipsoid.js CHANGED
@@ -21,8 +21,7 @@ class Ellipsoid {
21
21
  * @param size - Length of the semi-axes of the ellipsoid. Defaults to those
22
22
  * defined by the WGS84 ellipsoid.
23
23
  */
24
- constructor() {
25
- let size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ellipsoidSizes;
24
+ constructor(size = ellipsoidSizes) {
26
25
  this.size = new Vector3();
27
26
  this._radiiSquared = new Vector3();
28
27
  this._invRadiiSquared = new Vector3();
@@ -37,9 +36,9 @@ class Ellipsoid {
37
36
  * @param cartesian - The given cartesian coordinate.
38
37
  * @param target - An object to store this vector to. If this is not
39
38
  * specified, a new vector will be created.
39
+ * @returns
40
40
  */
41
- geodeticSurfaceNormal(cartesian) {
42
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
41
+ geodeticSurfaceNormal(cartesian, target = new Vector3()) {
43
42
  return cartesian.toVector3(target).multiply(this._invRadiiSquared).normalize();
44
43
  }
45
44
 
@@ -50,9 +49,9 @@ class Ellipsoid {
50
49
  * @param coordCarto - The given geographic coordinate.
51
50
  * @param target - An object to store this vector to. If this is not
52
51
  * specified, a new vector will be created.
52
+ * @returns
53
53
  */
54
- geodeticSurfaceNormalCartographic(coordCarto) {
55
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
54
+ geodeticSurfaceNormalCartographic(coordCarto, target = new Vector3()) {
56
55
  const longitude = MathUtils.degToRad(coordCarto.longitude);
57
56
  const latitude = MathUtils.degToRad(coordCarto.latitude);
58
57
  const cosLatitude = Math.cos(latitude);
@@ -65,6 +64,7 @@ class Ellipsoid {
65
64
  * properties.
66
65
  *
67
66
  * @param size - The source vector.
67
+ * @returns
68
68
  */
69
69
  setSize(size) {
70
70
  this.size.set(size.x, size.y, size.z);
@@ -75,8 +75,7 @@ class Ellipsoid {
75
75
  this.eccentricity = Math.sqrt(this._radiiSquared.x - this._radiiSquared.z) / this.size.x;
76
76
  return this;
77
77
  }
78
- cartographicToCartesian(coordCarto) {
79
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
78
+ cartographicToCartesian(coordCarto, target = new Vector3()) {
80
79
  normal.copy(coordCarto.geodesicNormal);
81
80
  target.multiplyVectors(this._radiiSquared, normal);
82
81
  const gamma = Math.sqrt(normal.dot(target));
@@ -93,8 +92,7 @@ class Ellipsoid {
93
92
  * @returns an object describing the coordinates on the reference ellipsoid,
94
93
  * angles are in degree
95
94
  */
96
- cartesianToCartographic(position) {
97
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Coordinates('EPSG:4326', 0, 0, 0);
95
+ cartesianToCartographic(position, target = new Coordinates('EPSG:4326', 0, 0, 0)) {
98
96
  // for details, see for example http://www.linz.govt.nz/data/geodetic-system/coordinate-conversion/geodetic-datum-conversions/equations-used-datum
99
97
  // TODO the following is only valable for oblate ellipsoid of
100
98
  // revolution. do we want to support triaxial ellipsoid?
@@ -139,7 +137,7 @@ class Ellipsoid {
139
137
  // both intersections are behind the ray origin
140
138
  return false;
141
139
  }
142
- let t = 0;
140
+ let t;
143
141
  if (t1 <= EPSILON) {
144
142
  t = t2;
145
143
  } else if (t2 <= EPSILON) {
@@ -0,0 +1,287 @@
1
+ import { Vector2, Vector4, Box3, type Matrix4 } from 'three';
2
+ import Coordinates from './Coordinates';
3
+ import type { ProjectionLike } from './Crs';
4
+ export interface ExtentLike {
5
+ readonly west: number;
6
+ readonly east: number;
7
+ readonly south: number;
8
+ readonly north: number;
9
+ }
10
+ /**
11
+ * A class representing a geographical extent.
12
+ *
13
+ * An extent is a geographical bounding rectangle defined by 4 limits: west,
14
+ * east, south and north.
15
+ *
16
+ * **Warning**: Using a geocentric projection is not suitable for representing a
17
+ * geographical extent. Please use a geographic projection.
18
+ */
19
+ declare class Extent {
20
+ /**
21
+ * Read-only flag to check if a given object is of type `Extent`.
22
+ */
23
+ readonly isExtent: true;
24
+ /**
25
+ * A default or user-defined CRS (see {@link ProjectionLike}).
26
+ */
27
+ crs: ProjectionLike;
28
+ /**
29
+ * West longitude bound of this extent.
30
+ */
31
+ west: number;
32
+ /**
33
+ * East longitude bound of this extent.
34
+ */
35
+ east: number;
36
+ /**
37
+ * South latitude bound of this extent.
38
+ */
39
+ south: number;
40
+ /**
41
+ * North latitude bound of this extent.
42
+ */
43
+ north: number;
44
+ /**
45
+ * @param crs - A default or user-defined CRS (see {@link ProjectionLike}).
46
+ * @param west - the `west` value of this extent. Default is 0.
47
+ * @param east - the `east` value of this extent. Default is 0.
48
+ * @param south - the `south` value of this extent. Default is 0.
49
+ * @param north - the `north` value of this extent. Default is 0.
50
+ */
51
+ constructor(crs: ProjectionLike, west?: number, east?: number, south?: number, north?: number);
52
+ /**
53
+ * Returns a new extent with the same bounds and crs as this one.
54
+ * @returns
55
+ */
56
+ clone(): Extent;
57
+ /**
58
+ * Projects this extent to the specified projection.
59
+ *
60
+ * @param crs - target's projection.
61
+ * @param target - The target to store the projected extent. If this not
62
+ * provided a new extent will be created.
63
+ * @returns
64
+ */
65
+ as(crs: string, target?: Extent): Extent;
66
+ /**
67
+ * Returns the center of the extent.
68
+ *
69
+ * @param target - The target to store the center coordinate. If this not
70
+ * provided a new coordinate will be created.
71
+ * @returns
72
+ */
73
+ center(target?: Coordinates): Coordinates;
74
+ /**
75
+ * Returns the planar dimensions as two-vector planar distances west/east
76
+ * and south/north.
77
+ * The planar distance is a straight-line Euclidean distance calculated in a
78
+ * 2D Cartesian coordinate system.
79
+ *
80
+ * @param target - optional target
81
+ * @returns
82
+ */
83
+ planarDimensions(target?: Vector2): Vector2;
84
+ /**
85
+ * Returns the geodetic dimensions as two-vector planar distances west/east
86
+ * and south/north.
87
+ * Geodetic distance is calculated in an ellispoid space as the distance
88
+ * across the curved surface of the ellipsoid.
89
+ *
90
+ * @param target - optional target
91
+ * @returns
92
+ */
93
+ geodeticDimensions(target?: Vector2): Vector2;
94
+ /**
95
+ * Returns the spatial euclidean dimensions as a two-vector spatial
96
+ * euclidean distances between west/east corner and south/north corner.
97
+ * Spatial euclidean distance chord is calculated in an ellispoid space.
98
+ *
99
+ * @param target - optional target
100
+ * @returns
101
+ */
102
+ spatialEuclideanDimensions(target?: Vector2): Vector2;
103
+ /**
104
+ * Checks whether a coordinates is inside the extent.
105
+ *
106
+ * @param coord - the given coordinates.
107
+ * @param epsilon - error margin when comparing to the coordinates.
108
+ * Default is 0.
109
+ * @returns
110
+ */
111
+ isPointInside(coord: Coordinates, epsilon?: number): boolean;
112
+ /**
113
+ * Checks whether another extent is inside the extent.
114
+ *
115
+ * @param extent - the extent to check
116
+ * @param epsilon - error margin when comparing the extent bounds.
117
+ * @returns
118
+ */
119
+ isInside(extent: Extent, epsilon?: number): boolean;
120
+ /**
121
+ * Return the translation and scale to transform this extent to the input
122
+ * extent.
123
+ *
124
+ * @param extent - input extent
125
+ * @param target - copy the result to target.
126
+ * @returns A {@link THREE.Vector4} where the `x` property encodes the
127
+ * translation on west-east, the `y` property the translation on
128
+ * south-north, the `z` property the scale on west-east, the `w` property
129
+ * the scale on south-north.
130
+ */
131
+ offsetToParent(extent: Extent, target?: Vector4): Vector4;
132
+ /**
133
+ * Checks wheter this bounding box intersects with the given extent
134
+ * parameter.
135
+ * @param extent - the provided extent
136
+ * @returns
137
+ */
138
+ intersectsExtent(extent: Extent): boolean;
139
+ /**
140
+ * Tests whether two extents intersect.
141
+ *
142
+ * This method checks if the geographic extents `extentA` and `extentB`
143
+ * overlap. If their coordinate reference systems (CRS) differ, `extentB`
144
+ * is reprojected into the CRS of `extentA` before performing the test.
145
+ *
146
+ * Extents that touch at an edge or a corner aren't treated as intersecting.
147
+ *
148
+ * @param extentA - The reference extent.
149
+ * @param extentB - The extent to test against.
150
+ *
151
+ * @returns `true` if the extents intersect, `false` otherwise.
152
+ */
153
+ static intersectsExtent(extentA: Extent, extentB: Extent): boolean;
154
+ /**
155
+ * Returns the intersection of this extent with another one.
156
+ *
157
+ * This method computes the overlapping region between this extent and
158
+ * another extent. If their coordinate reference systems (CRS) differ,
159
+ * the other extent is reprojected into the CRS of this extent before
160
+ * performing the intersection.
161
+ *
162
+ *
163
+ * @param extent - The extent to intersect with this one.
164
+ * @param target - The target extent to store the result. If not provided,
165
+ * a new extent will be created.
166
+ *
167
+ * @returns The intersection extent
168
+ * (may be empty if extents do not intersect).
169
+ */
170
+ intersect(extent: Extent, target?: Extent): Extent;
171
+ /**
172
+ * Set west, east, south and north values.
173
+ *
174
+ * @param v0 - the `west` value of this extent. Default is 0.
175
+ * @param v1 - the `east` value of this extent. Default is 0.
176
+ * @param v2 - the `south` value of this extent. Default is 0.
177
+ * @param v3 - the `north` value of this extent. Default is 0.
178
+ * @returns
179
+ */
180
+ set(v0: number, v1: number, v2: number, v3: number): this;
181
+ /**
182
+ * Sets this extent `west` property to `array[offset + 0]`, `east` property
183
+ * to `array[offset + 1]`, `south` property to `array[offset + 2]` and
184
+ * `north` property to `array[offset + 3]`.
185
+ * @param array - the source array
186
+ * @param offset - offset into the array. Default is 0.
187
+ * @returns
188
+ */
189
+ setFromArray(array: ArrayLike<number>, offset?: number): this;
190
+ /**
191
+ * Sets this extent `west`, `east`, `south` and `north` properties from an
192
+ * `extent` bounds.
193
+ * @param extent - the source extent
194
+ * @returns
195
+ */
196
+ setFromExtent(extent: ExtentLike): this;
197
+ /**
198
+ * Copies the passed extent to this extent.
199
+ * @param extent - extent to copy.
200
+ * @returns
201
+ */
202
+ copy(extent: Extent): this;
203
+ /**
204
+ * Union this extent with the input extent.
205
+ * @param extent - the extent to union.
206
+ * @returns
207
+ */
208
+ union(extent: Extent): this;
209
+ /**
210
+ * expandByCoordinates perfoms the minimal extension
211
+ * for the coordinates to belong to this Extent object
212
+ * @param coordinates - The coordinates to belong
213
+ */
214
+ expandByCoordinates(coordinates: Coordinates): void;
215
+ /**
216
+ * expandByValuesCoordinates perfoms the minimal extension
217
+ * for the coordinates values to belong to this Extent object
218
+ * @param we - The coordinate on west-east
219
+ * @param sn - The coordinate on south-north
220
+ */
221
+ expandByValuesCoordinates(we: number, sn: number): void;
222
+ /**
223
+ * Instance Extent with THREE.Box3.
224
+ *
225
+ * If crs is a geocentric projection, the `box3.min` and `box3.max`
226
+ * should be the geocentric coordinates of `min` and `max` of a `box3`
227
+ * in local tangent plane.
228
+ *
229
+ * @param crs - Projection of extent to instancied.
230
+ * @param box - Bounding-box
231
+ * @returns
232
+ */
233
+ static fromBox3(crs: ProjectionLike, box: Box3): Extent;
234
+ /**
235
+ * Return values of extent in string, separated by the separator input.
236
+ * @param sep - string separator
237
+ * @returns
238
+ */
239
+ toString(sep?: string): string;
240
+ /**
241
+ * Subdivide equally an extent from its center to return four extents:
242
+ * north-west, north-east, south-west and south-east.
243
+ *
244
+ * @returns An array containing the four sections of the extent. The order
245
+ * of the sections is [NW, NE, SW, SE].
246
+ */
247
+ subdivision(): Extent[];
248
+ /**
249
+ * subdivise extent by scheme.x on west-east and scheme.y on south-north.
250
+ *
251
+ * @param scheme - The scheme to subdivise.
252
+ * @returns subdivised extents.
253
+ */
254
+ subdivisionByScheme(scheme?: Vector2): Extent[];
255
+ /**
256
+ * Multiplies all extent `coordinates` (with an implicit 1 in the 4th
257
+ * dimension) and `matrix`.
258
+ *
259
+ * @param matrix - The matrix
260
+ * @returns return this extent instance.
261
+ */
262
+ applyMatrix4(matrix: Matrix4): this;
263
+ /**
264
+ * clamp south and north values
265
+ *
266
+ * @param south - The min south
267
+ * @param north - The max north
268
+ * @returns this extent
269
+ */
270
+ clampSouthNorth(south?: number, north?: number): this;
271
+ /**
272
+ * clamp west and east values
273
+ *
274
+ * @param west - The min west
275
+ * @param east - The max east
276
+ * @returns this extent
277
+ */
278
+ clampWestEast(west?: number, east?: number): this;
279
+ /**
280
+ * clamp this extent by passed extent
281
+ *
282
+ * @param extent - The maximum extent.
283
+ * @returns this extent.
284
+ */
285
+ clampByExtent(extent: ExtentLike): this;
286
+ }
287
+ export default Extent;