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

@turf/voronoi

Package Overview
Dependencies
Maintainers
4
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/voronoi - npm Package Compare versions

Comparing version 5.0.0 to 5.0.4

47

index.js

@@ -1,5 +0,4 @@

import lineStringToPolygon from '@turf/linestring-to-polygon';
import { lineString, featureCollection } from '@turf/helpers';
import { getCoords, collectionOf } from '@turf/invariant';
import d3voronoi from 'd3-voronoi';
import { polygon, featureCollection, isObject } from '@turf/helpers';
import { collectionOf } from '@turf/invariant';
import * as d3voronoi from 'd3-voronoi';

@@ -11,3 +10,5 @@ /**

function coordsToPolygon(coords) {
return lineStringToPolygon(lineString(coords.slice(0)));
coords = coords.slice();
coords.push(coords[0]);
return polygon([coords]);
}

@@ -23,23 +24,33 @@

* @param {FeatureCollection<Point>} points to find the Voronoi polygons around.
* @param {number[]} bbox clipping rectangle, in [minX, minY, maxX, MaxY] order.
* @returns {FeatureCollection<Polygon>} a set of polygons, one per input polygon.
* @param {Object} [options={}] Optional parameters
* @param {number[]} [options.bbox=[-180, -85, 180, -85]] clipping rectangle, in [minX, minY, maxX, MaxY] order.
* @returns {FeatureCollection<Polygon>} a set of polygons, one per input point.
* @example
* var bbox = [-70, 40, -60, 60];
* var points = turf.randomPoints(100, { bbox: bbox });
* var voronoiPolygons = turf.voronoi(points, bbox);
* var options = {
* bbox: [-70, 40, -60, 60]
* };
* var points = turf.randomPoint(100, options);
* var voronoiPolygons = turf.voronoi(points, options);
*
* //addToMap
* var addToMap = [voronoiPolygons, points];
*/
function voronoi(points, bbox) {
function voronoi(points, options) {
// Optional params
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var bbox = options.bbox || [-180, -85, 180, 85];
// Input Validation
if (!points) throw new Error('points is required');
if (!bbox) throw new Error('bbox is required');
if (!Array.isArray(bbox)) throw new Error('bbox is invalid');
collectionOf(points, 'Point', 'points');
// Inputs
var extent = [[bbox[0], bbox[1]], [bbox[2], bbox[3]]];
var coords = points.features.map(getCoords);
// Main
return featureCollection(
d3voronoi.voronoi()
.extent(extent)(coords)
.polygons()
.x(function (feature) { return feature.geometry.coordinates[0]; })
.y(function (feature) { return feature.geometry.coordinates[1]; })
.extent([[bbox[0], bbox[1]], [bbox[2], bbox[3]]])
.polygons(points.features)
.map(coordsToPolygon)

@@ -46,0 +57,0 @@ );

'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var lineStringToPolygon = _interopDefault(require('@turf/linestring-to-polygon'));
var helpers = require('@turf/helpers');
var invariant = require('@turf/invariant');
var d3voronoi = _interopDefault(require('d3-voronoi'));
var d3voronoi = require('d3-voronoi');

@@ -15,3 +12,5 @@ /**

function coordsToPolygon(coords) {
return lineStringToPolygon(helpers.lineString(coords.slice(0)));
coords = coords.slice();
coords.push(coords[0]);
return helpers.polygon([coords]);
}

@@ -27,23 +26,33 @@

* @param {FeatureCollection<Point>} points to find the Voronoi polygons around.
* @param {number[]} bbox clipping rectangle, in [minX, minY, maxX, MaxY] order.
* @returns {FeatureCollection<Polygon>} a set of polygons, one per input polygon.
* @param {Object} [options={}] Optional parameters
* @param {number[]} [options.bbox=[-180, -85, 180, -85]] clipping rectangle, in [minX, minY, maxX, MaxY] order.
* @returns {FeatureCollection<Polygon>} a set of polygons, one per input point.
* @example
* var bbox = [-70, 40, -60, 60];
* var points = turf.randomPoints(100, { bbox: bbox });
* var voronoiPolygons = turf.voronoi(points, bbox);
* var options = {
* bbox: [-70, 40, -60, 60]
* };
* var points = turf.randomPoint(100, options);
* var voronoiPolygons = turf.voronoi(points, options);
*
* //addToMap
* var addToMap = [voronoiPolygons, points];
*/
function voronoi(points, bbox) {
function voronoi$1(points, options) {
// Optional params
options = options || {};
if (!helpers.isObject(options)) throw new Error('options is invalid');
var bbox = options.bbox || [-180, -85, 180, 85];
// Input Validation
if (!points) throw new Error('points is required');
if (!bbox) throw new Error('bbox is required');
if (!Array.isArray(bbox)) throw new Error('bbox is invalid');
invariant.collectionOf(points, 'Point', 'points');
// Inputs
var extent = [[bbox[0], bbox[1]], [bbox[2], bbox[3]]];
var coords = points.features.map(invariant.getCoords);
// Main
return helpers.featureCollection(
d3voronoi.voronoi()
.extent(extent)(coords)
.polygons()
.x(function (feature) { return feature.geometry.coordinates[0]; })
.y(function (feature) { return feature.geometry.coordinates[1]; })
.extent([[bbox[0], bbox[1]], [bbox[2], bbox[3]]])
.polygons(points.features)
.map(coordsToPolygon)

@@ -53,3 +62,3 @@ );

module.exports = voronoi;
module.exports.default = voronoi;
module.exports = voronoi$1;
module.exports.default = voronoi$1;
{
"name": "@turf/voronoi",
"version": "5.0.0",
"version": "5.0.4",
"description": "turf voronoi module",

@@ -32,3 +32,6 @@ "main": "main",

"contributors": [
"Steve Bennett <@stevage1>"
"Philippe Riviere <@Fil>",
"Mike Bostock <@mbostock>",
"Steve Bennett <@stevage1>",
"Denis Carriere <@DenisCarriere>"
],

@@ -41,14 +44,14 @@ "license": "MIT",

"devDependencies": {
"@std/esm": "*",
"benchmark": "*",
"glob": "*",
"load-json-file": "*",
"rollup": "*",
"tape": "*",
"write-json-file": "*",
"rollup": "*",
"@std/esm": "*"
"write-json-file": "*"
},
"dependencies": {
"@turf/invariant": "5.x",
"@turf/linestring-to-polygon": "5.x",
"d3-voronoi": "^1.1.2",
"@turf/helpers": "5.x"
"@turf/helpers": "^5.0.4",
"@turf/invariant": "^5.0.4",
"d3-voronoi": "1.1.2"
},

@@ -55,0 +58,0 @@ "@std/esm": {

@@ -13,6 +13,6 @@ # @turf/voronoi

## turfVoronoi
## voronoi
Takes a FeatureCollection of points, and a bounding box, and returns a FeatureCollection
of Voronoi polygons.
of Voronoi polygons.

@@ -24,3 +24,4 @@ The Voronoi algorithim used comes from the d3-voronoi package.

- `points` **[FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)&lt;[Point](http://geojson.org/geojson-spec.html#point)>** to find the Voronoi polygons around.
- `bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** clipping rectangle, in [minX, minY, maxX, MaxY] order.
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`)
- `options.bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** clipping rectangle, in [minX, minY, maxX, MaxY] order. (optional, default `[-180,-85,180,-85]`)

@@ -30,8 +31,13 @@ **Examples**

```javascript
var bbox = [-70, 40, -60, 60];
var points = turf.randomPoints(100, { bbox: bbox });
var voronoiPolygons = turf.voronoi(points, bbox);
var options = {
bbox: [-70, 40, -60, 60]
};
var points = turf.randomPoint(100, options);
var voronoiPolygons = turf.voronoi(points, options);
//addToMap
var addToMap = [voronoiPolygons, points];
```
Returns **[FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)&lt;[Polygon](http://geojson.org/geojson-spec.html#polygon)>** a set of polygons, one per input polygon.
Returns **[FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)&lt;[Polygon](http://geojson.org/geojson-spec.html#polygon)>** a set of polygons, one per input point.

@@ -38,0 +44,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