Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid precision errors in TSR #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

davidisaaclee
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant