#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OperatingRegime {
SeaLevelStatic,
Climb,
Cruise,
Descent,
TakeOff,
MultiCondition {
regime_id: u8,
},
Unknown,
}
impl OperatingRegime {
#[must_use]
pub fn from_cmapss_settings(op1: f64, op2: f64, op3: f64) -> Self {
if op1.abs() < 1.0 && op2.abs() < 0.05 && (op3 - 100.0).abs() < 5.0 {
return Self::SeaLevelStatic;
}
const CENTROIDS: [(f64, f64, f64); 6] = [
(0.0, 0.00, 100.0),
(10.0, 0.25, 100.0),
(20.0, 0.70, 100.0),
(25.0, 0.62, 60.0),
(35.0, 0.84, 100.0),
(42.0, 0.84, 100.0),
];
let mut best_id = 0u8;
let mut best_dist = f64::MAX;
let mut i = 0;
while i < 6 {
let (ca, cm, ct) = CENTROIDS[i];
let d = (op1 - ca) * (op1 - ca) + (op2 - cm) * 1000.0 * (op2 - cm) * 1000.0 + (op3 - ct) * (op3 - ct);
if d < best_dist {
best_dist = d;
best_id = i as u8;
}
i += 1;
}
Self::MultiCondition { regime_id: best_id }
}
#[must_use]
pub const fn label(self) -> &'static str {
match self {
Self::SeaLevelStatic => "Sea Level Static",
Self::Climb => "Climb",
Self::Cruise => "Cruise",
Self::Descent => "Descent",
Self::TakeOff => "Take-Off",
Self::MultiCondition { .. } => "Multi-Condition",
Self::Unknown => "Unknown",
}
}
}