getboundingbox

1.0.0 • Public • Published

getboundingbox

stable

This is a utility function to calculate the bounding box of series of 2D points

var getBounds = require('getboundingbox')
 
var path = [ [-100, 12], [-52, 25], [6, 13] ]
var box = getBounds(path)

The result will be:

{ 
    maxX: 6,
    maxY: 25, 
    minX: -100, 
    minY: 12 
}

Usage

NPM

bounds(path[, out])

Computes the min and max [x, y] points for the given path. If path is an empty array, the bounds will be empty (all zero).

You can specify out to re-use an object rather than creating a new one.

This is safe to with Array.map/filter/etc, e.g.

if (paths.map(bounds).some(intersect)) {
    ...
}

License

MIT, see LICENSE.md for details.

Package Sidebar

Install

npm i getboundingbox

Weekly Downloads

52

Version

1.0.0

License

MIT

Last publish

Collaborators

  • mikkoh
  • mattdesl