@turf/rhumb-destination 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 +10 -9
- package/dist/es/index.js +15 -17
- package/dist/js/index.d.ts +3 -2
- package/dist/js/index.js +17 -19
- package/package.json +11 -9
package/README.md
CHANGED
|
@@ -7,16 +7,17 @@
|
|
|
7
7
|
Returns the destination [Point][1] having travelled the given distance along a Rhumb line from the
|
|
8
8
|
origin Point with the (varant) given bearing.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
### Parameters
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- `options.units` **[string][5]** can be degrees, radians, miles, or kilometers (optional, default `'kilometers'`)
|
|
17
|
-
- `options.properties` **[Object][4]** translate properties to destination point (optional, default `{}`)
|
|
12
|
+
* `origin` **[Coord][2]** starting point
|
|
13
|
+
* `distance` **[number][3]** distance from the starting point
|
|
14
|
+
* `bearing` **[number][3]** varant bearing angle ranging from -180 to 180 degrees from north
|
|
15
|
+
* `options` **[Object][4]** Optional parameters (optional, default `{}`)
|
|
18
16
|
|
|
19
|
-
**
|
|
17
|
+
* `options.units` **[string][5]** can be degrees, radians, miles, or kilometers (optional, default `'kilometers'`)
|
|
18
|
+
* `options.properties` **[Object][4]** translate properties to destination point (optional, default `{}`)
|
|
19
|
+
|
|
20
|
+
### Examples
|
|
20
21
|
|
|
21
22
|
```javascript
|
|
22
23
|
var pt = turf.point([-75.343, 39.984], {"marker-color": "F00"});
|
|
@@ -31,7 +32,7 @@ var addToMap = [pt, destination]
|
|
|
31
32
|
destination.properties['marker-color'] = '#00F';
|
|
32
33
|
```
|
|
33
34
|
|
|
34
|
-
Returns **[Feature][6]
|
|
35
|
+
Returns **[Feature][6]<[Point][7]>** Destination point.
|
|
35
36
|
|
|
36
37
|
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.2
|
|
37
38
|
|
package/dist/es/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// https://en.wikipedia.org/wiki/Rhumb_line
|
|
2
1
|
import { convertLength, degreesToRadians, earthRadius, point, } from "@turf/helpers";
|
|
3
2
|
import { getCoord } from "@turf/invariant";
|
|
4
3
|
/**
|
|
@@ -25,14 +24,13 @@ import { getCoord } from "@turf/invariant";
|
|
|
25
24
|
* var addToMap = [pt, destination]
|
|
26
25
|
* destination.properties['marker-color'] = '#00F';
|
|
27
26
|
*/
|
|
28
|
-
function rhumbDestination(origin, distance, bearing, options) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var distanceInMeters = convertLength(Math.abs(distance), options.units, "meters");
|
|
27
|
+
function rhumbDestination(origin, distance, bearing, options = {}) {
|
|
28
|
+
const wasNegativeDistance = distance < 0;
|
|
29
|
+
let distanceInMeters = convertLength(Math.abs(distance), options.units, "meters");
|
|
32
30
|
if (wasNegativeDistance)
|
|
33
31
|
distanceInMeters = -Math.abs(distanceInMeters);
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
const coords = getCoord(origin);
|
|
33
|
+
const destination = calculateRhumbDestination(coords, distanceInMeters, bearing);
|
|
36
34
|
// compensate the crossing of the 180th meridian (https://macwright.org/2016/09/26/the-180th-meridian.html)
|
|
37
35
|
// solution from https://github.com/mapbox/mapbox-gl-js/issues/3250#issuecomment-294887678
|
|
38
36
|
destination[0] +=
|
|
@@ -63,21 +61,21 @@ function calculateRhumbDestination(origin, distance, bearing, radius) {
|
|
|
63
61
|
// δ => delta
|
|
64
62
|
// θ => theta
|
|
65
63
|
radius = radius === undefined ? earthRadius : Number(radius);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
const delta = distance / radius; // angular distance in radians
|
|
65
|
+
const lambda1 = (origin[0] * Math.PI) / 180; // to radians, but without normalize to 𝜋
|
|
66
|
+
const phi1 = degreesToRadians(origin[1]);
|
|
67
|
+
const theta = degreesToRadians(bearing);
|
|
68
|
+
const DeltaPhi = delta * Math.cos(theta);
|
|
69
|
+
let phi2 = phi1 + DeltaPhi;
|
|
72
70
|
// check for some daft bugger going past the pole, normalise latitude if so
|
|
73
71
|
if (Math.abs(phi2) > Math.PI / 2) {
|
|
74
72
|
phi2 = phi2 > 0 ? Math.PI - phi2 : -Math.PI - phi2;
|
|
75
73
|
}
|
|
76
|
-
|
|
74
|
+
const DeltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
|
|
77
75
|
// E-W course becomes ill-conditioned with 0/0
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
const q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
|
|
77
|
+
const DeltaLambda = (delta * Math.sin(theta)) / q;
|
|
78
|
+
const lambda2 = lambda1 + DeltaLambda;
|
|
81
79
|
return [
|
|
82
80
|
(((lambda2 * 180) / Math.PI + 540) % 360) - 180,
|
|
83
81
|
(phi2 * 180) / Math.PI,
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Feature, Point, GeoJsonProperties } from "geojson";
|
|
2
|
+
import { Coord, Units } from "@turf/helpers";
|
|
2
3
|
/**
|
|
3
4
|
* Returns the destination {@link Point} having travelled the given distance along a Rhumb line from the
|
|
4
5
|
* origin Point with the (varant) given bearing.
|
|
@@ -23,7 +24,7 @@ import { Coord, Feature, Point, Properties, Units } from "@turf/helpers";
|
|
|
23
24
|
* var addToMap = [pt, destination]
|
|
24
25
|
* destination.properties['marker-color'] = '#00F';
|
|
25
26
|
*/
|
|
26
|
-
declare function rhumbDestination<P =
|
|
27
|
+
declare function rhumbDestination<P = GeoJsonProperties>(origin: Coord, distance: number, bearing: number, options?: {
|
|
27
28
|
units?: Units;
|
|
28
29
|
properties?: P;
|
|
29
30
|
}): Feature<Point, P>;
|
package/dist/js/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var invariant_1 = require("@turf/invariant");
|
|
3
|
+
const helpers_1 = require("@turf/helpers");
|
|
4
|
+
const invariant_1 = require("@turf/invariant");
|
|
6
5
|
/**
|
|
7
6
|
* Returns the destination {@link Point} having travelled the given distance along a Rhumb line from the
|
|
8
7
|
* origin Point with the (varant) given bearing.
|
|
@@ -27,14 +26,13 @@ var invariant_1 = require("@turf/invariant");
|
|
|
27
26
|
* var addToMap = [pt, destination]
|
|
28
27
|
* destination.properties['marker-color'] = '#00F';
|
|
29
28
|
*/
|
|
30
|
-
function rhumbDestination(origin, distance, bearing, options) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var distanceInMeters = helpers_1.convertLength(Math.abs(distance), options.units, "meters");
|
|
29
|
+
function rhumbDestination(origin, distance, bearing, options = {}) {
|
|
30
|
+
const wasNegativeDistance = distance < 0;
|
|
31
|
+
let distanceInMeters = helpers_1.convertLength(Math.abs(distance), options.units, "meters");
|
|
34
32
|
if (wasNegativeDistance)
|
|
35
33
|
distanceInMeters = -Math.abs(distanceInMeters);
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
const coords = invariant_1.getCoord(origin);
|
|
35
|
+
const destination = calculateRhumbDestination(coords, distanceInMeters, bearing);
|
|
38
36
|
// compensate the crossing of the 180th meridian (https://macwright.org/2016/09/26/the-180th-meridian.html)
|
|
39
37
|
// solution from https://github.com/mapbox/mapbox-gl-js/issues/3250#issuecomment-294887678
|
|
40
38
|
destination[0] +=
|
|
@@ -65,21 +63,21 @@ function calculateRhumbDestination(origin, distance, bearing, radius) {
|
|
|
65
63
|
// δ => delta
|
|
66
64
|
// θ => theta
|
|
67
65
|
radius = radius === undefined ? helpers_1.earthRadius : Number(radius);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
const delta = distance / radius; // angular distance in radians
|
|
67
|
+
const lambda1 = (origin[0] * Math.PI) / 180; // to radians, but without normalize to 𝜋
|
|
68
|
+
const phi1 = helpers_1.degreesToRadians(origin[1]);
|
|
69
|
+
const theta = helpers_1.degreesToRadians(bearing);
|
|
70
|
+
const DeltaPhi = delta * Math.cos(theta);
|
|
71
|
+
let phi2 = phi1 + DeltaPhi;
|
|
74
72
|
// check for some daft bugger going past the pole, normalise latitude if so
|
|
75
73
|
if (Math.abs(phi2) > Math.PI / 2) {
|
|
76
74
|
phi2 = phi2 > 0 ? Math.PI - phi2 : -Math.PI - phi2;
|
|
77
75
|
}
|
|
78
|
-
|
|
76
|
+
const DeltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
|
|
79
77
|
// E-W course becomes ill-conditioned with 0/0
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
const q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
|
|
79
|
+
const DeltaLambda = (delta * Math.sin(theta)) / q;
|
|
80
|
+
const lambda2 = lambda1 + DeltaLambda;
|
|
83
81
|
return [
|
|
84
82
|
(((lambda2 * 180) / Math.PI + 540) % 360) - 180,
|
|
85
83
|
(phi2 * 180) / Math.PI,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/rhumb-destination",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.1",
|
|
4
4
|
"description": "turf rhumb-destination module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"exports": {
|
|
38
38
|
"./package.json": "./package.json",
|
|
39
39
|
".": {
|
|
40
|
+
"types": "./dist/js/index.d.ts",
|
|
40
41
|
"import": "./dist/es/index.js",
|
|
41
42
|
"require": "./dist/js/index.js"
|
|
42
43
|
}
|
|
@@ -47,29 +48,30 @@
|
|
|
47
48
|
"dist"
|
|
48
49
|
],
|
|
49
50
|
"scripts": {
|
|
50
|
-
"bench": "
|
|
51
|
+
"bench": "tsx bench.js",
|
|
51
52
|
"build": "npm-run-all build:*",
|
|
52
53
|
"build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
|
|
53
54
|
"build:js": "tsc",
|
|
54
|
-
"docs": "
|
|
55
|
+
"docs": "tsx ../../scripts/generate-readmes",
|
|
55
56
|
"test": "npm-run-all test:*",
|
|
56
|
-
"test:tape": "
|
|
57
|
+
"test:tape": "tsx test.js"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
|
-
"@turf/truncate": "^
|
|
60
|
+
"@turf/truncate": "^7.0.0-alpha.1",
|
|
60
61
|
"@types/tape": "*",
|
|
61
62
|
"benchmark": "*",
|
|
62
63
|
"load-json-file": "*",
|
|
63
64
|
"npm-run-all": "*",
|
|
64
65
|
"tape": "*",
|
|
65
|
-
"ts-node": "*",
|
|
66
66
|
"tslint": "*",
|
|
67
|
+
"tsx": "*",
|
|
67
68
|
"typescript": "*",
|
|
68
69
|
"write-json-file": "*"
|
|
69
70
|
},
|
|
70
71
|
"dependencies": {
|
|
71
|
-
"@turf/helpers": "^
|
|
72
|
-
"@turf/invariant": "^
|
|
72
|
+
"@turf/helpers": "^7.0.0-alpha.1",
|
|
73
|
+
"@turf/invariant": "^7.0.0-alpha.1",
|
|
74
|
+
"tslib": "^2.3.0"
|
|
73
75
|
},
|
|
74
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
|
|
75
77
|
}
|