Paper.js: TypeError on Path.unite

Created on 2 Mar 2016  路  8Comments  路  Source: paperjs/paper.js

A regression between 0.9.25 and develop head:

Head is throwing the following error on calling Path.unite:
Uncaught TypeError: Cannot read property 'y' of null (propagateWinding: hor = Math.abs(curve.getTangentAtTime(t).y))
@ computeBoolean (propagateWinding(segment, _path1, _path2, monoCurves, operator);)
@ unite (return computeBoolean(this, path, 'unite');)

Both head and previous version render the actual Path fine, only the former gives this error on unite. Unite is being called on the path itself to remove any self-intersections, and the path is quite complex.

boolean-operations bug

Most helpful comment

This completely fixed the issue. Lehni, you're the best!

All 8 comments

Please provide a test case or at least the path data that produces this error.

Sorry for not replying sooner, it's quite tricky to reproduce. The following sketch reproduces the error: http://sketch.paperjs.org/#S/ndLRTsMgFAbgVznhZl3SEEZLd4bZ1V7AxEvrBZZj1qxCw1jUNH13i07djWb1v4I/+Q4kMDBnnolpdneg2OxZzhpv0743cQ9bcPQCvekp8NupyIbawZSntut2vvNBwyKQXeSfddP5I1kNMZyoduPypna1S4O4sTa7GOVbF7PhVcNKKclVDm8a1gXytRqXSf1tUODZIFazzUYWVxqFJS83P8EPvxKq4PKiv26WFOfz/+dlVX7dXygulfiOnMexwvm8RPztlU6ujZSlZaqm//MYyBz6ZI9M3z+M7w==

Interestingly, if you supply the pathData to the Path constructor, the error does not happen. The error is only reproducible when closed: true, and you have to add the points individually.

Ok, this is actually an error in Curve#getTimeAt(), and can be reduced to this case

@iconexperience do you feel like looking at this?

Regardless of that error, the boolean code should handle the rare case where no t is found for a given length.

@tjunnone the reason why pathData doesn't work the same way is rounding in the formatting as string.

@iconexperience I have a feeling that curve.length is imprecise and too large in this case, so the offset is actually outside. Now the question is, how to handle this case?

Interesting... Curve.isStraight() is true for this curve, and that leads to the length being slightly larger. Then getTimeAt() uses Numerical.integrate() to calculate the length of the range and results in a different value and decides that the offset is outside of the range.

This completely fixed the issue. Lehni, you're the best!

Was this page helpful?
0 / 5 - 0 ratings