@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 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
- **Parameters**
10
+ ### Parameters
11
11
 
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 `{}`)
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
- **Examples**
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]<[Point][7]>** Destination point.
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
- if (options === void 0) { options = {}; }
30
- var wasNegativeDistance = distance < 0;
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
- var coords = getCoord(origin);
35
- var destination = calculateRhumbDestination(coords, distanceInMeters, bearing);
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
- var delta = distance / radius; // angular distance in radians
67
- var lambda1 = (origin[0] * Math.PI) / 180; // to radians, but without normalize to 𝜋
68
- var phi1 = degreesToRadians(origin[1]);
69
- var theta = degreesToRadians(bearing);
70
- var DeltaPhi = delta * Math.cos(theta);
71
- var phi2 = phi1 + DeltaPhi;
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
- var DeltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
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
- var q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
79
- var DeltaLambda = (delta * Math.sin(theta)) / q;
80
- var lambda2 = lambda1 + DeltaLambda;
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,
@@ -1,4 +1,5 @@
1
- import { Coord, Feature, Point, Properties, Units } from "@turf/helpers";
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 = Properties>(origin: Coord, distance: number, bearing: number, options?: {
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
- // https://en.wikipedia.org/wiki/Rhumb_line
4
- var helpers_1 = require("@turf/helpers");
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
- if (options === void 0) { options = {}; }
32
- var wasNegativeDistance = distance < 0;
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
- var coords = invariant_1.getCoord(origin);
37
- var destination = calculateRhumbDestination(coords, distanceInMeters, bearing);
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
- var delta = distance / radius; // angular distance in radians
69
- var lambda1 = (origin[0] * Math.PI) / 180; // to radians, but without normalize to 𝜋
70
- var phi1 = helpers_1.degreesToRadians(origin[1]);
71
- var theta = helpers_1.degreesToRadians(bearing);
72
- var DeltaPhi = delta * Math.cos(theta);
73
- var phi2 = phi1 + DeltaPhi;
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
- var DeltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
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
- var q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
81
- var DeltaLambda = (delta * Math.sin(theta)) / q;
82
- var lambda2 = lambda1 + DeltaLambda;
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": "6.5.0",
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": "ts-node bench.js",
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": "node ../../scripts/generate-readmes",
55
+ "docs": "tsx ../../scripts/generate-readmes",
55
56
  "test": "npm-run-all test:*",
56
- "test:tape": "ts-node -r esm test.js"
57
+ "test:tape": "tsx test.js"
57
58
  },
58
59
  "devDependencies": {
59
- "@turf/truncate": "^6.5.0",
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": "^6.5.0",
72
- "@turf/invariant": "^6.5.0"
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": "5375941072b90d489389db22b43bfe809d5e451e"
76
+ "gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
75
77
  }