Turn SVG path into line segments

后端 未结 2 1317
天命终不由人
天命终不由人 2020-12-18 15:36

I am trying to turn a SVG path into a list of points in Node. I\'m using elementtree to parse the SVG file.

d is the definition for the path, getPos simply turns a \

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-18 16:24

    I'm not familiar with coffeescript, but there seem to be a few problems with your code.

    • Most importantly, it seems that your i += 1 only happens if word == 'm or 'M', so I would have thought you get stuck in a loop most of the time.

    • Second, you don't seem to do anything if word == 'l' or 'L' and I would have though that is when you would want to add a node. If you don't have curves, then surely you have lines, unless you're just using horizontal or vertical lines. You will also need to update your current position and do so differently depending on whether it is a relative or absolute command.

    • Finally, you probably shouldn't split with a space as d="M90,20L100,30L110,20z" is a valid path. You say you know there will be no curves in your path, so maybe you also know that all your paths will be split with spaces. In which case, that's fair enough, but it might be worth bearing in mind.

    Hope that's of some help.

提交回复
热议问题