@turf/sector
Advanced tools
Comparing version 4.7.3 to 5.0.4
@@ -1,10 +0,15 @@ | ||
/// <reference types="geojson" /> | ||
import { Feature, Polygon, Units, Coord } from '@turf/helpers'; | ||
import {Point, Polygon, Units} from '@turf/helpers'; | ||
/** | ||
* http://turfjs.org/docs/#sector | ||
*/ | ||
declare function sector(center: Point, radius: number, bearing1: number, bearing2: number, steps?: number, units?: Units): Polygon; | ||
declare namespace sector {} | ||
export = sector; | ||
export default function sector( | ||
center: Coord, | ||
radius: number, | ||
bearing1: number, | ||
bearing2: number, | ||
options?: { | ||
steps?: number, | ||
units?: Units | ||
} | ||
): Feature<Polygon>; |
38
index.js
@@ -1,7 +0,6 @@ | ||
var circle = require('@turf/circle'); | ||
var coordEach = require('@turf/meta').coordEach; | ||
var helpers = require('@turf/helpers'); | ||
var getCoords = require('@turf/invariant').getCoords; | ||
var polygon = helpers.polygon; | ||
var lineArc = require('@turf/line-arc'); | ||
import circle from '@turf/circle'; | ||
import lineArc from '@turf/line-arc'; | ||
import { coordEach } from '@turf/meta'; | ||
import { polygon, isObject } from '@turf/helpers'; | ||
import { getCoords } from '@turf/invariant'; | ||
@@ -17,4 +16,5 @@ /** | ||
* @param {number} bearing2 angle, in decimal degrees, of the second radius of the sector | ||
* @param {number} [steps=64] number of steps | ||
* @param {string} [units=kilometers] miles, kilometers, degrees, or radians | ||
* @param {Object} [options={}] Optional parameters | ||
* @param {string} [options.units='kilometers'] miles, kilometers, degrees, or radians | ||
* @param {number} [options.steps=64] number of steps | ||
* @returns {Feature<Polygon>} sector polygon | ||
@@ -32,3 +32,7 @@ * @example | ||
*/ | ||
module.exports = function (center, radius, bearing1, bearing2, steps, units) { | ||
function sector(center, radius, bearing1, bearing2, options) { | ||
// Optional parameters | ||
options = options || {}; | ||
if (!isObject(options)) throw new Error('options is invalid'); | ||
// validation | ||
@@ -39,11 +43,9 @@ if (!center) throw new Error('center is required'); | ||
if (!radius) throw new Error('radius is required'); | ||
if (typeof options !== 'object') throw new Error('options must be an object'); | ||
// default params | ||
steps = steps || 64; | ||
if (convertAngleTo360(bearing1) === convertAngleTo360(bearing2)) { | ||
return circle(center, radius, steps, units); | ||
return circle(center, radius, options); | ||
} | ||
var coords = getCoords(center); | ||
var arc = lineArc(center, radius, bearing1, bearing2, steps, units); | ||
var arc = lineArc(center, radius, bearing1, bearing2, options); | ||
var sliceCoords = [[coords]]; | ||
@@ -56,3 +58,3 @@ coordEach(arc, function (currentCoords) { | ||
return polygon(sliceCoords); | ||
}; | ||
} | ||
@@ -69,6 +71,6 @@ /** | ||
var beta = alfa % 360; | ||
if (beta < 0) { | ||
beta += 360; | ||
} | ||
if (beta < 0) beta += 360; | ||
return beta; | ||
} | ||
export default sector; |
{ | ||
"name": "@turf/sector", | ||
"version": "4.7.3", | ||
"version": "5.0.4", | ||
"description": "turf sector 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" | ||
}, | ||
@@ -30,15 +34,21 @@ "repository": { | ||
"devDependencies": { | ||
"@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/circle": "^4.7.3", | ||
"@turf/helpers": "^4.7.3", | ||
"@turf/invariant": "^4.7.3", | ||
"@turf/line-arc": "^4.7.3", | ||
"@turf/meta": "^4.7.3" | ||
"@turf/circle": "^5.0.4", | ||
"@turf/helpers": "^5.0.4", | ||
"@turf/invariant": "^5.0.4", | ||
"@turf/line-arc": "^5.0.4", | ||
"@turf/meta": "^5.0.4" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
} | ||
} |
# @turf/sector | ||
# sector | ||
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
## sector | ||
Creates a circular sector of a circle of given radius and center [Point](http://geojson.org/geojson-spec.html#point), | ||
@@ -14,4 +16,5 @@ between (clockwise) bearing1 and bearing2; 0 bearing is North of center point, positive clockwise. | ||
- `bearing2` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** angle, in decimal degrees, of the second radius of the sector | ||
- `steps` **\[[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)]** number of steps (optional, default `64`) | ||
- `units` **\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** miles, kilometers, degrees, or radians (optional, default `kilometers`) | ||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`) | ||
- `options.units` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** miles, kilometers, degrees, or radians (optional, default `'kilometers'`) | ||
- `options.steps` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** number of steps (optional, default `64`) | ||
@@ -18,0 +21,0 @@ **Examples** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10344
6
147
60
7
+ Added@turf/circle@5.1.5(transitive)
+ Added@turf/destination@5.1.5(transitive)
+ Added@turf/helpers@5.1.5(transitive)
+ Added@turf/invariant@5.2.0(transitive)
+ Added@turf/line-arc@5.1.5(transitive)
+ Added@turf/meta@5.2.0(transitive)
- Removed@turf/circle@4.7.3(transitive)
- Removed@turf/destination@4.7.3(transitive)
- Removed@turf/helpers@4.7.3(transitive)
- Removed@turf/invariant@4.7.3(transitive)
- Removed@turf/line-arc@4.7.3(transitive)
- Removed@turf/meta@4.7.4(transitive)
Updated@turf/circle@^5.0.4
Updated@turf/helpers@^5.0.4
Updated@turf/invariant@^5.0.4
Updated@turf/line-arc@^5.0.4
Updated@turf/meta@^5.0.4