0.1.0 • Published 7 years ago

square-sample-grid v0.1.0

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

squareGrid

creates a square grid from an arbitrary polygon. the grid can cover, or be inclusive of, the polygon.

based on @turf/square-grid but for use with arbitrary polygons in the viewport coordinate system, not just bounding boxes in the Cartesian coordinate system. For a square grid useful for geo applications, go to Turf.

Parameters

  • polygonArray<number> array of vertices in [[x, y],...]

  • cellSize number width of each cell

-coordSystem string either canvas or cartesian depending on whether the polygon is in viewport coordinate system coordinate space (e.g. top-left is 0,0) (e.g. for use with canvas or SVGs), or cartesian space (e.g. standard x,y graph stuff) (optional, default cartesian).

  • noClip [boolean] if true, does not remove sample grid units to fit completely within given polygon (optional, default false)

note on coordSystem:

cartesianviewport/canvas

usage

npm install square-sample-grid

usage

var grid = require('square-sample-grid');

var polygon = [ [20, 20],[60, 20],[80, 40],[10, 40] ];
var cellSize = 20;
var coordSystem = 'canvas';
var noClip = false;

var sampleGrid = grid(polygon, cellSize, coordSystem, noClip);
//  [
//     [[60, 40],[60, 20],[40, 20],[40, 40]],
//     [[40, 40],[40, 20],[20, 20],[20, 40]]
//   ]

To Do:

  • tests for internal functions
    • makeBbox
    • [] distance
    • [] calculateIntersections
  • performance improvements for complex polygons
  • make build/browserify step for client-side
0.1.0

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago