python - Fast way to sample geometric points from SVG paths -
i'm using excellent svgpathtools
library in python 3 work paths in svg file, created in vector drawing application.
i'd create detailed point arrays each of paths contained within svg, points equidistant along path. following that, becomes unbearably slow if more few thousand samples taken.
samples_per_px = 1 fname = "/path/to/file.svg" paths, attributes = svg2paths(fname) mypaths = {} path,attr in zip(paths, attributes): mypathlist = [] pathlength = path.length() pathcolour = attr['stroke'] numsamples = int(pathlength * samples_per_px) in range(numsamples): #parametric length = ilength(geometric length) mypathlist.append(path.point(path.ilength(pathlength * / (numsamples-1)))) mypaths[pathcolour] = np.array(mypathlist)
i've felt python ain't real pythonic. there way can take advantage of pythoness speed up?
wiki
Comments
Post a Comment