@turf/rhumb-distance 7.2.0 → 7.3.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
@@ -4,16 +4,15 @@
4
4
 
5
5
  ## rhumbDistance
6
6
 
7
- Calculates the distance along a rhumb line between two [points][1] in degrees, radians,
8
- miles, or kilometers.
7
+ Calculates the distance along a rhumb line between two [points][1] in [Units][2]
9
8
 
10
9
  ### Parameters
11
10
 
12
- * `from` **[Coord][2]** origin point
13
- * `to` **[Coord][2]** destination point
14
- * `options` **[Object][3]?** Optional parameters (optional, default `{}`)
11
+ * `from` **[Coord][3]** origin point
12
+ * `to` **[Coord][3]** destination point
13
+ * `options` **[Object][4]?** Optional parameters (optional, default `{}`)
15
14
 
16
- * `options.units` **[string][4]** can be degrees, radians, miles, or kilometers (optional, default `"kilometers"`)
15
+ * `options.units` **Units** Supports all valid Turf [Units][2] (optional, default `'kilometers'`)
17
16
 
18
17
  ### Examples
19
18
 
@@ -34,11 +33,11 @@ Returns **[number][5]** distance between the two points
34
33
 
35
34
  [1]: https://tools.ietf.org/html/rfc7946#section-3.1.2
36
35
 
37
- [2]: https://tools.ietf.org/html/rfc7946#section-3.1.1
36
+ [2]: https://turfjs.org/docs/api/types/Units
38
37
 
