Comparing version 0.1.0-alpha1 to 0.1.0-alpha2
@@ -6,3 +6,4 @@ export * from './bearingTo'; | ||
export * from './greatCircleIntersection'; | ||
export * from './getDistanceBounds'; | ||
export * from './placeBearingDistance'; | ||
export * from './trig'; |
@@ -179,2 +179,51 @@ 'use strict'; | ||
/** | ||
* Returns the Southwest and Northeast corner of a box around a point with a minimum distance | ||
* @param centre - The centre of the box | ||
* @param distance - Half the side length of the box, the minimum distance to the centre | ||
*/ | ||
const getDistanceBounds = (centre, distance) => { | ||
const radLat = DEG_TO_RAD(centre.lat); | ||
const radLong = DEG_TO_RAD(centre.long); | ||
const radDist = distance / EARTH_RADIUS; | ||
let minLat = radLat - radDist; | ||
let maxLat = radLat + radDist; | ||
const MAX_LAT_RAD = DEG_TO_RAD(MAX_LAT); | ||
const MIN_LAT_RAD = DEG_TO_RAD(MIN_LAT); | ||
const MAX_LON_RAD = DEG_TO_RAD(MAX_LON); | ||
const MIN_LON_RAD = DEG_TO_RAD(MIN_LON); | ||
let minLong; | ||
let maxLong; | ||
if (minLat > MIN_LAT_RAD && maxLat < MAX_LAT_RAD) { | ||
const deltaLong = Math.asin(Math.sin(radDist) / Math.cos(radLat)); | ||
minLong = radLong - deltaLong; | ||
if (minLong < MIN_LON_RAD) { | ||
minLong += Math.PI * 2; | ||
} | ||
maxLong = radLong + deltaLong; | ||
if (maxLong > MAX_LON_RAD) { | ||
maxLong -= Math.PI * 2; | ||
} | ||
} | ||
else { | ||
// A pole is within the distance. | ||
minLat = Math.max(minLat, MIN_LAT_RAD); | ||
maxLat = Math.min(maxLat, MAX_LAT_RAD); | ||
minLong = MIN_LON_RAD; | ||
maxLong = MAX_LON_RAD; | ||
} | ||
return [ | ||
// Southwest | ||
{ | ||
lat: RAD_TO_DEG(minLat), | ||
long: RAD_TO_DEG(minLong), | ||
}, | ||
// Northeast | ||
{ | ||
lat: RAD_TO_DEG(maxLat), | ||
long: RAD_TO_DEG(maxLong), | ||
}, | ||
]; | ||
}; | ||
exports.DEG_TO_RAD = DEG_TO_RAD; | ||
@@ -199,2 +248,3 @@ exports.EARTH_RADIUS = EARTH_RADIUS; | ||
exports.distanceTo = distanceTo; | ||
exports.getDistanceBounds = getDistanceBounds; | ||
exports.greatCircleIntersection = greatCircleIntersection; | ||
@@ -201,0 +251,0 @@ exports.placeBearingDistance = placeBearingDistance; |
{ | ||
"name": "msfs-geo", | ||
"version": "0.1.0-alpha1", | ||
"version": "0.1.0-alpha2", | ||
"description": "A set of geographic mathematical utility functions, designed for use in aviation, hence the use of Nautical Miles, Feet, and Degrees", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84416
546