I'm using the excellent svgpathtools
library in Python 3 to work with some paths in an SVG file, created in a vector drawing application.
I'd like to create detailed point arrays for each of the paths contained within the SVG, where the points are equidistant along the path. The following does just that but becomes unbearably slow if more than a few thousand samples are taken.
SAMPLES_PER_PX = 1
fname = "/path/to/file.svg"
paths, attributes = svg2paths(fname)
myPaths = {}
for path,attr in zip(paths, attributes):
myPathList = []
pathLength = path.length()
pathColour = attr['stroke']
numSamples = int(pathLength * SAMPLES_PER_PX)
for i in range(numSamples):
#parametric length = ilength(geometric length)
myPathList.append(path.point(path.ilength(pathLength * i / (numSamples-1))))
myPaths[pathColour] = np.array(myPathList)
I've always felt that my Python ain't very Pythonic. Is there a way I can take advantage of some Python-ness to speed this up?