@@ -8,53 +8,53 @@ export function calculate_bearing(old_coords, new_coords) {
88 const [ lat1 , lon1 ] = old_coords ;
99 const [ lat2 , lon2 ] = new_coords ;
1010
11- if ( lat1 == lat2 && lon1 == lon2 ) {
12- return null ;
13- }
14-
15- /*
16- Using simple trigonometry to calculate bearing
17- between two points on the Earth's surface.
18-
19- Using Great-circle bearing formula is not necessary
20- and too expensive for this task.
21-
22- The points are quite close to each other, so the
23- approximation is acceptable and the Earth's curvature
24- can be safely ignored.
25- */
26- const deltaLat = lat2 - lat1 ;
11+ if ( lat1 == lat2 && lon1 == lon2 ) {
12+ return null ;
13+ }
14+
15+ /*
16+ Using simple trigonometry to calculate bearing
17+ between two points on the Earth's surface.
18+
19+ Using Great-circle bearing formula is not necessary
20+ and too expensive for this task.
21+
22+ The points are quite close to each other, so the
23+ approximation is acceptable and the Earth's curvature
24+ can be safely ignored.
25+ */
26+ const deltaLat = lat2 - lat1 ;
2727 const deltaLon = lon2 - lon1 ;
2828 const bearingRad = Math . atan2 ( deltaLon , deltaLat ) ;
2929 const bearingDeg = toDegrees ( bearingRad ) ;
30- return ( ( bearingDeg + 180 ) % 360 ) . toFixed ( 0 ) ;
30+ return ( ( bearingDeg + 180 ) % 360 ) . toFixed ( 0 ) ;
3131}
3232
3333function toRadians ( degrees ) {
34- return degrees * ( Math . PI / 180 ) ;
34+ return degrees * ( Math . PI / 180 ) ;
3535}
3636
3737function toDegrees ( radians ) {
38- return radians * ( 180 / Math . PI ) ;
38+ return radians * ( 180 / Math . PI ) ;
3939}
4040
4141export function calculate_distance ( [ lat1 , lon1 ] , [ lat2 , lon2 ] ) {
4242 if ( lat1 == lat2 && lon1 == lon2 ) {
4343 return 0 ;
4444 }
4545
46- const R = 6371e3 ; // Earth radius in meters
47- const φ1 = toRadians ( lat1 ) ;
48- const φ2 = toRadians ( lat2 ) ;
49- const Δφ = toRadians ( lat2 - lat1 ) ;
50- const Δλ = toRadians ( lon2 - lon1 ) ;
46+ const R = 6371e3 ; // Earth radius in meters
47+ const phi1 = toRadians ( lat1 ) ;
48+ const phi2 = toRadians ( lat2 ) ;
49+ const deltaPhi = toRadians ( lat2 - lat1 ) ;
50+ const deltaLambda = toRadians ( lon2 - lon1 ) ;
5151
52- const a = Math . sin ( Δφ / 2 ) * Math . sin ( Δφ / 2 ) +
53- Math . cos ( φ1 ) * Math . cos ( φ2 ) *
54- Math . sin ( Δλ / 2 ) * Math . sin ( Δλ / 2 ) ;
55- const c = 2 * Math . atan2 ( Math . sqrt ( a ) , Math . sqrt ( 1 - a ) ) ;
52+ const a = Math . sin ( deltaPhi / 2 ) * Math . sin ( deltaPhi / 2 ) +
53+ Math . cos ( phi1 ) * Math . cos ( phi2 ) *
54+ Math . sin ( deltaLambda / 2 ) * Math . sin ( deltaLambda / 2 ) ;
55+ const c = 2 * Math . atan2 ( Math . sqrt ( a ) , Math . sqrt ( 1 - a ) ) ;
5656
57- return R * c ; // in meters
57+ return R * c ; // in meters
5858}
5959
6060export function proper_inv_number ( inv_number ) {
0 commit comments