@turf/transform-rotate
Advanced tools
Comparing version 4.7.3 to 5.0.4
@@ -1,16 +0,13 @@ | ||
/// <reference types="geojson" /> | ||
import { AllGeoJSON, Coord } from '@turf/helpers'; | ||
type Point = GeoJSON.Feature<GeoJSON.Point> | GeoJSON.Point | number[]; | ||
type Geoms = GeoJSON.Feature<any> | GeoJSON.FeatureCollection<any> | GeoJSON.GeometryObject | GeoJSON.GeometryCollection; | ||
/** | ||
* http://turfjs.org/docs/#transform-rotate | ||
* http://turfjs.org/docs/#transformrotate | ||
*/ | ||
declare function transformRotate<Geom extends Geoms>( | ||
geojson: Geom, | ||
export default function transformRotate<T extends AllGeoJSON>( | ||
geojson: T, | ||
angle: number, | ||
pivot?: Point, | ||
mutate?: boolean): Geom; | ||
declare namespace transformRotate { } | ||
export = transformRotate; | ||
options?: { | ||
pivot?: Coord, | ||
mutate?: boolean | ||
} | ||
): T; |
38
index.js
@@ -1,9 +0,9 @@ | ||
var meta = require('@turf/meta'); | ||
var centroid = require('@turf/centroid'); | ||
var invariant = require('@turf/invariant'); | ||
var rhumbBearing = require('@turf/rhumb-bearing'); | ||
var rhumbDistance = require('@turf/rhumb-distance'); | ||
var rhumbDestination = require('@turf/rhumb-destination'); | ||
var coordEach = meta.coordEach; | ||
var getCoords = invariant.getCoords; | ||
import centroid from '@turf/centroid'; | ||
import rhumbBearing from '@turf/rhumb-bearing'; | ||
import rhumbDistance from '@turf/rhumb-distance'; | ||
import rhumbDestination from '@turf/rhumb-destination'; | ||
import clone from '@turf/clone'; | ||
import { coordEach } from '@turf/meta'; | ||
import { getCoords } from '@turf/invariant'; | ||
import { isObject } from '@turf/helpers'; | ||
@@ -17,8 +17,10 @@ /** | ||
* @param {number} angle of rotation (along the vertical axis), from North in decimal degrees, negative clockwise | ||
* @param {Geometry|Feature<Point>|Array<number>} [pivot=`centroid`] point around which the rotation will be performed | ||
* @param {boolean} [mutate=false] allows GeoJSON input to be mutated (significant performance increase if true) | ||
* @param {Object} [options={}] Optional parameters | ||
* @param {Geometry|Feature<Point>|Array<number>} [options.pivot='centroid'] point around which the rotation will be performed | ||
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true) | ||
* @returns {GeoJSON} the rotated GeoJSON feature | ||
* @example | ||
* var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]); | ||
* var rotatedPoly = turf.transformRotate(poly, 10, [0, 25]); | ||
* var options = {pivot: [0, 25]}; | ||
* var rotatedPoly = turf.transformRotate(poly, 10, options); | ||
* | ||
@@ -29,3 +31,9 @@ * //addToMap | ||
*/ | ||
module.exports = function (geojson, angle, pivot, mutate) { | ||
function transformRotate(geojson, angle, options) { | ||
// Optional parameters | ||
options = options || {}; | ||
if (!isObject(options)) throw new Error('options is invalid'); | ||
var pivot = options.pivot; | ||
var mutate = options.mutate; | ||
// Input validation | ||
@@ -42,3 +50,3 @@ if (!geojson) throw new Error('geojson is required'); | ||
// Clone geojson to avoid side effects | ||
if (mutate === false || mutate === undefined) geojson = JSON.parse(JSON.stringify(geojson)); | ||
if (mutate === false || mutate === undefined) geojson = clone(geojson); | ||
@@ -55,2 +63,4 @@ // Rotate each coordinate | ||
return geojson; | ||
}; | ||
} | ||
export default transformRotate; |
{ | ||
"name": "@turf/transform-rotate", | ||
"version": "4.7.3", | ||
"version": "5.0.4", | ||
"description": "turf transform-rotate module", | ||
"main": "index.js", | ||
"main": "main", | ||
"module": "index", | ||
"jsnext:main": "index", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
"index.d.ts", | ||
"main.js" | ||
], | ||
"scripts": { | ||
"test": "node test.js", | ||
"bench": "node bench.js" | ||
"pretest": "rollup -c ../../rollup.config.js", | ||
"test": "node -r @std/esm test.js", | ||
"bench": "node -r @std/esm bench.js" | ||
}, | ||
@@ -36,17 +40,24 @@ "repository": { | ||
"devDependencies": { | ||
"@turf/helpers": "^4.7.3", | ||
"@turf/truncate": "^4.7.3", | ||
"benchmark": "^2.1.4", | ||
"load-json-file": "^2.0.0", | ||
"tape": "^4.6.3", | ||
"write-json-file": "^2.0.0" | ||
"@std/esm": "*", | ||
"@turf/truncate": "^5.0.4", | ||
"benchmark": "*", | ||
"load-json-file": "*", | ||
"rollup": "*", | ||
"tape": "*", | ||
"write-json-file": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/centroid": "^4.7.3", | ||
"@turf/invariant": "^4.7.3", | ||
"@turf/meta": "^4.7.3", | ||
"@turf/rhumb-bearing": "^4.7.3", | ||
"@turf/rhumb-destination": "^4.7.3", | ||
"@turf/rhumb-distance": "^4.7.3" | ||
"@turf/centroid": "^5.0.4", | ||
"@turf/clone": "^5.0.4", | ||
"@turf/helpers": "^5.0.4", | ||
"@turf/invariant": "^5.0.4", | ||
"@turf/meta": "^5.0.4", | ||
"@turf/rhumb-bearing": "^5.0.4", | ||
"@turf/rhumb-destination": "^5.0.4", | ||
"@turf/rhumb-distance": "^5.0.4" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
} | ||
} |
# @turf/transform-rotate | ||
# transformRotate | ||
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
## transformRotate | ||
Rotates any geojson Feature or Geometry of a specified angle, around its `centroid` or a given `pivot` point; | ||
@@ -12,4 +14,5 @@ all rotations follow the right-hand rule: <https://en.wikipedia.org/wiki/Right-hand_rule> | ||
- `angle` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** of rotation (along the vertical axis), from North in decimal degrees, negative clockwise | ||
- `pivot` **\[([Geometry](http://geojson.org/geojson-spec.html#geometry) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)> | [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>)]** point around which the rotation will be performed (optional, default `` `centroid` ``) | ||
- `mutate` **\[[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`) | ||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`) | ||
- `options.pivot` **([Geometry](http://geojson.org/geojson-spec.html#geometry) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)> | [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>)** point around which the rotation will be performed (optional, default `'centroid'`) | ||
- `options.mutate` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`) | ||
@@ -20,3 +23,4 @@ **Examples** | ||
var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]); | ||
var rotatedPoly = turf.transformRotate(poly, 10, [0, 25]); | ||
var options = {pivot: [0, 25]}; | ||
var rotatedPoly = turf.transformRotate(poly, 10, options); | ||
@@ -23,0 +27,0 @@ //addToMap |
10800
6
124
56
8
7
+ Added@turf/clone@^5.0.4
+ Added@turf/helpers@^5.0.4
+ Added@turf/centroid@5.1.5(transitive)
+ Added@turf/clone@5.1.5(transitive)
+ Added@turf/helpers@5.1.5(transitive)
+ Added@turf/invariant@5.2.0(transitive)
+ Added@turf/meta@5.2.0(transitive)
+ Added@turf/rhumb-bearing@5.1.5(transitive)
+ Added@turf/rhumb-destination@5.1.5(transitive)
+ Added@turf/rhumb-distance@5.1.5(transitive)
- Removed@turf/centroid@4.7.3(transitive)
- Removed@turf/helpers@4.7.3(transitive)
- Removed@turf/invariant@4.7.3(transitive)
- Removed@turf/meta@4.7.4(transitive)
- Removed@turf/rhumb-bearing@4.7.3(transitive)
- Removed@turf/rhumb-destination@4.7.3(transitive)
- Removed@turf/rhumb-distance@4.7.3(transitive)
- Removedgeodesy@1.1.2(transitive)
Updated@turf/centroid@^5.0.4
Updated@turf/invariant@^5.0.4
Updated@turf/meta@^5.0.4
Updated@turf/rhumb-bearing@^5.0.4
Updated@turf/rhumb-distance@^5.0.4