@turf/rhumb-distance 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,14 +7,15 @@
7
7
  Calculates the distance along a rhumb line between two [points][1] in degrees, radians,
8
8
  miles, or kilometers.
9
9
 
10
- **Parameters**
10
+ ### Parameters
11
11
 
12
- - `from` **[Coord][2]** origin point
13
- - `to` **[Coord][2]** destination point
14
- - `options` **[Object][3]?** Optional parameters
15
- - `options.units` **[string][4]** can be degrees, radians, miles, or kilometers (optional, default `"kilometers"`)
12
+ * `from` **[Coord][2]** origin point
13
+ * `to` **[Coord][2]** destination point
14
+ * `options` **[Object][3]?** Optional parameters
16
15
 
17
- **Examples**
16
+ * `options.units` **[string][4]** can be degrees, radians, miles, or kilometers (optional, default `"kilometers"`)
17
+
18
+ ### Examples
18
19
 
19
20
  ```javascript
20
21
  var from = turf.point([-75.343, 39.984]);
package/dist/es/index.js CHANGED
@@ -23,10 +23,9 @@ import { getCoord } from "@turf/invariant";
23
23
  * from.properties.distance = distance;
24
24
  * to.properties.distance = distance;
25
25
  */
26
- function rhumbDistance(from, to, options) {
27
- if (options === void 0) { options = {}; }
28
- var origin = getCoord(from);
29
- var destination = getCoord(to);
26
+ function rhumbDistance(from, to, options = {}) {
27
+ const origin = getCoord(from);
28
+ const destination = getCoord(to);
30
29
  // compensate the crossing of the 180th meridian (https://macwright.org/2016/09/26/the-180th-meridian.html)
31
30
  // solution from https://github.com/mapbox/mapbox-gl-js/issues/3250#issuecomment-294887678
32
31
  destination[0] +=
@@ -35,8 +34,8 @@ function rhumbDistance(from, to, options) {
35
34
  : origin[0] - destination[0] > 180
36
35
  ? 360
37
36
  : 0;
38
- var distanceInMeters = calculateRhumbDistance(origin, destination);
39
- var distance = convertLength(distanceInMeters, "meters", options.units);
37
+ const distanceInMeters = calculateRhumbDistance(origin, destination);
38
+ const distance = convertLength(distanceInMeters, "meters", options.units);
40
39
  return distance;
41
40
  }
42
41
  /**
@@ -63,22 +62,22 @@ function calculateRhumbDistance(origin, destination, radius) {
63
62
  // θ => theta
64
63
  radius = radius === undefined ? earthRadius : Number(radius);
65
64
  // see www.edwilliams.org/avform.htm#Rhumb
66
- var R = radius;
67
- var phi1 = (origin[1] * Math.PI) / 180;
68
- var phi2 = (destination[1] * Math.PI) / 180;
69
- var DeltaPhi = phi2 - phi1;
70
- var DeltaLambda = (Math.abs(destination[0] - origin[0]) * Math.PI) / 180;
65
+ const R = radius;
66
+ const phi1 = (origin[1] * Math.PI) / 180;
67
+ const phi2 = (destination[1] * Math.PI) / 180;
68
+ const DeltaPhi = phi2 - phi1;
69
+ let DeltaLambda = (Math.abs(destination[0] - origin[0]) * Math.PI) / 180;
71
70
  // if dLon over 180° take shorter rhumb line across the anti-meridian:
72
71
  if (DeltaLambda > Math.PI) {
73
72
  DeltaLambda -= 2 * Math.PI;
74
73
  }
75
74
  // on Mercator projection, longitude distances shrink by latitude; q is the 'stretch factor'
76
75
  // q becomes ill-conditioned along E-W line (0/0); use empirical tolerance to avoid it
77
- var DeltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
78
- var q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
76
+ const DeltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
77
+ const q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
79
78
  // distance is pythagoras on 'stretched' Mercator projection
80
- var delta = Math.sqrt(DeltaPhi * DeltaPhi + q * q * DeltaLambda * DeltaLambda); // angular distance in radians
81
- var dist = delta * R;
79
+ const delta = Math.sqrt(DeltaPhi * DeltaPhi + q * q * DeltaLambda * DeltaLambda); // angular distance in radians
80
+ const dist = delta * R;
82
81
  return dist;
83
82
  }
84
83
  export default rhumbDistance;
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
- var helpers_1 = require("@turf/helpers");
5
- var invariant_1 = require("@turf/invariant");
4
+ const helpers_1 = require("@turf/helpers");
5
+ const invariant_1 = require("@turf/invariant");
6
6
  /**
7
7
  * Calculates the distance along a rhumb line between two {@link Point|points} in degrees, radians,
8
8
  * miles, or kilometers.
@@ -25,10 +25,9 @@ var invariant_1 = require("@turf/invariant");
25
25
  * from.properties.distance = distance;
26
26
  * to.properties.distance = distance;
27
27
  */
28
- function rhumbDistance(from, to, options) {
29
- if (options === void 0) { options = {}; }
30
- var origin = invariant_1.getCoord(from);
31
- var destination = invariant_1.getCoord(to);
28
+ function rhumbDistance(from, to, options = {}) {
29
+ const origin = invariant_1.getCoord(from);
30
+ const destination = invariant_1.getCoord(to);
32
31
  // compensate the crossing of the 180th meridian (https://macwright.org/2016/09/26/the-180th-meridian.html)
33
32
  // solution from https://github.com/mapbox/mapbox-gl-js/issues/3250#issuecomment-294887678
34
33
  destination[0] +=
@@ -37,8 +36,8 @@ function rhumbDistance(from, to, options) {
37
36
  : origin[0] - destination[0] > 180
38
37
  ? 360
39
38
  : 0;
40
- var distanceInMeters = calculateRhumbDistance(origin, destination);
41
- var distance = helpers_1.convertLength(distanceInMeters, "meters", options.units);
39
+ const distanceInMeters = calculateRhumbDistance(origin, destination);
40
+ const distance = helpers_1.convertLength(distanceInMeters, "meters", options.units);
42
41
  return distance;
43
42
  }
44
43
  /**
@@ -65,22 +64,22 @@ function calculateRhumbDistance(origin, destination, radius) {
65
64
  // θ => theta
66
65
  radius = radius === undefined ? helpers_1.earthRadius : Number(radius);
67
66
  // see www.edwilliams.org/avform.htm#Rhumb
68
- var R = radius;
69
- var phi1 = (origin[1] * Math.PI) / 180;
70
- var phi2 = (destination[1] * Math.PI) / 180;
71
- var DeltaPhi = phi2 - phi1;
72
- var DeltaLambda = (Math.abs(destination[0] - origin[0]) * Math.PI) / 180;
67
+ const R = radius;
68
+ const phi1 = (origin[1] * Math.PI) / 180;
69
+ const phi2 = (destination[1] * Math.PI) / 180;
70
+ const DeltaPhi = phi2 - phi1;
71
+ let DeltaLambda = (Math.abs(destination[0] - origin[0]) * Math.PI) / 180;
73
72
  // if dLon over 180° take shorter rhumb line across the anti-meridian:
74
73
  if (DeltaLambda > Math.PI) {
75
74
  DeltaLambda -= 2 * Math.PI;
76
75
  }
77
76
  // on Mercator projection, longitude distances shrink by latitude; q is the 'stretch factor'
78
77
  // q becomes ill-conditioned along E-W line (0/0); use empirical tolerance to avoid it
79
- var DeltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
80
- var q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
78
+ const DeltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
79
+ const q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
81
80
  // distance is pythagoras on 'stretched' Mercator projection
82
- var delta = Math.sqrt(DeltaPhi * DeltaPhi + q * q * DeltaLambda * DeltaLambda); // angular distance in radians
83
- var dist = delta * R;
81
+ const delta = Math.sqrt(DeltaPhi * DeltaPhi + q * q * DeltaLambda * DeltaLambda); // angular distance in radians
82
+ const dist = delta * R;
84
83
  return dist;
85
84
  }
86
85
  exports.default = rhumbDistance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/rhumb-distance",
3
- "version": "6.5.0",
3
+ "version": "7.0.0-alpha.1",
4
4
  "description": "turf rhumb-distance module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -35,6 +35,7 @@
35
35
  "exports": {
36
36
  "./package.json": "./package.json",
37
37
  ".": {
38
+ "types": "./dist/js/index.d.ts",
38
39
  "import": "./dist/es/index.js",
39
40
  "require": "./dist/js/index.js"
40
41
  }
@@ -45,29 +46,30 @@
45
46
  "dist"
46
47
  ],
47
48
  "scripts": {
48
- "bench": "ts-node bench.js",
49
+ "bench": "tsx bench.js",
49
50
  "build": "npm-run-all build:*",
50
51
  "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
51
52
  "build:js": "tsc",
52
- "docs": "node ../../scripts/generate-readmes",
53
+ "docs": "tsx ../../scripts/generate-readmes",
53
54
  "test": "npm-run-all test:*",
54
- "test:tape": "ts-node -r esm test.js"
55
+ "test:tape": "tsx test.js"
55
56
  },
56
57
  "devDependencies": {
57
- "@turf/distance": "^6.5.0",
58
+ "@turf/distance": "^7.0.0-alpha.1",
58
59
  "@types/tape": "*",
59
60
  "benchmark": "*",
60
61
  "load-json-file": "*",
61
62
  "npm-run-all": "*",
62
63
  "tape": "*",
63
- "ts-node": "*",
64
64
  "tslint": "*",
65
+ "tsx": "*",
65
66
  "typescript": "*",
66
67
  "write-json-file": "*"
67
68
  },
68
69
  "dependencies": {
69
- "@turf/helpers": "^6.5.0",
70
- "@turf/invariant": "^6.5.0"
70
+ "@turf/helpers": "^7.0.0-alpha.1",
71
+ "@turf/invariant": "^7.0.0-alpha.1",
72
+ "tslib": "^2.3.0"
71
73
  },
72
- "gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
74
+ "gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
73
75
  }