@turf/rhumb-bearing 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 +8 -9
- package/dist/js/index.d.ts +0 -0
- package/dist/js/index.js +10 -11
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -7,14 +7,15 @@
|
|
|
7
7
|
Takes two [points][1] and finds the bearing angle between them along a Rhumb line
|
|
8
8
|
i.e. the angle measured in degrees start the north line (0 degrees)
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
### Parameters
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- `options.final` **[boolean][4]** calculates the final bearing if true (optional, default `false`)
|
|
12
|
+
* `start` **[Coord][2]** starting Point
|
|
13
|
+
* `end` **[Coord][2]** ending Point
|
|
14
|
+
* `options` **[Object][3]?** Optional parameters
|
|
16
15
|
|
|
17
|
-
**
|
|
16
|
+
* `options.final` **[boolean][4]** calculates the final bearing if true (optional, default `false`)
|
|
17
|
+
|
|
18
|
+
### Examples
|
|
18
19
|
|
|
19
20
|
```javascript
|
|
20
21
|
var point1 = turf.point([-75.343, 39.984], {"marker-color": "#F00"});
|
package/dist/es/index.js
CHANGED
|
@@ -22,16 +22,15 @@ import { getCoord } from "@turf/invariant";
|
|
|
22
22
|
* point1.properties.bearing = bearing;
|
|
23
23
|
* point2.properties.bearing = bearing;
|
|
24
24
|
*/
|
|
25
|
-
function rhumbBearing(start, end, options) {
|
|
26
|
-
|
|
27
|
-
var bear360;
|
|
25
|
+
function rhumbBearing(start, end, options = {}) {
|
|
26
|
+
let bear360;
|
|
28
27
|
if (options.final) {
|
|
29
28
|
bear360 = calculateRhumbBearing(getCoord(end), getCoord(start));
|
|
30
29
|
}
|
|
31
30
|
else {
|
|
32
31
|
bear360 = calculateRhumbBearing(getCoord(start), getCoord(end));
|
|
33
32
|
}
|
|
34
|
-
|
|
33
|
+
const bear180 = bear360 > 180 ? -(360 - bear360) : bear360;
|
|
35
34
|
return bear180;
|
|
36
35
|
}
|
|
37
36
|
/**
|
|
@@ -52,9 +51,9 @@ function calculateRhumbBearing(from, to) {
|
|
|
52
51
|
// Δλ => deltaLambda
|
|
53
52
|
// Δψ => deltaPsi
|
|
54
53
|
// θ => theta
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
const phi1 = degreesToRadians(from[1]);
|
|
55
|
+
const phi2 = degreesToRadians(to[1]);
|
|
56
|
+
let deltaLambda = degreesToRadians(to[0] - from[0]);
|
|
58
57
|
// if deltaLambdaon over 180° take shorter rhumb line across the anti-meridian:
|
|
59
58
|
if (deltaLambda > Math.PI) {
|
|
60
59
|
deltaLambda -= 2 * Math.PI;
|
|
@@ -62,8 +61,8 @@ function calculateRhumbBearing(from, to) {
|
|
|
62
61
|
if (deltaLambda < -Math.PI) {
|
|
63
62
|
deltaLambda += 2 * Math.PI;
|
|
64
63
|
}
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
const deltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
|
|
65
|
+
const theta = Math.atan2(deltaLambda, deltaPsi);
|
|
67
66
|
return (radiansToDegrees(theta) + 360) % 360;
|
|
68
67
|
}
|
|
69
68
|
export default rhumbBearing;
|
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
|
* Takes two {@link Point|points} and finds the bearing angle between them along a Rhumb line
|
|
8
8
|
* i.e. the angle measured in degrees start the north line (0 degrees)
|
|
@@ -24,16 +24,15 @@ var invariant_1 = require("@turf/invariant");
|
|
|
24
24
|
* point1.properties.bearing = bearing;
|
|
25
25
|
* point2.properties.bearing = bearing;
|
|
26
26
|
*/
|
|
27
|
-
function rhumbBearing(start, end, options) {
|
|
28
|
-
|
|
29
|
-
var bear360;
|
|
27
|
+
function rhumbBearing(start, end, options = {}) {
|
|
28
|
+
let bear360;
|
|
30
29
|
if (options.final) {
|
|
31
30
|
bear360 = calculateRhumbBearing(invariant_1.getCoord(end), invariant_1.getCoord(start));
|
|
32
31
|
}
|
|
33
32
|
else {
|
|
34
33
|
bear360 = calculateRhumbBearing(invariant_1.getCoord(start), invariant_1.getCoord(end));
|
|
35
34
|
}
|
|
36
|
-
|
|
35
|
+
const bear180 = bear360 > 180 ? -(360 - bear360) : bear360;
|
|
37
36
|
return bear180;
|
|
38
37
|
}
|
|
39
38
|
/**
|
|
@@ -54,9 +53,9 @@ function calculateRhumbBearing(from, to) {
|
|
|
54
53
|
// Δλ => deltaLambda
|
|
55
54
|
// Δψ => deltaPsi
|
|
56
55
|
// θ => theta
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
const phi1 = helpers_1.degreesToRadians(from[1]);
|
|
57
|
+
const phi2 = helpers_1.degreesToRadians(to[1]);
|
|
58
|
+
let deltaLambda = helpers_1.degreesToRadians(to[0] - from[0]);
|
|
60
59
|
// if deltaLambdaon over 180° take shorter rhumb line across the anti-meridian:
|
|
61
60
|
if (deltaLambda > Math.PI) {
|
|
62
61
|
deltaLambda -= 2 * Math.PI;
|
|
@@ -64,8 +63,8 @@ function calculateRhumbBearing(from, to) {
|
|
|
64
63
|
if (deltaLambda < -Math.PI) {
|
|
65
64
|
deltaLambda += 2 * Math.PI;
|
|
66
65
|
}
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
const deltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
|
|
67
|
+
const theta = Math.atan2(deltaLambda, deltaPsi);
|
|
69
68
|
return (helpers_1.radiansToDegrees(theta) + 360) % 360;
|
|
70
69
|
}
|
|
71
70
|
exports.default = rhumbBearing;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/rhumb-bearing",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.0",
|
|
4
4
|
"description": "turf rhumb-bearing 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
|
},
|
|
@@ -51,7 +52,7 @@
|
|
|
51
52
|
"test:tape": "ts-node -r esm test.js"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"@turf/destination": "^
|
|
55
|
+
"@turf/destination": "^7.0.0-alpha.0",
|
|
55
56
|
"@types/tape": "*",
|
|
56
57
|
"benchmark": "*",
|
|
57
58
|
"npm-run-all": "*",
|
|
@@ -62,8 +63,9 @@
|
|
|
62
63
|
"write-json-file": "*"
|
|
63
64
|
},
|
|
64
65
|
"dependencies": {
|
|
65
|
-
"@turf/helpers": "^
|
|
66
|
-
"@turf/invariant": "^
|
|
66
|
+
"@turf/helpers": "^7.0.0-alpha.0",
|
|
67
|
+
"@turf/invariant": "^7.0.0-alpha.0",
|
|
68
|
+
"tslib": "^2.3.0"
|
|
67
69
|
},
|
|
68
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
|
|
69
71
|
}
|