mathandy / svgpathtools

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

Public API for matrix transformation? #142

Open matthijskooijman opened 3 years ago

matthijskooijman commented 3 years ago

I'm looking at applying matrix transformations to paths and path segments. I see there is a translated(), scaled() and rotated() method on various classes, but there is no such method to apply a transformation matrix. There is a svgpathtools.path.transform() function that works, but I wonder if that is considered public API, or if there should be wrapper methods just like for translation etc.?

On a related note, I see there is a svgpathtools.parser.parse_transform() function that looks useful. Is that also considered public API?

tatarize commented 3 years ago

https://github.com/meerk40t/svgelements/issues svgelements has that feature. Lets you directly use the strings like matrices.

It looks like it's somewhat in there too. Calls: https://github.com/mathandy/svgpathtools/blob/3a1fe8695dd6236af81b5477714e74a094e3b088/svgpathtools/path.py#L292 which looks about right. Though yeah, this should be built into Path much like Path("M0,0L20,20") is now a permitted value. In svgelements I let you multiply by strings of matrices. path * "scale(1.2)" is a perfectly valid and understandable command, and might even be too liberal.