mathandy / svgpathtools

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

Distinguishing separated shapes within a single path #166

Closed jaggzh closed 2 years ago

jaggzh commented 2 years ago

If a path has some disconnected objects, which I believe is handled with the M (move) command in SVG, how do we detect this from within svgpathtools commands?

I'm currently using something like the following code, which ends up drawing a line between those two disconnected shapes:

lx=ly=None # Last x,y
paths, attributes = svg2paths(file)
for pathi,path in enumerate(paths):
  for parti,part in enumerate(path):
      for i in np.arange(0, 1, .32):
        pt = part.point(i)
        x,y = pt.real, pt.imag
        if lx is not None:
          line(lx, ly,  x, y)
        lx=x; ly=y
jaggzh commented 2 years ago

Okay, I figured it out. I was mistakenly connecting all path parts myself.