@turf/convex
Advanced tools
Comparing version 4.7.3 to 5.0.4
@@ -1,12 +0,11 @@ | ||
/// <reference types="geojson" /> | ||
import { Feature, AllGeoJSON, Polygon } from '@turf/helpers' | ||
type Feature = GeoJSON.Feature<any>; | ||
type Features = GeoJSON.FeatureCollection<any>; | ||
type Polygon = GeoJSON.Feature<GeoJSON.Polygon>; | ||
/** | ||
* http://turfjs.org/docs/#convex | ||
*/ | ||
declare function convex(features: Feature | Features): Polygon; | ||
declare namespace convex { } | ||
export = convex; | ||
export default function convex( | ||
geojson: AllGeoJSON, | ||
options?: { | ||
concavity?: number | ||
} | ||
): Feature<Polygon>; |
40
index.js
@@ -1,4 +0,4 @@ | ||
var each = require('@turf/meta').coordEach, | ||
convexHull = require('convex-hull'), | ||
polygon = require('@turf/helpers').polygon; | ||
var concaveman = require('concaveman'); | ||
import { coordEach } from '@turf/meta'; | ||
import { polygon, isObject } from '@turf/helpers'; | ||
@@ -13,3 +13,5 @@ /** | ||
* @name convex | ||
* @param {Feature|FeatureCollection} feature input Feature or FeatureCollection | ||
* @param {GeoJSON} geojson input Feature or FeatureCollection | ||
* @param {Object} [options={}] Optional parameters | ||
* @param {number} [options.concavity=Infinity] 1 - thin shape. Infinity - convex hull. | ||
* @returns {Feature<Polygon>} a convex hull | ||
@@ -31,22 +33,24 @@ * @example | ||
*/ | ||
module.exports = function (feature) { | ||
function convex(geojson, options) { | ||
// Optional parameters | ||
options = options || {}; | ||
if (!isObject(options)) throw new Error('options is invalid'); | ||
var concavity = options.concavity || Infinity; | ||
var points = []; | ||
// Remove Z in coordinates because it breaks the convexHull algorithm | ||
each(feature, function (coord) { | ||
// Convert all points to flat 2D coordinate Array | ||
coordEach(geojson, function (coord) { | ||
points.push([coord[0], coord[1]]); | ||
}); | ||
if (!points.length) return null; | ||
var hull = convexHull(points); | ||
var convexHull = concaveman(points, concavity); | ||
// Hull should have at least 3 different vertices in order to create a valid polygon | ||
if (hull.length >= 3) { | ||
var ring = []; | ||
for (var i = 0; i < hull.length; i++) { | ||
ring.push(points[hull[i][0]]); | ||
} | ||
ring.push(points[hull[hull.length - 1][1]]); | ||
return polygon([ring]); | ||
// Convex hull should have at least 3 different vertices in order to create a valid polygon | ||
if (convexHull.length > 3) { | ||
return polygon([convexHull]); | ||
} | ||
return undefined; | ||
}; | ||
return null; | ||
} | ||
export default convex; |
{ | ||
"name": "@turf/convex", | ||
"version": "4.7.3", | ||
"version": "5.0.4", | ||
"description": "turf convex 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,11 +34,19 @@ "repository": { | ||
"devDependencies": { | ||
"benchmark": "^2.1.4", | ||
"glob": "~4.3.5", | ||
"tape": "^4.6.3" | ||
"@std/esm": "*", | ||
"benchmark": "*", | ||
"glob": "*", | ||
"load-json-file": "*", | ||
"rollup": "*", | ||
"tape": "*", | ||
"write-json-file": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/helpers": "^4.7.3", | ||
"@turf/meta": "^4.7.3", | ||
"convex-hull": "^1.0.3" | ||
"@turf/helpers": "^5.0.4", | ||
"@turf/meta": "^5.0.4", | ||
"concaveman": "*" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
} | ||
} |
# @turf/convex | ||
# convex | ||
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
## convex | ||
Takes a [Feature](http://geojson.org/geojson-spec.html#feature-objects) or a [FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) and returns a convex hull [Polygon](http://geojson.org/geojson-spec.html#polygon). | ||
@@ -13,3 +15,5 @@ | ||
- `feature` **([Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects))** input Feature or FeatureCollection | ||
- `geojson` **[GeoJSON](http://geojson.org/geojson-spec.html#geojson-objects)** input Feature or FeatureCollection | ||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`) | ||
- `options.concavity` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** 1 - thin shape. Infinity - convex hull. (optional, default `Infinity`) | ||
@@ -16,0 +20,0 @@ **Examples** |
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
8298
6
110
63
7
1
+ Addedconcaveman@*
+ Added@turf/helpers@5.1.5(transitive)
+ Added@turf/meta@5.2.0(transitive)
+ Addedconcaveman@1.2.1(transitive)
+ Addedpoint-in-polygon@1.1.0(transitive)
+ Addedquickselect@2.0.0(transitive)
+ Addedrbush@3.0.1(transitive)
+ Addedrobust-predicates@2.0.4(transitive)
+ Addedtinyqueue@2.0.3(transitive)
- Removedconvex-hull@^1.0.3
- Removed@turf/helpers@4.7.3(transitive)
- Removed@turf/meta@4.7.4(transitive)
- Removedaffine-hull@1.0.0(transitive)
- Removedbit-twiddle@1.0.2(transitive)
- Removedconvex-hull@1.0.3(transitive)
- Removedincremental-convex-hull@1.0.1(transitive)
- Removedmonotone-convex-hull-2d@1.0.1(transitive)
- Removedrobust-orientation@1.2.1(transitive)
- Removedrobust-scale@1.0.2(transitive)
- Removedrobust-subtract@1.0.0(transitive)
- Removedrobust-sum@1.0.0(transitive)
- Removedsimplicial-complex@1.0.0(transitive)
- Removedtwo-product@1.0.2(transitive)
- Removedtwo-sum@1.0.0(transitive)
- Removedunion-find@1.0.2(transitive)
Updated@turf/helpers@^5.0.4
Updated@turf/meta@^5.0.4