@turf/hex-grid
Advanced tools
Comparing version 4.4.0 to 4.5.1
@@ -6,4 +6,4 @@ import {Units, BBox, Polygons} from '@turf/helpers' | ||
*/ | ||
declare function hexGrid(bbox: BBox, cellSize: number, units?: Units, triangles?: boolean): Polygons; | ||
declare function hexGrid(bbox: BBox, cellDiameter: number, units?: Units, triangles?: boolean): Polygons; | ||
declare namespace hexGrid { } | ||
export = hexGrid; |
18
index.js
@@ -18,4 +18,4 @@ var distance = require('@turf/distance'); | ||
/** | ||
* 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 | ||
* Takes a bounding box and the diameter of the cell and returns a {@link FeatureCollection} of flat-topped | ||
* hexagons or triangles ({@link Polygon} features) aligned in an "odd-q" vertical grid as | ||
* described in [Hexagonal Grids](http://www.redblobgames.com/grids/hexagons/). | ||
@@ -25,4 +25,4 @@ * | ||
* @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order | ||
* @param {number} cellSize dimension of cell in specified units | ||
* @param {string} [units=kilometers] used in calculating cellSize, can be degrees, radians, miles, or kilometers | ||
* @param {number} cellDiameter diameter of the circumcircle of the hexagons, in specified units | ||
* @param {string} [units=kilometers] used in calculating cell size, can be degrees, radians, miles, or kilometers | ||
* @param {boolean} [triangles=false] whether to return as triangles instead of hexagons | ||
@@ -32,6 +32,6 @@ * @returns {FeatureCollection<Polygon>} a hexagonal grid | ||
* var bbox = [-96,31,-84,40]; | ||
* var cellSize = 50; | ||
* var cellDiameter = 50; | ||
* var units = 'miles'; | ||
* | ||
* var hexgrid = turf.hexGrid(bbox, cellSize, units); | ||
* var hexgrid = turf.hexGrid(bbox, cellDiameter, units); | ||
* | ||
@@ -41,3 +41,3 @@ * //addToMap | ||
*/ | ||
module.exports = function hexGrid(bbox, cellSize, units, triangles) { | ||
module.exports = function hexGrid(bbox, cellDiameter, units, triangles) { | ||
var west = bbox[0]; | ||
@@ -51,5 +51,5 @@ var south = bbox[1]; | ||
// https://github.com/Turfjs/turf/issues/758 | ||
var xFraction = cellSize / (distance(point([west, centerY]), point([east, centerY]), units)); | ||
var xFraction = cellDiameter / (distance(point([west, centerY]), point([east, centerY]), units)); | ||
var cellWidth = xFraction * (east - west); | ||
var yFraction = cellSize / (distance(point([centerX, south]), point([centerX, north]), units)); | ||
var yFraction = cellDiameter / (distance(point([centerX, south]), point([centerX, north]), units)); | ||
var cellHeight = yFraction * (north - south); | ||
@@ -56,0 +56,0 @@ var radius = cellWidth / 2; |
{ | ||
"name": "@turf/hex-grid", | ||
"version": "4.4.0", | ||
"version": "4.5.1", | ||
"description": "turf hex-grid module", | ||
@@ -42,3 +42,4 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@turf/truncate": "^4.4.0", | ||
"@turf/centroid": "^4.5.1", | ||
"@turf/truncate": "^4.5.1", | ||
"benchmark": "^2.1.4", | ||
@@ -50,5 +51,5 @@ "load-json-file": "^2.0.0", | ||
"dependencies": { | ||
"@turf/distance": "^4.4.0", | ||
"@turf/helpers": "^4.4.0" | ||
"@turf/distance": "^4.5.1", | ||
"@turf/helpers": "^4.5.1" | ||
} | ||
} |
@@ -5,4 +5,4 @@ # @turf/hex-grid | ||
Takes a bounding box and a cell size in degrees and returns a [FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) of flat-topped | ||
hexagons ([Polygon](http://geojson.org/geojson-spec.html#polygon) features) aligned in an "odd-q" vertical grid as | ||
Takes a bounding box and the diameter of the cell and returns a [FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) of flat-topped | ||
hexagons or triangles ([Polygon](http://geojson.org/geojson-spec.html#polygon) features) aligned in an "odd-q" vertical grid as | ||
described in [Hexagonal Grids](http://www.redblobgames.com/grids/hexagons/). | ||
@@ -13,4 +13,4 @@ | ||
- `bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** extent in [minX, minY, maxX, maxY] order | ||
- `cellSize` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** dimension of cell in specified units | ||
- `units` **\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** used in calculating cellSize, can be degrees, radians, miles, or kilometers (optional, default `kilometers`) | ||
- `cellDiameter` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** diameter of the circumcircle of the hexagons, in specified units | ||
- `units` **\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** used in calculating cell size, can be degrees, radians, miles, or kilometers (optional, default `kilometers`) | ||
- `triangles` **\[[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** whether to return as triangles instead of hexagons (optional, default `false`) | ||
@@ -22,6 +22,6 @@ | ||
var bbox = [-96,31,-84,40]; | ||
var cellSize = 50; | ||
var cellDiameter = 50; | ||
var units = 'miles'; | ||
var hexgrid = turf.hexGrid(bbox, cellSize, units); | ||
var hexgrid = turf.hexGrid(bbox, cellDiameter, units); | ||
@@ -28,0 +28,0 @@ //addToMap |
9262
6
Updated@turf/distance@^4.5.1
Updated@turf/helpers@^4.5.1