steveruizok / perfect-freehand

Draw perfect pressure-sensitive freehand lines.

Home Page:https://perfectfreehand.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] Backtracking creates dots on end of lines

sandorex opened this issue · comments

As i mentioned in excalidraw/excalidraw#4802 (comment)

Moving cursor in opposite direction while drawing makes these weird dots, much more common on wacom tablet for some reason

freehand playground
image

freehand playground but using the mouse
image

Also found this - screenshot from the playground:
image

Quite a small issue I think, because it's generally quite hard to reproduce+notice, but I've been using perfect-freehand in an app where the stroke bounces back a bit at the end, which reliably causes it quite a lot:
image

Potentially related to this part? https://github.com/steveruizok/perfect-freehand/blob/main/packages/perfect-freehand/src/getStrokeOutlinePoints.ts#L210-L239

Answer: I don't think so! I disabled that section of code and it's still reproducible. FUTURE EDIT: It was actually this.
image

I'll look elsewhere!

Potentially related to it "flipping over"?
image image

You can see it cross over for a frame or two:
GIF 22-08-2022 14-20-49
GIF 22-08-2022 14-24-06

Making the Handle sharp corners code run based on previous dot-product instead of next dot-product helped in some cases:

Before:
image

After:
image

Ok and if I make it check nextDpr as well as prevDpr it seems to fix all those cases:
image

Still some issues going on though.

Ok so now we get this issue:
image

What's happening?
Answer: After a stroke does a sharp corner, it keeps doing sharp corners every point. This is because it now looks for sharp corners based on the next point AND the previous point. It can end up detecting a sharp corner twice, and then keeps on flip-flopping. Maybe we could keep some state to make sure it doesn't do the same sharp corner twice...

It works!
image

And the fix still works!
image

I'm gonna clean up the code and do a pull request I think.

Awesome work!

Nice work, ill close this now