Skip to content

Commit

Permalink
refactor(Coordinates/Extent): rename dimension and distance methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Nov 29, 2021
1 parent b535583 commit 6a436ac
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/Core/Geographic/Coordinates.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,17 @@ class Coordinates {
}

/**
* Calculate geodesic distance between this coordinates and `coord`.
* **Geodesic distance** is calculated in an ellispoid space as the distance
* Calculate geodetic distance between this coordinates and `coord`.
* **Geodetic distance** is calculated in an ellispoid space as the shortest distance
* across the curved surface of the world.
*
* => As the crow flies/ Orthodromy
*
* @param {Coordinates} coord The coordinate
* @return {number} geodesic distance
* @return {number} geodetic distance
*
*/
geodesicDistanceTo(coord) {
geodeticDistanceTo(coord) {
this.as('EPSG:4326', coord0);
coord.as('EPSG:4326', coord1);
return ellipsoid.geodesicDistance(coord0, coord1);
Expand All @@ -241,7 +241,7 @@ class Coordinates {
* @return {number} earth euclidean distance
*
*/
earthEuclideanDistanceTo(coord) {
spatialEuclideanDistanceTo(coord) {
this.as('EPSG:4978', coord0).toVector3(v0);
coord.as('EPSG:4978', coord1).toVector3(v1);
return v0.distanceTo(v1);
Expand Down
24 changes: 12 additions & 12 deletions src/Core/Geographic/Extent.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class Extent {
* @return {THREE.Vector2}
*/
dimensions(target = new THREE.Vector2()) {
console.warn('Extent.dimensions is deprecated, use planarDimensions, geodesicDimensions or geodesicChordDimensions');
console.warn('Extent.dimensions is deprecated, use planarDimensions, geodeticDimensions or spatialEuclideanDimensions');
target.x = Math.abs(this.east - this.west);
target.y = Math.abs(this.north - this.south);
return target;
Expand All @@ -277,14 +277,14 @@ class Extent {
}

/**
* Geodesic dimensions are two planar distances west/east and south/north.
* Geodesic distance is calculated in an ellispoid space as the distance
* Geodetic dimensions are two planar distances west/east and south/north.
* Geodetic distance is calculated in an ellispoid space as the distance
* across the curved surface of the world.
*
* @param {THREE.Vector2} [target=new THREE.Vector2()] The target
* @return {THREE.Vector2} Planar dimensions
* @return {THREE.Vector2} geodetic dimensions
*/
geodesicDimensions(target = new THREE.Vector2()) {
geodeticDimensions(target = new THREE.Vector2()) {
// set 3 corners extent
cNorthWest.crs = this.crs;
cSouthWest.crs = this.crs;
Expand All @@ -294,18 +294,18 @@ class Extent {
cSouthWest.setFromValues(this.west, this.south, 0);
cNorthEast.setFromValues(this.east, this.north, 0);

// calcul geodesic distance northWest/northEast and northWest/southWest
return target.set(cNorthWest.geodesicDistanceTo(cNorthEast), cNorthWest.geodesicDistanceTo(cSouthWest));
// calcul geodetic distance northWest/northEast and northWest/southWest
return target.set(cNorthWest.geodeticDistanceTo(cNorthEast), cNorthWest.geodeticDistanceTo(cSouthWest));
}

/**
* Earth euclidean dimensions are two earth euclidean distances between west/east and south/north.
* Earth euclidean distance chord is calculated in a ellispoid space.
* Spatial euclidean dimensions are two spatial euclidean distances between west/east corner and south/north corner.
* Spatial euclidean distance chord is calculated in a ellispoid space.
*
* @param {THREE.Vector2} [target=new THREE.Vector2()] The target
* @return {THREE.Vector2} Earth euclidean dimensions
* @return {THREE.Vector2} spatial euclidean dimensions
*/
earthEuclideanDimensions(target = new THREE.Vector2()) {
spatialEuclideanDimensions(target = new THREE.Vector2()) {
// set 3 corners extent
cNorthWest.crs = this.crs;
cSouthWest.crs = this.crs;
Expand All @@ -316,7 +316,7 @@ class Extent {
cNorthEast.setFromValues(this.east, this.north, 0);

// calcul chord distance northWest/northEast and northWest/southWest
return target.set(cNorthWest.earthEuclideanDistanceTo(cNorthEast), cNorthWest.earthEuclideanDistanceTo(cSouthWest));
return target.set(cNorthWest.spatialEuclideanDistanceTo(cNorthEast), cNorthWest.spatialEuclideanDistanceTo(cSouthWest));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions test/unit/coordinate.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@ describe('Coordinates', function () {
const coord0 = new Coordinates('EPSG:4326', 0, 45, 0);
const coord1 = new Coordinates('EPSG:4326', 1.83421, 46.2579066, 0);

const distance = coord0.geodesicDistanceTo(coord1) / 1000;
const distance = coord0.geodeticDistanceTo(coord1) / 1000;
assert.ok(Math.abs(distance - 200) < 0.01);
assert.equal(distance, coord1.geodesicDistanceTo(coord0) / 1000);
assert.equal(distance, coord1.geodeticDistanceTo(coord0) / 1000);
});

it('should correctly return earth euclidean distance to other coordinates', function () {
const coord0 = new Coordinates('EPSG:4326', 0, 45, 0);
const coord1 = new Coordinates('EPSG:4326', 1.83421, 46.2579066, 0);

const distance = coord0.earthEuclideanDistanceTo(coord1);
const distance = coord0.spatialEuclideanDistanceTo(coord1);
assert.equal(distance, 199991.80319097277);
assert.equal(distance, coord1.earthEuclideanDistanceTo(coord0));
assert.equal(distance, coord1.spatialEuclideanDistanceTo(coord0));
});
});
4 changes: 2 additions & 2 deletions test/unit/extent.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('Extent', function () {
const extent = new Extent('EPSG:4326', 3, 3.01, 46, 46.01);
const dimensions = new Vector2();

extent.earthEuclideanDimensions(dimensions);
extent.spatialEuclideanDimensions(dimensions);
assert.equal(dimensions.x, 774.4934293643765);
assert.equal(dimensions.y, 1111.5141604285038);
});
Expand All @@ -129,7 +129,7 @@ describe('Extent', function () {
const extent = new Extent('EPSG:4326', 3, 3.01, 46, 46.01);
const dimensions = new Vector2();

extent.geodesicDimensions(dimensions);
extent.geodeticDimensions(dimensions);
assert.equal(dimensions.x, 773.2375602074535);
assert.equal(dimensions.y, 1113.3197697640906);
});
Expand Down

0 comments on commit 6a436ac

Please sign in to comment.