Files
Nearfield_Friends/Proximity/Models/DistanceTier.swift

50 lines
1.4 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Foundation
/// The physical range band a user is open to connecting within.
///
/// Each tier maps to a different sensing technology. The tiers are ordered so
/// higher tiers *include* lower ones (being open "in the area" also means
/// you're open "nearby" and "right here").
enum DistanceTier: Int, CaseIterable, Identifiable, Codable {
/// 09 m. Ultra-wideband (Nearby Interaction). "This exact person."
case rightHere = 1
/// 10100 m. Bluetooth Low Energy / iBeacon. "This room, this block."
case nearby = 2
/// 100 m50 mi. Server-relayed, opt-in coarse location. "This neighborhood."
case inTheArea = 3
var id: Int { rawValue }
var title: String {
switch self {
case .rightHere: return "Right Here"
case .nearby: return "Nearby"
case .inTheArea: return "In the Area"
}
}
var subtitle: String {
switch self {
case .rightHere: return "09 m · UWB"
case .nearby: return "10100 m · BLE"
case .inTheArea: return "100 m50 mi · Network"
}
}
/// The primary engine used for this tier.
var engine: ProximityEngine {
switch self {
case .rightHere: return .uwb
case .nearby: return .ble
case .inTheArea: return .beacon
}
}
/// Higher tiers include lower ones.
func includes(_ other: DistanceTier) -> Bool {
self.rawValue >= other.rawValue
}
}