Paper.js: Path.flatten() failure with some paths.

Created on 11 Jun 2017  路  4Comments  路  Source: paperjs/paper.js

Found this while iterating through objects in this source SVG, https://openclipart.org/detail/19495/woodcut-horse, svg_6 is the first one with problems.

Simplifying down to just the following is enough to reproduce via import, finding the path as a child of the group, then attempting to flatten it:

<svg width="1150.005102955977" height="835.4203737053383" xmlns="http://www.w3.org/2000/svg">
 <g>
  <path id="svg_6" d="m445.26701,223.69688c6.1738,8.7566 -7.05172,14.0468 0,0z"/>
 </g>
</svg>

The error call stack message (as of paper v0.11.4):

Uncaught TypeError: Cannot read property '_point' of undefined
    at Function.getValues (paper-full.js:6249)
    at addCurve (paper-full.js:10662)
    at new initialize (paper-full.js:10697)
    at Path.flatten (paper-full.js:8428)

I _think_ the issue is that this is a closed filled path with only one segment? A bit of a weird teardrop. No sane person would build something like this by hand, I suspect this is some strange technically valid edge-case created by a vectorizer.

bug

Most helpful comment

Here is a little sketch created from the information provided above.

All 4 comments

Pretty much confirmed my hunch, a viable workaround for closed paths with only one segment:

path.divideAt(path.length / 2);

Basically just gives it a new segment without really messing with it via subdivision.

Here is a little sketch created from the information provided above.

Oh sweet! Thank you @iconexperience. It's been so long since I've submitted an issue I forgot to whip one of these up. 馃樃

@techninja I make a PR to fix @iconexperience's test case. It would be fixed in next version which would be released soon.

Was this page helpful?
0 / 5 - 0 ratings