@turf/rhumb-destination 7.0.0-alpha.1 → 7.0.0-alpha.111

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
@@ -48,26 +48,21 @@ Returns **[Feature][6]<[Point][7]>** Destination point.
48
48
 
49
49
  [7]: https://tools.ietf.org/html/rfc7946#section-3.1.2
50
50
 
51
- <!-- This file is automatically generated. Please don't edit it directly:
52
- if you find an error, edit the source file (likely index.js), and re-run
53
- ./scripts/generate-readmes in the turf project. -->
51
+ <!-- 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. -->
54
52
 
55
53
  ---
56
54
 
57
- This module is part of the [Turfjs project](http://turfjs.org/), an open source
58
- module collection dedicated to geographic algorithms. It is maintained in the
59
- [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
60
- PRs and issues.
55
+ 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.
61
56
 
62
57
  ### Installation
63
58
 
64
- Install this module individually:
59
+ Install this single module individually:
65
60
 
66
61
  ```sh
67
62
  $ npm install @turf/rhumb-destination
68
63
  ```
69
64
 
70
- Or install the Turf module that includes it as a function:
65
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
71
66
 
72
67
  ```sh
73
68
  $ npm install @turf/turf
@@ -0,0 +1,59 @@
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
+
6
+
7
+
8
+
9
+
10
+ var _helpers = require('@turf/helpers');
11
+ var _invariant = require('@turf/invariant');
12
+ function rhumbDestination(origin, distance, bearing, options = {}) {
13
+ const wasNegativeDistance = distance < 0;
14
+ let distanceInMeters = _helpers.convertLength.call(void 0,
15
+ Math.abs(distance),
16
+ options.units,
17
+ "meters"
18
+ );
19
+ if (wasNegativeDistance)
20
+ distanceInMeters = -Math.abs(distanceInMeters);
21
+ const coords = _invariant.getCoord.call(void 0, origin);
22
+ const destination = calculateRhumbDestination(
23
+ coords,
24
+ distanceInMeters,
25
+ bearing
26
+ );
27
+ destination[0] += destination[0] - coords[0] > 180 ? -360 : coords[0] - destination[0] > 180 ? 360 : 0;
28
+ return _helpers.point.call(void 0, destination, options.properties);
29
+ }
30
+ __name(rhumbDestination, "rhumbDestination");
31
+ function calculateRhumbDestination(origin, distance, bearing, radius) {
32
+ radius = radius === void 0 ? _helpers.earthRadius : Number(radius);
33
+ const delta = distance / radius;
34
+ const lambda1 = origin[0] * Math.PI / 180;
35
+ const phi1 = _helpers.degreesToRadians.call(void 0, origin[1]);
36
+ const theta = _helpers.degreesToRadians.call(void 0, bearing);
37
+ const DeltaPhi = delta * Math.cos(theta);
38
+ let phi2 = phi1 + DeltaPhi;
39
+ if (Math.abs(phi2) > Math.PI / 2) {
40
+ phi2 = phi2 > 0 ? Math.PI - phi2 : -Math.PI - phi2;
41
+ }
42
+ const DeltaPsi = Math.log(
43
+ Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4)
44
+ );
45
+ const q = Math.abs(DeltaPsi) > 1e-11 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
46
+ const DeltaLambda = delta * Math.sin(theta) / q;
47
+ const lambda2 = lambda1 + DeltaLambda;
48
+ return [
49
+ (lambda2 * 180 / Math.PI + 540) % 360 - 180,
50
+ phi2 * 180 / Math.PI
51
+ ];
52
+ }
53
+ __name(calculateRhumbDestination, "calculateRhumbDestination");
54
+ var turf_rhumb_destination_default = rhumbDestination;
55
+
56
+
57
+
58
+ exports.default = turf_rhumb_destination_default; exports.rhumbDestination = rhumbDestination;
59
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AAEA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,gBAAgB;AA0BzB,SAAS,iBACP,QACA,UACA,SACA,UAGI,CAAC,GACc;AACnB,QAAM,sBAAsB,WAAW;AACvC,MAAI,mBAAmB;AAAA,IACrB,KAAK,IAAI,QAAQ;AAAA,IACjB,QAAQ;AAAA,IACR;AAAA,EACF;AACA,MAAI;AAAqB,uBAAmB,CAAC,KAAK,IAAI,gBAAgB;AACtE,QAAM,SAAS,SAAS,MAAM;AAC9B,QAAM,cAAc;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAIA,cAAY,CAAC,KACX,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,MACzB,OACA,OAAO,CAAC,IAAI,YAAY,CAAC,IAAI,MAC3B,MACA;AACR,SAAO,MAAM,aAAa,QAAQ,UAAU;AAC9C;AAhCS;AA8CT,SAAS,0BACP,QACA,UACA,SACA,QACA;AAQA,WAAS,WAAW,SAAY,cAAc,OAAO,MAAM;AAE3D,QAAM,QAAQ,WAAW;AACzB,QAAM,UAAW,OAAO,CAAC,IAAI,KAAK,KAAM;AACxC,QAAM,OAAO,iBAAiB,OAAO,CAAC,CAAC;AACvC,QAAM,QAAQ,iBAAiB,OAAO;AAEtC,QAAM,WAAW,QAAQ,KAAK,IAAI,KAAK;AACvC,MAAI,OAAO,OAAO;AAGlB,MAAI,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,GAAG;AAChC,WAAO,OAAO,IAAI,KAAK,KAAK,OAAO,CAAC,KAAK,KAAK;AAAA,EAChD;AAEA,QAAM,WAAW,KAAK;AAAA,IACpB,KAAK,IAAI,OAAO,IAAI,KAAK,KAAK,CAAC,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK,KAAK,CAAC;AAAA,EACpE;AAEA,QAAM,IAAI,KAAK,IAAI,QAAQ,IAAI,QAAS,WAAW,WAAW,KAAK,IAAI,IAAI;AAE3E,QAAM,cAAe,QAAQ,KAAK,IAAI,KAAK,IAAK;AAChD,QAAM,UAAU,UAAU;AAE1B,SAAO;AAAA,KACF,UAAU,MAAO,KAAK,KAAK,OAAO,MAAO;AAAA,IAC3C,OAAO,MAAO,KAAK;AAAA,EACtB;AACF;AAzCS;AA4CT,IAAO,iCAAQ","sourcesContent":["// https://en.wikipedia.org/wiki/Rhumb_line\nimport { Feature, Point, GeoJsonProperties } from \"geojson\";\nimport {\n convertLength,\n Coord,\n degreesToRadians,\n earthRadius,\n point,\n Units,\n} from \"@turf/helpers\";\nimport { getCoord } from \"@turf/invariant\";\n\n/**\n * Returns the destination {@link Point} having travelled the given distance along a Rhumb line from the\n * origin Point with the (varant) given bearing.\n *\n * @name rhumbDestination\n * @param {Coord} origin starting point\n * @param {number} distance distance from the starting point\n * @param {number} bearing varant bearing angle ranging from -180 to 180 degrees from north\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers\n * @param {Object} [options.properties={}] translate properties to destination point\n * @returns {Feature<Point>} Destination point.\n * @example\n * var pt = turf.point([-75.343, 39.984], {\"marker-color\": \"F00\"});\n * var distance = 50;\n * var bearing = 90;\n * var options = {units: 'miles'};\n *\n * var destination = turf.rhumbDestination(pt, distance, bearing, options);\n *\n * //addToMap\n * var addToMap = [pt, destination]\n * destination.properties['marker-color'] = '#00F';\n */\nfunction rhumbDestination<P extends GeoJsonProperties = GeoJsonProperties>(\n origin: Coord,\n distance: number,\n bearing: number,\n options: {\n units?: Units;\n properties?: P;\n } = {}\n): Feature<Point, P> {\n const wasNegativeDistance = distance < 0;\n let distanceInMeters = convertLength(\n Math.abs(distance),\n options.units,\n \"meters\"\n );\n if (wasNegativeDistance) distanceInMeters = -Math.abs(distanceInMeters);\n const coords = getCoord(origin);\n const destination = calculateRhumbDestination(\n coords,\n distanceInMeters,\n bearing\n );\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] - coords[0] > 180\n ? -360\n : coords[0] - destination[0] > 180\n ? 360\n : 0;\n return point(destination, options.properties);\n}\n\n/**\n * Returns the destination point having travelled along a rhumb line from origin point the given\n * distance on the given bearing.\n * Adapted from Geodesy: http://www.movable-type.co.uk/scripts/latlong.html#rhumblines\n *\n * @private\n * @param {Array<number>} origin - point\n * @param {number} distance - Distance travelled, in same units as earth radius (default: metres).\n * @param {number} bearing - Bearing in degrees from north.\n * @param {number} [radius=6371e3] - (Mean) radius of earth (defaults to radius in metres).\n * @returns {Array<number>} Destination point.\n */\nfunction calculateRhumbDestination(\n origin: number[],\n distance: number,\n bearing: 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\n const delta = distance / radius; // angular distance in radians\n const lambda1 = (origin[0] * Math.PI) / 180; // to radians, but without normalize to 𝜋\n const phi1 = degreesToRadians(origin[1]);\n const theta = degreesToRadians(bearing);\n\n const DeltaPhi = delta * Math.cos(theta);\n let phi2 = phi1 + DeltaPhi;\n\n // check for some daft bugger going past the pole, normalise latitude if so\n if (Math.abs(phi2) > Math.PI / 2) {\n phi2 = phi2 > 0 ? Math.PI - phi2 : -Math.PI - phi2;\n }\n\n const DeltaPsi = Math.log(\n Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4)\n );\n // E-W course becomes ill-conditioned with 0/0\n const q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);\n\n const DeltaLambda = (delta * Math.sin(theta)) / q;\n const lambda2 = lambda1 + DeltaLambda;\n\n return [\n (((lambda2 * 180) / Math.PI + 540) % 360) - 180,\n (phi2 * 180) / Math.PI,\n ]; // normalise to −180..+180°\n}\n\nexport { rhumbDestination };\nexport default rhumbDestination;\n"]}
@@ -1,5 +1,6 @@
1
- import { Feature, Point, GeoJsonProperties } from "geojson";
2
- import { Coord, Units } from "@turf/helpers";
1
+ import { GeoJsonProperties, Feature, Point } from 'geojson';
2
+ import { Coord, Units } from '@turf/helpers';
3
+
3
4
  /**
4
5
  * Returns the destination {@link Point} having travelled the given distance along a Rhumb line from the
5
6
  * origin Point with the (varant) given bearing.
@@ -24,8 +25,9 @@ import { Coord, Units } from "@turf/helpers";
24
25
  * var addToMap = [pt, destination]
25
26
  * destination.properties['marker-color'] = '#00F';
26
27
  */
27
- declare function rhumbDestination<P = GeoJsonProperties>(origin: Coord, distance: number, bearing: number, options?: {
28
+ declare function rhumbDestination<P extends GeoJsonProperties = GeoJsonProperties>(origin: Coord, distance: number, bearing: number, options?: {
28
29
  units?: Units;
29
30
  properties?: P;
30
31
  }): Feature<Point, P>;
31
- export default rhumbDestination;
32
+
33
+ export { rhumbDestination as default, rhumbDestination };
@@ -0,0 +1,33 @@
1
+ import { GeoJsonProperties, Feature, Point } from 'geojson';
2
+ import { Coord, Units } from '@turf/helpers';
3
+
4
+ /**
5
+ * Returns the destination {@link Point} having travelled the given distance along a Rhumb line from the
6
+ * origin Point with the (varant) given bearing.
7
+ *
8
+ * @name rhumbDestination
9
+ * @param {Coord} origin starting point
10
+ * @param {number} distance distance from the starting point
11
+ * @param {number} bearing varant bearing angle ranging from -180 to 180 degrees from north
12
+ * @param {Object} [options={}] Optional parameters
13
+ * @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers
14
+ * @param {Object} [options.properties={}] translate properties to destination point
15
+ * @returns {Feature<Point>} Destination point.
16
+ * @example
17
+ * var pt = turf.point([-75.343, 39.984], {"marker-color": "F00"});
18
+ * var distance = 50;
19
+ * var bearing = 90;
20
+ * var options = {units: 'miles'};
21
+ *
22
+ * var destination = turf.rhumbDestination(pt, distance, bearing, options);
23
+ *
24
+ * //addToMap
25
+ * var addToMap = [pt, destination]
26
+ * destination.properties['marker-color'] = '#00F';
27
+ */
28
+ declare function rhumbDestination<P extends GeoJsonProperties = GeoJsonProperties>(origin: Coord, distance: number, bearing: number, options?: {
29
+ units?: Units;
30
+ properties?: P;
31
+ }): Feature<Point, P>;
32
+
33
+ export { rhumbDestination as default, rhumbDestination };
@@ -0,0 +1,59 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // index.ts
5
+ import {
6
+ convertLength,
7
+ degreesToRadians,
8
+ earthRadius,
9
+ point
10
+ } from "@turf/helpers";
11
+ import { getCoord } from "@turf/invariant";
12
+ function rhumbDestination(origin, distance, bearing, options = {}) {
13
+ const wasNegativeDistance = distance < 0;
14
+ let distanceInMeters = convertLength(
15
+ Math.abs(distance),
16
+ options.units,
17
+ "meters"
18
+ );
19
+ if (wasNegativeDistance)
20
+ distanceInMeters = -Math.abs(distanceInMeters);
21
+ const coords = getCoord(origin);
22
+ const destination = calculateRhumbDestination(
23
+ coords,
24
+ distanceInMeters,
25
+ bearing
26
+ );
27
+ destination[0] += destination[0] - coords[0] > 180 ? -360 : coords[0] - destination[0] > 180 ? 360 : 0;
28
+ return point(destination, options.properties);
29
+ }
30
+ __name(rhumbDestination, "rhumbDestination");
31
+ function calculateRhumbDestination(origin, distance, bearing, radius) {
32
+ radius = radius === void 0 ? earthRadius : Number(radius);
33
+ const delta = distance / radius;
34
+ const lambda1 = origin[0] * Math.PI / 180;
35
+ const phi1 = degreesToRadians(origin[1]);
36
+ const theta = degreesToRadians(bearing);
37
+ const DeltaPhi = delta * Math.cos(theta);
38
+ let phi2 = phi1 + DeltaPhi;
39
+ if (Math.abs(phi2) > Math.PI / 2) {
40
+ phi2 = phi2 > 0 ? Math.PI - phi2 : -Math.PI - phi2;
41
+ }
42
+ const DeltaPsi = Math.log(
43
+ Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4)
44
+ );
45
+ const q = Math.abs(DeltaPsi) > 1e-11 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
46
+ const DeltaLambda = delta * Math.sin(theta) / q;
47
+ const lambda2 = lambda1 + DeltaLambda;
48
+ return [
49
+ (lambda2 * 180 / Math.PI + 540) % 360 - 180,
50
+ phi2 * 180 / Math.PI
51
+ ];
52
+ }
53
+ __name(calculateRhumbDestination, "calculateRhumbDestination");
54
+ var turf_rhumb_destination_default = rhumbDestination;
55
+ export {
56
+ turf_rhumb_destination_default as default,
57
+ rhumbDestination
58
+ };
59
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["// https://en.wikipedia.org/wiki/Rhumb_line\nimport { Feature, Point, GeoJsonProperties } from \"geojson\";\nimport {\n convertLength,\n Coord,\n degreesToRadians,\n earthRadius,\n point,\n Units,\n} from \"@turf/helpers\";\nimport { getCoord } from \"@turf/invariant\";\n\n/**\n * Returns the destination {@link Point} having travelled the given distance along a Rhumb line from the\n * origin Point with the (varant) given bearing.\n *\n * @name rhumbDestination\n * @param {Coord} origin starting point\n * @param {number} distance distance from the starting point\n * @param {number} bearing varant bearing angle ranging from -180 to 180 degrees from north\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers\n * @param {Object} [options.properties={}] translate properties to destination point\n * @returns {Feature<Point>} Destination point.\n * @example\n * var pt = turf.point([-75.343, 39.984], {\"marker-color\": \"F00\"});\n * var distance = 50;\n * var bearing = 90;\n * var options = {units: 'miles'};\n *\n * var destination = turf.rhumbDestination(pt, distance, bearing, options);\n *\n * //addToMap\n * var addToMap = [pt, destination]\n * destination.properties['marker-color'] = '#00F';\n */\nfunction rhumbDestination<P extends GeoJsonProperties = GeoJsonProperties>(\n origin: Coord,\n distance: number,\n bearing: number,\n options: {\n units?: Units;\n properties?: P;\n } = {}\n): Feature<Point, P> {\n const wasNegativeDistance = distance < 0;\n let distanceInMeters = convertLength(\n Math.abs(distance),\n options.units,\n \"meters\"\n );\n if (wasNegativeDistance) distanceInMeters = -Math.abs(distanceInMeters);\n const coords = getCoord(origin);\n const destination = calculateRhumbDestination(\n coords,\n distanceInMeters,\n bearing\n );\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] - coords[0] > 180\n ? -360\n : coords[0] - destination[0] > 180\n ? 360\n : 0;\n return point(destination, options.properties);\n}\n\n/**\n * Returns the destination point having travelled along a rhumb line from origin point the given\n * distance on the given bearing.\n * Adapted from Geodesy: http://www.movable-type.co.uk/scripts/latlong.html#rhumblines\n *\n * @private\n * @param {Array<number>} origin - point\n * @param {number} distance - Distance travelled, in same units as earth radius (default: metres).\n * @param {number} bearing - Bearing in degrees from north.\n * @param {number} [radius=6371e3] - (Mean) radius of earth (defaults to radius in metres).\n * @returns {Array<number>} Destination point.\n */\nfunction calculateRhumbDestination(\n origin: number[],\n distance: number,\n bearing: 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\n const delta = distance / radius; // angular distance in radians\n const lambda1 = (origin[0] * Math.PI) / 180; // to radians, but without normalize to 𝜋\n const phi1 = degreesToRadians(origin[1]);\n const theta = degreesToRadians(bearing);\n\n const DeltaPhi = delta * Math.cos(theta);\n let phi2 = phi1 + DeltaPhi;\n\n // check for some daft bugger going past the pole, normalise latitude if so\n if (Math.abs(phi2) > Math.PI / 2) {\n phi2 = phi2 > 0 ? Math.PI - phi2 : -Math.PI - phi2;\n }\n\n const DeltaPsi = Math.log(\n Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4)\n );\n // E-W course becomes ill-conditioned with 0/0\n const q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);\n\n const DeltaLambda = (delta * Math.sin(theta)) / q;\n const lambda2 = lambda1 + DeltaLambda;\n\n return [\n (((lambda2 * 180) / Math.PI + 540) % 360) - 180,\n (phi2 * 180) / Math.PI,\n ]; // normalise to −180..+180°\n}\n\nexport { rhumbDestination };\nexport default rhumbDestination;\n"],"mappings":";;;;AAEA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,gBAAgB;AA0BzB,SAAS,iBACP,QACA,UACA,SACA,UAGI,CAAC,GACc;AACnB,QAAM,sBAAsB,WAAW;AACvC,MAAI,mBAAmB;AAAA,IACrB,KAAK,IAAI,QAAQ;AAAA,IACjB,QAAQ;AAAA,IACR;AAAA,EACF;AACA,MAAI;AAAqB,uBAAmB,CAAC,KAAK,IAAI,gBAAgB;AACtE,QAAM,SAAS,SAAS,MAAM;AAC9B,QAAM,cAAc;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAIA,cAAY,CAAC,KACX,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,MACzB,OACA,OAAO,CAAC,IAAI,YAAY,CAAC,IAAI,MAC3B,MACA;AACR,SAAO,MAAM,aAAa,QAAQ,UAAU;AAC9C;AAhCS;AA8CT,SAAS,0BACP,QACA,UACA,SACA,QACA;AAQA,WAAS,WAAW,SAAY,cAAc,OAAO,MAAM;AAE3D,QAAM,QAAQ,WAAW;AACzB,QAAM,UAAW,OAAO,CAAC,IAAI,KAAK,KAAM;AACxC,QAAM,OAAO,iBAAiB,OAAO,CAAC,CAAC;AACvC,QAAM,QAAQ,iBAAiB,OAAO;AAEtC,QAAM,WAAW,QAAQ,KAAK,IAAI,KAAK;AACvC,MAAI,OAAO,OAAO;AAGlB,MAAI,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,GAAG;AAChC,WAAO,OAAO,IAAI,KAAK,KAAK,OAAO,CAAC,KAAK,KAAK;AAAA,EAChD;AAEA,QAAM,WAAW,KAAK;AAAA,IACpB,KAAK,IAAI,OAAO,IAAI,KAAK,KAAK,CAAC,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK,KAAK,CAAC;AAAA,EACpE;AAEA,QAAM,IAAI,KAAK,IAAI,QAAQ,IAAI,QAAS,WAAW,WAAW,KAAK,IAAI,IAAI;AAE3E,QAAM,cAAe,QAAQ,KAAK,IAAI,KAAK,IAAK;AAChD,QAAM,UAAU,UAAU;AAE1B,SAAO;AAAA,KACF,UAAU,MAAO,KAAK,KAAK,OAAO,MAAO;AAAA,IAC3C,OAAO,MAAO,KAAK;AAAA,EACtB;AACF;AAzCS;AA4CT,IAAO,iCAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/rhumb-destination",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-alpha.111+08576cb50",
4
4
  "description": "turf rhumb-destination module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -32,46 +32,51 @@
32
32
  "miles",
33
33
  "km"
34
34
  ],
35
- "main": "dist/js/index.js",
36
- "module": "dist/es/index.js",
35
+ "type": "commonjs",
36
+ "main": "dist/cjs/index.cjs",
37
+ "module": "dist/esm/index.mjs",
38
+ "types": "dist/cjs/index.d.ts",
37
39
  "exports": {
38
40
  "./package.json": "./package.json",
39
41
  ".": {
40
- "types": "./dist/js/index.d.ts",
41
- "import": "./dist/es/index.js",
42
- "require": "./dist/js/index.js"
42
+ "import": {
43
+ "types": "./dist/esm/index.d.mts",
44
+ "default": "./dist/esm/index.mjs"
45
+ },
46
+ "require": {
47
+ "types": "./dist/cjs/index.d.ts",
48
+ "default": "./dist/cjs/index.cjs"
49
+ }
43
50
  }
44
51
  },
45
- "types": "dist/js/index.d.ts",
46
52
  "sideEffects": false,
47
53
  "files": [
48
54
  "dist"
49
55
  ],
50
56
  "scripts": {
51
- "bench": "tsx bench.js",
52
- "build": "npm-run-all build:*",
53
- "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
54
- "build:js": "tsc",
55
- "docs": "tsx ../../scripts/generate-readmes",
56
- "test": "npm-run-all test:*",
57
- "test:tape": "tsx test.js"
57
+ "bench": "tsx bench.ts",
58
+ "build": "tsup --config ../../tsup.config.ts",
59
+ "docs": "tsx ../../scripts/generate-readmes.ts",
60
+ "test": "npm-run-all --npm-path npm test:*",
61
+ "test:tape": "tsx test.ts"
58
62
  },
59
63
  "devDependencies": {
60
- "@turf/truncate": "^7.0.0-alpha.1",
61
- "@types/tape": "*",
62
- "benchmark": "*",
63
- "load-json-file": "*",
64
- "npm-run-all": "*",
65
- "tape": "*",
66
- "tslint": "*",
67
- "tsx": "*",
68
- "typescript": "*",
69
- "write-json-file": "*"
64
+ "@turf/truncate": "^7.0.0-alpha.111+08576cb50",
65
+ "@types/benchmark": "^2.1.5",
66
+ "@types/tape": "^4.2.32",
67
+ "benchmark": "^2.1.4",
68
+ "load-json-file": "^7.0.1",
69
+ "npm-run-all": "^4.1.5",
70
+ "tape": "^5.7.2",
71
+ "tsup": "^8.0.1",
72
+ "tsx": "^4.6.2",
73
+ "typescript": "^5.2.2",
74
+ "write-json-file": "^5.0.0"
70
75
  },
71
76
  "dependencies": {
72
- "@turf/helpers": "^7.0.0-alpha.1",
73
- "@turf/invariant": "^7.0.0-alpha.1",
74
- "tslib": "^2.3.0"
77
+ "@turf/helpers": "^7.0.0-alpha.111+08576cb50",
78
+ "@turf/invariant": "^7.0.0-alpha.111+08576cb50",
79
+ "tslib": "^2.6.2"
75
80
  },
76
- "gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
81
+ "gitHead": "08576cb50376e0199aea02dbd887e3af83672246"
77
82
  }
package/dist/es/index.js DELETED
@@ -1,84 +0,0 @@
1
- import { convertLength, degreesToRadians, earthRadius, point, } from "@turf/helpers";
2
- import { getCoord } from "@turf/invariant";
3
- /**
4
- * Returns the destination {@link Point} having travelled the given distance along a Rhumb line from the
5
- * origin Point with the (varant) given bearing.
6
- *
7
- * @name rhumbDestination
8
- * @param {Coord} origin starting point
9
- * @param {number} distance distance from the starting point
10
- * @param {number} bearing varant bearing angle ranging from -180 to 180 degrees from north
11
- * @param {Object} [options={}] Optional parameters
12
- * @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers
13
- * @param {Object} [options.properties={}] translate properties to destination point
14
- * @returns {Feature<Point>} Destination point.
15
- * @example
16
- * var pt = turf.point([-75.343, 39.984], {"marker-color": "F00"});
17
- * var distance = 50;
18
- * var bearing = 90;
19
- * var options = {units: 'miles'};
20
- *
21
- * var destination = turf.rhumbDestination(pt, distance, bearing, options);
22
- *
23
- * //addToMap
24
- * var addToMap = [pt, destination]
25
- * destination.properties['marker-color'] = '#00F';
26
- */
27
- function rhumbDestination(origin, distance, bearing, options = {}) {
28
- const wasNegativeDistance = distance < 0;
29
- let distanceInMeters = convertLength(Math.abs(distance), options.units, "meters");
30
- if (wasNegativeDistance)
31
- distanceInMeters = -Math.abs(distanceInMeters);
32
- const coords = getCoord(origin);
33
- const destination = calculateRhumbDestination(coords, distanceInMeters, bearing);
34
- // compensate the crossing of the 180th meridian (https://macwright.org/2016/09/26/the-180th-meridian.html)
35
- // solution from https://github.com/mapbox/mapbox-gl-js/issues/3250#issuecomment-294887678
36
- destination[0] +=
37
- destination[0] - coords[0] > 180
38
- ? -360
39
- : coords[0] - destination[0] > 180
40
- ? 360
41
- : 0;
42
- return point(destination, options.properties);
43
- }
44
- /**
45
- * Returns the destination point having travelled along a rhumb line from origin point the given
46
- * distance on the given bearing.
47
- * Adapted from Geodesy: http://www.movable-type.co.uk/scripts/latlong.html#rhumblines
48
- *
49
- * @private
50
- * @param {Array<number>} origin - point
51
- * @param {number} distance - Distance travelled, in same units as earth radius (default: metres).
52
- * @param {number} bearing - Bearing in degrees from north.
53
- * @param {number} [radius=6371e3] - (Mean) radius of earth (defaults to radius in metres).
54
- * @returns {Array<number>} Destination point.
55
- */
56
- function calculateRhumbDestination(origin, distance, bearing, radius) {
57
- // φ => phi
58
- // λ => lambda
59
- // ψ => psi
60
- // Δ => Delta
61
- // δ => delta
62
- // θ => theta
63
- radius = radius === undefined ? earthRadius : Number(radius);
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;
70
- // check for some daft bugger going past the pole, normalise latitude if so
71
- if (Math.abs(phi2) > Math.PI / 2) {
72
- phi2 = phi2 > 0 ? Math.PI - phi2 : -Math.PI - phi2;
73
- }
74
- const DeltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
75
- // E-W course becomes ill-conditioned with 0/0
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;
79
- return [
80
- (((lambda2 * 180) / Math.PI + 540) % 360) - 180,
81
- (phi2 * 180) / Math.PI,
82
- ]; // normalise to −180..+180°
83
- }
84
- export default rhumbDestination;
@@ -1 +0,0 @@
1
- {"type":"module"}
package/dist/js/index.js DELETED
@@ -1,86 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const helpers_1 = require("@turf/helpers");
4
- const invariant_1 = require("@turf/invariant");
5
- /**
6
- * Returns the destination {@link Point} having travelled the given distance along a Rhumb line from the
7
- * origin Point with the (varant) given bearing.
8
- *
9
- * @name rhumbDestination
10
- * @param {Coord} origin starting point
11
- * @param {number} distance distance from the starting point
12
- * @param {number} bearing varant bearing angle ranging from -180 to 180 degrees from north
13
- * @param {Object} [options={}] Optional parameters
14
- * @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers
15
- * @param {Object} [options.properties={}] translate properties to destination point
16
- * @returns {Feature<Point>} Destination point.
17
- * @example
18
- * var pt = turf.point([-75.343, 39.984], {"marker-color": "F00"});
19
- * var distance = 50;
20
- * var bearing = 90;
21
- * var options = {units: 'miles'};
22
- *
23
- * var destination = turf.rhumbDestination(pt, distance, bearing, options);
24
- *
25
- * //addToMap
26
- * var addToMap = [pt, destination]
27
- * destination.properties['marker-color'] = '#00F';
28
- */
29
- function rhumbDestination(origin, distance, bearing, options = {}) {
30
- const wasNegativeDistance = distance < 0;
31
- let distanceInMeters = helpers_1.convertLength(Math.abs(distance), options.units, "meters");
32
- if (wasNegativeDistance)
33
- distanceInMeters = -Math.abs(distanceInMeters);
34
- const coords = invariant_1.getCoord(origin);
35
- const destination = calculateRhumbDestination(coords, distanceInMeters, bearing);
36
- // compensate the crossing of the 180th meridian (https://macwright.org/2016/09/26/the-180th-meridian.html)
37
- // solution from https://github.com/mapbox/mapbox-gl-js/issues/3250#issuecomment-294887678
38
- destination[0] +=
39
- destination[0] - coords[0] > 180
40
- ? -360
41
- : coords[0] - destination[0] > 180
42
- ? 360
43
- : 0;
44
- return helpers_1.point(destination, options.properties);
45
- }
46
- /**
47
- * Returns the destination point having travelled along a rhumb line from origin point the given
48
- * distance on the given bearing.
49
- * Adapted from Geodesy: http://www.movable-type.co.uk/scripts/latlong.html#rhumblines
50
- *
51
- * @private
52
- * @param {Array<number>} origin - point
53
- * @param {number} distance - Distance travelled, in same units as earth radius (default: metres).
54
- * @param {number} bearing - Bearing in degrees from north.
55
- * @param {number} [radius=6371e3] - (Mean) radius of earth (defaults to radius in metres).
56
- * @returns {Array<number>} Destination point.
57
- */
58
- function calculateRhumbDestination(origin, distance, bearing, radius) {
59
- // φ => phi
60
- // λ => lambda
61
- // ψ => psi
62
- // Δ => Delta
63
- // δ => delta
64
- // θ => theta
65
- radius = radius === undefined ? helpers_1.earthRadius : Number(radius);
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;
72
- // check for some daft bugger going past the pole, normalise latitude if so
73
- if (Math.abs(phi2) > Math.PI / 2) {
74
- phi2 = phi2 > 0 ? Math.PI - phi2 : -Math.PI - phi2;
75
- }
76
- const DeltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
77
- // E-W course becomes ill-conditioned with 0/0
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;
81
- return [
82
- (((lambda2 * 180) / Math.PI + 540) % 360) - 180,
83
- (phi2 * 180) / Math.PI,
84
- ]; // normalise to −180..+180°
85
- }
86
- exports.default = rhumbDestination;