r-flash / PathBool.js

A low-level library for performing boolean operations on SVG paths.
https://r-flash.github.io/PathBool.js/
MIT License
27 stars 1 forks source link

Path structure #1

Open photopea opened 2 months ago

photopea commented 2 months ago

Your path representation seems a bit too complicated. Could you maybe switch to something like this: https://github.com/photopea/Typr.js?tab=readme-ov-file#typrushapetopathfont-shape . It has two arrays: array of strings and array of numbers, while you have an array for each coordinate.

BTW. it seems like your library contains an SVG path parser. Your library could be smaller without it, I already have it on my side.

Does your library relly work with Lines and Arcs? I would expect that you convert everything to cubic bézier splines to simplify your algorithms.

r-flash commented 2 months ago
r-flash commented 2 months ago

Added the "core" builds here.

photopea commented 2 months ago

Thanks a lot! I already started to use your library at www.photopea.com !

As you know a lot about bézier curves and you have quad trees for acceleration, could you implement hitTesting?

hitTest(paths: array, pX:Number, pY:Number, tolerance:Number)

It would find a point on a path that is closest to [pX,pY]. You can return the index of a path segment, where it is located, a location T:[0..1] of that point on that segment, and the actual absolute coordinate of that point.

It can also test whether a point is inside or outside a path, but I think it can be done already by intersecting a path with a tiny square. But if you can add it easily, it would be nice, too.

photopea commented 2 months ago

If you think hitTest() does not fit this library, I will jsut turn my curves into a polygon with 1 pixel edges and will find the closest vertex, I think it should work fine for my case.

r-flash commented 2 months ago

I think it's not entirely out of the scope of this project. Let me see if I can implement it during the next weekend :slightly_smiling_face:.