sdf-polygon-2d

2.0.0 • Public • Published

sdf-polygon-2d

sample the signed distance field of a polygon in 2d space

install

npm install sdf-polygon-2d

use

var createSDF = require('sdf-polygon-2d');
var points = [
  [-10, -10],
  [-10,  10],
  [ 10,  10],
  [ 10, -10]
];

// pass an array of polygons, including polygons with holes
var sample = createSDF([points]);
console.log(sample(0, 0)) // -10
console.log(sample({ x: 10, y: 0 })) // 0
console.log(sample([20, 0])) // 10

more examples in test.js

license

MIT

Package Sidebar

Install

npm i sdf-polygon-2d

Weekly Downloads

70

Version

2.0.0

License

MIT

Last publish

Collaborators

  • tmpvar