@turf/rhumb-distance 7.0.0-alpha.1 → 7.0.0-alpha.110
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 +42 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{js → cjs}/index.d.ts +4 -2
- package/dist/esm/index.d.mts +29 -0
- package/dist/esm/index.mjs +42 -0
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +33 -28
- package/dist/es/index.js +0 -83
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -85
package/README.md
CHANGED
|
@@ -42,26 +42,21 @@ Returns **[number][5]** distance between the two points
|
|
|
42
42
|
|
|
43
43
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
44
44
|
|
|
45
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
46
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
47
|
-
./scripts/generate-readmes in the turf project. -->
|
|
45
|
+
<!-- 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. -->
|
|
48
46
|
|
|
49
47
|
---
|
|
50
48
|
|
|
51
|
-
This module is part of the [Turfjs project](
|
|
52
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
53
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
54
|
-
PRs and issues.
|
|
49
|
+
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.
|
|
55
50
|
|
|
56
51
|
### Installation
|
|
57
52
|
|
|
58
|
-
Install this module individually:
|
|
53
|
+
Install this single module individually:
|
|
59
54
|
|
|
60
55
|
```sh
|
|
61
56
|
$ npm install @turf/rhumb-distance
|
|
62
57
|
```
|
|
63
58
|
|
|
64
|
-
Or install the
|
|
59
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
65
60
|
|
|
66
61
|
```sh
|
|
67
62
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,42 @@
|
|
|
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 rhumbDistance(from, to, options = {}) {
|
|
8
|
+
const origin = _invariant.getCoord.call(void 0, from);
|
|
9
|
+
const destination = _invariant.getCoord.call(void 0, to);
|
|
10
|
+
destination[0] += destination[0] - origin[0] > 180 ? -360 : origin[0] - destination[0] > 180 ? 360 : 0;
|
|
11
|
+
const distanceInMeters = calculateRhumbDistance(origin, destination);
|
|
12
|
+
const distance = _helpers.convertLength.call(void 0, distanceInMeters, "meters", options.units);
|
|
13
|
+
return distance;
|
|
14
|
+
}
|
|
15
|
+
__name(rhumbDistance, "rhumbDistance");
|
|
16
|
+
function calculateRhumbDistance(origin, destination, radius) {
|
|
17
|
+
radius = radius === void 0 ? _helpers.earthRadius : Number(radius);
|
|
18
|
+
const R = radius;
|
|
19
|
+
const phi1 = origin[1] * Math.PI / 180;
|
|
20
|
+
const phi2 = destination[1] * Math.PI / 180;
|
|
21
|
+
const DeltaPhi = phi2 - phi1;
|
|
22
|
+
let DeltaLambda = Math.abs(destination[0] - origin[0]) * Math.PI / 180;
|
|
23
|
+
if (DeltaLambda > Math.PI) {
|
|
24
|
+
DeltaLambda -= 2 * Math.PI;
|
|
25
|
+
}
|
|
26
|
+
const DeltaPsi = Math.log(
|
|
27
|
+
Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4)
|
|
28
|
+
);
|
|
29
|
+
const q = Math.abs(DeltaPsi) > 1e-11 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
|
|
30
|
+
const delta = Math.sqrt(
|
|
31
|
+
DeltaPhi * DeltaPhi + q * q * DeltaLambda * DeltaLambda
|
|
32
|
+
);
|
|
33
|
+
const dist = delta * R;
|
|
34
|
+
return dist;
|
|
35
|
+
}
|
|
36
|
+
__name(calculateRhumbDistance, "calculateRhumbDistance");
|
|
37
|
+
var turf_rhumb_distance_default = rhumbDistance;
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
exports.default = turf_rhumb_distance_default; exports.rhumbDistance = rhumbDistance;
|
|
42
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AACA,SAAS,eAAsB,mBAA0B;AACzD,SAAS,gBAAgB;AAwBzB,SAAS,cACP,MACA,IACA,UAEI,CAAC,GACG;AACR,QAAM,SAAS,SAAS,IAAI;AAC5B,QAAM,cAAc,SAAS,EAAE;AAI/B,cAAY,CAAC,KACX,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,MACzB,OACA,OAAO,CAAC,IAAI,YAAY,CAAC,IAAI,MAC3B,MACA;AACR,QAAM,mBAAmB,uBAAuB,QAAQ,WAAW;AACnE,QAAM,WAAW,cAAc,kBAAkB,UAAU,QAAQ,KAAK;AACxE,SAAO;AACT;AArBS;AAsCT,SAAS,uBACP,QACA,aACA,QACA;AAQA,WAAS,WAAW,SAAY,cAAc,OAAO,MAAM;AAG3D,QAAM,IAAI;AACV,QAAM,OAAQ,OAAO,CAAC,IAAI,KAAK,KAAM;AACrC,QAAM,OAAQ,YAAY,CAAC,IAAI,KAAK,KAAM;AAC1C,QAAM,WAAW,OAAO;AACxB,MAAI,cAAe,KAAK,IAAI,YAAY,CAAC,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,KAAM;AAErE,MAAI,cAAc,KAAK,IAAI;AACzB,mBAAe,IAAI,KAAK;AAAA,EAC1B;AAIA,QAAM,WAAW,KAAK;AAAA,IACpB,KAAK,IAAI,OAAO,IAAI,KAAK,KAAK,CAAC,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK,KAAK,CAAC;AAAA,EACpE;AACA,QAAM,IAAI,KAAK,IAAI,QAAQ,IAAI,QAAS,WAAW,WAAW,KAAK,IAAI,IAAI;AAG3E,QAAM,QAAQ,KAAK;AAAA,IACjB,WAAW,WAAW,IAAI,IAAI,cAAc;AAAA,EAC9C;AACA,QAAM,OAAO,QAAQ;AAErB,SAAO;AACT;AAvCS;AA0CT,IAAO,8BAAQ","sourcesContent":["// https://en.wikipedia.org/wiki/Rhumb_line\nimport { convertLength, Coord, earthRadius, Units } from \"@turf/helpers\";\nimport { getCoord } from \"@turf/invariant\";\n\n/**\n * Calculates the distance along a rhumb line between two {@link Point|points} in degrees, radians,\n * miles, or kilometers.\n *\n * @name rhumbDistance\n * @param {Coord} from origin point\n * @param {Coord} to destination point\n * @param {Object} [options] Optional parameters\n * @param {string} [options.units=\"kilometers\"] can be degrees, radians, miles, or kilometers\n * @returns {number} distance between the two points\n * @example\n * var from = turf.point([-75.343, 39.984]);\n * var to = turf.point([-75.534, 39.123]);\n * var options = {units: 'miles'};\n *\n * var distance = turf.rhumbDistance(from, to, options);\n *\n * //addToMap\n * var addToMap = [from, to];\n * from.properties.distance = distance;\n * to.properties.distance = distance;\n */\nfunction rhumbDistance(\n from: Coord,\n to: Coord,\n options: {\n units?: Units;\n } = {}\n): number {\n const origin = getCoord(from);\n const destination = getCoord(to);\n\n // compensate the crossing of the 180th meridian (https://macwright.org/2016/09/26/the-180th-meridian.html)\n // solution from https://github.com/mapbox/mapbox-gl-js/issues/3250#issuecomment-294887678\n destination[0] +=\n destination[0] - origin[0] > 180\n ? -360\n : origin[0] - destination[0] > 180\n ? 360\n : 0;\n const distanceInMeters = calculateRhumbDistance(origin, destination);\n const distance = convertLength(distanceInMeters, \"meters\", options.units);\n return distance;\n}\n\n/**\n * Returns the distance travelling 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>} origin point.\n * @param {Array<number>} destination point.\n * @param {number} [radius=6371e3] - (Mean) radius of earth (defaults to radius in metres).\n * @returns {number} Distance in km between this point and destination point (same units as radius).\n *\n * @example\n * var p1 = new LatLon(51.127, 1.338);\n * var p2 = new LatLon(50.964, 1.853);\n * var d = p1.distanceTo(p2); // 40.31 km\n */\nfunction calculateRhumbDistance(\n origin: number[],\n destination: number[],\n radius?: number\n) {\n // φ => phi\n // λ => lambda\n // ψ => psi\n // Δ => Delta\n // δ => delta\n // θ => theta\n\n radius = radius === undefined ? earthRadius : Number(radius);\n // see www.edwilliams.org/avform.htm#Rhumb\n\n const R = radius;\n const phi1 = (origin[1] * Math.PI) / 180;\n const phi2 = (destination[1] * Math.PI) / 180;\n const DeltaPhi = phi2 - phi1;\n let DeltaLambda = (Math.abs(destination[0] - origin[0]) * Math.PI) / 180;\n // if dLon over 180° take shorter rhumb line across the anti-meridian:\n if (DeltaLambda > Math.PI) {\n DeltaLambda -= 2 * Math.PI;\n }\n\n // on Mercator projection, longitude distances shrink by latitude; q is the 'stretch factor'\n // q becomes ill-conditioned along E-W line (0/0); use empirical tolerance to avoid it\n const DeltaPsi = Math.log(\n Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4)\n );\n const q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);\n\n // distance is pythagoras on 'stretched' Mercator projection\n const delta = Math.sqrt(\n DeltaPhi * DeltaPhi + q * q * DeltaLambda * DeltaLambda\n ); // angular distance in radians\n const dist = delta * R;\n\n return dist;\n}\n\nexport { rhumbDistance };\nexport default rhumbDistance;\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Coord, Units } from
|
|
1
|
+
import { Coord, Units } from '@turf/helpers';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Calculates the distance along a rhumb line between two {@link Point|points} in degrees, radians,
|
|
4
5
|
* miles, or kilometers.
|
|
@@ -24,4 +25,5 @@ import { Coord, Units } from "@turf/helpers";
|
|
|
24
25
|
declare function rhumbDistance(from: Coord, to: Coord, options?: {
|
|
25
26
|
units?: Units;
|
|
26
27
|
}): number;
|
|
27
|
-
|
|
28
|
+
|
|
29
|
+
export { rhumbDistance as default, rhumbDistance };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Coord, Units } from '@turf/helpers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Calculates the distance along a rhumb line between two {@link Point|points} in degrees, radians,
|
|
5
|
+
* miles, or kilometers.
|
|
6
|
+
*
|
|
7
|
+
* @name rhumbDistance
|
|
8
|
+
* @param {Coord} from origin point
|
|
9
|
+
* @param {Coord} to destination point
|
|
10
|
+
* @param {Object} [options] Optional parameters
|
|
11
|
+
* @param {string} [options.units="kilometers"] can be degrees, radians, miles, or kilometers
|
|
12
|
+
* @returns {number} distance between the two points
|
|
13
|
+
* @example
|
|
14
|
+
* var from = turf.point([-75.343, 39.984]);
|
|
15
|
+
* var to = turf.point([-75.534, 39.123]);
|
|
16
|
+
* var options = {units: 'miles'};
|
|
17
|
+
*
|
|
18
|
+
* var distance = turf.rhumbDistance(from, to, options);
|
|
19
|
+
*
|
|
20
|
+
* //addToMap
|
|
21
|
+
* var addToMap = [from, to];
|
|
22
|
+
* from.properties.distance = distance;
|
|
23
|
+
* to.properties.distance = distance;
|
|
24
|
+
*/
|
|
25
|
+
declare function rhumbDistance(from: Coord, to: Coord, options?: {
|
|
26
|
+
units?: Units;
|
|
27
|
+
}): number;
|
|
28
|
+
|
|
29
|
+
export { rhumbDistance as default, rhumbDistance };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
import { convertLength, earthRadius } from "@turf/helpers";
|
|
6
|
+
import { getCoord } from "@turf/invariant";
|
|
7
|
+
function rhumbDistance(from, to, options = {}) {
|
|
8
|
+
const origin = getCoord(from);
|
|
9
|
+
const destination = getCoord(to);
|
|
10
|
+
destination[0] += destination[0] - origin[0] > 180 ? -360 : origin[0] - destination[0] > 180 ? 360 : 0;
|
|
11
|
+
const distanceInMeters = calculateRhumbDistance(origin, destination);
|
|
12
|
+
const distance = convertLength(distanceInMeters, "meters", options.units);
|
|
13
|
+
return distance;
|
|
14
|
+
}
|
|
15
|
+
__name(rhumbDistance, "rhumbDistance");
|
|
16
|
+
function calculateRhumbDistance(origin, destination, radius) {
|
|
17
|
+
radius = radius === void 0 ? earthRadius : Number(radius);
|
|
18
|
+
const R = radius;
|
|
19
|
+
const phi1 = origin[1] * Math.PI / 180;
|
|
20
|
+
const phi2 = destination[1] * Math.PI / 180;
|
|
21
|
+
const DeltaPhi = phi2 - phi1;
|
|
22
|
+
let DeltaLambda = Math.abs(destination[0] - origin[0]) * Math.PI / 180;
|
|
23
|
+
if (DeltaLambda > Math.PI) {
|
|
24
|
+
DeltaLambda -= 2 * Math.PI;
|
|
25
|
+
}
|
|
26
|
+
const DeltaPsi = Math.log(
|
|
27
|
+
Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4)
|
|
28
|
+
);
|
|
29
|
+
const q = Math.abs(DeltaPsi) > 1e-11 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
|
|
30
|
+
const delta = Math.sqrt(
|
|
31
|
+
DeltaPhi * DeltaPhi + q * q * DeltaLambda * DeltaLambda
|
|
32
|
+
);
|
|
33
|
+
const dist = delta * R;
|
|
34
|
+
return dist;
|
|
35
|
+
}
|
|
36
|
+
__name(calculateRhumbDistance, "calculateRhumbDistance");
|
|
37
|
+
var turf_rhumb_distance_default = rhumbDistance;
|
|
38
|
+
export {
|
|
39
|
+
turf_rhumb_distance_default as default,
|
|
40
|
+
rhumbDistance
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["// https://en.wikipedia.org/wiki/Rhumb_line\nimport { convertLength, Coord, earthRadius, Units } from \"@turf/helpers\";\nimport { getCoord } from \"@turf/invariant\";\n\n/**\n * Calculates the distance along a rhumb line between two {@link Point|points} in degrees, radians,\n * miles, or kilometers.\n *\n * @name rhumbDistance\n * @param {Coord} from origin point\n * @param {Coord} to destination point\n * @param {Object} [options] Optional parameters\n * @param {string} [options.units=\"kilometers\"] can be degrees, radians, miles, or kilometers\n * @returns {number} distance between the two points\n * @example\n * var from = turf.point([-75.343, 39.984]);\n * var to = turf.point([-75.534, 39.123]);\n * var options = {units: 'miles'};\n *\n * var distance = turf.rhumbDistance(from, to, options);\n *\n * //addToMap\n * var addToMap = [from, to];\n * from.properties.distance = distance;\n * to.properties.distance = distance;\n */\nfunction rhumbDistance(\n from: Coord,\n to: Coord,\n options: {\n units?: Units;\n } = {}\n): number {\n const origin = getCoord(from);\n const destination = getCoord(to);\n\n // compensate the crossing of the 180th meridian (https://macwright.org/2016/09/26/the-180th-meridian.html)\n // solution from https://github.com/mapbox/mapbox-gl-js/issues/3250#issuecomment-294887678\n destination[0] +=\n destination[0] - origin[0] > 180\n ? -360\n : origin[0] - destination[0] > 180\n ? 360\n : 0;\n const distanceInMeters = calculateRhumbDistance(origin, destination);\n const distance = convertLength(distanceInMeters, \"meters\", options.units);\n return distance;\n}\n\n/**\n * Returns the distance travelling 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>} origin point.\n * @param {Array<number>} destination point.\n * @param {number} [radius=6371e3] - (Mean) radius of earth (defaults to radius in metres).\n * @returns {number} Distance in km between this point and destination point (same units as radius).\n *\n * @example\n * var p1 = new LatLon(51.127, 1.338);\n * var p2 = new LatLon(50.964, 1.853);\n * var d = p1.distanceTo(p2); // 40.31 km\n */\nfunction calculateRhumbDistance(\n origin: number[],\n destination: number[],\n radius?: number\n) {\n // φ => phi\n // λ => lambda\n // ψ => psi\n // Δ => Delta\n // δ => delta\n // θ => theta\n\n radius = radius === undefined ? earthRadius : Number(radius);\n // see www.edwilliams.org/avform.htm#Rhumb\n\n const R = radius;\n const phi1 = (origin[1] * Math.PI) / 180;\n const phi2 = (destination[1] * Math.PI) / 180;\n const DeltaPhi = phi2 - phi1;\n let DeltaLambda = (Math.abs(destination[0] - origin[0]) * Math.PI) / 180;\n // if dLon over 180° take shorter rhumb line across the anti-meridian:\n if (DeltaLambda > Math.PI) {\n DeltaLambda -= 2 * Math.PI;\n }\n\n // on Mercator projection, longitude distances shrink by latitude; q is the 'stretch factor'\n // q becomes ill-conditioned along E-W line (0/0); use empirical tolerance to avoid it\n const DeltaPsi = Math.log(\n Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4)\n );\n const q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);\n\n // distance is pythagoras on 'stretched' Mercator projection\n const delta = Math.sqrt(\n DeltaPhi * DeltaPhi + q * q * DeltaLambda * DeltaLambda\n ); // angular distance in radians\n const dist = delta * R;\n\n return dist;\n}\n\nexport { rhumbDistance };\nexport default rhumbDistance;\n"],"mappings":";;;;AACA,SAAS,eAAsB,mBAA0B;AACzD,SAAS,gBAAgB;AAwBzB,SAAS,cACP,MACA,IACA,UAEI,CAAC,GACG;AACR,QAAM,SAAS,SAAS,IAAI;AAC5B,QAAM,cAAc,SAAS,EAAE;AAI/B,cAAY,CAAC,KACX,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,MACzB,OACA,OAAO,CAAC,IAAI,YAAY,CAAC,IAAI,MAC3B,MACA;AACR,QAAM,mBAAmB,uBAAuB,QAAQ,WAAW;AACnE,QAAM,WAAW,cAAc,kBAAkB,UAAU,QAAQ,KAAK;AACxE,SAAO;AACT;AArBS;AAsCT,SAAS,uBACP,QACA,aACA,QACA;AAQA,WAAS,WAAW,SAAY,cAAc,OAAO,MAAM;AAG3D,QAAM,IAAI;AACV,QAAM,OAAQ,OAAO,CAAC,IAAI,KAAK,KAAM;AACrC,QAAM,OAAQ,YAAY,CAAC,IAAI,KAAK,KAAM;AAC1C,QAAM,WAAW,OAAO;AACxB,MAAI,cAAe,KAAK,IAAI,YAAY,CAAC,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,KAAM;AAErE,MAAI,cAAc,KAAK,IAAI;AACzB,mBAAe,IAAI,KAAK;AAAA,EAC1B;AAIA,QAAM,WAAW,KAAK;AAAA,IACpB,KAAK,IAAI,OAAO,IAAI,KAAK,KAAK,CAAC,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK,KAAK,CAAC;AAAA,EACpE;AACA,QAAM,IAAI,KAAK,IAAI,QAAQ,IAAI,QAAS,WAAW,WAAW,KAAK,IAAI,IAAI;AAG3E,QAAM,QAAQ,KAAK;AAAA,IACjB,WAAW,WAAW,IAAI,IAAI,cAAc;AAAA,EAC9C;AACA,QAAM,OAAO,QAAQ;AAErB,SAAO;AACT;AAvCS;AA0CT,IAAO,8BAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/rhumb-distance",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.110+1411d63a7",
|
|
4
4
|
"description": "turf rhumb-distance module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -30,46 +30,51 @@
|
|
|
30
30
|
"miles",
|
|
31
31
|
"km"
|
|
32
32
|
],
|
|
33
|
-
"
|
|
34
|
-
"
|
|
33
|
+
"type": "commonjs",
|
|
34
|
+
"main": "dist/cjs/index.cjs",
|
|
35
|
+
"module": "dist/esm/index.mjs",
|
|
36
|
+
"types": "dist/cjs/index.d.ts",
|
|
35
37
|
"exports": {
|
|
36
38
|
"./package.json": "./package.json",
|
|
37
39
|
".": {
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/esm/index.d.mts",
|
|
42
|
+
"default": "./dist/esm/index.mjs"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./dist/cjs/index.d.ts",
|
|
46
|
+
"default": "./dist/cjs/index.cjs"
|
|
47
|
+
}
|
|
41
48
|
}
|
|
42
49
|
},
|
|
43
|
-
"types": "dist/js/index.d.ts",
|
|
44
50
|
"sideEffects": false,
|
|
45
51
|
"files": [
|
|
46
52
|
"dist"
|
|
47
53
|
],
|
|
48
54
|
"scripts": {
|
|
49
|
-
"bench": "tsx bench.
|
|
50
|
-
"build": "
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"test": "npm-run-all test:*",
|
|
55
|
-
"test:tape": "tsx test.js"
|
|
55
|
+
"bench": "tsx bench.ts",
|
|
56
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
57
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
58
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
59
|
+
"test:tape": "tsx test.ts"
|
|
56
60
|
},
|
|
57
61
|
"devDependencies": {
|
|
58
|
-
"@turf/distance": "^7.0.0-alpha.
|
|
59
|
-
"@types/
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
62
|
+
"@turf/distance": "^7.0.0-alpha.110+1411d63a7",
|
|
63
|
+
"@types/benchmark": "^2.1.5",
|
|
64
|
+
"@types/tape": "^4.2.32",
|
|
65
|
+
"benchmark": "^2.1.4",
|
|
66
|
+
"load-json-file": "^7.0.1",
|
|
67
|
+
"npm-run-all": "^4.1.5",
|
|
68
|
+
"tape": "^5.7.2",
|
|
69
|
+
"tsup": "^8.0.1",
|
|
70
|
+
"tsx": "^4.6.2",
|
|
71
|
+
"typescript": "^5.2.2",
|
|
72
|
+
"write-json-file": "^5.0.0"
|
|
68
73
|
},
|
|
69
74
|
"dependencies": {
|
|
70
|
-
"@turf/helpers": "^7.0.0-alpha.
|
|
71
|
-
"@turf/invariant": "^7.0.0-alpha.
|
|
72
|
-
"tslib": "^2.
|
|
75
|
+
"@turf/helpers": "^7.0.0-alpha.110+1411d63a7",
|
|
76
|
+
"@turf/invariant": "^7.0.0-alpha.110+1411d63a7",
|
|
77
|
+
"tslib": "^2.6.2"
|
|
73
78
|
},
|
|
74
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "1411d63a74c275c9216fe48e9d3cb2d48a359068"
|
|
75
80
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
// https://en.wikipedia.org/wiki/Rhumb_line
|
|
2
|
-
import { convertLength, earthRadius } from "@turf/helpers";
|
|
3
|
-
import { getCoord } from "@turf/invariant";
|
|
4
|
-
/**
|
|
5
|
-
* Calculates the distance along a rhumb line between two {@link Point|points} in degrees, radians,
|
|
6
|
-
* miles, or kilometers.
|
|
7
|
-
*
|
|
8
|
-
* @name rhumbDistance
|
|
9
|
-
* @param {Coord} from origin point
|
|
10
|
-
* @param {Coord} to destination point
|
|
11
|
-
* @param {Object} [options] Optional parameters
|
|
12
|
-
* @param {string} [options.units="kilometers"] can be degrees, radians, miles, or kilometers
|
|
13
|
-
* @returns {number} distance between the two points
|
|
14
|
-
* @example
|
|
15
|
-
* var from = turf.point([-75.343, 39.984]);
|
|
16
|
-
* var to = turf.point([-75.534, 39.123]);
|
|
17
|
-
* var options = {units: 'miles'};
|
|
18
|
-
*
|
|
19
|
-
* var distance = turf.rhumbDistance(from, to, options);
|
|
20
|
-
*
|
|
21
|
-
* //addToMap
|
|
22
|
-
* var addToMap = [from, to];
|
|
23
|
-
* from.properties.distance = distance;
|
|
24
|
-
* to.properties.distance = distance;
|
|
25
|
-
*/
|
|
26
|
-
function rhumbDistance(from, to, options = {}) {
|
|
27
|
-
const origin = getCoord(from);
|
|
28
|
-
const destination = getCoord(to);
|
|
29
|
-
// compensate the crossing of the 180th meridian (https://macwright.org/2016/09/26/the-180th-meridian.html)
|
|
30
|
-
// solution from https://github.com/mapbox/mapbox-gl-js/issues/3250#issuecomment-294887678
|
|
31
|
-
destination[0] +=
|
|
32
|
-
destination[0] - origin[0] > 180
|
|
33
|
-
? -360
|
|
34
|
-
: origin[0] - destination[0] > 180
|
|
35
|
-
? 360
|
|
36
|
-
: 0;
|
|
37
|
-
const distanceInMeters = calculateRhumbDistance(origin, destination);
|
|
38
|
-
const distance = convertLength(distanceInMeters, "meters", options.units);
|
|
39
|
-
return distance;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Returns the distance travelling from ‘this’ point to destination point along a rhumb line.
|
|
43
|
-
* Adapted from Geodesy: https://github.com/chrisveness/geodesy/blob/master/latlon-spherical.js
|
|
44
|
-
*
|
|
45
|
-
* @private
|
|
46
|
-
* @param {Array<number>} origin point.
|
|
47
|
-
* @param {Array<number>} destination point.
|
|
48
|
-
* @param {number} [radius=6371e3] - (Mean) radius of earth (defaults to radius in metres).
|
|
49
|
-
* @returns {number} Distance in km between this point and destination point (same units as radius).
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* var p1 = new LatLon(51.127, 1.338);
|
|
53
|
-
* var p2 = new LatLon(50.964, 1.853);
|
|
54
|
-
* var d = p1.distanceTo(p2); // 40.31 km
|
|
55
|
-
*/
|
|
56
|
-
function calculateRhumbDistance(origin, destination, radius) {
|
|
57
|
-
// φ => phi
|
|
58
|
-
// λ => lambda
|
|
59
|
-
// ψ => psi
|
|
60
|
-
// Δ => Delta
|
|
61
|
-
// δ => delta
|
|
62
|
-
// θ => theta
|
|
63
|
-
radius = radius === undefined ? earthRadius : Number(radius);
|
|
64
|
-
// see www.edwilliams.org/avform.htm#Rhumb
|
|
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;
|
|
70
|
-
// if dLon over 180° take shorter rhumb line across the anti-meridian:
|
|
71
|
-
if (DeltaLambda > Math.PI) {
|
|
72
|
-
DeltaLambda -= 2 * Math.PI;
|
|
73
|
-
}
|
|
74
|
-
// on Mercator projection, longitude distances shrink by latitude; q is the 'stretch factor'
|
|
75
|
-
// q becomes ill-conditioned along E-W line (0/0); use empirical tolerance to avoid it
|
|
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);
|
|
78
|
-
// distance is pythagoras on 'stretched' Mercator projection
|
|
79
|
-
const delta = Math.sqrt(DeltaPhi * DeltaPhi + q * q * DeltaLambda * DeltaLambda); // angular distance in radians
|
|
80
|
-
const dist = delta * R;
|
|
81
|
-
return dist;
|
|
82
|
-
}
|
|
83
|
-
export default rhumbDistance;
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,85 +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
|
-
* Calculates the distance along a rhumb line between two {@link Point|points} in degrees, radians,
|
|
8
|
-
* miles, or kilometers.
|
|
9
|
-
*
|
|
10
|
-
* @name rhumbDistance
|
|
11
|
-
* @param {Coord} from origin point
|
|
12
|
-
* @param {Coord} to destination point
|
|
13
|
-
* @param {Object} [options] Optional parameters
|
|
14
|
-
* @param {string} [options.units="kilometers"] can be degrees, radians, miles, or kilometers
|
|
15
|
-
* @returns {number} distance between the two points
|
|
16
|
-
* @example
|
|
17
|
-
* var from = turf.point([-75.343, 39.984]);
|
|
18
|
-
* var to = turf.point([-75.534, 39.123]);
|
|
19
|
-
* var options = {units: 'miles'};
|
|
20
|
-
*
|
|
21
|
-
* var distance = turf.rhumbDistance(from, to, options);
|
|
22
|
-
*
|
|
23
|
-
* //addToMap
|
|
24
|
-
* var addToMap = [from, to];
|
|
25
|
-
* from.properties.distance = distance;
|
|
26
|
-
* to.properties.distance = distance;
|
|
27
|
-
*/
|
|
28
|
-
function rhumbDistance(from, to, options = {}) {
|
|
29
|
-
const origin = invariant_1.getCoord(from);
|
|
30
|
-
const destination = invariant_1.getCoord(to);
|
|
31
|
-
// compensate the crossing of the 180th meridian (https://macwright.org/2016/09/26/the-180th-meridian.html)
|
|
32
|
-
// solution from https://github.com/mapbox/mapbox-gl-js/issues/3250#issuecomment-294887678
|
|
33
|
-
destination[0] +=
|
|
34
|
-
destination[0] - origin[0] > 180
|
|
35
|
-
? -360
|
|
36
|
-
: origin[0] - destination[0] > 180
|
|
37
|
-
? 360
|
|
38
|
-
: 0;
|
|
39
|
-
const distanceInMeters = calculateRhumbDistance(origin, destination);
|
|
40
|
-
const distance = helpers_1.convertLength(distanceInMeters, "meters", options.units);
|
|
41
|
-
return distance;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Returns the distance travelling from ‘this’ point to destination point along a rhumb line.
|
|
45
|
-
* Adapted from Geodesy: https://github.com/chrisveness/geodesy/blob/master/latlon-spherical.js
|
|
46
|
-
*
|
|
47
|
-
* @private
|
|
48
|
-
* @param {Array<number>} origin point.
|
|
49
|
-
* @param {Array<number>} destination point.
|
|
50
|
-
* @param {number} [radius=6371e3] - (Mean) radius of earth (defaults to radius in metres).
|
|
51
|
-
* @returns {number} Distance in km between this point and destination point (same units as radius).
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* var p1 = new LatLon(51.127, 1.338);
|
|
55
|
-
* var p2 = new LatLon(50.964, 1.853);
|
|
56
|
-
* var d = p1.distanceTo(p2); // 40.31 km
|
|
57
|
-
*/
|
|
58
|
-
function calculateRhumbDistance(origin, destination, radius) {
|
|
59
|
-
// φ => phi
|
|
60
|
-
// λ => lambda
|
|
61
|
-
// ψ => psi
|
|
62
|
-
// Δ => Delta
|
|
63
|
-
// δ => delta
|
|
64
|
-
// θ => theta
|
|
65
|
-
radius = radius === undefined ? helpers_1.earthRadius : Number(radius);
|
|
66
|
-
// see www.edwilliams.org/avform.htm#Rhumb
|
|
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;
|
|
72
|
-
// if dLon over 180° take shorter rhumb line across the anti-meridian:
|
|
73
|
-
if (DeltaLambda > Math.PI) {
|
|
74
|
-
DeltaLambda -= 2 * Math.PI;
|
|
75
|
-
}
|
|
76
|
-
// on Mercator projection, longitude distances shrink by latitude; q is the 'stretch factor'
|
|
77
|
-
// q becomes ill-conditioned along E-W line (0/0); use empirical tolerance to avoid it
|
|
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);
|
|
80
|
-
// distance is pythagoras on 'stretched' Mercator projection
|
|
81
|
-
const delta = Math.sqrt(DeltaPhi * DeltaPhi + q * q * DeltaLambda * DeltaLambda); // angular distance in radians
|
|
82
|
-
const dist = delta * R;
|
|
83
|
-
return dist;
|
|
84
|
-
}
|
|
85
|
-
exports.default = rhumbDistance;
|