glenzli/paperjs-offset

TypeError when calling offsetStroke on Path object

Opened this issue · 1 comments

Thanks for your effort with this package and making it available.

Unfortunately I can't get offsetStroke to work. I'd like to create a fiddle, but I can't find a CDN to load the script from.

This refers to v1.0.5. in Node.js environment. I also wanted to try it with v.1.0.7., but the version isn't bumped at yarn yet, so I don't know how.

This is my code (loaded with node -r esm index.js):

import paper from 'paper-jsdom-canvas';
paper.setup(new paper.Size(63, 21));
//also tried to paper.setup _after_ ExtendPaperJs(paper) - same result...
import ExtendPaperJs from 'paperjs-offset';
ExtendPaperJs(paper);
const oldPath = new paper.Path({pathData: "M4,11L5,13"});
//also tried new paper.Path("M4,11L5,13"); - same result...
const offset = 10;
const options = {cap: "round", join: "round"};
const newPath = oldPath.offsetStroke(offset, options);

Am I missing something?

This is the error trace:

(node:13708) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'slice' of undefined
at ConnectBeziers ([...]\node_modules\paperjs-offset\dist\index.umd.js:140:38)
at OffsetSimpleShape ([...]\node_modules\paperjs-offset\dist\index.umd.js:236:47)
at Object.OffsetSimpleStroke ([...]\node_modules\paperjs-offset\dist\index.umd.js:276:32)
at OffsetStroke ([...]\node_modules\paperjs-offset\dist\index.umd.js:341:28)
at PrototypedOffsetStroke ([...]\node_modules\paperjs-offset\dist\index.umd.js:370:24)
at Path.ExtendPaperJs.paper.Path.offsetStroke ([...]\node_modules\paperjs-offset\dist\index.umd.js:384:18)

It's the third line in this function:

 function ConnectBeziers(rawSegments, join, source, offset, limit) {
    var originSegments = source.segments;
    var first = rawSegments[0].slice();
    for (var i = 0; i < rawSegments.length - 1; ++i) {
        ConnectAdjacentBezier(rawSegments[i], rawSegments[i + 1], originSegments[i + 1], join, offset, limit);
    }
    if (source.closed) {
        ConnectAdjacentBezier(rawSegments[rawSegments.length - 1], first, originSegments[0], join, offset, limit);
        rawSegments[0][0] = first[0];
    }
    return rawSegments;
}

update to 1.0.8, problem should be solved. @hl222ih