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

turf-hex

Package Overview
Dependencies
Maintainers
8
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turf-hex - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

43

index.js
var polygon = require('turf-polygon');
/**
* Takes a bounding box and a cell size in degrees and returns a {@link FeatureCollection} of flat-topped
* hexagons ({@link Polygon} features) aligned in an "odd-q" vertical grid as
* described in [Hexagonal Grids](http://www.redblobgames.com/grids/hexagons/)
*
* @module turf/hex
* @category interpolation
* @param {Array<number>} bbox bounding box in [minX, minY, maxX, maxY] order
* @param {Number} size size of cells in degrees
* @return {FeatureCollection} a FeatureCollection of hexagonal {@link Polygon} features in a grid
* @example
* var bbox = [7.2669410, 43.695307, 7.2862529, 43.706476];
* var size = 0.001;
*
* var hexgrid = turf.hex(bbox, size);
*
* //=hexgrid
*/
module.exports = hexgrid;

@@ -32,13 +50,3 @@

// Creates a FeatureCollection of flat-topped
// hexagons aligned in an "odd-q" vertical grid as
// described on http://www.redblobgames.com/grids/hexagons/
//
// bbox: [xmin, ymin, xmax, ymax]
// radius: distance from hex center to vertex (in degrees)
// done: node-style callback (optional)
//
// Returns a GeoJSON FeatureCollection of tessellated hexagons
// that cover the given bbox
function hexgrid(bbox, radius, done) {
function hexgrid(bbox, radius) {
var xmin = bbox[0];

@@ -56,3 +64,3 @@ var ymin = bbox[1];

var hex_height = Math.sqrt(3)/2 * hex_width;
var box_width = xmax - xmin;

@@ -69,3 +77,3 @@ var box_height = ymax - ymin;

}
var x_adjust = ((x_count * x_interval - radius/2) - box_width)/2 - radius/2;

@@ -81,6 +89,6 @@

}
for (var x = 0; x < x_count; x++) {
for (var y = 0; y <= y_count; y++) {
var isOdd = x % 2 === 1;

@@ -97,3 +105,3 @@ if (y === 0 && isOdd) {

var center_y = y * y_interval + ymin + y_adjust;
if (isOdd) {

@@ -107,6 +115,3 @@ center_y -= hex_height/2;

done = done || function () {};
done(null, fc);
return fc;
}
{
"name": "turf-hex",
"version": "1.0.1",
"version": "1.0.2",
"description": "turf hex module",
"main": "index.js",
"scripts": {
"test": "tape test.js"
"test": "tape test.js",
"doc": "dox -r < index.js | doxme --readme > README.md"
},
"repository": {
"type": "git",
"url": "git://github.com/turfjs/turf-hex.git"
"url": "git://github.com/Turfjs/turf-hex.git"
},

@@ -27,16 +28,18 @@ "keywords": [

"bugs": {
"url": "https://github.com/turfjs/turf-hex/issues"
"url": "https://github.com/Turfjs/turf-hex/issues"
},
"homepage": "https://github.com/turfjs/turf-hex",
"homepage": "https://github.com/Turfjs/turf-hex",
"devDependencies": {
"benchmark": "^1.0.0",
"tape": "^2.13.4",
"turf-bbox-polygon": "^0.1.5",
"turf-explode": "^0.1.3",
"turf-extent": "^0.1.4",
"turf-inside": "^0.1.4"
"tape": "^3.5.0",
"turf-bbox-polygon": "^1.0.0",
"turf-explode": "^1.0.0",
"turf-extent": "^1.0.3",
"turf-inside": "^1.1.3",
"dox": "^0.6.1",
"doxme": "^1.4.3"
},
"dependencies": {
"turf-polygon": "^0.1.1"
"turf-polygon": "^1.0.2"
}
}

@@ -1,34 +0,47 @@

turf-hex
========
[![Build Status](https://travis-ci.org/Turfjs/turf-hex.svg?branch=master)](https://travis-ci.org/Turfjs/turf-hex)
# turf-hex
Generates a hexgrid that covers the specified bbox.
[![build status](https://secure.travis-ci.org/Turfjs/turf-hex.png)](http://travis-ci.org/Turfjs/turf-hex)
![Example](example.png)
turf hex module
###Install
```sh
npm install turf-hex
```
### `turf.hex(bbox, size)`
###Parameters
Takes a bounding box and a cell size in degrees and returns a FeatureCollection of flat-topped
hexagons (Polygon features) aligned in an "odd-q" vertical grid as
described in [Hexagonal Grids](http://www.redblobgames.com/grids/hexagons/)
name|description
---|---
bbox|[minX, minY, maxX, maxY]
size|size of cells in degrees
###Usage
### Parameters
| parameter | type | description |
| --------- | -------------- | ---------------------------------------------- |
| `bbox` | Array.<number> | bounding box in [minX, minY, maxX, maxY] order |
| `size` | Number | size of cells in degrees |
### Example
```js
hex(bbox, size)
var bbox = [7.2669410, 43.695307, 7.2862529, 43.706476];
var size = 0.001;
var hexgrid = turf.hex(bbox, size);
//=hexgrid
```
###Example
## Installation
```js
var hex = require('turf-hex');
Requires [nodejs](http://nodejs.org/).
var hexgrid = hex([0,0,10,10], 1)
```sh
$ npm install turf-hex
```
## Tests
```sh
$ npm test
```
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