Skip to content

Commit

Permalink
chore(Ellipsoid): add implicit return types
Browse files Browse the repository at this point in the history
  • Loading branch information
Desplandis committed Dec 18, 2024
1 parent b958ac5 commit 826f483
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/Core/Math/Ellipsoid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class Ellipsoid {
* @param target - An object to store this vector to. If this is not
* specified, a new vector will be created.
*/
geodeticSurfaceNormal(cartesian: Coordinates, target = new THREE.Vector3()) {
geodeticSurfaceNormal(
cartesian: Coordinates,
target = new THREE.Vector3(),
): THREE.Vector3 {
return cartesian.toVector3(target).multiply(this._invRadiiSquared).normalize();
}

Expand All @@ -59,7 +62,10 @@ class Ellipsoid {
* @param target - An object to store this vector to. If this is not
* specified, a new vector will be created.
*/
geodeticSurfaceNormalCartographic(coordCarto: Coordinates, target = new THREE.Vector3()) {
geodeticSurfaceNormalCartographic(
coordCarto: Coordinates,
target = new THREE.Vector3(),
): THREE.Vector3 {
const longitude = THREE.MathUtils.degToRad(coordCarto.longitude);
const latitude = THREE.MathUtils.degToRad(coordCarto.latitude);
const cosLatitude = Math.cos(latitude);
Expand Down Expand Up @@ -90,7 +96,10 @@ class Ellipsoid {
return this;
}

cartographicToCartesian(coordCarto: Coordinates, target = new THREE.Vector3()) {
cartographicToCartesian(
coordCarto: Coordinates,
target = new THREE.Vector3(),
): THREE.Vector3 {
normal.copy(coordCarto.geodesicNormal);

target.multiplyVectors(this._radiiSquared, normal);
Expand All @@ -115,7 +124,7 @@ class Ellipsoid {
cartesianToCartographic(
position: THREE.Vector3Like,
target = new Coordinates('EPSG:4326', 0, 0, 0),
) {
): Coordinates {
// for details, see for example http://www.linz.govt.nz/data/geodetic-system/coordinate-conversion/geodetic-datum-conversions/equations-used-datum
// TODO the following is only valable for oblate ellipsoid of
// revolution. do we want to support triaxial ellipsoid?
Expand Down Expand Up @@ -149,7 +158,7 @@ class Ellipsoid {
);
}

cartographicToCartesianArray(coordCartoArray: Coordinates[]) {
cartographicToCartesianArray(coordCartoArray: Coordinates[]): THREE.Vector3[] {
const cartesianArray = [];
for (let i = 0; i < coordCartoArray.length; i++) {
cartesianArray.push(this.cartographicToCartesian(coordCartoArray[i]));
Expand All @@ -158,7 +167,7 @@ class Ellipsoid {
return cartesianArray;
}

intersection(ray: THREE.Ray) {
intersection(ray: THREE.Ray): THREE.Vector3 | null {
const EPSILON = 0.0001;
const O_C = ray.origin;
const dir = ray.direction;
Expand All @@ -180,7 +189,7 @@ class Ellipsoid {
((O_C.z * O_C.z) * this._invRadiiSquared.z) - 1;

let d = ((b * b) - (4 * a * c));
if (d < 0 || a === 0 || b === 0 || c === 0) { return false; }
if (d < 0 || a === 0 || b === 0 || c === 0) { return null; }

d = Math.sqrt(d);

Expand All @@ -189,14 +198,14 @@ class Ellipsoid {

if (t1 <= EPSILON && t2 <= EPSILON) {
// both intersections are behind the ray origin
return false;
return null;
}

let t = 0;
if (t1 <= EPSILON) { t = t2; } else
if (t2 <= EPSILON) { t = t1; } else { t = (t1 < t2) ? t1 : t2; }

if (t < EPSILON) { return false; } // Too close to intersection
if (t < EPSILON) { return null; } // Too close to intersection

const inter = new THREE.Vector3();

Expand All @@ -215,7 +224,7 @@ class Ellipsoid {
* @param coordCarto2 - The coordinate carto 2
* @returns The orthodromic distance between the two given coordinates.
*/
geodesicDistance(coordCarto1: Coordinates, coordCarto2: Coordinates) {
geodesicDistance(coordCarto1: Coordinates, coordCarto2: Coordinates): number {
// The formula uses the distance on approximated sphere,
// with the nearest local radius of curvature of the ellipsoid
// https://geodesie.ign.fr/contenu/fichiers/Distance_longitude_latitude.pdf
Expand Down

0 comments on commit 826f483

Please sign in to comment.