Clarify Best Value route confidence
This commit is contained in:
@@ -1343,6 +1343,29 @@ struct FuelStore {
|
||||
roadDistanceEntry(for: station, userLat: userLat, userLng: userLng) != nil
|
||||
}
|
||||
|
||||
/// True only for current-format route cache entries with a separately
|
||||
/// measured return route. Legacy one-way entries are still usable for journey
|
||||
/// arithmetic (`outward × 2`) but Best Value must describe them as estimated.
|
||||
static func hasMeasuredReturnRoadDistance(for station: FuelStation, userLat: Double, userLng: Double) -> Bool {
|
||||
roadDistanceEntry(for: station, userLat: userLat, userLng: userLng)?.returnMeters != nil
|
||||
}
|
||||
|
||||
static func roadDistanceDiagnostics(for station: FuelStation, userLat: Double, userLng: Double) -> RoadDistanceDiagnostics {
|
||||
let displayKM = displayDistanceKM(station: station, userLat: userLat, userLng: userLng)
|
||||
let entry = roadDistanceEntry(for: station, userLat: userLat, userLng: userLng)
|
||||
let outward = entry?.meters
|
||||
let returnMeters = entry?.returnMeters
|
||||
return RoadDistanceDiagnostics(
|
||||
displayDistanceKM: displayKM,
|
||||
displaySource: outward == nil ? .straightLine : .roadRoute,
|
||||
outwardMeters: outward,
|
||||
returnMeters: returnMeters,
|
||||
totalJourneyMeters: outward.map { $0 + (returnMeters ?? $0) },
|
||||
hasMeasuredReturn: returnMeters != nil,
|
||||
hasValidCacheEntry: entry != nil
|
||||
)
|
||||
}
|
||||
|
||||
private static func roadDistanceEntry(for station: FuelStation, userLat: Double, userLng: Double) -> CachedRoadDistance? {
|
||||
guard let cache = loadRoadDistances(),
|
||||
let entry = cache.entries[station.id] else { return nil }
|
||||
@@ -1432,6 +1455,18 @@ struct FuelStore {
|
||||
}
|
||||
}
|
||||
|
||||
/// Lightweight description of the distance value shown for a station and any
|
||||
/// usable road-route cache behind it. No user coordinates are included.
|
||||
struct RoadDistanceDiagnostics: Equatable {
|
||||
let displayDistanceKM: Double
|
||||
let displaySource: FuelSavingsDistanceBasis
|
||||
let outwardMeters: Double?
|
||||
let returnMeters: Double?
|
||||
let totalJourneyMeters: Double?
|
||||
let hasMeasuredReturn: Bool
|
||||
let hasValidCacheEntry: Bool
|
||||
}
|
||||
|
||||
/// Cached Apple-Maps road distances for nearby stations (see
|
||||
/// A single cached road distance plus the station pin it was routed to. Keeping
|
||||
/// the pin lets `roadDistanceMeters` refuse to serve a route computed for a
|
||||
|
||||
Reference in New Issue
Block a user