@itowns/geographic 2.46.1-next.5 → 2.46.1-next.51

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,246 @@
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
+ */
55
+ clone(): Extent;
56
+ /**
57
+ * Projects this extent to the specified projection.
58
+ *
59
+ * @param crs - target's projection.
60
+ * @param target - The target to store the projected extent. If this not
61
+ * provided a new extent will be created.
62
+ */
63
+ as(crs: string, target?: Extent): Extent;
64
+ /**
65
+ * Returns the center of the extent.
66
+ *
67
+ * @param target - The target to store the center coordinate. If this not
68
+ * provided a new coordinate will be created.
69
+ */
70
+ center(target?: Coordinates): Coordinates;
71
+ /**
72
+ * Returns the planar dimensions as two-vector planar distances west/east
73
+ * and south/north.
74
+ * The planar distance is a straight-line Euclidean distance calculated in a
75
+ * 2D Cartesian coordinate system.
76
+ *
77
+ * @param target - optional target
78
+ */
79
+ planarDimensions(target?: Vector2): Vector2;
80
+ /**
81
+ * Returns the geodetic dimensions as two-vector planar distances west/east
82
+ * and south/north.
83
+ * Geodetic distance is calculated in an ellispoid space as the distance
84
+ * across the curved surface of the ellipsoid.
85
+ *
86
+ * @param target - optional target
87
+ */
88
+ geodeticDimensions(target?: Vector2): Vector2;
89
+ /**
90
+ * Returns the spatial euclidean dimensions as a two-vector spatial
91
+ * euclidean distances between west/east corner and south/north corner.
92
+ * Spatial euclidean distance chord is calculated in an ellispoid space.
93
+ *
94
+ * @param target - optional target
95
+ */
96
+ spatialEuclideanDimensions(target?: Vector2): Vector2;
97
+ /**
98
+ * Checks whether a coordinates is inside the extent.
99
+ *
100
+ * @param coord - the given coordinates.
101
+ * @param epsilon - error margin when comparing to the coordinates.
102
+ * Default is 0.
103
+ */
104
+ isPointInside(coord: Coordinates, epsilon?: number): boolean;
105
+ /**
106
+ * Checks whether another extent is inside the extent.
107
+ *
108
+ * @param extent - the extent to check
109
+ * @param epsilon - error margin when comparing the extent bounds.
110
+ */
111
+ isInside(extent: Extent, epsilon?: number): boolean;
112
+ /**
113
+ * Return the translation and scale to transform this extent to the input
114
+ * extent.
115
+ *
116
+ * @param extent - input extent
117
+ * @param target - copy the result to target.
118
+ * @returns A {@link THREE.Vector4} where the `x` property encodes the
119
+ * translation on west-east, the `y` property the translation on
120
+ * south-north, the `z` property the scale on west-east, the `w` property
121
+ * the scale on south-north.
122
+ */
123
+ offsetToParent(extent: Extent, target?: Vector4): Vector4;
124
+ /**
125
+ * Checks wheter this bounding box intersects with the given extent
126
+ * parameter.
127
+ * @param extent - the provided extent
128
+ */
129
+ intersectsExtent(extent: Extent): boolean;
130
+ static intersectsExtent(extentA: Extent, extentB: Extent): boolean;
131
+ /**
132
+ * Returns the intersection of this extent with another one.
133
+ * @param extent - extent to intersect
134
+ */
135
+ intersect(extent: Extent): Extent;
136
+ /**
137
+ * Set west, east, south and north values.
138
+ *
139
+ * @param v0 - the `west` value of this extent. Default is 0.
140
+ * @param v1 - the `east` value of this extent. Default is 0.
141
+ * @param v2 - the `south` value of this extent. Default is 0.
142
+ * @param v3 - the `north` value of this extent. Default is 0.
143
+ */
144
+ set(v0: number, v1: number, v2: number, v3: number): this;
145
+ /**
146
+ * Sets this extent `west` property to `array[offset + 0]`, `east` property
147
+ * to `array[offset + 1]`, `south` property to `array[offset + 2]` and
148
+ * `north` property to `array[offset + 3]`.
149
+ * @param array - the source array
150
+ * @param offset - offset into the array. Default is 0.
151
+ */
152
+ setFromArray(array: ArrayLike<number>, offset?: number): this;
153
+ /**
154
+ * Sets this extent `west`, `east`, `south` and `north` properties from an
155
+ * `extent` bounds.
156
+ * @param extent - the source extent
157
+ */
158
+ setFromExtent(extent: ExtentLike): this;
159
+ /**
160
+ * Copies the passed extent to this extent.
161
+ * @param extent - extent to copy.
162
+ */
163
+ copy(extent: Extent): this;
164
+ /**
165
+ * Union this extent with the input extent.
166
+ * @param extent - the extent to union.
167
+ */
168
+ union(extent: Extent): void;
169
+ /**
170
+ * expandByCoordinates perfoms the minimal extension
171
+ * for the coordinates to belong to this Extent object
172
+ * @param coordinates - The coordinates to belong
173
+ */
174
+ expandByCoordinates(coordinates: Coordinates): void;
175
+ /**
176
+ * expandByValuesCoordinates perfoms the minimal extension
177
+ * for the coordinates values to belong to this Extent object
178
+ * @param we - The coordinate on west-east
179
+ * @param sn - The coordinate on south-north
180
+ *
181
+ */
182
+ expandByValuesCoordinates(we: number, sn: number): void;
183
+ /**
184
+ * Instance Extent with THREE.Box3.
185
+ *
186
+ * If crs is a geocentric projection, the `box3.min` and `box3.max`
187
+ * should be the geocentric coordinates of `min` and `max` of a `box3`
188
+ * in local tangent plane.
189
+ *
190
+ * @param crs - Projection of extent to instancied.
191
+ * @param box - Bounding-box
192
+ */
193
+ static fromBox3(crs: ProjectionLike, box: Box3): Extent;
194
+ /**
195
+ * Return values of extent in string, separated by the separator input.
196
+ * @param sep - string separator
197
+ */
198
+ toString(sep?: string): string;
199
+ /**
200
+ * Subdivide equally an extent from its center to return four extents:
201
+ * north-west, north-east, south-west and south-east.
202
+ *
203
+ * @returns An array containing the four sections of the extent. The order
204
+ * of the sections is [NW, NE, SW, SE].
205
+ */
206
+ subdivision(): Extent[];
207
+ /**
208
+ * subdivise extent by scheme.x on west-east and scheme.y on south-north.
209
+ *
210
+ * @param scheme - The scheme to subdivise.
211
+ * @returns subdivised extents.
212
+ */
213
+ subdivisionByScheme(scheme?: Vector2): Extent[];
214
+ /**
215
+ * Multiplies all extent `coordinates` (with an implicit 1 in the 4th
216
+ * dimension) and `matrix`.
217
+ *
218
+ * @param matrix - The matrix
219
+ * @returns return this extent instance.
220
+ */
221
+ applyMatrix4(matrix: Matrix4): this;
222
+ /**
223
+ * clamp south and north values
224
+ *
225
+ * @param south - The min south
226
+ * @param north - The max north
227
+ * @returns this extent
228
+ */
229
+ clampSouthNorth(south?: number, north?: number): this;
230
+ /**
231
+ * clamp west and east values
232
+ *
233
+ * @param west - The min west
234
+ * @param east - The max east
235
+ * @returns this extent
236
+ */
237
+ clampWestEast(west?: number, east?: number): this;
238
+ /**
239
+ * clamp this extent by passed extent
240
+ *
241
+ * @param extent - The maximum extent.
242
+ * @returns this extent.
243
+ */
244
+ clampByExtent(extent: ExtentLike): this;
245
+ }
246
+ export default Extent;
package/lib/Extent.js CHANGED
@@ -54,11 +54,7 @@ class Extent {
54
54
  * @param south - the `south` value of this extent. Default is 0.
55
55
  * @param north - the `north` value of this extent. Default is 0.
56
56
  */
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;
57
+ constructor(crs, west = 0, east = 0, south = 0, north = 0) {
62
58
  if (CRS.isGeocentric(crs)) {
63
59
  throw new Error(`Non-compatible geocentric projection ${crs} to build a geographical extent`);
64
60
  }
@@ -85,8 +81,7 @@ class Extent {
85
81
  * @param target - The target to store the projected extent. If this not
86
82
  * provided a new extent will be created.
87
83
  */
88
- as(crs) {
89
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Extent('EPSG:4326');
84
+ as(crs, target = new Extent('EPSG:4326')) {
90
85
  CRS.isValid(crs);
91
86
  if (this.crs != crs) {
92
87
  // Compute min/max in x/y by projecting 8 cardinal points,
@@ -126,8 +121,7 @@ class Extent {
126
121
  * @param target - The target to store the center coordinate. If this not
127
122
  * provided a new coordinate will be created.
128
123
  */
129
- center() {
130
- let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Coordinates(this.crs);
124
+ center(target = new Coordinates(this.crs)) {
131
125
  this.planarDimensions(_dim);
132
126
  target.crs = this.crs;
133
127
  target.setFromValues(this.west + _dim.x * 0.5, this.south + _dim.y * 0.5);
@@ -142,8 +136,7 @@ class Extent {
142
136
  *
143
137
  * @param target - optional target
144
138
  */
145
- planarDimensions() {
146
- let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector2();
139
+ planarDimensions(target = new Vector2()) {
147
140
  // Calculte the dimensions for x and y
148
141
  return target.set(Math.abs(this.east - this.west), Math.abs(this.north - this.south));
149
142
  }
@@ -156,8 +149,7 @@ class Extent {
156
149
  *
157
150
  * @param target - optional target
158
151
  */
159
- geodeticDimensions() {
160
- let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector2();
152
+ geodeticDimensions(target = new Vector2()) {
161
153
  // set 3 corners extent
162
154
  cNorthWest.crs = this.crs;
163
155
  cSouthWest.crs = this.crs;
@@ -177,8 +169,7 @@ class Extent {
177
169
  *
178
170
  * @param target - optional target
179
171
  */
180
- spatialEuclideanDimensions() {
181
- let target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector2();
172
+ spatialEuclideanDimensions(target = new Vector2()) {
182
173
  // set 3 corners extent
183
174
  cNorthWest.crs = this.crs;
184
175
  cSouthWest.crs = this.crs;
@@ -198,8 +189,7 @@ class Extent {
198
189
  * @param epsilon - error margin when comparing to the coordinates.
199
190
  * Default is 0.
200
191
  */
201
- isPointInside(coord) {
202
- let epsilon = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
192
+ isPointInside(coord, epsilon = 0) {
203
193
  if (this.crs == coord.crs) {
204
194
  _c.copy(coord);
205
195
  } else {
@@ -216,8 +206,7 @@ class Extent {
216
206
  * @param extent - the extent to check
217
207
  * @param epsilon - error margin when comparing the extent bounds.
218
208
  */
219
- isInside(extent) {
220
- let epsilon = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : CRS.reasonableEpsilon(this.crs);
209
+ isInside(extent, epsilon = CRS.reasonableEpsilon(this.crs)) {
221
210
  extent.as(this.crs, _extent);
222
211
  return this.east - _extent.east <= epsilon && _extent.west - this.west <= epsilon && this.north - _extent.north <= epsilon && _extent.south - this.south <= epsilon;
223
212
  }
@@ -233,8 +222,7 @@ class Extent {
233
222
  * south-north, the `z` property the scale on west-east, the `w` property
234
223
  * the scale on south-north.
235
224
  */
236
- offsetToParent(extent) {
237
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector4();
225
+ offsetToParent(extent, target = new Vector4()) {
238
226
  if (this.crs != extent.crs) {
239
227
  throw new Error('unsupported mix');
240
228
  }
@@ -314,8 +302,7 @@ class Extent {
314
302
  * @param array - the source array
315
303
  * @param offset - offset into the array. Default is 0.
316
304
  */
317
- setFromArray(array) {
318
- let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
305
+ setFromArray(array, offset = 0) {
319
306
  this.west = array[offset];
320
307
  this.east = array[offset + 1];
321
308
  this.south = array[offset + 2];
@@ -439,8 +426,7 @@ class Extent {
439
426
  * Return values of extent in string, separated by the separator input.
440
427
  * @param sep - string separator
441
428
  */
442
- toString() {
443
- let sep = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
429
+ toString(sep = '') {
444
430
  return `${this.east}${sep}${this.north}${sep}${this.west}${sep}${this.south}`;
445
431
  }
446
432
 
@@ -461,8 +447,7 @@ class Extent {
461
447
  * @param scheme - The scheme to subdivise.
462
448
  * @returns subdivised extents.
463
449
  */
464
- subdivisionByScheme() {
465
- let scheme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultScheme;
450
+ subdivisionByScheme(scheme = defaultScheme) {
466
451
  const subdivisedExtents = [];
467
452
  const dimSub = this.planarDimensions(_dim).divide(scheme);
468
453
  for (let x = scheme.x - 1; x >= 0; x--) {
@@ -509,9 +494,7 @@ class Extent {
509
494
  * @param north - The max north
510
495
  * @returns this extent
511
496
  */
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;
497
+ clampSouthNorth(south = this.south, north = this.north) {
515
498
  this.south = Math.max(this.south, south);
516
499
  this.north = Math.min(this.north, north);
517
500
  return this;
@@ -524,9 +507,7 @@ class Extent {
524
507
  * @param east - The max east
525
508
  * @returns this extent
526
509
  */
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;
510
+ clampWestEast(west = this.west, east = this.east) {
530
511
  this.west = Math.max(this.west, west);
531
512
  this.east = Math.min(this.east, east);
532
513
  return this;
@@ -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
+ type LCCProjection = {
24
+ long0: number;
25
+ lat0: number;
26
+ };
27
+ type 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 {};