@wemap/geo 7.2.1 → 7.3.1

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/index.js CHANGED
@@ -4,6 +4,7 @@ export * as Utils from './src/Utils.js';
4
4
  /** Coordinates */
5
5
  export { default as BoundingBox } from './src/coordinates/BoundingBox.js';
6
6
  export { default as GeoRelativePosition } from './src/coordinates/GeoRelativePosition.js';
7
+ export { default as GeoRef } from './src/coordinates/GeoRef.js';
7
8
  export { default as Level } from './src/coordinates/Level.js';
8
9
  export { default as RelativePosition } from './src/coordinates/RelativePosition.js';
9
10
  export { default as Coordinates } from './src/coordinates/Coordinates.js';
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/geo"
13
13
  },
14
14
  "name": "@wemap/geo",
15
- "version": "7.2.1",
15
+ "version": "7.3.1",
16
16
  "bugs": {
17
17
  "url": "https://github.com/wemap/wemap-modules-js/issues"
18
18
  },
@@ -30,5 +30,5 @@
30
30
  "@wemap/logger": "^7.0.0",
31
31
  "@wemap/maths": "^7.0.0"
32
32
  },
33
- "gitHead": "64528ea2d1a6384ca0d33a794975960c38f25fe0"
33
+ "gitHead": "e5431db888821781448e7e05b047e2f4a5d8a1ce"
34
34
  }
@@ -38,10 +38,10 @@ class Coordinates {
38
38
  /**
39
39
  * @param {Number} lat
40
40
  * @param {Number} lng
41
- * @param {Number|null} alt
42
- * @param {Level|null} level
41
+ * @param {?(Number|null)} alt
42
+ * @param {?(Level|null)} level
43
43
  */
44
- constructor(lat, lng, alt, level) {
44
+ constructor(lat, lng, alt = null, level = null) {
45
45
  this.lat = lat;
46
46
  this.lng = lng;
47
47
  this.alt = alt;
@@ -0,0 +1,43 @@
1
+ import { Quaternion, Vector3 } from '@wemap/maths';
2
+
3
+ import Coordinates from './Coordinates.js';
4
+
5
+ class GeoRef {
6
+
7
+ /** @type {!Coordinates} */
8
+ origin;
9
+
10
+ /** @type {number} */
11
+ scale = 1;
12
+
13
+ /** @type {number} */
14
+ heading = 0;
15
+
16
+
17
+ /**
18
+ * @param {number[]} localPosition in ENU frame
19
+ * @returns {Coordinates}
20
+ */
21
+ localToWorld(localPosition) {
22
+ const localPositionScaled = Vector3.multiplyScalar(localPosition, this.scale);
23
+ const rotationOffset = Quaternion.fromAxisAngle([0, 0, 1], this.heading);
24
+ const ecefToEnuRotationOrigin = Quaternion.multiply(rotationOffset, this.origin.ecefToEnuRotation);
25
+ const ecefTranslation = Quaternion.rotate(ecefToEnuRotationOrigin, localPositionScaled);
26
+ const ecef = Vector3.add(this.origin.ecef, ecefTranslation);
27
+ return Coordinates.fromECEF(ecef);
28
+ }
29
+
30
+ /**
31
+ * @param {Coordinates} coords
32
+ * @returns {number[]} localPosition in ENU frame
33
+ */
34
+ worldToLocal(coords) {
35
+ const rotationOffset = Quaternion.fromAxisAngle([0, 0, 1], -this.heading);
36
+ const enuToEcefRotationOrigin = Quaternion.multiply(this.origin.enuToEcefRotation, rotationOffset);
37
+ const ecefTranslation = Vector3.subtract(coords.ecef, this.origin.ecef);
38
+ const ecefTranslationScaled = Vector3.multiplyScalar(ecefTranslation, 1 / this.scale);
39
+ return Quaternion.rotate(enuToEcefRotationOrigin, ecefTranslationScaled);
40
+ }
41
+ }
42
+
43
+ export default GeoRef;