@turf/rhumb-bearing 7.0.0-alpha.2 → 7.0.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 +4 -9
- package/dist/cjs/index.cjs +40 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +28 -0
- package/dist/{js → esm}/index.d.ts +4 -2
- package/dist/esm/index.js +40 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +32 -27
- package/dist/es/index.js +0 -68
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -70
package/README.md
CHANGED
|
@@ -41,26 +41,21 @@ Returns **[number][5]** bearing from north in decimal degrees, between -180 and
|
|
|
41
41
|
|
|
42
42
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
43
43
|
|
|
44
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
45
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
46
|
-
./scripts/generate-readmes in the turf project. -->
|
|
44
|
+
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
|
|
47
45
|
|
|
48
46
|
---
|
|
49
47
|
|
|
50
|
-
This module is part of the [Turfjs project](
|
|
51
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
52
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
53
|
-
PRs and issues.
|
|
48
|
+
This module is part of the [Turfjs project](https://turfjs.org/), an open source module collection dedicated to geographic algorithms. It is maintained in the [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create PRs and issues.
|
|
54
49
|
|
|
55
50
|
### Installation
|
|
56
51
|
|
|
57
|
-
Install this module individually:
|
|
52
|
+
Install this single module individually:
|
|
58
53
|
|
|
59
54
|
```sh
|
|
60
55
|
$ npm install @turf/rhumb-bearing
|
|
61
56
|
```
|
|
62
57
|
|
|
63
|
-
Or install the
|
|
58
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
64
59
|
|
|
65
60
|
```sh
|
|
66
61
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
var _helpers = require('@turf/helpers');
|
|
6
|
+
var _invariant = require('@turf/invariant');
|
|
7
|
+
function rhumbBearing(start, end, options = {}) {
|
|
8
|
+
let bear360;
|
|
9
|
+
if (options.final) {
|
|
10
|
+
bear360 = calculateRhumbBearing(_invariant.getCoord.call(void 0, end), _invariant.getCoord.call(void 0, start));
|
|
11
|
+
} else {
|
|
12
|
+
bear360 = calculateRhumbBearing(_invariant.getCoord.call(void 0, start), _invariant.getCoord.call(void 0, end));
|
|
13
|
+
}
|
|
14
|
+
const bear180 = bear360 > 180 ? -(360 - bear360) : bear360;
|
|
15
|
+
return bear180;
|
|
16
|
+
}
|
|
17
|
+
__name(rhumbBearing, "rhumbBearing");
|
|
18
|
+
function calculateRhumbBearing(from, to) {
|
|
19
|
+
const phi1 = _helpers.degreesToRadians.call(void 0, from[1]);
|
|
20
|
+
const phi2 = _helpers.degreesToRadians.call(void 0, to[1]);
|
|
21
|
+
let deltaLambda = _helpers.degreesToRadians.call(void 0, to[0] - from[0]);
|
|
22
|
+
if (deltaLambda > Math.PI) {
|
|
23
|
+
deltaLambda -= 2 * Math.PI;
|
|
24
|
+
}
|
|
25
|
+
if (deltaLambda < -Math.PI) {
|
|
26
|
+
deltaLambda += 2 * Math.PI;
|
|
27
|
+
}
|
|
28
|
+
const deltaPsi = Math.log(
|
|
29
|
+
Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4)
|
|
30
|
+
);
|
|
31
|
+
const theta = Math.atan2(deltaLambda, deltaPsi);
|
|
32
|
+
return (_helpers.radiansToDegrees.call(void 0, theta) + 360) % 360;
|
|
33
|
+
}
|
|
34
|
+
__name(calculateRhumbBearing, "calculateRhumbBearing");
|
|
35
|
+
var turf_rhumb_bearing_default = rhumbBearing;
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
exports.default = turf_rhumb_bearing_default; exports.rhumbBearing = rhumbBearing;
|
|
40
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AACA,SAAgB,kBAAkB,wBAAwB;AAC1D,SAAS,gBAAgB;AAuBzB,SAAS,aACP,OACA,KACA,UAA+B,CAAC,GACxB;AACR,MAAI;AACJ,MAAI,QAAQ,OAAO;AACjB,cAAU,sBAAsB,SAAS,GAAG,GAAG,SAAS,KAAK,CAAC;AAAA,EAChE,OAAO;AACL,cAAU,sBAAsB,SAAS,KAAK,GAAG,SAAS,GAAG,CAAC;AAAA,EAChE;AAEA,QAAM,UAAU,UAAU,MAAM,EAAE,MAAM,WAAW;AAEnD,SAAO;AACT;AAfS;AA8BT,SAAS,sBAAsB,MAAgB,IAAc;AAK3D,QAAM,OAAO,iBAAiB,KAAK,CAAC,CAAC;AACrC,QAAM,OAAO,iBAAiB,GAAG,CAAC,CAAC;AACnC,MAAI,cAAc,iBAAiB,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC;AAElD,MAAI,cAAc,KAAK,IAAI;AACzB,mBAAe,IAAI,KAAK;AAAA,EAC1B;AACA,MAAI,cAAc,CAAC,KAAK,IAAI;AAC1B,mBAAe,IAAI,KAAK;AAAA,EAC1B;AAEA,QAAM,WAAW,KAAK;AAAA,IACpB,KAAK,IAAI,OAAO,IAAI,KAAK,KAAK,CAAC,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK,KAAK,CAAC;AAAA,EACpE;AAEA,QAAM,QAAQ,KAAK,MAAM,aAAa,QAAQ;AAE9C,UAAQ,iBAAiB,KAAK,IAAI,OAAO;AAC3C;AAvBS;AA0BT,IAAO,6BAAQ","sourcesContent":["// https://en.wikipedia.org/wiki/Rhumb_line\nimport { Coord, degreesToRadians, radiansToDegrees } from \"@turf/helpers\";\nimport { getCoord } from \"@turf/invariant\";\n\n/**\n * Takes two {@link Point|points} and finds the bearing angle between them along a Rhumb line\n * i.e. the angle measured in degrees start the north line (0 degrees)\n *\n * @name rhumbBearing\n * @param {Coord} start starting Point\n * @param {Coord} end ending Point\n * @param {Object} [options] Optional parameters\n * @param {boolean} [options.final=false] calculates the final bearing if true\n * @returns {number} bearing from north in decimal degrees, between -180 and 180 degrees (positive clockwise)\n * @example\n * var point1 = turf.point([-75.343, 39.984], {\"marker-color\": \"#F00\"});\n * var point2 = turf.point([-75.534, 39.123], {\"marker-color\": \"#00F\"});\n *\n * var bearing = turf.rhumbBearing(point1, point2);\n *\n * //addToMap\n * var addToMap = [point1, point2];\n * point1.properties.bearing = bearing;\n * point2.properties.bearing = bearing;\n */\nfunction rhumbBearing(\n start: Coord,\n end: Coord,\n options: { final?: boolean } = {}\n): number {\n let bear360;\n if (options.final) {\n bear360 = calculateRhumbBearing(getCoord(end), getCoord(start));\n } else {\n bear360 = calculateRhumbBearing(getCoord(start), getCoord(end));\n }\n\n const bear180 = bear360 > 180 ? -(360 - bear360) : bear360;\n\n return bear180;\n}\n\n/**\n * Returns the bearing from ‘this’ point to destination point along a rhumb line.\n * Adapted from Geodesy: https://github.com/chrisveness/geodesy/blob/master/latlon-spherical.js\n *\n * @private\n * @param {Array<number>} from - origin point.\n * @param {Array<number>} to - destination point.\n * @returns {number} Bearing in degrees from north.\n * @example\n * var p1 = new LatLon(51.127, 1.338);\n * var p2 = new LatLon(50.964, 1.853);\n * var d = p1.rhumbBearingTo(p2); // 116.7 m\n */\nfunction calculateRhumbBearing(from: number[], to: number[]) {\n // φ => phi\n // Δλ => deltaLambda\n // Δψ => deltaPsi\n // θ => theta\n const phi1 = degreesToRadians(from[1]);\n const phi2 = degreesToRadians(to[1]);\n let deltaLambda = degreesToRadians(to[0] - from[0]);\n // if deltaLambdaon over 180° take shorter rhumb line across the anti-meridian:\n if (deltaLambda > Math.PI) {\n deltaLambda -= 2 * Math.PI;\n }\n if (deltaLambda < -Math.PI) {\n deltaLambda += 2 * Math.PI;\n }\n\n const deltaPsi = Math.log(\n Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4)\n );\n\n const theta = Math.atan2(deltaLambda, deltaPsi);\n\n return (radiansToDegrees(theta) + 360) % 360;\n}\n\nexport { rhumbBearing };\nexport default rhumbBearing;\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Coord } from '@turf/helpers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Takes two {@link Point|points} and finds the bearing angle between them along a Rhumb line
|
|
5
|
+
* i.e. the angle measured in degrees start the north line (0 degrees)
|
|
6
|
+
*
|
|
7
|
+
* @name rhumbBearing
|
|
8
|
+
* @param {Coord} start starting Point
|
|
9
|
+
* @param {Coord} end ending Point
|
|
10
|
+
* @param {Object} [options] Optional parameters
|
|
11
|
+
* @param {boolean} [options.final=false] calculates the final bearing if true
|
|
12
|
+
* @returns {number} bearing from north in decimal degrees, between -180 and 180 degrees (positive clockwise)
|
|
13
|
+
* @example
|
|
14
|
+
* var point1 = turf.point([-75.343, 39.984], {"marker-color": "#F00"});
|
|
15
|
+
* var point2 = turf.point([-75.534, 39.123], {"marker-color": "#00F"});
|
|
16
|
+
*
|
|
17
|
+
* var bearing = turf.rhumbBearing(point1, point2);
|
|
18
|
+
*
|
|
19
|
+
* //addToMap
|
|
20
|
+
* var addToMap = [point1, point2];
|
|
21
|
+
* point1.properties.bearing = bearing;
|
|
22
|
+
* point2.properties.bearing = bearing;
|
|
23
|
+
*/
|
|
24
|
+
declare function rhumbBearing(start: Coord, end: Coord, options?: {
|
|
25
|
+
final?: boolean;
|
|
26
|
+
}): number;
|
|
27
|
+
|
|
28
|
+
export { rhumbBearing as default, rhumbBearing };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Coord } from
|
|
1
|
+
import { Coord } from '@turf/helpers';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Takes two {@link Point|points} and finds the bearing angle between them along a Rhumb line
|
|
4
5
|
* i.e. the angle measured in degrees start the north line (0 degrees)
|
|
@@ -23,4 +24,5 @@ import { Coord } from "@turf/helpers";
|
|
|
23
24
|
declare function rhumbBearing(start: Coord, end: Coord, options?: {
|
|
24
25
|
final?: boolean;
|
|
25
26
|
}): number;
|
|
26
|
-
|
|
27
|
+
|
|
28
|
+
export { rhumbBearing as default, rhumbBearing };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
import { degreesToRadians, radiansToDegrees } from "@turf/helpers";
|
|
6
|
+
import { getCoord } from "@turf/invariant";
|
|
7
|
+
function rhumbBearing(start, end, options = {}) {
|
|
8
|
+
let bear360;
|
|
9
|
+
if (options.final) {
|
|
10
|
+
bear360 = calculateRhumbBearing(getCoord(end), getCoord(start));
|
|
11
|
+
} else {
|
|
12
|
+
bear360 = calculateRhumbBearing(getCoord(start), getCoord(end));
|
|
13
|
+
}
|
|
14
|
+
const bear180 = bear360 > 180 ? -(360 - bear360) : bear360;
|
|
15
|
+
return bear180;
|
|
16
|
+
}
|
|
17
|
+
__name(rhumbBearing, "rhumbBearing");
|
|
18
|
+
function calculateRhumbBearing(from, to) {
|
|
19
|
+
const phi1 = degreesToRadians(from[1]);
|
|
20
|
+
const phi2 = degreesToRadians(to[1]);
|
|
21
|
+
let deltaLambda = degreesToRadians(to[0] - from[0]);
|
|
22
|
+
if (deltaLambda > Math.PI) {
|
|
23
|
+
deltaLambda -= 2 * Math.PI;
|
|
24
|
+
}
|
|
25
|
+
if (deltaLambda < -Math.PI) {
|
|
26
|
+
deltaLambda += 2 * Math.PI;
|
|
27
|
+
}
|
|
28
|
+
const deltaPsi = Math.log(
|
|
29
|
+
Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4)
|
|
30
|
+
);
|
|
31
|
+
const theta = Math.atan2(deltaLambda, deltaPsi);
|
|
32
|
+
return (radiansToDegrees(theta) + 360) % 360;
|
|
33
|
+
}
|
|
34
|
+
__name(calculateRhumbBearing, "calculateRhumbBearing");
|
|
35
|
+
var turf_rhumb_bearing_default = rhumbBearing;
|
|
36
|
+
export {
|
|
37
|
+
turf_rhumb_bearing_default as default,
|
|
38
|
+
rhumbBearing
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["// https://en.wikipedia.org/wiki/Rhumb_line\nimport { Coord, degreesToRadians, radiansToDegrees } from \"@turf/helpers\";\nimport { getCoord } from \"@turf/invariant\";\n\n/**\n * Takes two {@link Point|points} and finds the bearing angle between them along a Rhumb line\n * i.e. the angle measured in degrees start the north line (0 degrees)\n *\n * @name rhumbBearing\n * @param {Coord} start starting Point\n * @param {Coord} end ending Point\n * @param {Object} [options] Optional parameters\n * @param {boolean} [options.final=false] calculates the final bearing if true\n * @returns {number} bearing from north in decimal degrees, between -180 and 180 degrees (positive clockwise)\n * @example\n * var point1 = turf.point([-75.343, 39.984], {\"marker-color\": \"#F00\"});\n * var point2 = turf.point([-75.534, 39.123], {\"marker-color\": \"#00F\"});\n *\n * var bearing = turf.rhumbBearing(point1, point2);\n *\n * //addToMap\n * var addToMap = [point1, point2];\n * point1.properties.bearing = bearing;\n * point2.properties.bearing = bearing;\n */\nfunction rhumbBearing(\n start: Coord,\n end: Coord,\n options: { final?: boolean } = {}\n): number {\n let bear360;\n if (options.final) {\n bear360 = calculateRhumbBearing(getCoord(end), getCoord(start));\n } else {\n bear360 = calculateRhumbBearing(getCoord(start), getCoord(end));\n }\n\n const bear180 = bear360 > 180 ? -(360 - bear360) : bear360;\n\n return bear180;\n}\n\n/**\n * Returns the bearing from ‘this’ point to destination point along a rhumb line.\n * Adapted from Geodesy: https://github.com/chrisveness/geodesy/blob/master/latlon-spherical.js\n *\n * @private\n * @param {Array<number>} from - origin point.\n * @param {Array<number>} to - destination point.\n * @returns {number} Bearing in degrees from north.\n * @example\n * var p1 = new LatLon(51.127, 1.338);\n * var p2 = new LatLon(50.964, 1.853);\n * var d = p1.rhumbBearingTo(p2); // 116.7 m\n */\nfunction calculateRhumbBearing(from: number[], to: number[]) {\n // φ => phi\n // Δλ => deltaLambda\n // Δψ => deltaPsi\n // θ => theta\n const phi1 = degreesToRadians(from[1]);\n const phi2 = degreesToRadians(to[1]);\n let deltaLambda = degreesToRadians(to[0] - from[0]);\n // if deltaLambdaon over 180° take shorter rhumb line across the anti-meridian:\n if (deltaLambda > Math.PI) {\n deltaLambda -= 2 * Math.PI;\n }\n if (deltaLambda < -Math.PI) {\n deltaLambda += 2 * Math.PI;\n }\n\n const deltaPsi = Math.log(\n Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4)\n );\n\n const theta = Math.atan2(deltaLambda, deltaPsi);\n\n return (radiansToDegrees(theta) + 360) % 360;\n}\n\nexport { rhumbBearing };\nexport default rhumbBearing;\n"],"mappings":";;;;AACA,SAAgB,kBAAkB,wBAAwB;AAC1D,SAAS,gBAAgB;AAuBzB,SAAS,aACP,OACA,KACA,UAA+B,CAAC,GACxB;AACR,MAAI;AACJ,MAAI,QAAQ,OAAO;AACjB,cAAU,sBAAsB,SAAS,GAAG,GAAG,SAAS,KAAK,CAAC;AAAA,EAChE,OAAO;AACL,cAAU,sBAAsB,SAAS,KAAK,GAAG,SAAS,GAAG,CAAC;AAAA,EAChE;AAEA,QAAM,UAAU,UAAU,MAAM,EAAE,MAAM,WAAW;AAEnD,SAAO;AACT;AAfS;AA8BT,SAAS,sBAAsB,MAAgB,IAAc;AAK3D,QAAM,OAAO,iBAAiB,KAAK,CAAC,CAAC;AACrC,QAAM,OAAO,iBAAiB,GAAG,CAAC,CAAC;AACnC,MAAI,cAAc,iBAAiB,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC;AAElD,MAAI,cAAc,KAAK,IAAI;AACzB,mBAAe,IAAI,KAAK;AAAA,EAC1B;AACA,MAAI,cAAc,CAAC,KAAK,IAAI;AAC1B,mBAAe,IAAI,KAAK;AAAA,EAC1B;AAEA,QAAM,WAAW,KAAK;AAAA,IACpB,KAAK,IAAI,OAAO,IAAI,KAAK,KAAK,CAAC,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK,KAAK,CAAC;AAAA,EACpE;AAEA,QAAM,QAAQ,KAAK,MAAM,aAAa,QAAQ;AAE9C,UAAQ,iBAAiB,KAAK,IAAI,OAAO;AAC3C;AAvBS;AA0BT,IAAO,6BAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/rhumb-bearing",
|
|
3
|
-
"version": "7.0.0
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "turf rhumb-bearing module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -28,45 +28,50 @@
|
|
|
28
28
|
"rhumb",
|
|
29
29
|
"rhumb line"
|
|
30
30
|
],
|
|
31
|
-
"
|
|
32
|
-
"
|
|
31
|
+
"type": "module",
|
|
32
|
+
"main": "dist/cjs/index.cjs",
|
|
33
|
+
"module": "dist/esm/index.js",
|
|
34
|
+
"types": "dist/esm/index.d.ts",
|
|
33
35
|
"exports": {
|
|
34
36
|
"./package.json": "./package.json",
|
|
35
37
|
".": {
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/esm/index.d.ts",
|
|
40
|
+
"default": "./dist/esm/index.js"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./dist/cjs/index.d.cts",
|
|
44
|
+
"default": "./dist/cjs/index.cjs"
|
|
45
|
+
}
|
|
39
46
|
}
|
|
40
47
|
},
|
|
41
|
-
"types": "dist/js/index.d.ts",
|
|
42
48
|
"sideEffects": false,
|
|
43
49
|
"files": [
|
|
44
50
|
"dist"
|
|
45
51
|
],
|
|
46
52
|
"scripts": {
|
|
47
|
-
"bench": "tsx bench.
|
|
48
|
-
"build": "
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"test": "npm-run-all test:*",
|
|
53
|
-
"test:tape": "tsx test.js"
|
|
53
|
+
"bench": "tsx bench.ts",
|
|
54
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
55
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
56
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
57
|
+
"test:tape": "tsx test.ts"
|
|
54
58
|
},
|
|
55
59
|
"devDependencies": {
|
|
56
|
-
"@turf/destination": "^7.0.0
|
|
57
|
-
"@types/
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
60
|
+
"@turf/destination": "^7.0.0",
|
|
61
|
+
"@types/benchmark": "^2.1.5",
|
|
62
|
+
"@types/tape": "^4.2.32",
|
|
63
|
+
"benchmark": "^2.1.4",
|
|
64
|
+
"npm-run-all": "^4.1.5",
|
|
65
|
+
"tape": "^5.7.2",
|
|
66
|
+
"tsup": "^8.0.1",
|
|
67
|
+
"tsx": "^4.6.2",
|
|
68
|
+
"typescript": "^5.2.2",
|
|
69
|
+
"write-json-file": "^5.0.0"
|
|
65
70
|
},
|
|
66
71
|
"dependencies": {
|
|
67
|
-
"@turf/helpers": "^7.0.0
|
|
68
|
-
"@turf/invariant": "^7.0.0
|
|
69
|
-
"tslib": "^2.
|
|
72
|
+
"@turf/helpers": "^7.0.0",
|
|
73
|
+
"@turf/invariant": "^7.0.0",
|
|
74
|
+
"tslib": "^2.6.2"
|
|
70
75
|
},
|
|
71
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "3d3a7917025fbabe191dbddbc89754b86f9c7739"
|
|
72
77
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// https://en.wikipedia.org/wiki/Rhumb_line
|
|
2
|
-
import { degreesToRadians, radiansToDegrees } from "@turf/helpers";
|
|
3
|
-
import { getCoord } from "@turf/invariant";
|
|
4
|
-
/**
|
|
5
|
-
* Takes two {@link Point|points} and finds the bearing angle between them along a Rhumb line
|
|
6
|
-
* i.e. the angle measured in degrees start the north line (0 degrees)
|
|
7
|
-
*
|
|
8
|
-
* @name rhumbBearing
|
|
9
|
-
* @param {Coord} start starting Point
|
|
10
|
-
* @param {Coord} end ending Point
|
|
11
|
-
* @param {Object} [options] Optional parameters
|
|
12
|
-
* @param {boolean} [options.final=false] calculates the final bearing if true
|
|
13
|
-
* @returns {number} bearing from north in decimal degrees, between -180 and 180 degrees (positive clockwise)
|
|
14
|
-
* @example
|
|
15
|
-
* var point1 = turf.point([-75.343, 39.984], {"marker-color": "#F00"});
|
|
16
|
-
* var point2 = turf.point([-75.534, 39.123], {"marker-color": "#00F"});
|
|
17
|
-
*
|
|
18
|
-
* var bearing = turf.rhumbBearing(point1, point2);
|
|
19
|
-
*
|
|
20
|
-
* //addToMap
|
|
21
|
-
* var addToMap = [point1, point2];
|
|
22
|
-
* point1.properties.bearing = bearing;
|
|
23
|
-
* point2.properties.bearing = bearing;
|
|
24
|
-
*/
|
|
25
|
-
function rhumbBearing(start, end, options = {}) {
|
|
26
|
-
let bear360;
|
|
27
|
-
if (options.final) {
|
|
28
|
-
bear360 = calculateRhumbBearing(getCoord(end), getCoord(start));
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
bear360 = calculateRhumbBearing(getCoord(start), getCoord(end));
|
|
32
|
-
}
|
|
33
|
-
const bear180 = bear360 > 180 ? -(360 - bear360) : bear360;
|
|
34
|
-
return bear180;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Returns the bearing from ‘this’ point to destination point along a rhumb line.
|
|
38
|
-
* Adapted from Geodesy: https://github.com/chrisveness/geodesy/blob/master/latlon-spherical.js
|
|
39
|
-
*
|
|
40
|
-
* @private
|
|
41
|
-
* @param {Array<number>} from - origin point.
|
|
42
|
-
* @param {Array<number>} to - destination point.
|
|
43
|
-
* @returns {number} Bearing in degrees from north.
|
|
44
|
-
* @example
|
|
45
|
-
* var p1 = new LatLon(51.127, 1.338);
|
|
46
|
-
* var p2 = new LatLon(50.964, 1.853);
|
|
47
|
-
* var d = p1.rhumbBearingTo(p2); // 116.7 m
|
|
48
|
-
*/
|
|
49
|
-
function calculateRhumbBearing(from, to) {
|
|
50
|
-
// φ => phi
|
|
51
|
-
// Δλ => deltaLambda
|
|
52
|
-
// Δψ => deltaPsi
|
|
53
|
-
// θ => theta
|
|
54
|
-
const phi1 = degreesToRadians(from[1]);
|
|
55
|
-
const phi2 = degreesToRadians(to[1]);
|
|
56
|
-
let deltaLambda = degreesToRadians(to[0] - from[0]);
|
|
57
|
-
// if deltaLambdaon over 180° take shorter rhumb line across the anti-meridian:
|
|
58
|
-
if (deltaLambda > Math.PI) {
|
|
59
|
-
deltaLambda -= 2 * Math.PI;
|
|
60
|
-
}
|
|
61
|
-
if (deltaLambda < -Math.PI) {
|
|
62
|
-
deltaLambda += 2 * Math.PI;
|
|
63
|
-
}
|
|
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);
|
|
66
|
-
return (radiansToDegrees(theta) + 360) % 360;
|
|
67
|
-
}
|
|
68
|
-
export default rhumbBearing;
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// https://en.wikipedia.org/wiki/Rhumb_line
|
|
4
|
-
const helpers_1 = require("@turf/helpers");
|
|
5
|
-
const invariant_1 = require("@turf/invariant");
|
|
6
|
-
/**
|
|
7
|
-
* Takes two {@link Point|points} and finds the bearing angle between them along a Rhumb line
|
|
8
|
-
* i.e. the angle measured in degrees start the north line (0 degrees)
|
|
9
|
-
*
|
|
10
|
-
* @name rhumbBearing
|
|
11
|
-
* @param {Coord} start starting Point
|
|
12
|
-
* @param {Coord} end ending Point
|
|
13
|
-
* @param {Object} [options] Optional parameters
|
|
14
|
-
* @param {boolean} [options.final=false] calculates the final bearing if true
|
|
15
|
-
* @returns {number} bearing from north in decimal degrees, between -180 and 180 degrees (positive clockwise)
|
|
16
|
-
* @example
|
|
17
|
-
* var point1 = turf.point([-75.343, 39.984], {"marker-color": "#F00"});
|
|
18
|
-
* var point2 = turf.point([-75.534, 39.123], {"marker-color": "#00F"});
|
|
19
|
-
*
|
|
20
|
-
* var bearing = turf.rhumbBearing(point1, point2);
|
|
21
|
-
*
|
|
22
|
-
* //addToMap
|
|
23
|
-
* var addToMap = [point1, point2];
|
|
24
|
-
* point1.properties.bearing = bearing;
|
|
25
|
-
* point2.properties.bearing = bearing;
|
|
26
|
-
*/
|
|
27
|
-
function rhumbBearing(start, end, options = {}) {
|
|
28
|
-
let bear360;
|
|
29
|
-
if (options.final) {
|
|
30
|
-
bear360 = calculateRhumbBearing(invariant_1.getCoord(end), invariant_1.getCoord(start));
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
bear360 = calculateRhumbBearing(invariant_1.getCoord(start), invariant_1.getCoord(end));
|
|
34
|
-
}
|
|
35
|
-
const bear180 = bear360 > 180 ? -(360 - bear360) : bear360;
|
|
36
|
-
return bear180;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Returns the bearing from ‘this’ point to destination point along a rhumb line.
|
|
40
|
-
* Adapted from Geodesy: https://github.com/chrisveness/geodesy/blob/master/latlon-spherical.js
|
|
41
|
-
*
|
|
42
|
-
* @private
|
|
43
|
-
* @param {Array<number>} from - origin point.
|
|
44
|
-
* @param {Array<number>} to - destination point.
|
|
45
|
-
* @returns {number} Bearing in degrees from north.
|
|
46
|
-
* @example
|
|
47
|
-
* var p1 = new LatLon(51.127, 1.338);
|
|
48
|
-
* var p2 = new LatLon(50.964, 1.853);
|
|
49
|
-
* var d = p1.rhumbBearingTo(p2); // 116.7 m
|
|
50
|
-
*/
|
|
51
|
-
function calculateRhumbBearing(from, to) {
|
|
52
|
-
// φ => phi
|
|
53
|
-
// Δλ => deltaLambda
|
|
54
|
-
// Δψ => deltaPsi
|
|
55
|
-
// θ => theta
|
|
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]);
|
|
59
|
-
// if deltaLambdaon over 180° take shorter rhumb line across the anti-meridian:
|
|
60
|
-
if (deltaLambda > Math.PI) {
|
|
61
|
-
deltaLambda -= 2 * Math.PI;
|
|
62
|
-
}
|
|
63
|
-
if (deltaLambda < -Math.PI) {
|
|
64
|
-
deltaLambda += 2 * Math.PI;
|
|
65
|
-
}
|
|
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);
|
|
68
|
-
return (helpers_1.radiansToDegrees(theta) + 360) % 360;
|
|
69
|
-
}
|
|
70
|
-
exports.default = rhumbBearing;
|