Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when calling offsetStroke on Path object #7

Open
hlridge opened this issue Apr 20, 2020 · 1 comment
Open

TypeError when calling offsetStroke on Path object #7

hlridge opened this issue Apr 20, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@hlridge
Copy link

hlridge commented Apr 20, 2020

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;
}
@glenzli glenzli added the bug Something isn't working label Apr 26, 2020
@glenzli
Copy link
Owner

glenzli commented Apr 26, 2020

update to 1.0.8, problem should be solved. @hl222ih

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants