From 3bf418c6b71a819a9faa14b78167cfc9dfcac783 Mon Sep 17 00:00:00 2001 From: quarktwain <51277869+quarktwain@users.noreply.github.com> Date: Sat, 9 May 2026 09:56:16 -0400 Subject: [PATCH] Cap prediction cone to shortest predBG array length Fixes #637. The cone of uncertainty in updateOpenAPSPredictionDisplay() was capped at the longest predBG array (.max()), which let the band visibly deform at the tail as shorter arrays dropped out one by one. Cap at the shortest array length instead so every cone point is computed from the same set of contributing arrays. Matches Trio's ForecastSetup (Trio/Sources/Modules/Home/HomeStateModel+Setup/ForecastSetup.swift), which uses allForecastValues.map(\.count).min() and then iterates 0 ..< localMinCount. Renamed maxLength to coneLength since the variable no longer represents a max. --- LoopFollow/Controllers/Graphs.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/LoopFollow/Controllers/Graphs.swift b/LoopFollow/Controllers/Graphs.swift index 9789e9c46..2b6c05934 100644 --- a/LoopFollow/Controllers/Graphs.swift +++ b/LoopFollow/Controllers/Graphs.swift @@ -1991,9 +1991,11 @@ extension MainViewController { var coneData = [ConeChartDataEntry]() if !allArrays.isEmpty { - let maxLength = min(allArrays.map { $0.count }.max()!, toLoad + 1) + // Cap at the shortest predBG array length so every cone point uses + // the same set of contributing arrays. Matches Trio's ForecastSetup. + let coneLength = min(allArrays.map { $0.count }.min()!, toLoad + 1) var t = predictionStart - for i in 0 ..< maxLength { + for i in 0 ..< coneLength { var valuesAtIndex = [Double]() for arr in allArrays where i < arr.count { valuesAtIndex.append(arr[i])