@turf/destination 7.0.0-alpha.2 → 7.1.0-alpha.7

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
@@ -52,26 +52,21 @@ Returns **[Feature][7]<[Point][8]>** destination point
52
52
 
53
53
  [8]: https://tools.ietf.org/html/rfc7946#section-3.1.2
54
54
 
55
- <!-- This file is automatically generated. Please don't edit it directly:
56
- if you find an error, edit the source file (likely index.js), and re-run
57
- ./scripts/generate-readmes in the turf project. -->
55
+ <!-- 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. -->
58
56
 
59
57
  ---
60
58
 
61
- This module is part of the [Turfjs project](http://turfjs.org/), an open source
62
- module collection dedicated to geographic algorithms. It is maintained in the
63
- [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
64
- PRs and issues.
59
+ 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.
65
60
 
66
61
  ### Installation
67
62
 
68
- Install this module individually:
63
+ Install this single module individually:
69
64
 
70
65
  ```sh
71
66
  $ npm install @turf/destination
72
67
  ```
73
68
 
74
- Or install the Turf module that includes it as a function:
69
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
75
70
 
76
71
  ```sh
77
72
  $ npm install @turf/turf
@@ -0,0 +1,31 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
2
+
3
+
4
+
5
+
6
+
7
+ var _helpers = require('@turf/helpers');
8
+ var _invariant = require('@turf/invariant');
9
+ function destination(origin, distance, bearing, options = {}) {
10
+ const coordinates1 = _invariant.getCoord.call(void 0, origin);
11
+ const longitude1 = _helpers.degreesToRadians.call(void 0, coordinates1[0]);
12
+ const latitude1 = _helpers.degreesToRadians.call(void 0, coordinates1[1]);
13
+ const bearingRad = _helpers.degreesToRadians.call(void 0, bearing);
14
+ const radians = _helpers.lengthToRadians.call(void 0, distance, options.units);
15
+ const latitude2 = Math.asin(
16
+ Math.sin(latitude1) * Math.cos(radians) + Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad)
17
+ );
18
+ const longitude2 = longitude1 + Math.atan2(
19
+ Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1),
20
+ Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2)
21
+ );
22
+ const lng = _helpers.radiansToDegrees.call(void 0, longitude2);
23
+ const lat = _helpers.radiansToDegrees.call(void 0, latitude2);
24
+ return _helpers.point.call(void 0, [lng, lat], options.properties);
25
+ }
26
+ var turf_destination_default = destination;
27
+
28
+
29
+
30
+ exports.default = turf_destination_default; exports.destination = destination;
31
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AAGA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,gBAAgB;AA4BzB,SAAS,YACP,QACA,UACA,SACA,UAGI,CAAC,GACc;AAEnB,QAAM,eAAe,SAAS,MAAM;AACpC,QAAM,aAAa,iBAAiB,aAAa,CAAC,CAAC;AACnD,QAAM,YAAY,iBAAiB,aAAa,CAAC,CAAC;AAClD,QAAM,aAAa,iBAAiB,OAAO;AAC3C,QAAM,UAAU,gBAAgB,UAAU,QAAQ,KAAK;AAGvD,QAAM,YAAY,KAAK;AAAA,IACrB,KAAK,IAAI,SAAS,IAAI,KAAK,IAAI,OAAO,IACpC,KAAK,IAAI,SAAS,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK,IAAI,UAAU;AAAA,EACjE;AACA,QAAM,aACJ,aACA,KAAK;AAAA,IACH,KAAK,IAAI,UAAU,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK,IAAI,SAAS;AAAA,IAC7D,KAAK,IAAI,OAAO,IAAI,KAAK,IAAI,SAAS,IAAI,KAAK,IAAI,SAAS;AAAA,EAC9D;AACF,QAAM,MAAM,iBAAiB,UAAU;AACvC,QAAM,MAAM,iBAAiB,SAAS;AAEtC,SAAO,MAAM,CAAC,KAAK,GAAG,GAAG,QAAQ,UAAU;AAC7C;AAGA,IAAO,2BAAQ","sourcesContent":["// http://en.wikipedia.org/wiki/Haversine_formula\n// http://www.movable-type.co.uk/scripts/latlong.html\nimport { Feature, Point, GeoJsonProperties } from \"geojson\";\nimport {\n Coord,\n degreesToRadians,\n lengthToRadians,\n point,\n radiansToDegrees,\n Units,\n} from \"@turf/helpers\";\nimport { getCoord } from \"@turf/invariant\";\n\n/**\n * Takes a {@link Point} and calculates the location of a destination point given a distance in\n * degrees, radians, miles, or kilometers; and bearing in degrees.\n * This uses the [Haversine formula](http://en.wikipedia.org/wiki/Haversine_formula) to account for global curvature.\n *\n * @name destination\n * @param {Coord} origin starting point\n * @param {number} distance distance from the origin point\n * @param {number} bearing ranging from -180 to 180\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] miles, kilometers, degrees, or radians\n * @param {Object} [options.properties={}] Translate properties to Point\n * @returns {Feature<Point>} destination point\n * @example\n * var point = turf.point([-75.343, 39.984]);\n * var distance = 50;\n * var bearing = 90;\n * var options = {units: 'miles'};\n *\n * var destination = turf.destination(point, distance, bearing, options);\n *\n * //addToMap\n * var addToMap = [point, destination]\n * destination.properties['marker-color'] = '#f00';\n * point.properties['marker-color'] = '#0f0';\n */\nfunction destination<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 // Handle input\n const coordinates1 = getCoord(origin);\n const longitude1 = degreesToRadians(coordinates1[0]);\n const latitude1 = degreesToRadians(coordinates1[1]);\n const bearingRad = degreesToRadians(bearing);\n const radians = lengthToRadians(distance, options.units);\n\n // Main\n const latitude2 = Math.asin(\n Math.sin(latitude1) * Math.cos(radians) +\n Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad)\n );\n const longitude2 =\n longitude1 +\n Math.atan2(\n Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1),\n Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2)\n );\n const lng = radiansToDegrees(longitude2);\n const lat = radiansToDegrees(latitude2);\n\n return point([lng, lat], options.properties);\n}\n\nexport { destination };\nexport default destination;\n"]}
@@ -1,5 +1,6 @@
1
- import { degreesToRadians, lengthToRadians, point, radiansToDegrees, } from "@turf/helpers";
2
- import { getCoord } from "@turf/invariant";
1
+ import { GeoJsonProperties, Feature, Point } from 'geojson';
2
+ import { Coord, Units } from '@turf/helpers';
3
+
3
4
  /**
4
5
  * Takes a {@link Point} and calculates the location of a destination point given a distance in
5
6
  * degrees, radians, miles, or kilometers; and bearing in degrees.
@@ -26,19 +27,9 @@ import { getCoord } from "@turf/invariant";
26
27
  * destination.properties['marker-color'] = '#f00';
27
28
  * point.properties['marker-color'] = '#0f0';
28
29
  */
29
- export default function destination(origin, distance, bearing, options = {}) {
30
- // Handle input
31
- const coordinates1 = getCoord(origin);
32
- const longitude1 = degreesToRadians(coordinates1[0]);
33
- const latitude1 = degreesToRadians(coordinates1[1]);
34
- const bearingRad = degreesToRadians(bearing);
35
- const radians = lengthToRadians(distance, options.units);
36
- // Main
37
- const latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) +
38
- Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad));
39
- const longitude2 = longitude1 +
40
- Math.atan2(Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1), Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2));
41
- const lng = radiansToDegrees(longitude2);
42
- const lat = radiansToDegrees(latitude2);
43
- return point([lng, lat], options.properties);
44
- }
30
+ declare function destination<P extends GeoJsonProperties = GeoJsonProperties>(origin: Coord, distance: number, bearing: number, options?: {
31
+ units?: Units;
32
+ properties?: P;
33
+ }): Feature<Point, P>;
34
+
35
+ export { destination as default, destination };
@@ -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
  * Takes a {@link Point} and calculates the location of a destination point given a distance in
5
6
  * degrees, radians, miles, or kilometers; and bearing in degrees.
@@ -26,7 +27,9 @@ import { Coord, Units } from "@turf/helpers";
26
27
  * destination.properties['marker-color'] = '#f00';
27
28
  * point.properties['marker-color'] = '#0f0';
28
29
  */
29
- export default function destination<P = GeoJsonProperties>(origin: Coord, distance: number, bearing: number, options?: {
30
+ declare function destination<P extends GeoJsonProperties = GeoJsonProperties>(origin: Coord, distance: number, bearing: number, options?: {
30
31
  units?: Units;
31
32
  properties?: P;
32
33
  }): Feature<Point, P>;
34
+
35
+ export { destination as default, destination };
@@ -0,0 +1,31 @@
1
+ // index.ts
2
+ import {
3
+ degreesToRadians,
4
+ lengthToRadians,
5
+ point,
6
+ radiansToDegrees
7
+ } from "@turf/helpers";
8
+ import { getCoord } from "@turf/invariant";
9
+ function destination(origin, distance, bearing, options = {}) {
10
+ const coordinates1 = getCoord(origin);
11
+ const longitude1 = degreesToRadians(coordinates1[0]);
12
+ const latitude1 = degreesToRadians(coordinates1[1]);
13
+ const bearingRad = degreesToRadians(bearing);
14
+ const radians = lengthToRadians(distance, options.units);
15
+ const latitude2 = Math.asin(
16
+ Math.sin(latitude1) * Math.cos(radians) + Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad)
17
+ );
18
+ const longitude2 = longitude1 + Math.atan2(
19
+ Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1),
20
+ Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2)
21
+ );
22
+ const lng = radiansToDegrees(longitude2);
23
+ const lat = radiansToDegrees(latitude2);
24
+ return point([lng, lat], options.properties);
25
+ }
26
+ var turf_destination_default = destination;
27
+ export {
28
+ turf_destination_default as default,
29
+ destination
30
+ };
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["// http://en.wikipedia.org/wiki/Haversine_formula\n// http://www.movable-type.co.uk/scripts/latlong.html\nimport { Feature, Point, GeoJsonProperties } from \"geojson\";\nimport {\n Coord,\n degreesToRadians,\n lengthToRadians,\n point,\n radiansToDegrees,\n Units,\n} from \"@turf/helpers\";\nimport { getCoord } from \"@turf/invariant\";\n\n/**\n * Takes a {@link Point} and calculates the location of a destination point given a distance in\n * degrees, radians, miles, or kilometers; and bearing in degrees.\n * This uses the [Haversine formula](http://en.wikipedia.org/wiki/Haversine_formula) to account for global curvature.\n *\n * @name destination\n * @param {Coord} origin starting point\n * @param {number} distance distance from the origin point\n * @param {number} bearing ranging from -180 to 180\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] miles, kilometers, degrees, or radians\n * @param {Object} [options.properties={}] Translate properties to Point\n * @returns {Feature<Point>} destination point\n * @example\n * var point = turf.point([-75.343, 39.984]);\n * var distance = 50;\n * var bearing = 90;\n * var options = {units: 'miles'};\n *\n * var destination = turf.destination(point, distance, bearing, options);\n *\n * //addToMap\n * var addToMap = [point, destination]\n * destination.properties['marker-color'] = '#f00';\n * point.properties['marker-color'] = '#0f0';\n */\nfunction destination<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 // Handle input\n const coordinates1 = getCoord(origin);\n const longitude1 = degreesToRadians(coordinates1[0]);\n const latitude1 = degreesToRadians(coordinates1[1]);\n const bearingRad = degreesToRadians(bearing);\n const radians = lengthToRadians(distance, options.units);\n\n // Main\n const latitude2 = Math.asin(\n Math.sin(latitude1) * Math.cos(radians) +\n Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad)\n );\n const longitude2 =\n longitude1 +\n Math.atan2(\n Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1),\n Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2)\n );\n const lng = radiansToDegrees(longitude2);\n const lat = radiansToDegrees(latitude2);\n\n return point([lng, lat], options.properties);\n}\n\nexport { destination };\nexport default destination;\n"],"mappings":";AAGA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,gBAAgB;AA4BzB,SAAS,YACP,QACA,UACA,SACA,UAGI,CAAC,GACc;AAEnB,QAAM,eAAe,SAAS,MAAM;AACpC,QAAM,aAAa,iBAAiB,aAAa,CAAC,CAAC;AACnD,QAAM,YAAY,iBAAiB,aAAa,CAAC,CAAC;AAClD,QAAM,aAAa,iBAAiB,OAAO;AAC3C,QAAM,UAAU,gBAAgB,UAAU,QAAQ,KAAK;AAGvD,QAAM,YAAY,KAAK;AAAA,IACrB,KAAK,IAAI,SAAS,IAAI,KAAK,IAAI,OAAO,IACpC,KAAK,IAAI,SAAS,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK,IAAI,UAAU;AAAA,EACjE;AACA,QAAM,aACJ,aACA,KAAK;AAAA,IACH,KAAK,IAAI,UAAU,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK,IAAI,SAAS;AAAA,IAC7D,KAAK,IAAI,OAAO,IAAI,KAAK,IAAI,SAAS,IAAI,KAAK,IAAI,SAAS;AAAA,EAC9D;AACF,QAAM,MAAM,iBAAiB,UAAU;AACvC,QAAM,MAAM,iBAAiB,SAAS;AAEtC,SAAO,MAAM,CAAC,KAAK,GAAG,GAAG,QAAQ,UAAU;AAC7C;AAGA,IAAO,2BAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/destination",
3
- "version": "7.0.0-alpha.2",
3
+ "version": "7.1.0-alpha.7+0ce6ecca0",
4
4
  "description": "turf destination module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -24,47 +24,52 @@
24
24
  "miles",
25
25
  "km"
26
26
  ],
27
- "main": "dist/js/index.js",
28
- "module": "dist/es/index.js",
27
+ "type": "module",
28
+ "main": "dist/cjs/index.cjs",
29
+ "module": "dist/esm/index.js",
30
+ "types": "dist/esm/index.d.ts",
29
31
  "exports": {
30
32
  "./package.json": "./package.json",
31
33
  ".": {
32
- "types": "./dist/js/index.d.ts",
33
- "import": "./dist/es/index.js",
34
- "require": "./dist/js/index.js"
34
+ "import": {
35
+ "types": "./dist/esm/index.d.ts",
36
+ "default": "./dist/esm/index.js"
37
+ },
38
+ "require": {
39
+ "types": "./dist/cjs/index.d.cts",
40
+ "default": "./dist/cjs/index.cjs"
41
+ }
35
42
  }
36
43
  },
37
- "types": "dist/js/index.d.ts",
38
44
  "sideEffects": false,
39
45
  "files": [
40
46
  "dist"
41
47
  ],
42
48
  "scripts": {
43
- "bench": "tsx bench.js",
44
- "build": "npm-run-all build:*",
45
- "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
46
- "build:js": "tsc",
47
- "docs": "tsx ../../scripts/generate-readmes",
48
- "test": "npm-run-all test:*",
49
- "test:tape": "tsx test.js"
49
+ "bench": "tsx bench.ts",
50
+ "build": "tsup --config ../../tsup.config.ts",
51
+ "docs": "tsx ../../scripts/generate-readmes.ts",
52
+ "test": "npm-run-all --npm-path npm test:*",
53
+ "test:tape": "tsx test.ts"
50
54
  },
51
55
  "devDependencies": {
52
- "@turf/truncate": "^7.0.0-alpha.2",
53
- "@types/tape": "*",
54
- "benchmark": "*",
55
- "glob": "*",
56
- "load-json-file": "*",
57
- "npm-run-all": "*",
58
- "tape": "*",
59
- "tslint": "*",
60
- "tsx": "*",
61
- "typescript": "*",
62
- "write-json-file": "*"
56
+ "@turf/truncate": "^7.1.0-alpha.7+0ce6ecca0",
57
+ "@types/benchmark": "^2.1.5",
58
+ "@types/tape": "^4.2.32",
59
+ "benchmark": "^2.1.4",
60
+ "glob": "^10.3.10",
61
+ "load-json-file": "^7.0.1",
62
+ "npm-run-all": "^4.1.5",
63
+ "tape": "^5.7.2",
64
+ "tsup": "^8.0.1",
65
+ "tsx": "^4.6.2",
66
+ "typescript": "^5.2.2",
67
+ "write-json-file": "^5.0.0"
63
68
  },
64
69
  "dependencies": {
65
- "@turf/helpers": "^7.0.0-alpha.2",
66
- "@turf/invariant": "^7.0.0-alpha.2",
67
- "tslib": "^2.3.0"
70
+ "@turf/helpers": "^7.1.0-alpha.7+0ce6ecca0",
71
+ "@turf/invariant": "^7.1.0-alpha.7+0ce6ecca0",
72
+ "tslib": "^2.6.2"
68
73
  },
69
- "gitHead": "dd35b52725945b4fa29a98d9a550733e06cc222e"
74
+ "gitHead": "0ce6ecca05829690270fec6d6bed2003495fe0ea"
70
75
  }
@@ -1 +0,0 @@
1
- {"type":"module"}
package/dist/js/index.js DELETED
@@ -1,47 +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
- * Takes a {@link Point} and calculates the location of a destination point given a distance in
7
- * degrees, radians, miles, or kilometers; and bearing in degrees.
8
- * This uses the [Haversine formula](http://en.wikipedia.org/wiki/Haversine_formula) to account for global curvature.
9
- *
10
- * @name destination
11
- * @param {Coord} origin starting point
12
- * @param {number} distance distance from the origin point
13
- * @param {number} bearing ranging from -180 to 180
14
- * @param {Object} [options={}] Optional parameters
15
- * @param {string} [options.units='kilometers'] miles, kilometers, degrees, or radians
16
- * @param {Object} [options.properties={}] Translate properties to Point
17
- * @returns {Feature<Point>} destination point
18
- * @example
19
- * var point = turf.point([-75.343, 39.984]);
20
- * var distance = 50;
21
- * var bearing = 90;
22
- * var options = {units: 'miles'};
23
- *
24
- * var destination = turf.destination(point, distance, bearing, options);
25
- *
26
- * //addToMap
27
- * var addToMap = [point, destination]
28
- * destination.properties['marker-color'] = '#f00';
29
- * point.properties['marker-color'] = '#0f0';
30
- */
31
- function destination(origin, distance, bearing, options = {}) {
32
- // Handle input
33
- const coordinates1 = invariant_1.getCoord(origin);
34
- const longitude1 = helpers_1.degreesToRadians(coordinates1[0]);
35
- const latitude1 = helpers_1.degreesToRadians(coordinates1[1]);
36
- const bearingRad = helpers_1.degreesToRadians(bearing);
37
- const radians = helpers_1.lengthToRadians(distance, options.units);
38
- // Main
39
- const latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) +
40
- Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad));
41
- const longitude2 = longitude1 +
42
- Math.atan2(Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1), Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2));
43
- const lng = helpers_1.radiansToDegrees(longitude2);
44
- const lat = helpers_1.radiansToDegrees(latitude2);
45
- return helpers_1.point([lng, lat], options.properties);
46
- }
47
- exports.default = destination;