1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! Typed error enum for `vision-calibration-linear`.
use vision_calibration_core::Error as CoreError;
/// Errors returned by public APIs in `vision-calibration-linear`.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
/// Input data is invalid (e.g. mismatched lengths, wrong point count).
#[error("invalid input: {reason}")]
InvalidInput { reason: String },
/// Not enough data to proceed (e.g. fewer correspondences than required).
#[error("insufficient data: need {need}, got {got}")]
InsufficientData { need: usize, got: usize },
/// A matrix inversion or decomposition produced a degenerate result.
#[error("singular matrix or degenerate configuration")]
Singular,
/// A numerical operation failed unexpectedly.
#[error("numerical failure: {0}")]
Numerical(String),
/// Forwarded error from `vision-calibration-core`.
#[error(transparent)]
Core(#[from] CoreError),
}
impl Error {
/// Convenience constructor for [`Error::InvalidInput`].
pub(crate) fn invalid_input(reason: impl Into<String>) -> Self {
Self::InvalidInput {
reason: reason.into(),
}
}
/// Convenience constructor for [`Error::Numerical`].
pub(crate) fn numerical(msg: impl Into<String>) -> Self {
Self::Numerical(msg.into())
}
}