steveruizok / perfect-freehand

Draw perfect pressure-sensitive freehand lines.

Home Page:https://perfectfreehand.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getStroke cannot handle a single input point if there's no tapering or it's the last point

glenn-allen opened this issue · comments

Firstly, thanks for the amazing library Steve!

I've noticed an issue with the latest release where a single point will result in a stroke of NaNs if either the taper is 0 or the last parameter is false. E.g:

const stroke = getStroke([ [1, 1, 0] ], {
        size: 1,
        thinning: 0.6,
        smoothing: 0.5,
        streamline: 0.5,
        start: {
            taper: 0,
        },
        end: {
            taper: 0,
        },
        simulatePressure: true,
        last: false,
});
// [ [ NaN, NaN ], [ NaN, NaN ],  [ NaN, NaN ], [ NaN, NaN ],  [ NaN, NaN ], [ NaN, NaN ],  [ NaN, NaN ], [ NaN, NaN ],  [ NaN, NaN ], [ NaN, NaN ],  [ NaN, NaN ]]

This means that single clicks don't create a stroke.
I've tested this in the example app and while it works in your hosted version it doesn't seem to work locally, so I assume the hosted version is on a previous library version?

As far as I can gather it's due to the following line - I guess it's trying to take a unit vector of a point with 0 length, but I'm not really sure what the fix should be:

vec.per(vec.uni(vec.vec(lastPoint.point, firstPoint.point))),

Hey, looked at this today. Should be fixed on 0.4.10!

Working perfectly, thanks Steve!