import Foundation /// Geometry for a single appended sample, including the outgoing point at full capacity. nonisolated enum TrendScroll { static func isAppend(from old: [Double?], to new: [Double?]) -> Bool { guard !old.isEmpty, !new.isEmpty else { return false } if old.count < MetricHistory.capacity { return new.count == old.count + 1 && Array(new.dropLast()) == old } return new.count == old.count && Array(old.dropFirst()) == Array(new.dropLast()) } static func position(index: Int, count: Int, progress: CGFloat, scrolling: Bool) -> CGFloat { let offset = MetricHistory.capacity - count let shift = scrolling ? 1 - min(1, max(0, progress)) : 0 return (CGFloat(index + offset) + shift) / CGFloat(MetricHistory.capacity - 1) } }