Doodle3D-Slicer/src/getFillTemplate.js

32 lines
764 B
JavaScript
Raw Normal View History

2016-04-21 22:14:22 +02:00
import Shape from 'Doodle3D/clipper-js';
export default function getFillTemplate(bounds, size, even, uneven) {
2016-04-22 19:37:34 +02:00
const paths = [];
2016-04-22 19:37:34 +02:00
const left = Math.floor(bounds.left / size) * size;
const right = Math.ceil(bounds.right / size) * size;
const top = Math.floor(bounds.top / size) * size;
const bottom = Math.ceil(bounds.bottom / size) * size;
2016-04-22 19:37:34 +02:00
const width = right - left;
if (even) {
2016-04-22 19:37:34 +02:00
for (let y = top; y <= bottom + width; y += size) {
paths.push([
{ x: left, y },
{ x: right, y: y - width }
]);
}
}
if (uneven) {
2016-04-22 19:37:34 +02:00
for (let y = top - width; y <= bottom; y += size) {
paths.push([
{ x: left, y },
{ x: right, y: y + width }
]);
}
}
2016-04-22 19:37:34 +02:00
return new Shape(paths, false, true);
}