Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean operations #1341

Merged
merged 10 commits into from
Sep 24, 2023
Merged

Boolean operations #1341

merged 10 commits into from
Sep 24, 2023

Conversation

GColoy
Copy link
Contributor

@GColoy GColoy commented Sep 19, 2023

Hello,
This is what the title says, an ea script to make boolean operations on shapes.
image

But it is still kind of janky right now. But I've got some problems/questions that I want to ask.

So first of all: I tried using the package polybooljs, but when building I got an error with the colormaster package (see error message below, maybe you have an Idea why it didn't work?). I implemented bolybooljs in the pullrequest how I think it would be done, but couldn't test if it works.
So to still be able to write and test the script, I simply copied the single build file from bolybool into the script. So the script actually works in the current version of excalidraw, but it's kind of bodged together right now.
But if the polybool would be implemented in the excalidraw automate api I can change it, so it uses the api properly.

image

Then I wanted to ask if it's okay that I assign a custom property to some of the object that my script makes. I added the isShadowCloneOf property, which marks any shadow clone and stores the ID of the element it is the shadow clone of. I need a shadow clone in the script in case you want to cut a hole into another element, and being able to quickly filter out shadow clones and find out which object they belong to is super useful.

Lastly I was wondering, if you have an Idea how the curve of curvy lines is calculated or maybe if there is some function in the excalidraw api that could be ported to Excalidraw automate, that would help with that. Because right now, curvy lines would be handled like regular lines with sharp edges.

@GColoy
Copy link
Contributor Author

GColoy commented Sep 20, 2023

Okay, after finding README-BUILD.md I solved the issue with building the project.
So the remaining question is if it's okay, that I use a custom property.

I will soon add an Icon and the index entries, and it should be ready.

@GColoy GColoy marked this pull request as ready for review September 22, 2023 23:11
@GColoy
Copy link
Contributor Author

GColoy commented Sep 22, 2023

I think the script should be ready now.
I added the version requirement for 1.9.20, in the hope that this will be included in the next version.
The script also doesn't use a custom property anymore. It instead uses the fact, that it's possible to write any data into the groupIds.

@zsviczian zsviczian merged commit 2eab136 into zsviczian:master Sep 24, 2023
2 checks passed
@zsviczian
Copy link
Owner

I updated the script with a check for supported types and limited the selection to those only.

if(!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.9.20")) {
  new Notice("This script requires a newer version of Excalidraw. Please install the latest version.");
  return;
}
const ShadowGroupMarker = "ShadowCloneOf-";

const elements = ea.getViewSelectedElements().filter(el=>["ellipse", "rectangle", "diamond"].indludes(el.type) || element.groupIds.some(id => id.startsWith(ShadowGroupMarker)));
if(elements.length === 0) {
  new Notice ("Select ellipses, rectangles or diamonds");
  return;
}

const PolyBool = ea.getPolyBool();
const polyboolAction = await utils.suggester(["union (a + b)", "intersect (a && b)", "diffrence (a - b)", "reversed diffrence (b - a)", "xor"], [
  PolyBool.union, PolyBool.intersect, PolyBool.difference, PolyBool.differenceRev, PolyBool.xor
], "What would you like todo with the object");

const shadowClones = elements.filter(element => element.groupIds.some(id => id.startsWith(ShadowGroupMarker)));

@GColoy
Copy link
Contributor Author

GColoy commented Sep 24, 2023

@zsviczian Thank you for merging!
But the script actually works with sharp lines and arrows as well, only with rounded edges they don't work.

@zsviczian
Copy link
Owner

In that case, I will modify the filter to include sharp lines and arrows as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants