Files
grungnet/src/helpers/actions.js
2021-03-12 11:03:54 +11:00

45 lines
1.0 KiB
JavaScript

import shortid from "shortid";
export function addPolygonDifferenceToShapes(shape, difference, shapes) {
for (let i = 0; i < difference.length; i++) {
let newId = shortid.generate();
// Holes detected
let holes = [];
if (difference[i].length > 1) {
for (let j = 1; j < difference[i].length; j++) {
holes.push(difference[i][j].map(([x, y]) => ({ x, y })));
}
}
const points = difference[i][0].map(([x, y]) => ({ x, y }));
shapes[newId] = {
...shape,
id: newId,
data: {
points,
holes,
},
};
}
}
export function addPolygonIntersectionToShapes(shape, intersection, shapes) {
for (let i = 0; i < intersection.length; i++) {
let newId = shortid.generate();
const points = intersection[i][0].map(([x, y]) => ({ x, y }));
shapes[newId] = {
...shape,
id: newId,
data: {
points,
holes: [],
},
// Default intersection visibility to false
visible: false,
};
}
}