-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Added mathods for finding/setting the bounding box of a path #17
Conversation
I don't like suggested API change. It becomes not consistent. |
Could you be more precise ? |
I'd add |
My first version was like your |
Suggested methods goes too far from original concept - (short names + chaining + non trivial ops). Also i'm not sure that formatting to viewbox should be part of this lib. |
If you don't want to have |
I don't like to put the precision in . |
I'd like to avoid specific data formats. Let's keep it aside if simple data is not enougth for your needs.
I don't reject possibility of API change. But it's better to discuss those first. |
Yes this is how it should be IMO. But now round() is applied to the path, not saved. And this is a big change. For me the methods like |
Create a separate issue with examples of all new methods you wish (without implementation details) |
Would you be happy with this two methods :
|
I don't like idea of attached methods. Also, output probably could be [ x1, y1, x2, y2 ] - don't know what is better.
That looks very specific. Not sure someone else need it. Also, implementation is a simple math, and that will not add a lot of value. |
You can do every transform with |
There are different approach to API design. I prefer micromodules/minimalistic. If i start to add everything, API will become a mess like
|
I agree with you. You can close this pull request I think. |
Sad to see this PR be closed as this was just the functionality I was looking for. I needed to get the dimensions of a given path in order to calculate the correct transform scale so it would fit my given width and height restrictions. |
I explained the reasons above. This PR suggested more than just simple bbox calc, and it's signature become a bit "strange" in context of this project. If you wish to do PR with something like Or check dependents of this project in npm registry, there are bbox calculation somewhere. |
Sweet, exactly what i was looking for as i also needed it in browser and less strict parsing :p!
|
Ah, yes. I can also recommend to take a look at @kpym's fork https://github.com/kpym/SVGPathy. He helped a lot to improve math about arcs and he really know what he does. |
Are there any plans to merge this? |
As is - no. |
In SVG specification bounding box is defined as |
|
@ktzanev as far as i remember, you created fork because had no time (or no wish) to rewrite your code for alternate signaure. What do you think now? Potentially, i would be interested to add
|
@puzrin I forked this library because at the time my requests were very specific and didn't fit very well with your needs, I think. The code of my fork has diverged from the original over time, but if you can/wish to use some of my code, you are welcome to do so of course. I'm sorry, but I didn't quite understand your questions... May be because I have to dive in my own code to remember what I've done ;) |
In PR you returned I'd prefer |
svgpath(__your_path__).toViewBoxString(d)
return a string encoding the minimal box containing the path : "min max width height" (with precision d).The default precision is 2.
svgpath('__your_path__').toBox('0 0 100 100 slice xMinYMax')
put the path in a box controlled by parameters similar topreserveAspectRatio
.There is also a method
svgpath('__your_path__')getBoundingBox()
that return a Box object and that is used by the previous two methods.