nudged
nudged copied to clipboard
Avoid precision errors in TSR
I'm using the TSR estimator for multitouch gestures that can be arbitrary number of points (something like estimate('tsr', touchesBefore.map(clientPosition), touchesAfter.map(clientPosition))
). When doing this with some single-touch point sets, I found that the resulting transform had a === b === 0
– confusing because a single pointer pan should always be a valid translation, no?
I looked into it – it looks like the specific points I was providing were causing a precision error when calculating det
. Here's a test that fails on current master
: https://github.com/davidisaaclee/nudged/blob/2594af5c79660ef805f8892b20c135151faf03e7/test/estimators/TSR.test.js#L100-L111
Some other valid solutions:
- I could round my inputs to more reasonable precisions
- I could switch to
T
estimator when I know I have one point
But I'd prefer not to think about that stuff! so here's a PR that fixes this by just switching the order of det
expression so that the terms that probably will cancel each other out are next to each other. I don't fully get why it works, but it makes the test pass.
Thanks for the great library, I use it in almost every web app I make.