mathandy / svgpathtools

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

Reading in dpaths introduces a lot of floating point approximation noise #223

Open ohnorobo opened 2 weeks ago

ohnorobo commented 2 weeks ago

Example

import svgpathtools
d = "M70.63,10.42c0.11,0.33-0.89,2.09-1.54,2.45c-4.95,2.73-17.52,7.24-39.46,11.04"  # path from KanjiVG
p = svgpathtools.parse_path(d)
# some kind of simple path modification not yet implemented
print(p.d())

outputs

M 70.63,10.42 C 70.74,10.75 69.74,12.51 69.08999999999999,12.870000000000001 C 64.13999999999999,15.600000000000001 51.56999999999999,20.11 29.62999999999999,23.91

I understand the performance gain from using floats, and I don't mind a bit of jitter, but I would like to keep my svg files somewhat clean if possible, also it really increases the text size.

Is it possible to allow something like rounding to n decimal places in .d()? (I would be happy to take a crack at implementing this.) Or maybe there's another good way to solve this I haven't understood?