Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@turf/convex

Package Overview
Dependencies
Maintainers
4
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/convex - npm Package Compare versions

Comparing version 4.7.3 to 5.0.4

main.js

15

index.d.ts

@@ -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>;

@@ -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**

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc