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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions Source/Charts/Charts/PieRadarChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -677,13 +677,25 @@ open class PieRadarChartViewBase: ChartViewBase
}()

// Remove samples older than our sample time - 1 seconds
// while keeping at least one samples
let index = velocitySamples
.dropLast()
.lastIndex { $0.time < currentSample.time - 1 }
if let index = index {
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 :-)

while (i < count - 2)
{
if currentSample.time - velocitySamples[i].time > 1.0
{
velocitySamples.remove(at: 0)
i -= 1
count -= 1
}
else
{
break
}

i += 1
}

velocitySamples.append(currentSample)
}

Expand Down