@turf/hex-grid
Advanced tools
Comparing version 5.0.5 to 5.1.0
@@ -6,3 +6,3 @@ import { Units, BBox, Polygon, MultiPolygon, Feature, FeatureCollection, Point, Properties } from '@turf/helpers'; | ||
*/ | ||
export default function hexGrid( | ||
export default function hexGrid<P = Properties>( | ||
bbox: BBox, | ||
@@ -13,5 +13,5 @@ cellSide: number, | ||
triangles?: boolean, | ||
properties?: Properties, | ||
properties?: P, | ||
mask?: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon; | ||
} | ||
): FeatureCollection<Polygon>; | ||
): FeatureCollection<Polygon, P>; |
@@ -12,3 +12,3 @@ import distance from '@turf/distance'; | ||
* @name hexGrid | ||
* @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order | ||
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order | ||
* @param {number} cellSide length of the side of the the hexagons or triangles, in units. It will also coincide with the | ||
@@ -15,0 +15,0 @@ * radius of the circumcircle of the hexagons. |
24
main.js
@@ -16,3 +16,3 @@ 'use strict'; | ||
* @name hexGrid | ||
* @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order | ||
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order | ||
* @param {number} cellSide length of the side of the the hexagons or triangles, in units. It will also coincide with the | ||
@@ -39,3 +39,3 @@ * radius of the circumcircle of the hexagons. | ||
options = options || {}; | ||
if (!helpers.isObject(options)) throw new Error('options is invalid'); | ||
if (!helpers.isObject(options)) { throw new Error('options is invalid'); } | ||
// var units = options.units; | ||
@@ -47,8 +47,8 @@ var properties = options.properties || {}; | ||
// validation | ||
if (cellSide === null || cellSide === undefined) throw new Error('cellSide is required'); | ||
if (!helpers.isNumber(cellSide)) throw new Error('cellSide is invalid'); | ||
if (!bbox) throw new Error('bbox is required'); | ||
if (!Array.isArray(bbox)) throw new Error('bbox must be array'); | ||
if (bbox.length !== 4) throw new Error('bbox must contain 4 numbers'); | ||
if (mask && ['Polygon', 'MultiPolygon'].indexOf(invariant.getType(mask)) === -1) throw new Error('options.mask must be a (Multi)Polygon'); | ||
if (cellSide === null || cellSide === undefined) { throw new Error('cellSide is required'); } | ||
if (!helpers.isNumber(cellSide)) { throw new Error('cellSide is invalid'); } | ||
if (!bbox) { throw new Error('bbox is required'); } | ||
if (!Array.isArray(bbox)) { throw new Error('bbox must be array'); } | ||
if (bbox.length !== 4) { throw new Error('bbox must contain 4 numbers'); } | ||
if (mask && ['Polygon', 'MultiPolygon'].indexOf(invariant.getType(mask)) === -1) { throw new Error('options.mask must be a (Multi)Polygon'); } | ||
@@ -108,4 +108,4 @@ var west = bbox[0]; | ||
var isOdd = x % 2 === 1; | ||
if (y === 0 && isOdd) continue; | ||
if (y === 0 && hasOffsetY) continue; | ||
if (y === 0 && isOdd) { continue; } | ||
if (y === 0 && hasOffsetY) { continue; } | ||
@@ -128,3 +128,3 @@ var center_x = x * x_interval + west - x_adjust; | ||
if (mask) { | ||
if (intersect(mask, triangle)) results.push(triangle); | ||
if (intersect(mask, triangle)) { results.push(triangle); } | ||
} else { | ||
@@ -144,3 +144,3 @@ results.push(triangle); | ||
if (mask) { | ||
if (intersect(mask, hex)) results.push(hex); | ||
if (intersect(mask, hex)) { results.push(hex); } | ||
} else { | ||
@@ -147,0 +147,0 @@ results.push(hex); |
{ | ||
"name": "@turf/hex-grid", | ||
"version": "5.0.5", | ||
"version": "5.1.0", | ||
"description": "turf hex-grid module", | ||
"main": "main", | ||
"module": "index", | ||
"jsnext:main": "index", | ||
"main": "main.js", | ||
"module": "main.mjs", | ||
"types": "index.d.ts", | ||
@@ -12,3 +11,4 @@ "files": [ | ||
"index.d.ts", | ||
"main.js" | ||
"main.js", | ||
"main.mjs" | ||
], | ||
@@ -49,7 +49,8 @@ "scripts": { | ||
"@std/esm": "*", | ||
"@turf/bbox-polygon": "*", | ||
"@turf/truncate": "*", | ||
"@turf/bbox-polygon": "^5.1.0", | ||
"@turf/truncate": "^5.1.0", | ||
"benchmark": "*", | ||
"load-json-file": "*", | ||
"rollup": "*", | ||
"rollup-plugin-buble": "*", | ||
"tape": "*", | ||
@@ -59,6 +60,6 @@ "write-json-file": "*" | ||
"dependencies": { | ||
"@turf/distance": "^5.0.4", | ||
"@turf/helpers": "^5.0.4", | ||
"@turf/intersect": "*", | ||
"@turf/invariant": "^5.0.4" | ||
"@turf/distance": "^5.1.0", | ||
"@turf/helpers": "^5.1.0", | ||
"@turf/intersect": "^5.1.0", | ||
"@turf/invariant": "^5.1.0" | ||
}, | ||
@@ -65,0 +66,0 @@ "@std/esm": { |
@@ -7,4 +7,4 @@ # @turf/hex-grid | ||
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 | ||
Takes a bounding box and the diameter of the cell and returns a [FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) of flat-topped | ||
hexagons or triangles ([Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6) features) aligned in an "odd-q" vertical grid as | ||
described in [Hexagonal Grids](http://www.redblobgames.com/grids/hexagons/). | ||
@@ -14,3 +14,3 @@ | ||
- `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 | ||
- `bbox` **[BBox](https://tools.ietf.org/html/rfc7946#section-5)** extent in [minX, minY, maxX, maxY] order | ||
- `cellSide` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** length of the side of the the hexagons or triangles, in units. It will also coincide with the | ||
@@ -21,3 +21,3 @@ radius of the circumcircle of the hexagons. | ||
- `options.properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** passed to each hexagon or triangle of the grid (optional, default `{}`) | ||
- `options.mask` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<([Polygon](http://geojson.org/geojson-spec.html#polygon) \| [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon))>?** if passed a Polygon or MultiPolygon, the grid Points will be created only inside it | ||
- `options.mask` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)<([Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6) \| [MultiPolygon](https://tools.ietf.org/html/rfc7946#section-3.1.7))>?** if passed a Polygon or MultiPolygon, the grid Points will be created only inside it | ||
- `options.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`) | ||
@@ -38,3 +38,3 @@ | ||
Returns **[FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)<[Polygon](http://geojson.org/geojson-spec.html#polygon)>** a hexagonal grid | ||
Returns **[FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3)<[Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6)>** a hexagonal grid | ||
@@ -41,0 +41,0 @@ <!-- This file is automatically generated. Please don't edit it directly: |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
27908
7
554
0
9
+ Added@turf/clean-coords@5.1.5(transitive)
+ Added@turf/intersect@5.1.6(transitive)
+ Added@turf/meta@5.2.0(transitive)
+ Added@turf/truncate@5.1.5(transitive)
+ Addedturf-jsts@1.2.3(transitive)
- Removed@turf/helpers@7.2.0(transitive)
- Removed@turf/intersect@7.2.0(transitive)
- Removed@turf/meta@7.2.0(transitive)
- Removed@types/geojson@7946.0.15(transitive)
- Removedbignumber.js@9.1.2(transitive)
- Removedpolyclip-ts@0.16.8(transitive)
- Removedsplaytree-ts@1.0.2(transitive)
- Removedtslib@2.8.1(transitive)
Updated@turf/distance@^5.1.0
Updated@turf/helpers@^5.1.0
Updated@turf/intersect@^5.1.0
Updated@turf/invariant@^5.1.0