@turf/transform-rotate 7.1.0-alpha.7 → 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 +4 -4
- package/dist/cjs/index.cjs +10 -9
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +21 -8
- package/dist/esm/index.d.ts +21 -8
- package/dist/esm/index.js +10 -9
- package/dist/esm/index.js.map +1 -1
- package/package.json +14 -11
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
26
|
+
const addToMap = [poly, rotatedPoly];
|
|
27
27
|
rotatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};
|
|
28
28
|
```
|
|
29
29
|
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
|
|
2
2
|
var _centroid = require('@turf/centroid');
|
|
3
3
|
var _rhumbbearing = require('@turf/rhumb-bearing');
|
|
4
4
|
var _rhumbdistance = require('@turf/rhumb-distance');
|
|
@@ -11,23 +11,24 @@ function transformRotate(geojson, angle, options) {
|
|
|
11
11
|
options = options || {};
|
|
12
12
|
if (!_helpers.isObject.call(void 0, options))
|
|
13
13
|
throw new Error("options is invalid");
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const pivot = options.pivot;
|
|
15
|
+
const mutate = options.mutate;
|
|
16
16
|
if (!geojson)
|
|
17
17
|
throw new Error("geojson is required");
|
|
18
18
|
if (angle === void 0 || angle === null || isNaN(angle))
|
|
19
19
|
throw new Error("angle is required");
|
|
20
20
|
if (angle === 0)
|
|
21
21
|
return geojson;
|
|
22
|
-
|
|
23
|
-
pivot = _centroid.centroid.call(void 0, geojson);
|
|
22
|
+
const pivotCoord = pivot != null ? pivot : _centroid.centroid.call(void 0, geojson);
|
|
24
23
|
if (mutate === false || mutate === void 0)
|
|
25
24
|
geojson = _clone.clone.call(void 0, geojson);
|
|
26
25
|
_meta.coordEach.call(void 0, geojson, function(pointCoords) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
);
|
|
31
32
|
pointCoords[0] = newCoords[0];
|
|
32
33
|
pointCoords[1] = newCoords[1];
|
|
33
34
|
});
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.
|
|
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"]}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GeoJSON, GeometryCollection } from 'geojson';
|
|
2
|
+
import { Coord } from '@turf/helpers';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
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
|
|
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.d.ts
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GeoJSON, GeometryCollection } from 'geojson';
|
|
2
|
+
import { Coord } from '@turf/helpers';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
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
|
|
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,4 +1,4 @@
|
|
|
1
|
-
// index.
|
|
1
|
+
// index.ts
|
|
2
2
|
import { centroid } from "@turf/centroid";
|
|
3
3
|
import { rhumbBearing } from "@turf/rhumb-bearing";
|
|
4
4
|
import { rhumbDistance } from "@turf/rhumb-distance";
|
|
@@ -11,23 +11,24 @@ function transformRotate(geojson, angle, options) {
|
|
|
11
11
|
options = options || {};
|
|
12
12
|
if (!isObject(options))
|
|
13
13
|
throw new Error("options is invalid");
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const pivot = options.pivot;
|
|
15
|
+
const mutate = options.mutate;
|
|
16
16
|
if (!geojson)
|
|
17
17
|
throw new Error("geojson is required");
|
|
18
18
|
if (angle === void 0 || angle === null || isNaN(angle))
|
|
19
19
|
throw new Error("angle is required");
|
|
20
20
|
if (angle === 0)
|
|
21
21
|
return geojson;
|
|
22
|
-
|
|
23
|
-
pivot = centroid(geojson);
|
|
22
|
+
const pivotCoord = pivot != null ? pivot : centroid(geojson);
|
|
24
23
|
if (mutate === false || mutate === void 0)
|
|
25
24
|
geojson = clone(geojson);
|
|
26
25
|
coordEach(geojson, function(pointCoords) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
);
|
|
31
32
|
pointCoords[0] = newCoords[0];
|
|
32
33
|
pointCoords[1] = newCoords[1];
|
|
33
34
|
});
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.
|
|
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.1.0-alpha.
|
|
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.1.0-alpha.
|
|
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.1.0-alpha.
|
|
72
|
-
"@turf/clone": "^7.1.0-alpha.
|
|
73
|
-
"@turf/helpers": "^7.1.0-alpha.
|
|
74
|
-
"@turf/invariant": "^7.1.0-alpha.
|
|
75
|
-
"@turf/meta": "^7.1.0-alpha.
|
|
76
|
-
"@turf/rhumb-bearing": "^7.1.0-alpha.
|
|
77
|
-
"@turf/rhumb-destination": "^7.1.0-alpha.
|
|
78
|
-
"@turf/rhumb-distance": "^7.1.0-alpha.
|
|
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": "
|
|
83
|
+
"gitHead": "948cdafaf70606d2e27fcc79973fa48ee1182067"
|
|
81
84
|
}
|