From a4fcd872bd694f77897fd6cc91cd9068f11d0acd Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Fri, 25 Sep 2020 13:25:11 -0700 Subject: Use log LUT rather than binary search for last mouse move point --- grapher/Models/Calculations/AccelChartData.cs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'grapher/Models/Calculations/AccelChartData.cs') diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs index 54685a2..98d501b 100644 --- a/grapher/Models/Calculations/AccelChartData.cs +++ b/grapher/Models/Calculations/AccelChartData.cs @@ -13,8 +13,8 @@ namespace grapher.Models.Calculations AccelPoints = new SortedDictionary(); VelocityPoints = new SortedDictionary(); GainPoints = new SortedDictionary(); - OrderedVelocityPointsList = new List(); OutVelocityToPoints = new Dictionary(); + LogToIndex = new int[601]; } #endregion Constructors @@ -35,7 +35,7 @@ namespace grapher.Models.Calculations public SortedDictionary GainPoints { get; } - public List OrderedVelocityPointsList { get; } + public int[] LogToIndex { get; } public Dictionary OutVelocityToPoints { get; } @@ -48,8 +48,8 @@ namespace grapher.Models.Calculations AccelPoints.Clear(); VelocityPoints.Clear(); GainPoints.Clear(); - OrderedVelocityPointsList.Clear(); OutVelocityToPoints.Clear(); + Array.Clear(LogToIndex, 0, LogToIndex.Length); } public (double, double, double) FindPointValuesFromOut(double outVelocityValue) @@ -80,15 +80,21 @@ namespace grapher.Models.Calculations public int GetVelocityIndex(double outVelocityValue) { - var velIdx = OrderedVelocityPointsList.BinarySearch(outVelocityValue); - - if (velIdx < 0) + var log = Math.Log10(outVelocityValue); + if (log < -2) + { + log = -2; + } + else if (log > 4) + { + log = 4; + } + else { - velIdx = ~velIdx; + log = log * 100 + 200; } - velIdx = Math.Min(velIdx, VelocityPoints.Count - 1); - velIdx = Math.Max(velIdx, 0); + var velIdx = LogToIndex[(int)log]; return velIdx; } -- cgit v1.2.3 From 206cdc1712d02d15b85393a57ca744fbc014a55c Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Fri, 25 Sep 2020 23:03:00 -0700 Subject: SetActive changes field default, bugs fixed --- grapher/Models/Calculations/AccelChartData.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'grapher/Models/Calculations/AccelChartData.cs') diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs index 98d501b..60d4c89 100644 --- a/grapher/Models/Calculations/AccelChartData.cs +++ b/grapher/Models/Calculations/AccelChartData.cs @@ -14,7 +14,7 @@ namespace grapher.Models.Calculations VelocityPoints = new SortedDictionary(); GainPoints = new SortedDictionary(); OutVelocityToPoints = new Dictionary(); - LogToIndex = new int[601]; + LogToIndex = new int[701]; } #endregion Constructors @@ -85,15 +85,13 @@ namespace grapher.Models.Calculations { log = -2; } - else if (log > 4) + else if (log > 5) { - log = 4; - } - else - { - log = log * 100 + 200; + log = 5; } + log = log * 100 + 200; + var velIdx = LogToIndex[(int)log]; return velIdx; -- cgit v1.2.3