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

Path structure #1

Open
photopea opened this issue Aug 24, 2024 · 5 comments
Open

Path structure #1

photopea opened this issue Aug 24, 2024 · 5 comments

Comments

@photopea
Copy link

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
Copy link
Owner

r-flash commented Aug 24, 2024

  • The "array of segments" representation works best for the needs of the algorithm, where I need to be able to work with individual segments in isolation. I can, however, add conversion functions from and to the format you are using in Typr, similarly to the conversion functions for the "array of commands" representation. Would that be helpful?
  • Let me see if I can make an alternative build without the parser. I don't want to drop it entirely because the automated tests are using it.
  • Yes, lines and arcs are supported. Lines make certain computations faster and arcs can only be approximated with cubic beziers. Also, once you have all the math routines neccesary for doing the conversion, you are already halfway there to implementing full support.

@r-flash
Copy link
Owner

r-flash commented Aug 24, 2024

Added the "core" builds here.

@photopea
Copy link
Author

photopea commented Aug 25, 2024

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
Copy link
Author

photopea commented Aug 25, 2024

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
Copy link
Owner

r-flash commented Aug 27, 2024

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 🙂.

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

2 participants