itowns 2.44.3-next.29 → 2.44.3-next.30

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.
@@ -1,9 +1,26 @@
1
1
  import * as THREE from 'three';
2
2
  import proj4 from 'proj4';
3
3
  import Coordinates from "../Geographic/Coordinates.js";
4
+
5
+ /**
6
+ * Length of the semi-axes of the WGS84 ellipsoid.
7
+ * @internal
8
+ */
4
9
  export const ellipsoidSizes = new THREE.Vector3(proj4.WGS84.a, proj4.WGS84.a, proj4.WGS84.b);
5
10
  const normal = new THREE.Vector3();
6
11
  class Ellipsoid {
12
+ /**
13
+ * Length of the semi-axes of the ellipsoid.
14
+ */
15
+
16
+ /**
17
+ * Eccentricity of the ellipsoid.
18
+ */
19
+
20
+ /**
21
+ * @param size - Length of the semi-axes of the ellipsoid. Defaults to those
22
+ * defined by the WGS84 ellipsoid.
23
+ */
7
24
  constructor() {
8
25
  let size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ellipsoidSizes;
9
26
  this.size = new THREE.Vector3();
@@ -12,10 +29,28 @@ class Ellipsoid {
12
29
  this.eccentricity = 0;
13
30
  this.setSize(size);
14
31
  }
32
+
33
+ /**
34
+ * Computes the normal vector to an ellipsoid at the given cartesian
35
+ * coordinate `(x, y, z)`.
36
+ *
37
+ * @param cartesian - The given cartesian coordinate.
38
+ * @param target - An object to store this vector to. If this is not
39
+ * specified, a new vector will be created.
40
+ */
15
41
  geodeticSurfaceNormal(cartesian) {
16
42
  let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new THREE.Vector3();
17
43
  return cartesian.toVector3(target).multiply(this._invRadiiSquared).normalize();
18
44
  }
45
+
46
+ /**
47
+ * Computes the normal vector to an ellipsoid at the given geographic
48
+ * coordinate `(longitude, latitude, altitude)`.
49
+ *
50
+ * @param coordCarto - The given geographic coordinate.
51
+ * @param target - An object to store this vector to. If this is not
52
+ * specified, a new vector will be created.
53
+ */
19
54
  geodeticSurfaceNormalCartographic(coordCarto) {
20
55
  let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new THREE.Vector3();
21
56
  const longitude = THREE.MathUtils.degToRad(coordCarto.longitude);
@@ -23,13 +58,22 @@ class Ellipsoid {
23
58
  const cosLatitude = Math.cos(latitude);
24
59
  return target.set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude));
25
60
  }
61
+
62
+ /**
63
+ * Sets the length of the semi-axes of this ellipsoid from a 3-dimensional
64
+ * vector-like object. The object shall have both `x`, `y` and `z`
65
+ * properties.
66
+ *
67
+ * @param size - The source vector.
68
+ */
26
69
  setSize(size) {
27
70
  this.size.set(size.x, size.y, size.z);
28
71
  this._radiiSquared.multiplyVectors(size, size);
29
- this._invRadiiSquared.x = size.x == 0 ? 0 : 1 / this._radiiSquared.x;
30
- this._invRadiiSquared.y = size.y == 0 ? 0 : 1 / this._radiiSquared.y;
31
- this._invRadiiSquared.z = size.z == 0 ? 0 : 1 / this._radiiSquared.z;
72
+ this._invRadiiSquared.x = size.x === 0 ? 0 : 1 / this._radiiSquared.x;
73
+ this._invRadiiSquared.y = size.y === 0 ? 0 : 1 / this._radiiSquared.y;
74
+ this._invRadiiSquared.z = size.z === 0 ? 0 : 1 / this._radiiSquared.z;
32
75
  this.eccentricity = Math.sqrt(this._radiiSquared.x - this._radiiSquared.z) / this.size.x;
76
+ return this;
33
77
  }
34
78
  cartographicToCartesian(coordCarto) {
35
79
  let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new THREE.Vector3();
@@ -42,18 +86,18 @@ class Ellipsoid {
42
86
  }
43
87
 
44
88
  /**
45
- * Convert cartesian coordinates to geographic according to the current ellipsoid of revolution.
46
- * @param {Object} position - The coordinate to convert
47
- * @param {number} position.x
48
- * @param {number} position.y
49
- * @param {number} position.z
50
- * @param {Coordinate} [target] coordinate to copy result
51
- * @returns {Coordinate} an object describing the coordinates on the reference ellipsoid, angles are in degree
89
+ * Convert cartesian coordinates to geographic according to the current
90
+ * ellipsoid of revolution.
91
+ * @param position - The coordinate to convert
92
+ * @param target - coordinate to copy result
93
+ * @returns an object describing the coordinates on the reference ellipsoid,
94
+ * angles are in degree
52
95
  */
53
96
  cartesianToCartographic(position) {
54
97
  let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Coordinates('EPSG:4326', 0, 0, 0);
55
98
  // for details, see for example http://www.linz.govt.nz/data/geodetic-system/coordinate-conversion/geodetic-datum-conversions/equations-used-datum
56
- // TODO the following is only valable for oblate ellipsoid of revolution. do we want to support triaxial ellipsoid?
99
+ // TODO the following is only valable for oblate ellipsoid of
100
+ // revolution. do we want to support triaxial ellipsoid?
57
101
  const R = Math.sqrt(position.x * position.x + position.y * position.y + position.z * position.z);
58
102
  const a = this.size.x; // x
59
103
  const b = this.size.z; // z
@@ -92,9 +136,9 @@ class Ellipsoid {
92
136
  const t1 = (-b + d) / (2 * a);
93
137
  const t2 = (-b - d) / (2 * a);
94
138
  if (t1 <= EPSILON && t2 <= EPSILON) {
139
+ // both intersections are behind the ray origin
95
140
  return false;
96
- } // both intersections are behind the ray origin
97
- // var back = (t1 <= EPSILON || t2 <= EPSILON); // If only one intersection (t>0) then we are inside the ellipsoid and the intersection is at the back of the ellipsoid
141
+ }
98
142
  let t = 0;
99
143
  if (t1 <= EPSILON) {
100
144
  t = t2;
@@ -111,19 +155,16 @@ class Ellipsoid {
111
155
  inter.addVectors(ray.origin, dir.clone().setLength(t));
112
156
  return inter;
113
157
  }
114
- computeDistance(coordCarto1, coordCarto2) {
115
- console.warn('computeDistance is renamed to geodesicDistance');
116
- this.geodesicDistance(coordCarto1, coordCarto2);
117
- }
118
158
 
119
159
  /**
120
160
  * Calculate the geodesic distance, between coordCarto1 and coordCarto2.
121
- * It's most short distance on ellipsoid surface between coordCarto1 and coordCarto2.
161
+ * It's most short distance on ellipsoid surface between coordCarto1 and
162
+ * coordCarto2.
122
163
  * It's called orthodromy.
123
164
  *
124
- * @param {Coordinates} coordCarto1 The coordinate carto 1
125
- * @param {Coordinates} coordCarto2 The coordinate carto 2
126
- * @return {number} The orthodromic distance between the two given coordinates.
165
+ * @param coordCarto1 - The coordinate carto 1
166
+ * @param coordCarto2 - The coordinate carto 2
167
+ * @returns The orthodromic distance between the two given coordinates.
127
168
  */
128
169
  geodesicDistance(coordCarto1, coordCarto2) {
129
170
  // The formula uses the distance on approximated sphere,
@@ -173,7 +173,7 @@ class Camera {
173
173
  * @return {Coordinates} Coordinates object holding camera's position.
174
174
  */
175
175
  position(crs) {
176
- return new Coordinates(this.crs, this.camera3D.position).as(crs || this.crs);
176
+ return new Coordinates(this.crs).setFromVector3(this.camera3D.position).as(crs || this.crs);
177
177
  }
178
178
 
179
179
  /**
@@ -156,7 +156,7 @@ class CameraRig extends THREE.Object3D {
156
156
 
157
157
  // set rig's objects transformation from camera's position and target's position
158
158
  setFromPositions(view, cameraPosition) {
159
- this.setTargetFromCoordinate(view, new Coordinates(view.referenceCrs, targetPosition));
159
+ this.setTargetFromCoordinate(view, new Coordinates(view.referenceCrs).setFromVector3(targetPosition));
160
160
  this.target.rotation.set(0, 0, 0);
161
161
  this.updateMatrixWorld(true);
162
162
  this.camera.position.copy(cameraPosition);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itowns",
3
- "version": "2.44.3-next.29",
3
+ "version": "2.44.3-next.30",
4
4
  "description": "A JS/WebGL framework for 3D geospatial data visualization",
5
5
  "type": "module",
6
6
  "main": "lib/Main.js",
@@ -121,6 +121,7 @@
121
121
  "sinon": "^19.0.2",
122
122
  "three": "^0.168.0",
123
123
  "typescript": "^5.6.2",
124
+ "undici": "^7.2.0",
124
125
  "webgl-mock": "^0.1.7",
125
126
  "webpack": "^5.94.0",
126
127
  "webpack-cli": "^5.1.4",