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

Making Boolean Operations Faster #2077

Open
photopea opened this issue May 10, 2024 · 6 comments
Open

Making Boolean Operations Faster #2077

photopea opened this issue May 10, 2024 · 6 comments

Comments

@photopea
Copy link

Hi, my name is Ivan. I am the creator a popular photo editor www.photopea.com, used by 1 million people every day.

I use Paper.js in Photopea to allow my users to do boolean operations on vector shapes (cubic bezier curves). However, it tends to be very slow wor complex shapes. It might take 20 seconds up to several minutes to process it.

Is there any way to make it faster? In your interface, you need to create many objects using constructors, these objects have properties and methods, etc. You even have to specify a color, which seems to be totally unrelated to a purely geometric problem.

Could it be slow because of your geometry representation / overhead? Is there any library in Javascript (or maybe even C++, I could compile it to WASM), that you could recommend me instead of paper.js? Or could you make it faster by removing some bottlenecks in Paper.js?

@northamerican
Copy link

@photopea nice project. i use clipper wasm for faster boolean operations. i've made a package that interfaces paper with clipper here: https://github.com/northamerican/paper-clipper maybe it is worth tinkering with.

@photopea
Copy link
Author

@northamerican wow, that sounds great! Can it handle cubic bézier curves, or just polygons?

@northamerican
Copy link

northamerican commented Jul 20, 2024

@northamerican wow, that sounds great! Can it handle cubic bézier curves, or just polygons?

clipper doesn't support bezier curves as far as i know. the primary and maybe only practical use for my tool may be for offsetting (growing/shrinking) bezier curves because it's already a lossy operation. what it does is it flattens the curve, offsets, then re-integrates it using a custom simplifying algorithm. it's practical for my use but might not cut it as it will distort bezier curves. probably even if you flatten with fine precision, then 'simplify' the shape again.

@r-flash
Copy link

r-flash commented Jul 28, 2024

Hello Ivan, I just published a low-level TypeScript library with the sole purpose (at least for now 🙂) of performing boolean operations on SVG paths. It's available here. It's still in development and in desperate need of testing. It would be a tremendous help for me if you could try implementing it in Photopea and gave me feedback on potential problems or missing features.

@photopea
Copy link
Author

@r-flash Hi Adam, that looks amazing! Could you provide me Javascript file with a function inside it? I never worked with Typescript or NPM so I dont know what native programs should I download and install, and learn how to use, to be able to use your library.

@r-flash
Copy link

r-flash commented Jul 30, 2024

I've added the built files here. You probably want to use the UMD version which you can just <script src=... into your project to have the global PathBool variable available.

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

No branches or pull requests

3 participants