@turf/rhumb-distance 6.4.0 → 7.0.0-alpha.0
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/README.md +7 -6
- package/dist/es/index.js +14 -15
- package/dist/js/index.d.ts +0 -0
- package/dist/js/index.js +16 -17
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -7,14 +7,15 @@
|
|
|
7
7
|
Calculates the distance along a rhumb line between two [points][1] in degrees, radians,
|
|
8
8
|
miles, or kilometers.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
### Parameters
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- `options.units` **[string][4]** can be degrees, radians, miles, or kilometers (optional, default `"kilometers"`)
|
|
12
|
+
* `from` **[Coord][2]** origin point
|
|
13
|
+
* `to` **[Coord][2]** destination point
|
|
14
|
+
* `options` **[Object][3]?** Optional parameters
|
|
16
15
|
|
|
17
|
-
**
|
|
16
|
+
* `options.units` **[string][4]** can be degrees, radians, miles, or kilometers (optional, default `"kilometers"`)
|
|
17
|
+
|
|
18
|
+
### Examples
|
|
18
19
|
|
|
19
20
|
```javascript
|
|
20
21
|
var from = turf.point([-75.343, 39.984]);
|
package/dist/es/index.js
CHANGED
|
@@ -23,10 +23,9 @@ import { getCoord } from "@turf/invariant";
|
|
|
23
23
|
* from.properties.distance = distance;
|
|
24
24
|
* to.properties.distance = distance;
|
|
25
25
|
*/
|
|
26
|
-
function rhumbDistance(from, to, options) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var destination = getCoord(to);
|
|
26
|
+
function rhumbDistance(from, to, options = {}) {
|
|
27
|
+
const origin = getCoord(from);
|
|
28
|
+
const destination = getCoord(to);
|
|
30
29
|
// compensate the crossing of the 180th meridian (https://macwright.org/2016/09/26/the-180th-meridian.html)
|
|
31
30
|
// solution from https://github.com/mapbox/mapbox-gl-js/issues/3250#issuecomment-294887678
|
|
32
31
|
destination[0] +=
|
|
@@ -35,8 +34,8 @@ function rhumbDistance(from, to, options) {
|
|
|
35
34
|
: origin[0] - destination[0] > 180
|
|
36
35
|
? 360
|
|
37
36
|
: 0;
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const distanceInMeters = calculateRhumbDistance(origin, destination);
|
|
38
|
+
const distance = convertLength(distanceInMeters, "meters", options.units);
|
|
40
39
|
return distance;
|
|
41
40
|
}
|
|
42
41
|
/**
|
|
@@ -63,22 +62,22 @@ function calculateRhumbDistance(origin, destination, radius) {
|
|
|
63
62
|
// θ => theta
|
|
64
63
|
radius = radius === undefined ? earthRadius : Number(radius);
|
|
65
64
|
// see www.edwilliams.org/avform.htm#Rhumb
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
const R = radius;
|
|
66
|
+
const phi1 = (origin[1] * Math.PI) / 180;
|
|
67
|
+
const phi2 = (destination[1] * Math.PI) / 180;
|
|
68
|
+
const DeltaPhi = phi2 - phi1;
|
|
69
|
+
let DeltaLambda = (Math.abs(destination[0] - origin[0]) * Math.PI) / 180;
|
|
71
70
|
// if dLon over 180° take shorter rhumb line across the anti-meridian:
|
|
72
71
|
if (DeltaLambda > Math.PI) {
|
|
73
72
|
DeltaLambda -= 2 * Math.PI;
|
|
74
73
|
}
|
|
75
74
|
// on Mercator projection, longitude distances shrink by latitude; q is the 'stretch factor'
|
|
76
75
|
// q becomes ill-conditioned along E-W line (0/0); use empirical tolerance to avoid it
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
const DeltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
|
|
77
|
+
const q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
|
|
79
78
|
// distance is pythagoras on 'stretched' Mercator projection
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
const delta = Math.sqrt(DeltaPhi * DeltaPhi + q * q * DeltaLambda * DeltaLambda); // angular distance in radians
|
|
80
|
+
const dist = delta * R;
|
|
82
81
|
return dist;
|
|
83
82
|
}
|
|
84
83
|
export default rhumbDistance;
|
package/dist/js/index.d.ts
CHANGED
|
File without changes
|
package/dist/js/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
// https://en.wikipedia.org/wiki/Rhumb_line
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const helpers_1 = require("@turf/helpers");
|
|
5
|
+
const invariant_1 = require("@turf/invariant");
|
|
6
6
|
/**
|
|
7
7
|
* Calculates the distance along a rhumb line between two {@link Point|points} in degrees, radians,
|
|
8
8
|
* miles, or kilometers.
|
|
@@ -25,10 +25,9 @@ var invariant_1 = require("@turf/invariant");
|
|
|
25
25
|
* from.properties.distance = distance;
|
|
26
26
|
* to.properties.distance = distance;
|
|
27
27
|
*/
|
|
28
|
-
function rhumbDistance(from, to, options) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var destination = invariant_1.getCoord(to);
|
|
28
|
+
function rhumbDistance(from, to, options = {}) {
|
|
29
|
+
const origin = invariant_1.getCoord(from);
|
|
30
|
+
const destination = invariant_1.getCoord(to);
|
|
32
31
|
// compensate the crossing of the 180th meridian (https://macwright.org/2016/09/26/the-180th-meridian.html)
|
|
33
32
|
// solution from https://github.com/mapbox/mapbox-gl-js/issues/3250#issuecomment-294887678
|
|
34
33
|
destination[0] +=
|
|
@@ -37,8 +36,8 @@ function rhumbDistance(from, to, options) {
|
|
|
37
36
|
: origin[0] - destination[0] > 180
|
|
38
37
|
? 360
|
|
39
38
|
: 0;
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
const distanceInMeters = calculateRhumbDistance(origin, destination);
|
|
40
|
+
const distance = helpers_1.convertLength(distanceInMeters, "meters", options.units);
|
|
42
41
|
return distance;
|
|
43
42
|
}
|
|
44
43
|
/**
|
|
@@ -65,22 +64,22 @@ function calculateRhumbDistance(origin, destination, radius) {
|
|
|
65
64
|
// θ => theta
|
|
66
65
|
radius = radius === undefined ? helpers_1.earthRadius : Number(radius);
|
|
67
66
|
// see www.edwilliams.org/avform.htm#Rhumb
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
const R = radius;
|
|
68
|
+
const phi1 = (origin[1] * Math.PI) / 180;
|
|
69
|
+
const phi2 = (destination[1] * Math.PI) / 180;
|
|
70
|
+
const DeltaPhi = phi2 - phi1;
|
|
71
|
+
let DeltaLambda = (Math.abs(destination[0] - origin[0]) * Math.PI) / 180;
|
|
73
72
|
// if dLon over 180° take shorter rhumb line across the anti-meridian:
|
|
74
73
|
if (DeltaLambda > Math.PI) {
|
|
75
74
|
DeltaLambda -= 2 * Math.PI;
|
|
76
75
|
}
|
|
77
76
|
// on Mercator projection, longitude distances shrink by latitude; q is the 'stretch factor'
|
|
78
77
|
// q becomes ill-conditioned along E-W line (0/0); use empirical tolerance to avoid it
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
const DeltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
|
|
79
|
+
const q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
|
|
81
80
|
// distance is pythagoras on 'stretched' Mercator projection
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
const delta = Math.sqrt(DeltaPhi * DeltaPhi + q * q * DeltaLambda * DeltaLambda); // angular distance in radians
|
|
82
|
+
const dist = delta * R;
|
|
84
83
|
return dist;
|
|
85
84
|
}
|
|
86
85
|
exports.default = rhumbDistance;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/rhumb-distance",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.0",
|
|
4
4
|
"description": "turf rhumb-distance module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"type": "git",
|
|
18
18
|
"url": "git://github.com/Turfjs/turf.git"
|
|
19
19
|
},
|
|
20
|
+
"funding": "https://opencollective.com/turf",
|
|
20
21
|
"publishConfig": {
|
|
21
22
|
"access": "public"
|
|
22
23
|
},
|
|
@@ -53,7 +54,7 @@
|
|
|
53
54
|
"test:tape": "ts-node -r esm test.js"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@turf/distance": "^
|
|
57
|
+
"@turf/distance": "^7.0.0-alpha.0",
|
|
57
58
|
"@types/tape": "*",
|
|
58
59
|
"benchmark": "*",
|
|
59
60
|
"load-json-file": "*",
|
|
@@ -65,8 +66,9 @@
|
|
|
65
66
|
"write-json-file": "*"
|
|
66
67
|
},
|
|
67
68
|
"dependencies": {
|
|
68
|
-
"@turf/helpers": "^
|
|
69
|
-
"@turf/invariant": "^
|
|
69
|
+
"@turf/helpers": "^7.0.0-alpha.0",
|
|
70
|
+
"@turf/invariant": "^7.0.0-alpha.0",
|
|
71
|
+
"tslib": "^2.3.0"
|
|
70
72
|
},
|
|
71
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
|
|
72
74
|
}
|