Skip to content

Instantly share code, notes, and snippets.

@tmpvar
Last active December 13, 2015 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmpvar/4975227 to your computer and use it in GitHub Desktop.
Save tmpvar/4975227 to your computer and use it in GitHub Desktop.
var edgeNormal = require('./edgeNormal');
var Vec2 = require('vec2');
var segseg = require('segseg');
module.exports = function(poly, delta) {
var ret = [], lines = [];
for (var polyIndex = 0; polyIndex < poly.length; polyIndex++) {
var current = poly[polyIndex];
var next = (polyIndex<poly.length-1) ?
poly[polyIndex+1] :
poly[0];
var normal = edgeNormal(current, next, delta);
var length = next.subtract(current, true).length();
var rotated = normal.normalize(true).skew().multiply(length*2)
lines.push([
normal.add(current, true).add(rotated),
normal.add(next, true).subtract(rotated)
]);
}
lines.forEach(function(line, idx) {
var prev = (idx === 0) ? lines[lines.length-1] : lines[idx-1];
var i = segseg(line[0], line[1], prev[0], prev[1]);
i && i!==true && ret.push(Vec2.fromArray(i));
});
return ret;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment