#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FrameField {
Resolution,
Stream,
}
impl FrameField {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Resolution => "resolution",
Self::Stream => "stream",
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum ComposeError {
FrameMismatch {
field: FrameField,
expected: String,
got: String,
},
CameraMoved {
landmark: String,
offset_px: f64,
},
DriftUnverified,
OutlineOffFrame,
Undecodable {
detail: String,
},
Encode {
detail: String,
},
}
impl core::fmt::Display for ComposeError {
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::FrameMismatch {
field,
expected,
got,
} => write!(
formatter,
"the frame's {} is {got}, and the calibration's is {expected}",
field.as_str()
),
Self::CameraMoved {
landmark,
offset_px,
} => write!(
formatter,
"the camera has moved since it was calibrated: {landmark} is {offset_px:.1} px from where it was"
),
Self::DriftUnverified => formatter.write_str(
"fewer than two of the calibration's landmarks are visible, so whether the camera has moved is unknown",
),
Self::OutlineOffFrame => {
formatter.write_str("nothing of the planned geometry lands in the frame")
}
Self::Undecodable { detail } => write!(formatter, "the frame is not a JPEG: {detail}"),
Self::Encode { detail } => write!(formatter, "the check image: {detail}"),
}
}
}
impl std::error::Error for ComposeError {}