@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.
package/lib/Extent.js CHANGED
@@ -10,7 +10,6 @@ const cSouthWest = /* @__PURE__ */new Coordinates('EPSG:4326', 0, 0, 0);
10
10
  const cNorthEast = /* @__PURE__ */new Coordinates('EPSG:4326', 0, 0, 0);
11
11
  const southWest = /* @__PURE__ */new Vector3();
12
12
  const northEast = /* @__PURE__ */new Vector3();
13
- let _extent;
14
13
  const cardinals = [/* @__PURE__ */new Coordinates('EPSG:4326', 0, 0, 0), /* @__PURE__ */new Coordinates('EPSG:4326', 0, 0, 0), /* @__PURE__ */new Coordinates('EPSG:4326', 0, 0, 0), /* @__PURE__ */new Coordinates('EPSG:4326', 0, 0, 0), /* @__PURE__ */new Coordinates('EPSG:4326', 0, 0, 0), /* @__PURE__ */new Coordinates('EPSG:4326', 0, 0, 0), /* @__PURE__ */new Coordinates('EPSG:4326', 0, 0, 0), /* @__PURE__ */new Coordinates('EPSG:4326', 0, 0, 0)];
15
14
  const _c = /* @__PURE__ */new Coordinates('EPSG:4326', 0, 0);
16
15
  /**
@@ -54,11 +53,7 @@ class Extent {
54
53
  * @param south - the `south` value of this extent. Default is 0.
55
54
  * @param north - the `north` value of this extent. Default is 0.
56
55
  */
