mathandy / svgpathtools

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

Approximation Problem #27

Open sensor56 opened 7 years ago

sensor56 commented 7 years ago

Hi,

A Path object contain for example :

CubicBezier(start=(27.080179592571874+157.03434674518752j), control1=(27.61140677353281+155.774203506625j), control2=(28.261543320386714+154.57737991657814j), end=(29.016691803786323+153.45777340439065j)), CubicBezier(start=(29.016691803786323+153.45777340439065j), control1=(29.771840287185935+152.33816689220313j), control2=(30.632000707131247+151.295777457875j), end=(31.583275634274997+150.34450253075j)), CubicBezier(start=(31.583275634274997+150.34450253075j), control1=(32.53455056141875+149.393227603625j), control2=(33.57693999576094+148.53306718370314j), end=(34.696546507954295+147.77791870032814j)), CubicBezier(start=(34.696546507954295+147.77791870032814j), control1=(35.81615302014765+147.02277021695315j), control2=(37.01297661019218+146.37263367012503j), end=(38.27311984874062+145.8414064891875j)), CubicBezier(start=(38.27311984874062+145.8414064891875j), control1=(39.53326308728906+145.31017930824999j), control2=(40.8567259743414+144.89786149320312j), end=(42.229611080550384+144.61835047339065j)), CubicBezier(start=(42.229611080550384+144.61835047339065j), control1=(43.60249618675937+144.33883945357815j), control2=(45.024803512125+144.192135229j), end=(46.4826356273+144.192135229j)))]

I want to reuse the start and end point from each object to build Line object with : spt.Line(elem.point(0), elem.point(1))

where elem is an element in Path source

I obtain :

Line(start=(27.080179592571874+157.03434674518752j), end=(29.01669180378633+153.45777340439054j)), Line(start=(29.016691803786323+153.45777340439065j), end=(31.58327563427502+150.34450253075013j)), Line(start=(31.583275634274997+150.34450253075j), end=(34.69654650795428+147.77791870032806j)), Line(start=(34.696546507954295+147.77791870032814j), end=(38.27311984874062+145.84140648918756j)), Line(start=(38.27311984874062+145.8414064891875j), end=(42.2296110805504+144.61835047339065j)), Line(start=(42.229611080550384+144.61835047339065j), end=(46.48263562729995+144.1921352290001j)))]

As you can see, there is a little difference : 29.016691803786323+153.45777340439065j give 29.01669180378633+153.45777340439054j 31.58327563427502+150.34450253075013j give 31.583275634274997+150.34450253075j 46.4826356273+144.192135229j give 46.48263562729995+144.1921352290001j

Only end point seem have this problem.

Logically, Path() obtained is not continuous, etc.

Is it possible to give a tolerance for continuous or limit precision to 6 or 8 decimal for example ?

Thanks in advance for your suggest.

sensor56 commented 7 years ago

My workaround at this time : if the source Path is continous, I use for each Line only start points : new_line=spt.Line(path[index].point(0), path[index+1].point(0))

And if the source Path is closed, the last Line is : spt.Line(pathIn[-1].point(0), pathIn[0].point(0))

Simple and it seems to work : new path is continuous anc closed.