@turf/bearing 6.5.0 → 7.0.0-alpha.1
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 +10 -11
- package/dist/js/index.d.ts +0 -0
- package/dist/js/index.js +12 -13
- package/package.json +11 -9
package/README.md
CHANGED
|
@@ -7,14 +7,15 @@
|
|
|
7
7
|
Takes two [points][1] and finds the geographic bearing between them,
|
|
8
8
|
i.e. the angle measured in degrees from 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 (optional, default `{}`)
|
|
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]);
|
package/dist/es/index.js
CHANGED
|
@@ -24,20 +24,19 @@ import { getCoord } from "@turf/invariant";
|
|
|
24
24
|
* point2.properties['marker-color'] = '#0f0'
|
|
25
25
|
* point1.properties.bearing = bearing
|
|
26
26
|
*/
|
|
27
|
-
export default function bearing(start, end, options) {
|
|
28
|
-
if (options === void 0) { options = {}; }
|
|
27
|
+
export default function bearing(start, end, options = {}) {
|
|
29
28
|
// Reverse calculation
|
|
30
29
|
if (options.final === true) {
|
|
31
30
|
return calculateFinalBearing(start, end);
|
|
32
31
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
const coordinates1 = getCoord(start);
|
|
33
|
+
const coordinates2 = getCoord(end);
|
|
34
|
+
const lon1 = degreesToRadians(coordinates1[0]);
|
|
35
|
+
const lon2 = degreesToRadians(coordinates2[0]);
|
|
36
|
+
const lat1 = degreesToRadians(coordinates1[1]);
|
|
37
|
+
const lat2 = degreesToRadians(coordinates2[1]);
|
|
38
|
+
const a = Math.sin(lon2 - lon1) * Math.cos(lat2);
|
|
39
|
+
const b = Math.cos(lat1) * Math.sin(lat2) -
|
|
41
40
|
Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1);
|
|
42
41
|
return radiansToDegrees(Math.atan2(a, b));
|
|
43
42
|
}
|
|
@@ -51,7 +50,7 @@ export default function bearing(start, end, options) {
|
|
|
51
50
|
*/
|
|
52
51
|
function calculateFinalBearing(start, end) {
|
|
53
52
|
// Swap start & end
|
|
54
|
-
|
|
53
|
+
let bear = bearing(end, start);
|
|
55
54
|
bear = (bear + 180) % 360;
|
|
56
55
|
return bear;
|
|
57
56
|
}
|
package/dist/js/index.d.ts
CHANGED
|
File without changes
|
package/dist/js/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const helpers_1 = require("@turf/helpers");
|
|
4
|
+
const invariant_1 = require("@turf/invariant");
|
|
5
5
|
// http://en.wikipedia.org/wiki/Haversine_formula
|
|
6
6
|
// http://www.movable-type.co.uk/scripts/latlong.html
|
|
7
7
|
/**
|
|
@@ -26,20 +26,19 @@ var invariant_1 = require("@turf/invariant");
|
|
|
26
26
|
* point2.properties['marker-color'] = '#0f0'
|
|
27
27
|
* point1.properties.bearing = bearing
|
|
28
28
|
*/
|
|
29
|
-
function bearing(start, end, options) {
|
|
30
|
-
if (options === void 0) { options = {}; }
|
|
29
|
+
function bearing(start, end, options = {}) {
|
|
31
30
|
// Reverse calculation
|
|
32
31
|
if (options.final === true) {
|
|
33
32
|
return calculateFinalBearing(start, end);
|
|
34
33
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
const coordinates1 = invariant_1.getCoord(start);
|
|
35
|
+
const coordinates2 = invariant_1.getCoord(end);
|
|
36
|
+
const lon1 = helpers_1.degreesToRadians(coordinates1[0]);
|
|
37
|
+
const lon2 = helpers_1.degreesToRadians(coordinates2[0]);
|
|
38
|
+
const lat1 = helpers_1.degreesToRadians(coordinates1[1]);
|
|
39
|
+
const lat2 = helpers_1.degreesToRadians(coordinates2[1]);
|
|
40
|
+
const a = Math.sin(lon2 - lon1) * Math.cos(lat2);
|
|
41
|
+
const b = Math.cos(lat1) * Math.sin(lat2) -
|
|
43
42
|
Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1);
|
|
44
43
|
return helpers_1.radiansToDegrees(Math.atan2(a, b));
|
|
45
44
|
}
|
|
@@ -54,7 +53,7 @@ exports.default = bearing;
|
|
|
54
53
|
*/
|
|
55
54
|
function calculateFinalBearing(start, end) {
|
|
56
55
|
// Swap start & end
|
|
57
|
-
|
|
56
|
+
let bear = bearing(end, start);
|
|
58
57
|
bear = (bear + 180) % 360;
|
|
59
58
|
return bear;
|
|
60
59
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/bearing",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.1",
|
|
4
4
|
"description": "turf bearing module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"exports": {
|
|
26
26
|
"./package.json": "./package.json",
|
|
27
27
|
".": {
|
|
28
|
+
"types": "./dist/js/index.d.ts",
|
|
28
29
|
"import": "./dist/es/index.js",
|
|
29
30
|
"require": "./dist/js/index.js"
|
|
30
31
|
}
|
|
@@ -35,28 +36,29 @@
|
|
|
35
36
|
"dist"
|
|
36
37
|
],
|
|
37
38
|
"scripts": {
|
|
38
|
-
"bench": "
|
|
39
|
+
"bench": "tsx bench.js",
|
|
39
40
|
"build": "npm-run-all build:*",
|
|
40
41
|
"build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
|
|
41
42
|
"build:js": "tsc",
|
|
42
|
-
"docs": "
|
|
43
|
+
"docs": "tsx ../../scripts/generate-readmes",
|
|
43
44
|
"test": "npm-run-all test:*",
|
|
44
|
-
"test:tape": "
|
|
45
|
+
"test:tape": "tsx test.js"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"@turf/destination": "^
|
|
48
|
+
"@turf/destination": "^7.0.0-alpha.1",
|
|
48
49
|
"@types/tape": "*",
|
|
49
50
|
"benchmark": "*",
|
|
50
51
|
"npm-run-all": "*",
|
|
51
52
|
"tape": "*",
|
|
52
|
-
"ts-node": "*",
|
|
53
53
|
"tslint": "*",
|
|
54
|
+
"tsx": "*",
|
|
54
55
|
"typescript": "*",
|
|
55
56
|
"write-json-file": "*"
|
|
56
57
|
},
|
|
57
58
|
"dependencies": {
|
|
58
|
-
"@turf/helpers": "^
|
|
59
|
-
"@turf/invariant": "^
|
|
59
|
+
"@turf/helpers": "^7.0.0-alpha.1",
|
|
60
|
+
"@turf/invariant": "^7.0.0-alpha.1",
|
|
61
|
+
"tslib": "^2.3.0"
|
|
60
62
|
},
|
|
61
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
|
|
62
64
|
}
|