39
- [3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
38
+ [3]: https://tools.ietf.org/html/rfc7946#section-3.1.1
40
39
 
41
- [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
40
+ [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
42
41
 
43
42
  [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
44
43
 
@@ -29,9 +29,9 @@ function calculateRhumbDistance(origin, destination, radius) {
29
29
  const dist = delta * R;
30
30
  return dist;
31
31
  }
32
- var turf_rhumb_distance_default = rhumbDistance;
32
+ var index_default = rhumbDistance;
33
33
 
34
34
 
35
35
 
36
- exports.default = turf_rhumb_distance_default; exports.rhumbDistance = rhumbDistance;
36
+ exports.default = index_default; exports.rhumbDistance = rhumbDistance;
37
37
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-rhumb-distance/dist/cjs/index.cjs","../../index.ts"],"names":[],"mappings":"AAAA;ACCA,wCAAyD;AACzD,4CAAyB;AAwBzB,SAAS,aAAA,CACP,IAAA,EACA,EAAA,EACA,QAAA,EAEI,CAAC,CAAA,EACG;AACR,EAAA,MAAM,OAAA,EAAS,iCAAA,IAAa,CAAA;AAC5B,EAAA,MAAM,YAAA,EAAc,iCAAA,EAAW,CAAA;AAI/B,EAAA,WAAA,CAAY,CAAC,EAAA,GACX,WAAA,CAAY,CAAC,EAAA,EAAI,MAAA,CAAO,CAAC,EAAA,EAAI,IAAA,EACzB,CAAA,IAAA,EACA,MAAA,CAAO,CAAC,EAAA,EAAI,WAAA,CAAY,CAAC,EAAA,EAAI,IAAA,EAC3B,IAAA,EACA,CAAA;AACR,EAAA,MAAM,iBAAA,EAAmB,sBAAA,CAAuB,MAAA,EAAQ,WAAW,CAAA;AACnE,EAAA,MAAM,SAAA,EAAW,oCAAA,gBAAc,EAAkB,QAAA,EAAU,OAAA,CAAQ,KAAK,CAAA;AACxE,EAAA,OAAO,QAAA;AACT;AAiBA,SAAS,sBAAA,CACP,MAAA,EACA,WAAA,EACA,MAAA,EACA;AAQA,EAAA,OAAA,EAAS,OAAA,IAAW,KAAA,EAAA,EAAY,qBAAA,EAAc,MAAA,CAAO,MAAM,CAAA;AAG3D,EAAA,MAAM,EAAA,EAAI,MAAA;AACV,EAAA,MAAM,KAAA,EAAQ,MAAA,CAAO,CAAC,EAAA,EAAI,IAAA,CAAK,GAAA,EAAM,GAAA;AACrC,EAAA,MAAM,KAAA,EAAQ,WAAA,CAAY,CAAC,EAAA,EAAI,IAAA,CAAK,GAAA,EAAM,GAAA;AAC1C,EAAA,MAAM,SAAA,EAAW,KAAA,EAAO,IAAA;AACxB,EAAA,IAAI,YAAA,EAAe,IAAA,CAAK,GAAA,CAAI,WAAA,CAAY,CAAC,EAAA,EAAI,MAAA,CAAO,CAAC,CAAC,EAAA,EAAI,IAAA,CAAK,GAAA,EAAM,GAAA;AAErE,EAAA,GAAA,CAAI,YAAA,EAAc,IAAA,CAAK,EAAA,EAAI;AACzB,IAAA,YAAA,GAAe,EAAA,EAAI,IAAA,CAAK,EAAA;AAAA,EAC1B;AAIA,EAAA,MAAM,SAAA,EAAW,IAAA,CAAK,GAAA;AAAA,IACpB,IAAA,CAAK,GAAA,CAAI,KAAA,EAAO,EAAA,EAAI,IAAA,CAAK,GAAA,EAAK,CAAC,EAAA,EAAI,IAAA,CAAK,GAAA,CAAI,KAAA,EAAO,EAAA,EAAI,IAAA,CAAK,GAAA,EAAK,CAAC;AAAA,EACpE,CAAA;AACA,EAAA,MAAM,EAAA,EAAI,IAAA,CAAK,GAAA,CAAI,QAAQ,EAAA,EAAI,MAAA,EAAS,SAAA,EAAW,SAAA,EAAW,IAAA,CAAK,GAAA,CAAI,IAAI,CAAA;AAG3E,EAAA,MAAM,MAAA,EAAQ,IAAA,CAAK,IAAA;AAAA,IACjB,SAAA,EAAW,SAAA,EAAW,EAAA,EAAI,EAAA,EAAI,YAAA,EAAc;AAAA,EAC9C,CAAA;AACA,EAAA,MAAM,KAAA,EAAO,MAAA,EAAQ,CAAA;AAErB,EAAA,OAAO,IAAA;AACT;AAGA,IAAO,4BAAA,EAAQ,aAAA;AD1Ef;AACE;AACA;AACF,qFAAC","file":"/home/runner/work/turf/turf/packages/turf-rhumb-distance/dist/cjs/index.cjs","sourcesContent":[null,"// 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 * @function\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
+ {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-rhumb-distance/dist/cjs/index.cjs","../../index.ts"],"names":[],"mappings":"AAAA;ACCA,wCAAyD;AACzD,4CAAyB;AAuBzB,SAAS,aAAA,CACP,IAAA,EACA,EAAA,EACA,QAAA,EAEI,CAAC,CAAA,EACG;AACR,EAAA,MAAM,OAAA,EAAS,iCAAA,IAAa,CAAA;AAC5B,EAAA,MAAM,YAAA,EAAc,iCAAA,EAAW,CAAA;AAI/B,EAAA,WAAA,CAAY,CAAC,EAAA,GACX,WAAA,CAAY,CAAC,EAAA,EAAI,MAAA,CAAO,CAAC,EAAA,EAAI,IAAA,EACzB,CAAA,IAAA,EACA,MAAA,CAAO,CAAC,EAAA,EAAI,WAAA,CAAY,CAAC,EAAA,EAAI,IAAA,EAC3B,IAAA,EACA,CAAA;AACR,EAAA,MAAM,iBAAA,EAAmB,sBAAA,CAAuB,MAAA,EAAQ,WAAW,CAAA;AACnE,EAAA,MAAM,SAAA,EAAW,oCAAA,gBAAc,EAAkB,QAAA,EAAU,OAAA,CAAQ,KAAK,CAAA;AACxE,EAAA,OAAO,QAAA;AACT;AAiBA,SAAS,sBAAA,CACP,MAAA,EACA,WAAA,EACA,MAAA,EACA;AAQA,EAAA,OAAA,EAAS,OAAA,IAAW,KAAA,EAAA,EAAY,qBAAA,EAAc,MAAA,CAAO,MAAM,CAAA;AAG3D,EAAA,MAAM,EAAA,EAAI,MAAA;AACV,EAAA,MAAM,KAAA,EAAQ,MAAA,CAAO,CAAC,EAAA,EAAI,IAAA,CAAK,GAAA,EAAM,GAAA;AACrC,EAAA,MAAM,KAAA,EAAQ,WAAA,CAAY,CAAC,EAAA,EAAI,IAAA,CAAK,GAAA,EAAM,GAAA;AAC1C,EAAA,MAAM,SAAA,EAAW,KAAA,EAAO,IAAA;AACxB,EAAA,IAAI,YAAA,EAAe,IAAA,CAAK,GAAA,CAAI,WAAA,CAAY,CAAC,EAAA,EAAI,MAAA,CAAO,CAAC,CAAC,EAAA,EAAI,IAAA,CAAK,GAAA,EAAM,GAAA;AAErE,EAAA,GAAA,CAAI,YAAA,EAAc,IAAA,CAAK,EAAA,EAAI;AACzB,IAAA,YAAA,GAAe,EAAA,EAAI,IAAA,CAAK,EAAA;AAAA,EAC1B;AAIA,EAAA,MAAM,SAAA,EAAW,IAAA,CAAK,GAAA;AAAA,IACpB,IAAA,CAAK,GAAA,CAAI,KAAA,EAAO,EAAA,EAAI,IAAA,CAAK,GAAA,EAAK,CAAC,EAAA,EAAI,IAAA,CAAK,GAAA,CAAI,KAAA,EAAO,EAAA,EAAI,IAAA,CAAK,GAAA,EAAK,CAAC;AAAA,EACpE,CAAA;AACA,EAAA,MAAM,EAAA,EAAI,IAAA,CAAK,GAAA,CAAI,QAAQ,EAAA,EAAI,MAAA,EAAS,SAAA,EAAW,SAAA,EAAW,IAAA,CAAK,GAAA,CAAI,IAAI,CAAA;AAG3E,EAAA,MAAM,MAAA,EAAQ,IAAA,CAAK,IAAA;AAAA,IACjB,SAAA,EAAW,SAAA,EAAW,EAAA,EAAI,EAAA,EAAI,YAAA,EAAc;AAAA,EAC9C,CAAA;AACA,EAAA,MAAM,KAAA,EAAO,MAAA,EAAQ,CAAA;AAErB,EAAA,OAAO,IAAA;AACT;AAGA,IAAO,cAAA,EAAQ,aAAA;ADzEf;AACE;AACA;AACF,uEAAC","file":"/home/runner/work/turf/turf/packages/turf-rhumb-distance/dist/cjs/index.cjs","sourcesContent":[null,"// 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 {@link https://turfjs.org/docs/api/types/Units Units}\n *\n * @function\n * @param {Coord} from origin point\n * @param {Coord} to destination point\n * @param {Object} [options] Optional parameters\n * @param {Units} [options.units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}\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,14 +1,13 @@
1
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,
5
- * miles, or kilometers.
4
+ * Calculates the distance along a rhumb line between two {@link Point|points} in {@link https://turfjs.org/docs/api/types/Units Units}
6
5
  *
7
6
  * @function
8
7
  * @param {Coord} from origin point
9
8
  * @param {Coord} to destination point
10
9
  * @param {Object} [options] Optional parameters
11
- * @param {string} [options.units="kilometers"] can be degrees, radians, miles, or kilometers
10
+ * @param {Units} [options.units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}
12
11
  * @returns {number} distance between the two points
13
12
  * @example
14
13
  * var from = turf.point([-75.343, 39.984]);
@@ -1,14 +1,13 @@
1
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,
5
- * miles, or kilometers.
4
+ * Calculates the distance along a rhumb line between two {@link Point|points} in {@link https://turfjs.org/docs/api/types/Units Units}
6
5
  *
7
6
  * @function
8
7
  * @param {Coord} from origin point
9
8
  * @param {Coord} to destination point
10
9
  * @param {Object} [options] Optional parameters
11
- * @param {string} [options.units="kilometers"] can be degrees, radians, miles, or kilometers
10
+ * @param {Units} [options.units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}
12
11
  * @returns {number} distance between the two points
13
12
  * @example
14
13
  * var from = turf.point([-75.343, 39.984]);
package/dist/esm/index.js CHANGED
@@ -29,9 +29,9 @@ function calculateRhumbDistance(origin, destination, radius) {
29
29
  const dist = delta * R;
30
30
  return dist;
31
31
  }
32
- var turf_rhumb_distance_default = rhumbDistance;
32
+ var index_default = rhumbDistance;
33
33
  export {
34
- turf_rhumb_distance_default as default,
34
+ index_default as default,
35
35
  rhumbDistance
36
36
  };
37
37
  //# sourceMappingURL=index.js.map
@@ -1 +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 * @function\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;AAiBA,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;AAGA,IAAO,8BAAQ;","names":[]}
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 {@link https://turfjs.org/docs/api/types/Units Units}\n *\n * @function\n * @param {Coord} from origin point\n * @param {Coord} to destination point\n * @param {Object} [options] Optional parameters\n * @param {Units} [options.units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}\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;AAuBzB,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;AAiBA,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;AAGA,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@turf/rhumb-distance",
3
- "version": "7.2.0",
4
- "description": "turf rhumb-distance module",
3
+ "version": "7.3.1",
4
+ "description": "Calculates the distance along a rhumb line between two points.",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
7
7
  "Chris Veness <@chrisveness>",
@@ -55,27 +55,26 @@
55
55
  "bench": "tsx bench.ts",
56
56
  "build": "tsup --config ../../tsup.config.ts",
57
57
  "docs": "tsx ../../scripts/generate-readmes.ts",
58
- "test": "npm-run-all --npm-path npm test:*",
58
+ "test": "pnpm run /test:.*/",
59
59
  "test:tape": "tsx test.ts"
60
60
  },
61
61
  "devDependencies": {
62
- "@turf/distance": "^7.2.0",
62
+ "@turf/distance": "7.3.1",
63
63
  "@types/benchmark": "^2.1.5",
64
- "@types/tape": "^4.13.4",
64
+ "@types/tape": "^5.8.1",
65
65
  "benchmark": "^2.1.4",
66
66
  "load-json-file": "^7.0.1",
67
- "npm-run-all": "^4.1.5",
68
67
  "tape": "^5.9.0",
69
- "tsup": "^8.3.5",
70
- "tsx": "^4.19.2",
71
- "typescript": "^5.5.4",
72
- "write-json-file": "^5.0.0"
68
+ "tsup": "^8.4.0",
69
+ "tsx": "^4.19.4",
70
+ "typescript": "^5.8.3",
71
+ "write-json-file": "^6.0.0"
73
72
  },
74
73
  "dependencies": {
75
- "@turf/helpers": "^7.2.0",
76
- "@turf/invariant": "^7.2.0",
74
+ "@turf/helpers": "7.3.1",
75
+ "@turf/invariant": "7.3.1",
77
76
  "@types/geojson": "^7946.0.10",
78
77
  "tslib": "^2.8.1"
79
78
  },
80
- "gitHead": "7b0f0374c4668cd569f8904c71e2ae7d941be867"
79
+ "gitHead": "b7f1b4eafb760431e03955499d8eac9489438219"
81
80
  }