@turf/transform-rotate 7.0.0 → 7.1.0-alpha.70

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
@@ -18,12 +18,12 @@ Rotates any geojson Feature or Geometry of a specified angle, around its `centro
18
18
  ### Examples
19
19
 
20
20
  ```javascript
21
- var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
22
- var options = {pivot: [0, 25]};
23
- var rotatedPoly = turf.transformRotate(poly, 10, options);
21
+ const poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
22
+ const options = {pivot: [0, 25]};
23
+ const rotatedPoly = turf.transformRotate(poly, 10, options);
24
24
 
25
25
  //addToMap
26
- var addToMap = [poly, rotatedPoly];
26
+ const addToMap = [poly, rotatedPoly];
27
27
  rotatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};
28
28
  ```
29
29
 
@@ -1,7 +1,4 @@
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.js
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
5
2
  var _centroid = require('@turf/centroid');
6
3
  var _rhumbbearing = require('@turf/rhumb-bearing');
7
4
  var _rhumbdistance = require('@turf/rhumb-distance');
@@ -14,29 +11,29 @@ function transformRotate(geojson, angle, options) {
14
11
  options = options || {};
15
12
  if (!_helpers.isObject.call(void 0, options))
16
13
  throw new Error("options is invalid");
17
- var pivot = options.pivot;
18
- var mutate = options.mutate;
14
+ const pivot = options.pivot;
15
+ const mutate = options.mutate;
19
16
  if (!geojson)
20
17
  throw new Error("geojson is required");
21
18
  if (angle === void 0 || angle === null || isNaN(angle))
22
19
  throw new Error("angle is required");
23
20
  if (angle === 0)
24
21
  return geojson;
25
- if (!pivot)
26
- pivot = _centroid.centroid.call(void 0, geojson);
22
+ const pivotCoord = pivot != null ? pivot : _centroid.centroid.call(void 0, geojson);
27
23
  if (mutate === false || mutate === void 0)
28
24
  geojson = _clone.clone.call(void 0, geojson);
29
25
  _meta.coordEach.call(void 0, geojson, function(pointCoords) {
30
- var initialAngle = _rhumbbearing.rhumbBearing.call(void 0, pivot, pointCoords);
31
- var finalAngle = initialAngle + angle;
32
- var distance = _rhumbdistance.rhumbDistance.call(void 0, pivot, pointCoords);
33
- var newCoords = _invariant.getCoords.call(void 0, _rhumbdestination.rhumbDestination.call(void 0, pivot, distance, finalAngle));
26
+ const initialAngle = _rhumbbearing.rhumbBearing.call(void 0, pivotCoord, pointCoords);
27
+ const finalAngle = initialAngle + angle;
28
+ const distance = _rhumbdistance.rhumbDistance.call(void 0, pivotCoord, pointCoords);
29
+ const newCoords = _invariant.getCoords.call(void 0,
30
+ _rhumbdestination.rhumbDestination.call(void 0, pivotCoord, distance, finalAngle)
31
+ );
34
32
  pointCoords[0] = newCoords[0];
35
33
  pointCoords[1] = newCoords[1];
36
34
  });
37
35
  return geojson;
38
36
  }
39
- __name(transformRotate, "transformRotate");
40
37
  var turf_transform_rotate_default = transformRotate;
41
38
 
42
39
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.js"],"names":[],"mappings":";;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AAqBzB,SAAS,gBAAgB,SAAS,OAAO,SAAS;AAEhD,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,MAAI,QAAQ,QAAQ;AACpB,MAAI,SAAS,QAAQ;AAGrB,MAAI,CAAC;AAAS,UAAM,IAAI,MAAM,qBAAqB;AACnD,MAAI,UAAU,UAAa,UAAU,QAAQ,MAAM,KAAK;AACtD,UAAM,IAAI,MAAM,mBAAmB;AAGrC,MAAI,UAAU;AAAG,WAAO;AAGxB,MAAI,CAAC;AAAO,YAAQ,SAAS,OAAO;AAGpC,MAAI,WAAW,SAAS,WAAW;AAAW,cAAU,MAAM,OAAO;AAGrE,YAAU,SAAS,SAAU,aAAa;AACxC,QAAI,eAAe,aAAa,OAAO,WAAW;AAClD,QAAI,aAAa,eAAe;AAChC,QAAI,WAAW,cAAc,OAAO,WAAW;AAC/C,QAAI,YAAY,UAAU,iBAAiB,OAAO,UAAU,UAAU,CAAC;AACvE,gBAAY,CAAC,IAAI,UAAU,CAAC;AAC5B,gBAAY,CAAC,IAAI,UAAU,CAAC;AAAA,EAC9B,CAAC;AACD,SAAO;AACT;AA/BS;AAkCT,IAAO,gCAAQ","sourcesContent":["import { centroid } from \"@turf/centroid\";\nimport { rhumbBearing } from \"@turf/rhumb-bearing\";\nimport { rhumbDistance } from \"@turf/rhumb-distance\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\nimport { clone } from \"@turf/clone\";\nimport { coordEach } from \"@turf/meta\";\nimport { getCoords } from \"@turf/invariant\";\nimport { isObject } from \"@turf/helpers\";\n\n/**\n * Rotates any geojson Feature or Geometry of a specified angle, around its `centroid` or a given `pivot` point.\n *\n * @name transformRotate\n * @param {GeoJSON} geojson object to be rotated\n * @param {number} angle of rotation in decimal degrees, positive clockwise\n * @param {Object} [options={}] Optional parameters\n * @param {Coord} [options.pivot='centroid'] point around which the rotation will be performed\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} the rotated GeoJSON feature\n * @example\n * var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * var options = {pivot: [0, 25]};\n * var rotatedPoly = turf.transformRotate(poly, 10, options);\n *\n * //addToMap\n * var addToMap = [poly, rotatedPoly];\n * rotatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformRotate(geojson, angle, options) {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var pivot = options.pivot;\n var mutate = options.mutate;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (angle === undefined || angle === null || isNaN(angle))\n throw new Error(\"angle is required\");\n\n // Shortcut no-rotation\n if (angle === 0) return geojson;\n\n // Use centroid of GeoJSON if pivot is not provided\n if (!pivot) pivot = centroid(geojson);\n\n // Clone geojson to avoid side effects\n if (mutate === false || mutate === undefined) geojson = clone(geojson);\n\n // Rotate each coordinate\n coordEach(geojson, function (pointCoords) {\n var initialAngle = rhumbBearing(pivot, pointCoords);\n var finalAngle = initialAngle + angle;\n var distance = rhumbDistance(pivot, pointCoords);\n var newCoords = getCoords(rhumbDestination(pivot, distance, finalAngle));\n pointCoords[0] = newCoords[0];\n pointCoords[1] = newCoords[1];\n });\n return geojson;\n}\n\nexport { transformRotate };\nexport default transformRotate;\n"]}
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AACA,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,gBAAuB;AAqBhC,SAAS,gBACP,SACA,OACA,SAIG;AAEH,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,QAAM,QAAQ,QAAQ;AACtB,QAAM,SAAS,QAAQ;AAGvB,MAAI,CAAC;AAAS,UAAM,IAAI,MAAM,qBAAqB;AACnD,MAAI,UAAU,UAAa,UAAU,QAAQ,MAAM,KAAK;AACtD,UAAM,IAAI,MAAM,mBAAmB;AAGrC,MAAI,UAAU;AAAG,WAAO;AAGxB,QAAM,aAAa,wBAAS,SAAS,OAAO;AAG5C,MAAI,WAAW,SAAS,WAAW;AAAW,cAAU,MAAM,OAAO;AAGrE,YAAU,SAAS,SAAU,aAAa;AACxC,UAAM,eAAe,aAAa,YAAY,WAAW;AACzD,UAAM,aAAa,eAAe;AAClC,UAAM,WAAW,cAAc,YAAY,WAAW;AACtD,UAAM,YAAY;AAAA,MAChB,iBAAiB,YAAY,UAAU,UAAU;AAAA,IACnD;AACA,gBAAY,CAAC,IAAI,UAAU,CAAC;AAC5B,gBAAY,CAAC,IAAI,UAAU,CAAC;AAAA,EAC9B,CAAC;AACD,SAAO;AACT;AAGA,IAAO,gCAAQ","sourcesContent":["import { GeoJSON, GeometryCollection } from \"geojson\";\nimport { centroid } from \"@turf/centroid\";\nimport { rhumbBearing } from \"@turf/rhumb-bearing\";\nimport { rhumbDistance } from \"@turf/rhumb-distance\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\nimport { clone } from \"@turf/clone\";\nimport { coordEach } from \"@turf/meta\";\nimport { getCoords } from \"@turf/invariant\";\nimport { isObject, Coord } from \"@turf/helpers\";\n\n/**\n * Rotates any geojson Feature or Geometry of a specified angle, around its `centroid` or a given `pivot` point.\n *\n * @name transformRotate\n * @param {GeoJSON} geojson object to be rotated\n * @param {number} angle of rotation in decimal degrees, positive clockwise\n * @param {Object} [options={}] Optional parameters\n * @param {Coord} [options.pivot='centroid'] point around which the rotation will be performed\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} the rotated GeoJSON feature\n * @example\n * const poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * const options = {pivot: [0, 25]};\n * const rotatedPoly = turf.transformRotate(poly, 10, options);\n *\n * //addToMap\n * const addToMap = [poly, rotatedPoly];\n * rotatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformRotate<T extends GeoJSON | GeometryCollection>(\n geojson: T,\n angle: number,\n options?: {\n pivot?: Coord;\n mutate?: boolean;\n }\n): T {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const pivot = options.pivot;\n const mutate = options.mutate;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (angle === undefined || angle === null || isNaN(angle))\n throw new Error(\"angle is required\");\n\n // Shortcut no-rotation\n if (angle === 0) return geojson;\n\n // Use centroid of GeoJSON if pivot is not provided\n const pivotCoord = pivot ?? centroid(geojson);\n\n // Clone geojson to avoid side effects\n if (mutate === false || mutate === undefined) geojson = clone(geojson);\n\n // Rotate each coordinate\n coordEach(geojson, function (pointCoords) {\n const initialAngle = rhumbBearing(pivotCoord, pointCoords);\n const finalAngle = initialAngle + angle;\n const distance = rhumbDistance(pivotCoord, pointCoords);\n const newCoords = getCoords(\n rhumbDestination(pivotCoord, distance, finalAngle)\n );\n pointCoords[0] = newCoords[0];\n pointCoords[1] = newCoords[1];\n });\n return geojson;\n}\n\nexport { transformRotate };\nexport default transformRotate;\n"]}
@@ -1,15 +1,28 @@
1
- import { AllGeoJSON, Coord } from '@turf/helpers';
1
+ import { GeoJSON, GeometryCollection } from 'geojson';
2
+ import { Coord } from '@turf/helpers';
2
3
 
3
4
  /**
4
- * http://turfjs.org/docs/#transformrotate
5
+ * Rotates any geojson Feature or Geometry of a specified angle, around its `centroid` or a given `pivot` point.
6
+ *
7
+ * @name transformRotate
8
+ * @param {GeoJSON} geojson object to be rotated
9
+ * @param {number} angle of rotation in decimal degrees, positive clockwise
10
+ * @param {Object} [options={}] Optional parameters
11
+ * @param {Coord} [options.pivot='centroid'] point around which the rotation will be performed
12
+ * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
13
+ * @returns {GeoJSON} the rotated GeoJSON feature
14
+ * @example
15
+ * const poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
16
+ * const options = {pivot: [0, 25]};
17
+ * const rotatedPoly = turf.transformRotate(poly, 10, options);
18
+ *
19
+ * //addToMap
20
+ * const addToMap = [poly, rotatedPoly];
21
+ * rotatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};
5
22
  */
6
- declare function transformRotate<T extends AllGeoJSON>(
7
- geojson: T,
8
- angle: number,
9
- options?: {
23
+ declare function transformRotate<T extends GeoJSON | GeometryCollection>(geojson: T, angle: number, options?: {
10
24
  pivot?: Coord;
11
25
  mutate?: boolean;
12
- }
13
- ): T;
26
+ }): T;
14
27
 
15
28
  export { transformRotate as default, transformRotate };
@@ -1,15 +1,28 @@
1
- import { AllGeoJSON, Coord } from '@turf/helpers';
1
+ import { GeoJSON, GeometryCollection } from 'geojson';
2
+ import { Coord } from '@turf/helpers';
2
3
 
3
4
  /**
4
- * http://turfjs.org/docs/#transformrotate
5
+ * Rotates any geojson Feature or Geometry of a specified angle, around its `centroid` or a given `pivot` point.
6
+ *
7
+ * @name transformRotate
8
+ * @param {GeoJSON} geojson object to be rotated
9
+ * @param {number} angle of rotation in decimal degrees, positive clockwise
10
+ * @param {Object} [options={}] Optional parameters
11
+ * @param {Coord} [options.pivot='centroid'] point around which the rotation will be performed
12
+ * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
13
+ * @returns {GeoJSON} the rotated GeoJSON feature
14
+ * @example
15
+ * const poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
16
+ * const options = {pivot: [0, 25]};
17
+ * const rotatedPoly = turf.transformRotate(poly, 10, options);
18
+ *
19
+ * //addToMap
20
+ * const addToMap = [poly, rotatedPoly];
21
+ * rotatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};
5
22
  */
6
- declare function transformRotate<T extends AllGeoJSON>(
7
- geojson: T,
8
- angle: number,
9
- options?: {
23
+ declare function transformRotate<T extends GeoJSON | GeometryCollection>(geojson: T, angle: number, options?: {
10
24
  pivot?: Coord;
11
25
  mutate?: boolean;
12
- }
13
- ): T;
26
+ }): T;
14
27
 
15
28
  export { transformRotate as default, transformRotate };
package/dist/esm/index.js CHANGED
@@ -1,7 +1,4 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
- // index.js
1
+ // index.ts
5
2
  import { centroid } from "@turf/centroid";
6
3
  import { rhumbBearing } from "@turf/rhumb-bearing";
7
4
  import { rhumbDistance } from "@turf/rhumb-distance";
@@ -14,29 +11,29 @@ function transformRotate(geojson, angle, options) {
14
11
  options = options || {};
15
12
  if (!isObject(options))
16
13
  throw new Error("options is invalid");
17
- var pivot = options.pivot;
18
- var mutate = options.mutate;
14
+ const pivot = options.pivot;
15
+ const mutate = options.mutate;
19
16
  if (!geojson)
20
17
  throw new Error("geojson is required");
21
18
  if (angle === void 0 || angle === null || isNaN(angle))
22
19
  throw new Error("angle is required");
23
20
  if (angle === 0)
24
21
  return geojson;
25
- if (!pivot)
26
- pivot = centroid(geojson);
22
+ const pivotCoord = pivot != null ? pivot : centroid(geojson);
27
23
  if (mutate === false || mutate === void 0)
28
24
  geojson = clone(geojson);
29
25
  coordEach(geojson, function(pointCoords) {
30
- var initialAngle = rhumbBearing(pivot, pointCoords);
31
- var finalAngle = initialAngle + angle;
32
- var distance = rhumbDistance(pivot, pointCoords);
33
- var newCoords = getCoords(rhumbDestination(pivot, distance, finalAngle));
26
+ const initialAngle = rhumbBearing(pivotCoord, pointCoords);
27
+ const finalAngle = initialAngle + angle;
28
+ const distance = rhumbDistance(pivotCoord, pointCoords);
29
+ const newCoords = getCoords(
30
+ rhumbDestination(pivotCoord, distance, finalAngle)
31
+ );
34
32
  pointCoords[0] = newCoords[0];
35
33
  pointCoords[1] = newCoords[1];
36
34
  });
37
35
  return geojson;
38
36
  }
39
- __name(transformRotate, "transformRotate");
40
37
  var turf_transform_rotate_default = transformRotate;
41
38
  export {
42
39
  turf_transform_rotate_default as default,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.js"],"sourcesContent":["import { centroid } from \"@turf/centroid\";\nimport { rhumbBearing } from \"@turf/rhumb-bearing\";\nimport { rhumbDistance } from \"@turf/rhumb-distance\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\nimport { clone } from \"@turf/clone\";\nimport { coordEach } from \"@turf/meta\";\nimport { getCoords } from \"@turf/invariant\";\nimport { isObject } from \"@turf/helpers\";\n\n/**\n * Rotates any geojson Feature or Geometry of a specified angle, around its `centroid` or a given `pivot` point.\n *\n * @name transformRotate\n * @param {GeoJSON} geojson object to be rotated\n * @param {number} angle of rotation in decimal degrees, positive clockwise\n * @param {Object} [options={}] Optional parameters\n * @param {Coord} [options.pivot='centroid'] point around which the rotation will be performed\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} the rotated GeoJSON feature\n * @example\n * var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * var options = {pivot: [0, 25]};\n * var rotatedPoly = turf.transformRotate(poly, 10, options);\n *\n * //addToMap\n * var addToMap = [poly, rotatedPoly];\n * rotatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformRotate(geojson, angle, options) {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var pivot = options.pivot;\n var mutate = options.mutate;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (angle === undefined || angle === null || isNaN(angle))\n throw new Error(\"angle is required\");\n\n // Shortcut no-rotation\n if (angle === 0) return geojson;\n\n // Use centroid of GeoJSON if pivot is not provided\n if (!pivot) pivot = centroid(geojson);\n\n // Clone geojson to avoid side effects\n if (mutate === false || mutate === undefined) geojson = clone(geojson);\n\n // Rotate each coordinate\n coordEach(geojson, function (pointCoords) {\n var initialAngle = rhumbBearing(pivot, pointCoords);\n var finalAngle = initialAngle + angle;\n var distance = rhumbDistance(pivot, pointCoords);\n var newCoords = getCoords(rhumbDestination(pivot, distance, finalAngle));\n pointCoords[0] = newCoords[0];\n pointCoords[1] = newCoords[1];\n });\n return geojson;\n}\n\nexport { transformRotate };\nexport default transformRotate;\n"],"mappings":";;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AAqBzB,SAAS,gBAAgB,SAAS,OAAO,SAAS;AAEhD,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,MAAI,QAAQ,QAAQ;AACpB,MAAI,SAAS,QAAQ;AAGrB,MAAI,CAAC;AAAS,UAAM,IAAI,MAAM,qBAAqB;AACnD,MAAI,UAAU,UAAa,UAAU,QAAQ,MAAM,KAAK;AACtD,UAAM,IAAI,MAAM,mBAAmB;AAGrC,MAAI,UAAU;AAAG,WAAO;AAGxB,MAAI,CAAC;AAAO,YAAQ,SAAS,OAAO;AAGpC,MAAI,WAAW,SAAS,WAAW;AAAW,cAAU,MAAM,OAAO;AAGrE,YAAU,SAAS,SAAU,aAAa;AACxC,QAAI,eAAe,aAAa,OAAO,WAAW;AAClD,QAAI,aAAa,eAAe;AAChC,QAAI,WAAW,cAAc,OAAO,WAAW;AAC/C,QAAI,YAAY,UAAU,iBAAiB,OAAO,UAAU,UAAU,CAAC;AACvE,gBAAY,CAAC,IAAI,UAAU,CAAC;AAC5B,gBAAY,CAAC,IAAI,UAAU,CAAC;AAAA,EAC9B,CAAC;AACD,SAAO;AACT;AA/BS;AAkCT,IAAO,gCAAQ;","names":[]}
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { GeoJSON, GeometryCollection } from \"geojson\";\nimport { centroid } from \"@turf/centroid\";\nimport { rhumbBearing } from \"@turf/rhumb-bearing\";\nimport { rhumbDistance } from \"@turf/rhumb-distance\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\nimport { clone } from \"@turf/clone\";\nimport { coordEach } from \"@turf/meta\";\nimport { getCoords } from \"@turf/invariant\";\nimport { isObject, Coord } from \"@turf/helpers\";\n\n/**\n * Rotates any geojson Feature or Geometry of a specified angle, around its `centroid` or a given `pivot` point.\n *\n * @name transformRotate\n * @param {GeoJSON} geojson object to be rotated\n * @param {number} angle of rotation in decimal degrees, positive clockwise\n * @param {Object} [options={}] Optional parameters\n * @param {Coord} [options.pivot='centroid'] point around which the rotation will be performed\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} the rotated GeoJSON feature\n * @example\n * const poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * const options = {pivot: [0, 25]};\n * const rotatedPoly = turf.transformRotate(poly, 10, options);\n *\n * //addToMap\n * const addToMap = [poly, rotatedPoly];\n * rotatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformRotate<T extends GeoJSON | GeometryCollection>(\n geojson: T,\n angle: number,\n options?: {\n pivot?: Coord;\n mutate?: boolean;\n }\n): T {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const pivot = options.pivot;\n const mutate = options.mutate;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (angle === undefined || angle === null || isNaN(angle))\n throw new Error(\"angle is required\");\n\n // Shortcut no-rotation\n if (angle === 0) return geojson;\n\n // Use centroid of GeoJSON if pivot is not provided\n const pivotCoord = pivot ?? centroid(geojson);\n\n // Clone geojson to avoid side effects\n if (mutate === false || mutate === undefined) geojson = clone(geojson);\n\n // Rotate each coordinate\n coordEach(geojson, function (pointCoords) {\n const initialAngle = rhumbBearing(pivotCoord, pointCoords);\n const finalAngle = initialAngle + angle;\n const distance = rhumbDistance(pivotCoord, pointCoords);\n const newCoords = getCoords(\n rhumbDestination(pivotCoord, distance, finalAngle)\n );\n pointCoords[0] = newCoords[0];\n pointCoords[1] = newCoords[1];\n });\n return geojson;\n}\n\nexport { transformRotate };\nexport default transformRotate;\n"],"mappings":";AACA,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,gBAAuB;AAqBhC,SAAS,gBACP,SACA,OACA,SAIG;AAEH,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,QAAM,QAAQ,QAAQ;AACtB,QAAM,SAAS,QAAQ;AAGvB,MAAI,CAAC;AAAS,UAAM,IAAI,MAAM,qBAAqB;AACnD,MAAI,UAAU,UAAa,UAAU,QAAQ,MAAM,KAAK;AACtD,UAAM,IAAI,MAAM,mBAAmB;AAGrC,MAAI,UAAU;AAAG,WAAO;AAGxB,QAAM,aAAa,wBAAS,SAAS,OAAO;AAG5C,MAAI,WAAW,SAAS,WAAW;AAAW,cAAU,MAAM,OAAO;AAGrE,YAAU,SAAS,SAAU,aAAa;AACxC,UAAM,eAAe,aAAa,YAAY,WAAW;AACzD,UAAM,aAAa,eAAe;AAClC,UAAM,WAAW,cAAc,YAAY,WAAW;AACtD,UAAM,YAAY;AAAA,MAChB,iBAAiB,YAAY,UAAU,UAAU;AAAA,IACnD;AACA,gBAAY,CAAC,IAAI,UAAU,CAAC;AAC5B,gBAAY,CAAC,IAAI,UAAU,CAAC;AAAA,EAC9B,CAAC;AACD,SAAO;AACT;AAGA,IAAO,gCAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/transform-rotate",
3
- "version": "7.0.0",
3
+ "version": "7.1.0-alpha.70+948cdafaf",
4
4
  "description": "turf transform-rotate module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -56,7 +56,7 @@
56
56
  "test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
57
57
  },
58
58
  "devDependencies": {
59
- "@turf/truncate": "^7.0.0",
59
+ "@turf/truncate": "^7.1.0-alpha.70+948cdafaf",
60
60
  "@types/benchmark": "^2.1.5",
61
61
  "@types/tape": "^4.2.32",
62
62
  "benchmark": "^2.1.4",
@@ -65,17 +65,20 @@
65
65
  "tape": "^5.7.2",
66
66
  "tsup": "^8.0.1",
67
67
  "tsx": "^4.6.2",
68
+ "typescript": "^5.2.2",
68
69
  "write-json-file": "^5.0.0"
69
70
  },
70
71
  "dependencies": {
71
- "@turf/centroid": "^7.0.0",
72
- "@turf/clone": "^7.0.0",
73
- "@turf/helpers": "^7.0.0",
74
- "@turf/invariant": "^7.0.0",
75
- "@turf/meta": "^7.0.0",
76
- "@turf/rhumb-bearing": "^7.0.0",
77
- "@turf/rhumb-destination": "^7.0.0",
78
- "@turf/rhumb-distance": "^7.0.0"
72
+ "@turf/centroid": "^7.1.0-alpha.70+948cdafaf",
73
+ "@turf/clone": "^7.1.0-alpha.70+948cdafaf",
74
+ "@turf/helpers": "^7.1.0-alpha.70+948cdafaf",
75
+ "@turf/invariant": "^7.1.0-alpha.70+948cdafaf",
76
+ "@turf/meta": "^7.1.0-alpha.70+948cdafaf",
77
+ "@turf/rhumb-bearing": "^7.1.0-alpha.70+948cdafaf",
78
+ "@turf/rhumb-destination": "^7.1.0-alpha.70+948cdafaf",
79
+ "@turf/rhumb-distance": "^7.1.0-alpha.70+948cdafaf",
80
+ "@types/geojson": "^7946.0.10",
81
+ "tslib": "^2.6.2"
79
82
  },
80
- "gitHead": "3d3a7917025fbabe191dbddbc89754b86f9c7739"
83
+ "gitHead": "948cdafaf70606d2e27fcc79973fa48ee1182067"
81
84
  }