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

Restored correct velocity sampler #4273

Merged
merged 1 commit into from
Jan 26, 2020
Merged

Restored correct velocity sampler #4273

merged 1 commit into from
Jan 26, 2020

Conversation

danielgindi
Copy link
Collaborator

Issue Link 🔗

#3883

Goals ⚽

The sampling algorithm was butchered, so much that old samples do not get dropped (only one of them gets dropped).
The issue is presented when dragging the chart for more than a second, and the releasing. The velocity is incorrect.

Implementation Details 🚧

Restored older algorithm.

@danielgindi
Copy link
Collaborator Author

@jjatie Unless you did something there that I'm missing?

velocitySamples.remove(at: index)
// while keeping at least one sample

var i = 0, count = velocitySamples.count
Copy link
Collaborator

@jjatie jjatie Jan 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what I was doing above.

let index = velocitySamples.firstIndex { currentSample.time - velocitySamples[i].time > 1.0 }
    ?? velocitySamples.reversed.firstIndex
velocitySamples = velocitySamples.suffix(from: index)

Should achieve the same thing without writing a custom algorithm

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do you want to add another commit over this PR? Then we will merge it (please test the code first to see that all irrelevant samples are being dropped)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjatie I'm merging this, please add a PR for a Swiftier version when you have the time :-)

@danielgindi danielgindi merged commit 6ab4b03 into master Jan 26, 2020
@danielgindi danielgindi deleted the bugfix/velocity branch January 26, 2020 11:51
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.

2 participants