New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@turf/concave

Package Overview
Dependencies
Maintainers
4
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/concave - npm Package Compare versions

Comparing version 4.6.0 to 4.7.0

6

index.d.ts
/// <reference types="geojson" />
import {Units} from '@turf/helpers'
type Points = GeoJSON.FeatureCollection<GeoJSON.Point>;
type Polygon = GeoJSON.Feature<GeoJSON.Polygon>;
type Polygon = GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.MultiPolygon>;

@@ -9,4 +11,4 @@ /**

*/
declare function concave(points: Points, maxEdge: number, units: string): Polygon;
declare function concave(points: Points, maxEdge: number, units?: Units): Polygon;
declare namespace concave { }
export = concave;

@@ -1,18 +0,18 @@

// 1. run tin on points
// 2. calculate lenth of all edges and area of all triangles
// 3. remove triangles that fail the max length test
// 4. buffer the results slightly
// 5. merge the results
var tin = require('@turf/tin');
var union = require('@turf/union');
var helpers = require('@turf/helpers');
var distance = require('@turf/distance');
var dissolve = require('geojson-dissolve');
var featureEach = require('@turf/meta').featureEach;
var feature = helpers.feature;
var featureCollection = helpers.featureCollection;
/**
* Takes a set of {@link Point|points} and returns a concave hull polygon.
* Takes a set of {@link Point|points} and returns a concave hull Polygon or MultiPolygon.
* Internally, this uses [turf-tin](https://github.com/Turfjs/turf-tin) to generate geometries.
*
* @name concave
* @param {FeatureCollection<Point>} points input points
* @param {number} maxEdge the size of an edge necessary for part of the hull to become concave (in miles)
* @param {number} maxEdge the length (in 'units') of an edge necessary for part of the hull to become concave
* @param {string} [units=kilometers] can be degrees, radians, miles, or kilometers
* @returns {Feature<Polygon>} a concave hull
* @returns {Feature<(Polygon|MultiPolygon)>} a concave hull
* @throws {Error} if maxEdge parameter is missing or unable to compute hull

@@ -34,13 +34,14 @@ * @example

*/
function concave(points, maxEdge, units) {
if (typeof maxEdge !== 'number') throw new Error('maxEdge parameter is required');
module.exports = function (points, maxEdge, units) {
// validation
if (!points) throw new Error('points is required');
if (maxEdge === undefined || maxEdge === null) throw new Error('maxEdge is required');
if (typeof maxEdge !== 'number') throw new Error('invalid maxEdge');
var tinPolys = tin(points);
var filteredPolys = tinPolys.features.filter(filterTriangles);
tinPolys.features = filteredPolys;
if (tinPolys.features.length < 1) {
throw new Error('too few polygons found to compute concave hull');
}
var cleaned = removeDuplicates(points);
function filterTriangles(triangle) {
var tinPolys = tin(cleaned);
// calculate length of all edges and area of all triangles
// and remove triangles that fail the max length test
tinPolys.features = tinPolys.features.filter(function (triangle) {
var pt1 = triangle.geometry.coordinates[0][0];

@@ -53,20 +54,36 @@ var pt2 = triangle.geometry.coordinates[0][1];

return (dist1 <= maxEdge && dist2 <= maxEdge && dist3 <= maxEdge);
});
if (tinPolys.features.length < 1) throw new Error('too few polygons found to compute concave hull');
// merge the adjacent triangles
var dissolved = dissolve(tinPolys.features);
// geojson-dissolve always returns a MultiPolygon
if (dissolved.coordinates.length === 1) {
dissolved.coordinates = dissolved.coordinates[0];
dissolved.type = 'Polygon';
}
return feature(dissolved);
};
return merge(tinPolys);
}
/**
* Removes duplicated points in a collection returning a new collection
*
* @private
* @param {FeatureCollection<Point>} points to be cleaned
* @returns {FeatureCollection<Point>} cleaned set of points
*/
function removeDuplicates(points) {
var cleaned = [];
var existing = {};
function merge(polygons) {
var merged = JSON.parse(JSON.stringify(polygons.features[0])),
features = polygons.features;
for (var i = 0, len = features.length; i < len; i++) {
var poly = features[i];
if (poly.geometry) {
merged = union(merged, poly);
featureEach(points, function (pt) {
if (!pt.geometry) return;
var key = pt.geometry.coordinates.join('-');
if (!existing.hasOwnProperty(key)) {
cleaned.push(pt);
existing[key] = true;
}
}
return merged;
});
return featureCollection(cleaned);
}
module.exports = concave;
{
"name": "@turf/concave",
"version": "4.6.0",
"version": "4.7.0",
"description": "turf concave module",

@@ -22,5 +22,17 @@ "main": "index.js",

"gis",
"concave",
"geometry"
],
"author": "Turf Authors",
"contributors": [
"Tom MacWright <@tmcw>",
"Lyzi Diamond <@lyzidiamond>",
"Denis Carriere <@DenisCarriere>",
"Stefano Borghi <@stebogit>",
"Rowan Winsemius <@rowanwins>",
"Daniel Pulido <@dpmcmlxxvi>",
"Stephen Whitmore <@noffle>",
"Gregor MacLennan <@gmaclennan>",
"Mike Bostock <@mbostock>"
],
"license": "MIT",

@@ -32,12 +44,14 @@ "bugs": {

"devDependencies": {
"@turf/helpers": "^4.6.0",
"benchmark": "^2.1.4",
"glob": "~4.3.5",
"tape": "^4.6.3"
"load-json-file": "^2.0.0",
"tape": "^4.6.3",
"write-json-file": "^2.1.4"
},
"dependencies": {
"@turf/distance": "^4.6.0",
"@turf/tin": "^4.6.0",
"@turf/union": "^4.6.0"
"@turf/distance": "4.7.0",
"@turf/helpers": "4.7.0",
"@turf/meta": "4.7.0",
"@turf/tin": "4.7.0",
"geojson-dissolve": "3.1.0"
}
}

@@ -5,3 +5,3 @@ # @turf/concave

Takes a set of [points](http://geojson.org/geojson-spec.html#point) and returns a concave hull polygon.
Takes a set of [points](http://geojson.org/geojson-spec.html#point) and returns a concave hull Polygon or MultiPolygon.
Internally, this uses [turf-tin](https://github.com/Turfjs/turf-tin) to generate geometries.

@@ -12,3 +12,3 @@

- `points` **[FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)&lt;[Point](http://geojson.org/geojson-spec.html#point)>** input points
- `maxEdge` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the size of an edge necessary for part of the hull to become concave (in miles)
- `maxEdge` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the length (in 'units') of an edge necessary for part of the hull to become concave
- `units` **\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** can be degrees, radians, miles, or kilometers (optional, default `kilometers`)

@@ -36,3 +36,3 @@

Returns **[Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;[Polygon](http://geojson.org/geojson-spec.html#polygon)>** a concave hull
Returns **[Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;([Polygon](http://geojson.org/geojson-spec.html#polygon) \| [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon))>** a concave hull

@@ -39,0 +39,0 @@ <!-- This file is automatically generated. Please don't edit it directly:

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