1.0.8 • Published 12 months ago

@reload-kurt/grid-snap v1.0.8

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

Grid Snap


License: MIT Node.js CI

Grid snap is a zero-dependency library that allows you to pass through a point (or array of points) along with a grid-spacing metric which will return a similarly dimensioned variable of the points snapped to the spacing sent through.

Installation


To install, simply include the JS file (dist/snap.min.js) or using NPM:

npm i --save grid-snap

Usage


To snap a unidimensional number to a grid spacing of 5 units:

let snap = require('grid-snap'); // for nodejs, for browser window.snap is avaiable (as just snap(...))

let pointA = snap(1.4, 5) // returns 0
let pointB = snap(2.6, 5) // returns 5

For multidimensional arrays, pass either an array or an object to the method

let snap = require('grid-snap');

// as an array (// returns [64,0])
let pointA = snap([50, 24], [64,64])

// as an object (returns {x: 16, y:0})
let pointB = snap({x: 14.5, y: 2.5}, {x: 16, y: 16})

License

MIT

1.0.8

12 months ago

1.0.7

2 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago