Suggestion: Skip duplicate points
donpark opened this issue · 5 comments
getStroke()
returns array withNaN
values If first two points are same (mousedown+mousemove) which apparently happens frequently (1 out of 5). I don't know if it's just at the beginning of a stroke or at any two consecutive points in the stroke.
While I've already worked around the problem by ignoring new point if it's same as previous, I thought you may want to add the logic internally to avoid future issues as it can result in misleading behaviors.
BTW, thanks for sharing this wonderful library. It's great.
Thanks Don! We'd noticed some failures on Excalidraw but I hadn't had a chance to look into it yet. This looks like it could be the cause.
Added this in the most recent version. Seems to be working well. :)
Hi @steveruizok. Thanks for this beautiful lib...
I have a question. I got to this issue after seeing a similar symptom to the one reported here... Just to clarify. Should something like this work?
getStroke([ [0, 0, 0] ] );
I see it returning the following with 0.4.91:
[
[ null, null
],
[ null, null
],
[ null, null
],
[ null, null
],
[ null, null
],
[ null, null
],
[ null, null
],
[ null, null
],
[ null, null
],
[ null, null
],
[ null, null
]
]
Showing in the console as
The same goes for getStroke([ [0, 0, 0],[0, 0, 0] ] );
or getStroke([ [0, 0, 0],[0, 0, 0] ],[0, 0, 0] ] );
Hey, yes that should work (or at least, it should fail correctly). I'll add a test and fix it if it's failing.
Separately, but maybe still relevant here, it might be better to handle such data in a different way. For example, in most of the projects that use freehand, I handle short lines (lines with 0-2 points) with a dot rather than calling to freehand.
Ah I see. Thanks for the tip!