Public
Edited
May 2, 2023
Importers
Insert cell
Insert cell
Insert cell
import { pointInventory as Inv } from "90d0ee0bf9ccdd9b"
Insert cell
import { canvasValues as canvVals } from "eb11a24ab32ae888"
Insert cell
setOperators = ["unite", "intersect", "subtract"]
Insert cell
function enableBoolOperationfunctions(item, f, p) {
if (item.length > 1) {
setOperators.forEach((op) => {
f.querySelector(`#${op}`).addEventListener("click", () =>
operatorFunctions(p, op)
);
});
}
}
Insert cell
function operatorFunctions(p, operator) {
//selectedHidden is an Array, after the intersection delete all selected;
//intersect two paths at index 0 and 1 will be selectedHidden[0].intersect(selectedHidden[1])
var selectedHidden = selection.hid(p);
var res = selectedHidden[0];
for (let i = 1; i < selectedHidden.length; i++) {
var tmp = res;
res = res[operator](selectedHidden[i]);
tmp.remove();
}

// Remove the selected hidden and main paths from the canvas
for (const hiddenItem of selectedHidden) {
hiddenItem.remove();
var mainItem = mainKids(p)[hiddenItem.name.replace("hidden", "main")];
mainItem.remove();
Inv.deletePath(mainItem, p, false);
}
selection.clear(p);

// Add the intersection result to the canvas and apply desired styling... only if the
// geometry after operation is not an empty set......
var success = false;
if (
(res instanceof p.Path && res.segments.length > 0) ||
(res instanceof p.CompoundPath && res.children.length > 0)
) {
res.name = `$hiddenCompoundPath${Date.now()}`;
var mainRes = createMainFromHidden(p, res, canvVals.gridScale);
selection.clear(p);
selection.push(mainKids(p)[res.name.replace("hidden", "main")]);
Inv.addPath(mainRes, p);
}
// this should be outside loop since, the recalc is disabled earier,
// in case of failure happens, all intersections should be recalc
Inv.recalcIntersections(p);
document.dispatchEvent(new CustomEvent("formChange"));
// Redraw the canvas
p.view.draw();
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more