mathandy / svgpathtools

A collection of tools for manipulating and analyzing SVG Path objects and Bezier curves.
MIT License
557 stars 142 forks source link

pull request for correction of issue #125 and add of split_extremum_y function to Arc, CubicBezier and QuadraticBezier #132

Closed piscvau closed 3 years ago

piscvau commented 4 years ago

Test file for split_extremum_y is included

tatarize commented 3 years ago

Also, I'm curious why this is needed. Is the desire here to rationalize the bezier curves? If that's needed why not make a path function called rationalize bezier curves? You can then solve for any inflection point within the bezier curve and break the curve at those points replacing the curves in the path in place. It would work a bit like #130 but rather than replacing arcs we'd be replacing irrational beziers with series of of rational ones. So, for example, the bounding box of all the bezier curves would be the extrema of the start and end points.

piscvau commented 3 years ago

The need is for a knitting application where curves must be splitted in their extremum y to be knitted.

tatarize commented 3 years ago

Hm. You could just convert those arcs to bezier curves using #130. Then it would but also you can calculate the extrema arc bit with the same code used to calculate the bbox there too. At least in theory. Though it would really be the pretty easy to split those too. So if you converted everything to a bunch of rational bezier curves would that suffice? Like nothing has a position either right or left or above or below the end points and And any inflections occur at the nodes?

piscvau commented 3 years ago

why would this be any better than using the functions proposed in the pull request which are pretty straight forward?

tatarize commented 3 years ago

Scipy is as a requirement tends to make things depend on more and more things. Anybody who uses svgpathtools would now also require scipy.

Prerequisites numpy svgwrite

This is the set of actual requirements declared in the readme. For example quad is used elsewhere but isn't a requirement since it falls back to other methods when and if that requirement isn't met. It would be somewhat acceptable to make a soft requirement so folks with scipy installed would get this functionality and those without would get some other functionality. However, here those aren't very hard functions to write. You solve for the extremas and split there. I'm pretty sure the math without scipy would be really quick anyway, and you'd tend to need fallback code, or maybe to throw NotImplementedError if they the soft requirement.

piscvau commented 3 years ago

I clearly do not have the math expertise required to implement this other functionality you are talking about. Neither do I have the time, also considering that for my application needs, the full implementation of Arc intersection is a requirement not yet fulllfilled by the package. I propose to move the import of scipy within the split_extremum_function and in case the package is not installed to raise an exception. This I can easily do!...... Let us wait for the opinion of the owner of the repository.

tatarize commented 3 years ago

If you ran the code to convert the arcs to bezier curves you'd actually be able to calculate the intersections and thus solve that needed data.