From 9a9b04c2ec8bbdbd14d1de3036c3b72411b917d8 Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Thu, 23 Jan 2020 12:52:16 +0200 Subject: [PATCH] Restored correct velocity sampler Fixes https://github.com/danielgindi/Charts/pull/3883 --- .../Charts/Charts/PieRadarChartViewBase.swift | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Source/Charts/Charts/PieRadarChartViewBase.swift b/Source/Charts/Charts/PieRadarChartViewBase.swift index 61ea101d67..86edcd84ba 100644 --- a/Source/Charts/Charts/PieRadarChartViewBase.swift +++ b/Source/Charts/Charts/PieRadarChartViewBase.swift @@ -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 + 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) }