57
- constructor(crs) {
58
- let west = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
59
- let east = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
60
- let south = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
61
- let north = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
56
+ constructor(crs, west = 0, east = 0, south = 0, north = 0) {
62
57
  if (CRS.isGeocentric(crs)) {
63
58
  throw new Error(`Non-compatible geocentric projection ${crs} to build a geographical extent`);
64
59
  }
@@ -73,6 +68,7 @@ class Extent {
73
68
 
74
69
  /**
75
70
  * Returns a new extent with the same bounds and crs as this one.
71
+ * @returns
76
72
  */
77
73
  clone() {
78
74
  return new Extent(this.crs, this.west, this.east, this.south, this.north);
@@ -84,9 +80,9 @@ class Extent {
84
80
  * @param crs - target's projection.
85
81
  * @param target - The target to store the projected extent. If this not
86
82
  * provided a new extent will be created.
83
+ * @returns
87
84
  */
88
- as(crs) {
89
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Extent('EPSG:4326');
85
+ as(crs, target = new Extent('EPSG:4326')) {
90
86
  CRS.isValid(crs);
91
87
  if (this.crs != crs) {
92
88
  // Compute min/max in x/y by projecting 8 cardinal points,
@@ -125,9 +121,9 @@ class Extent {
125
121
  *
126
122
  * @param target - The target to store the center coordinate. If this not
127
123
  * provided a new coordinate will be created.
124
+ * @returns
128
125
  */
129
- center() {
130
- let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Coordinates(this.crs);
126
+ center(target = new Coordinates(this.crs)) {
131
127
  this.planarDimensions(_dim);
132
128
  target.crs = this.crs;
133
129
  target.setFromValues(this.west + _dim.x * 0.5, this.south + _dim.y * 0.5);
@@ -141,9 +137,9 @@ class Extent {
141
137
  * 2D Cartesian coordinate system.
142
138
  *
143
139
  * @param target - optional target
140
+ * @returns
144
141
  */
145
- planarDimensions() {
146
- let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector2();
142
+ planarDimensions(target = new Vector2()) {
147
143
  // Calculte the dimensions for x and y
148
144
  return target.set(Math.abs(this.east - this.west), Math.abs(this.north - this.south));
149
145
  }
@@ -155,9 +151,9 @@ class Extent {
155
151
  * across the curved surface of the ellipsoid.
156
152
  *
157
153
  * @param target - optional target
154
+ * @returns
158
155
  */
159
- geodeticDimensions() {
160
- let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector2();
156
+ geodeticDimensions(target = new Vector2()) {
161
157
  // set 3 corners extent
162
158
  cNorthWest.crs = this.crs;
163
159
  cSouthWest.crs = this.crs;
@@ -176,9 +172,9 @@ class Extent {
176
172
  * Spatial euclidean distance chord is calculated in an ellispoid space.
177
173
  *
178
174
  * @param target - optional target
175
+ * @returns
179
176
  */
180
- spatialEuclideanDimensions() {
181
- let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector2();
177
+ spatialEuclideanDimensions(target = new Vector2()) {
182
178
  // set 3 corners extent
183
179
  cNorthWest.crs = this.crs;
184
180
  cSouthWest.crs = this.crs;
@@ -197,9 +193,9 @@ class Extent {
197
193
  * @param coord - the given coordinates.
198
194
  * @param epsilon - error margin when comparing to the coordinates.
199
195
  * Default is 0.
196
+ * @returns
200
197
  */
201
- isPointInside(coord) {
202
- let epsilon = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
198
+ isPointInside(coord, epsilon = 0) {
203
199
  if (this.crs == coord.crs) {
204
200
  _c.copy(coord);
205
201
  } else {
@@ -215,9 +211,9 @@ class Extent {
215
211
  *
216
212
  * @param extent - the extent to check
217
213
  * @param epsilon - error margin when comparing the extent bounds.
214
+ * @returns
218
215
  */
219
- isInside(extent) {
220
- let epsilon = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : CRS.reasonableEpsilon(this.crs);
216
+ isInside(extent, epsilon = CRS.reasonableEpsilon(this.crs)) {
221
217
  extent.as(this.crs, _extent);
222
218
  return this.east - _extent.east <= epsilon && _extent.west - this.west <= epsilon && this.north - _extent.north <= epsilon && _extent.south - this.south <= epsilon;
223
219
  }
@@ -233,8 +229,7 @@ class Extent {
233
229
  * south-north, the `z` property the scale on west-east, the `w` property
234
230
  * the scale on south-north.
235
231
  */
236
- offsetToParent(extent) {
237
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector4();
232
+ offsetToParent(extent, target = new Vector4()) {
238
233
  if (this.crs != extent.crs) {
239
234
  throw new Error('unsupported mix');
240
235
  }
@@ -251,28 +246,55 @@ class Extent {
251
246
  * Checks wheter this bounding box intersects with the given extent
252
247
  * parameter.
253
248
  * @param extent - the provided extent
249
+ * @returns
254
250
  */
255
251
  intersectsExtent(extent) {
256
252
  return Extent.intersectsExtent(this, extent);
257
253
  }
254
+
255
+ /**
256
+ * Tests whether two extents intersect.
257
+ *
258
+ * This method checks if the geographic extents `extentA` and `extentB`
259
+ * overlap. If their coordinate reference systems (CRS) differ, `extentB`
260
+ * is reprojected into the CRS of `extentA` before performing the test.
261
+ *
262
+ * Extents that touch at an edge or a corner aren't treated as intersecting.
263
+ *
264
+ * @param extentA - The reference extent.
265
+ * @param extentB - The extent to test against.
266
+ *
267
+ * @returns `true` if the extents intersect, `false` otherwise.
268
+ */
258
269
  static intersectsExtent(extentA, extentB) {
259
- // TODO don't work when is on limit
260
270
  const other = extentB.crs == extentA.crs ? extentB : extentB.as(extentA.crs, _extent);
261
271
  return !(extentA.west >= other.east || extentA.east <= other.west || extentA.south >= other.north || extentA.north <= other.south);
262
272
  }
263
273
 
264
274
  /**
265
275
  * Returns the intersection of this extent with another one.
266
- * @param extent - extent to intersect
276
+ *
277
+ * This method computes the overlapping region between this extent and
278
+ * another extent. If their coordinate reference systems (CRS) differ,
279
+ * the other extent is reprojected into the CRS of this extent before
280
+ * performing the intersection.
281
+ *
282
+ *
283
+ * @param extent - The extent to intersect with this one.
284
+ * @param target - The target extent to store the result. If not provided,
285
+ * a new extent will be created.
286
+ *
287
+ * @returns The intersection extent
288
+ * (may be empty if extents do not intersect).
267
289
  */
268
- intersect(extent) {
290
+ intersect(extent, target = new Extent(this.crs)) {
269
291
  if (!this.intersectsExtent(extent)) {
270
- return new Extent(this.crs);
292
+ return target;
271
293
  }
272
294
  if (extent.crs != this.crs) {
273
295
  extent = extent.as(this.crs, _extent);
274
296
  }
275
- return new Extent(this.crs, Math.max(this.west, extent.west), Math.min(this.east, extent.east), Math.max(this.south, extent.south), Math.min(this.north, extent.north));
297
+ return target.set(Math.max(this.west, extent.west), Math.min(this.east, extent.east), Math.max(this.south, extent.south), Math.min(this.north, extent.north));
276
298
  }
277
299
 
278
300
  /**
@@ -282,6 +304,7 @@ class Extent {
282
304
  * @param v1 - the `east` value of this extent. Default is 0.
283
305
  * @param v2 - the `south` value of this extent. Default is 0.
284
306
  * @param v3 - the `north` value of this extent. Default is 0.
307
+ * @returns
285
308
  */
286
309
  set(v0, v1, v2, v3) {
287
310
  if (v0 == undefined) {
@@ -313,9 +336,9 @@ class Extent {
313
336
  * `north` property to `array[offset + 3]`.
314
337
  * @param array - the source array
315
338
  * @param offset - offset into the array. Default is 0.
339
+ * @returns
316
340
  */
317
- setFromArray(array) {
318
- let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
341
+ setFromArray(array, offset = 0) {
319
342
  this.west = array[offset];
320
343
  this.east = array[offset + 1];
321
344
  this.south = array[offset + 2];
@@ -327,6 +350,7 @@ class Extent {
327
350
  * Sets this extent `west`, `east`, `south` and `north` properties from an
328
351
  * `extent` bounds.
329
352
  * @param extent - the source extent
353
+ * @returns
330
354
  */
331
355
  setFromExtent(extent) {
332
356
  this.west = extent.west;
@@ -339,6 +363,7 @@ class Extent {
339
363
  /**
340
364
  * Copies the passed extent to this extent.
341
365
  * @param extent - extent to copy.
366
+ * @returns
342
367
  */
343
368
  copy(extent) {
344
369
  this.crs = extent.crs;
@@ -348,6 +373,7 @@ class Extent {
348
373
  /**
349
374
  * Union this extent with the input extent.
350
375
  * @param extent - the extent to union.
376
+ * @returns
351
377
  */
352
378
  union(extent) {
353
379
  if (extent.crs != this.crs) {
@@ -373,6 +399,7 @@ class Extent {
373
399
  this.north = north;
374
400
  }
375
401
  }
402
+ return this;
376
403
  }
377
404
 
378
405
  /**
@@ -386,12 +413,11 @@ class Extent {
386
413
  }
387
414
 
388
415
  /**
389
- * expandByValuesCoordinates perfoms the minimal extension
390
- * for the coordinates values to belong to this Extent object
391
- * @param we - The coordinate on west-east
392
- * @param sn - The coordinate on south-north
393
- *
394
- */
416
+ * expandByValuesCoordinates perfoms the minimal extension
417
+ * for the coordinates values to belong to this Extent object
418
+ * @param we - The coordinate on west-east
419
+ * @param sn - The coordinate on south-north
420
+ */
395
421
  expandByValuesCoordinates(we, sn) {
396
422
  if (we < this.west) {
397
423
  this.west = we;
@@ -416,6 +442,7 @@ class Extent {
416
442
  *
417
443
  * @param crs - Projection of extent to instancied.
418
444
  * @param box - Bounding-box
445
+ * @returns
419
446
  */
420
447
  static fromBox3(crs, box) {
421
448
  if (CRS.isGeocentric(crs)) {
@@ -438,9 +465,9 @@ class Extent {
438
465
  /**
439
466
  * Return values of extent in string, separated by the separator input.
440
467
  * @param sep - string separator
468
+ * @returns
441
469
  */
442
- toString() {
443
- let sep = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
470
+ toString(sep = '') {
444
471
  return `${this.east}${sep}${this.north}${sep}${this.west}${sep}${this.south}`;
445
472
  }
446
473
 
@@ -461,8 +488,7 @@ class Extent {
461
488
  * @param scheme - The scheme to subdivise.
462
489
  * @returns subdivised extents.
463
490
  */
464
- subdivisionByScheme() {
465
- let scheme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultScheme;
491
+ subdivisionByScheme(scheme = defaultScheme) {
466
492
  const subdivisedExtents = [];
467
493
  const dimSub = this.planarDimensions(_dim).divide(scheme);
468
494
  for (let x = scheme.x - 1; x >= 0; x--) {
@@ -509,9 +535,7 @@ class Extent {
509
535
  * @param north - The max north
510
536
  * @returns this extent
511
537
  */
512
- clampSouthNorth() {
513
- let south = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.south;
514
- let north = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.north;
538
+ clampSouthNorth(south = this.south, north = this.north) {
515
539
  this.south = Math.max(this.south, south);
516
540
  this.north = Math.min(this.north, north);
517
541
  return this;
@@ -524,9 +548,7 @@ class Extent {
524
548
  * @param east - The max east
525
549
  * @returns this extent
526
550
  */
527
- clampWestEast() {
528
- let west = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.west;
529
- let east = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.east;
551
+ clampWestEast(west = this.west, east = this.east) {
530
552
  this.west = Math.max(this.west, west);
531
553
  this.east = Math.min(this.east, east);
532
554
  return this;
@@ -543,5 +565,5 @@ class Extent {
543
565
  return this.clampWestEast(extent.west, extent.east);
544
566
  }
545
567
  }
546
- _extent = /* @__PURE__ */new Extent('EPSG:4326');
568
+ const _extent = /* @__PURE__ */new Extent('EPSG:4326');
547
569
  export default Extent;
@@ -0,0 +1,105 @@
1
+ import { Quaternion } from 'three';
2
+ import { type ProjectionDefinition } from 'proj4';
3
+ import Coordinates from './Coordinates';
4
+ interface EulerAngles {
5
+ /** angle in degrees */
6
+ roll: number;
7
+ /** angle in degrees */
8
+ pitch: number;
9
+ /** angle in degrees */
10
+ heading: number;
11
+ }
12
+ interface PhotogrammetryAngles {
13
+ /** angle in degrees */
14
+ omega: number;
15
+ /** angle in degrees */
16
+ phi: number;
17
+ /** angle in degrees */
18
+ kappa: number;
19
+ }
20
+ type Attitude = Partial<EulerAngles> | Partial<PhotogrammetryAngles>;
21
+ type QuaternionFunction = (coords: Coordinates, target?: Quaternion) => Quaternion;
22
+ type ProjectionLike = ProjectionDefinition | string;
23
+ interface LCCProjection {
24
+ long0: number;
25
+ lat0: number;
26
+ }
27
+ interface TMercProjection {
28
+ a: number;
29
+ b: number;
30
+ e?: number;
31
+ long0: number;
32
+ }
33
+ /**
34
+ * The transform from the platform frame to the local East, North, Up (ENU)
35
+ * frame is `RotationZ(heading).RotationX(pitch).RotationY(roll)`.
36
+ *
37
+ * @param roll - angle in degrees. Default is 0.
38
+ * @param pitch - angle in degrees. Default is 0.
39
+ * @param heading - angle in degrees. Default is 0
40
+ * @param target - output Quaternion
41
+ *
42
+ * @returns The target quaternion
43
+ */
44
+ export declare function quaternionFromRollPitchHeading(roll?: number, pitch?: number, heading?: number, target?: Quaternion): Quaternion;
45
+ /**
46
+ * From
47
+ * [DocMicMac](https://github.com/micmacIGN/Documentation/raw/master/DocMicMac.pdf),
48
+ * the transform from the platform frame to the local East, North, Up (ENU)
49
+ * frame is:
50
+ *
51
+ * ```
52
+ * RotationX(omega).RotationY(phi).RotationZ(kappa).RotationX(PI)
53
+ * Converts between the 2 conventions for the camera local frame:
54
+ * RotationX(PI) <=> Quaternion(1,0,0,0)
55
+ * X right, Y bottom, Z front : convention in photogrammetry and computer vision
56
+ * X right, Y top, Z back : convention in webGL, threejs
57
+ * ```
58
+ *
59
+ * @param omega - angle in degrees. Default is 0.
60
+ * @param phi - angle in degrees. Default is 0.
61
+ * @param kappa - angle in degrees. Default is 0.
62
+ * @param target - output quaternion
63
+ *
64
+ * @returns The target quaternion
65
+ */
66
+ export declare function quaternionFromOmegaPhiKappa(omega?: number, phi?: number, kappa?: number, target?: Quaternion): Quaternion;
67
+ /**
68
+ * Sets the quaternion according to the rotation from the platform frame to the
69
+ * local frame.
70
+ *
71
+ * @param attitude - either euler angles or photogrammetry angles
72
+ * @param target - output Quaternion
73
+ *
74
+ * @returns The target quaternion
75
+ */
76
+ export declare function quaternionFromAttitude(attitude: Attitude, target?: Quaternion): Quaternion;
77
+ export declare function quaternionFromEnuToGeocent(): QuaternionFunction;
78
+ export declare function quaternionFromEnuToGeocent(coords: Coordinates, target?: Quaternion): Quaternion;
79
+ export declare function quaternionFromGeocentToEnu(): QuaternionFunction;
80
+ export declare function quaternionFromGeocentToEnu(coords: Coordinates, target?: Quaternion): Quaternion;
81
+ export declare function quaternionFromLCCToEnu(proj: LCCProjection): QuaternionFunction;
82
+ export declare function quaternionFromLCCToEnu(proj: LCCProjection, coords: Coordinates, target?: Quaternion): Quaternion;
83
+ export declare function quaternionFromEnuToLCC(proj: LCCProjection): QuaternionFunction;
84
+ export declare function quaternionFromEnuToLCC(proj: LCCProjection, coords: Coordinates, target?: Quaternion): Quaternion;
85
+ export declare function quaternionFromTMercToEnu(proj: TMercProjection): QuaternionFunction;
86
+ export declare function quaternionFromTMercToEnu(proj: TMercProjection, coords: Coordinates, target?: Quaternion): Quaternion;
87
+ export declare function quaternionFromEnuToTMerc(proj: TMercProjection): QuaternionFunction;
88
+ export declare function quaternionFromEnuToTMerc(proj: TMercProjection, coords: Coordinates, target?: Quaternion): Quaternion;
89
+ export declare function quaternionFromLongLatToEnu(): QuaternionFunction;
90
+ export declare function quaternionFromLongLatToEnu(coords: Coordinates, target?: Quaternion): Quaternion;
91
+ export declare function quaternionFromEnuToLongLat(): QuaternionFunction;
92
+ export declare function quaternionFromEnuToLongLat(coords: Coordinates, target?: Quaternion): Quaternion;
93
+ export declare function quaternionUnimplemented(proj: {
94
+ projName?: string;
95
+ }): QuaternionFunction;
96
+ export declare function quaternionUnimplemented(proj: {
97
+ projName?: string;
98
+ }, coords: Coordinates, target?: Quaternion): Quaternion;
99
+ export declare function quaternionFromEnuToCRS(proj: ProjectionLike): QuaternionFunction;
100
+ export declare function quaternionFromEnuToCRS(proj: ProjectionLike, coords: Coordinates, target?: Quaternion): Quaternion;
101
+ export declare function quaternionFromCRSToEnu(proj: ProjectionLike): QuaternionFunction;
102
+ export declare function quaternionFromCRSToEnu(proj: ProjectionLike, coords: Coordinates, target?: Quaternion): Quaternion;
103
+ export declare function quaternionFromCRSToCRS(crsIn: string, crsOut: string): QuaternionFunction;
104
+ export declare function quaternionFromCRSToCRS(crsIn: string, crsOut: string, coords: Coordinates, target?: Quaternion): Quaternion;
105
+ export {};