Using a polygon area calculation, it's incredibly simple to determine if a buffer of x,y mouse coords is technically, mathematically moving clockwise, or counterclockwise:
let dir = Math.sign(coords.reduce((prev, coord, i) => prev +
(coords[i+1].x - coord.x) *
(coords[i+1].y + coord.y),0
))
But that simple code will always return either clockwise or counterclockwise, which isn't practically what ought to be the correct result.
Rapid up-and-down, or left-and-right motions, or very approximately straight lines, may technically be moving clockwise, but aren't moving clockwise in the common understanding of clockwise - there isn't an option for "NEITHER".
Is there a way to adjust that calculation to quickly determine if the 'clockwise-ness' is beyond a certain threshold?
Well, what you can do is
|y| > EpswhereEpsis the threshold that you consider to discriminate rotating movement or straight linesTo do so, you can for example have a look here https://dracoblue.net/dev/linear-least-squares-in-javascript/ and you will see that at some point there are
m(angle) andb(intercept)