Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
concaveman
Advanced tools
Fast 2D concave hull algorithm in JavaScript (generates an outline of a point set)
Concaveman is a very fast 2D concave hull algorithm that is used to compute the concave hull of a set of 2D points. It is particularly useful in computational geometry for tasks such as shape analysis, clustering, and spatial data visualization.
Compute Concave Hull
This feature allows you to compute the concave hull of a set of 2D points. The code sample demonstrates how to use the concaveman package to calculate the concave hull for a given set of points.
const concaveman = require('concaveman');
const points = [[10, 10], [20, 20], [30, 10], [40, 40], [50, 30]];
const concaveHull = concaveman(points);
console.log(concaveHull);
Hull.js is a JavaScript library for computing the convex hull of a set of 2D points. Unlike concaveman, which computes a concave hull, hull.js focuses on convex hulls, which are the smallest convex shape that can enclose all the points.
Alpha-shape is a library for computing the alpha shape (a generalization of the convex hull) of a set of points. It provides more flexibility in defining the shape of the hull compared to concaveman, which strictly computes concave hulls.
D3-polygon is part of the D3.js library and provides utilities for polygon geometry, including computing the convex hull of a set of points. While it is more general-purpose and part of a larger visualization library, it does not specifically focus on concave hulls like concaveman.
A very fast 2D concave hull algorithm in JavaScript (generates a general outline of a point set).
var points = [[10, 20], [30, 12.5], ...];
var polygon = concaveman(points);
Signature: concaveman(points[, concavity = 2, lengthThreshold = 0])
points
is an array of [x, y]
points.concavity
is a relative measure of concavity. 1
results in a relatively detailed shape, Infinity
results in a convex hull.
You can use values lower than 1
, but they can produce pretty crazy shapes.lengthThreshold
: when a segment length is under this threshold, it stops being considered for further detalization.
Higher values result in simpler shapes.The algorithm is based on ideas from the paper A New Concave Hull Algorithm and Concaveness Measure for n-dimensional Datasets, 2012 by Jin-Seo Park and Se-Jong Oh.
This implementation dramatically improves performance over the one stated in the paper
(O(rn)
, where r
is a number of output points, to O(n log n)
)
by introducing a fast k nearest points to a segment algorithm,
a modification of a depth-first kNN R-tree search using a priority queue.
TypeScript type definitions
are available through npm install --save @types/concaveman
.
In 2019, a C++ port has been created, allowing for efficient usage from C/C++, Python (via cffi) and other languages featuring an FFI and/or plug-in mechanism for C (e.g. a MATLAB MEX file should be easy to prepare).
FAQs
Fast 2D concave hull algorithm in JavaScript (generates an outline of a point set)
The npm package concaveman receives a total of 736,166 weekly downloads. As such, concaveman popularity was classified as popular.
We found that concaveman demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 15 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.