Skip to main content

projective_grid/
error.rs

1//! Error types for grid tasks.
2
3use thiserror::Error;
4
5use crate::lattice::LatticeKind;
6
7/// Grid task that reported an error.
8#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
9#[non_exhaustive]
10pub enum GridTask {
11    /// Recover lattice labels from features.
12    Detection,
13    /// Check caller-supplied coordinate hypotheses.
14    Consistency,
15}
16
17/// Evidence kind supplied to a grid task.
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
19#[non_exhaustive]
20pub enum EvidenceKind {
21    /// Position-only point features.
22    Positions,
23    /// Features with one local axis.
24    Oriented1,
25    /// Features with two local axes.
26    Oriented2,
27    /// Features with three local axes.
28    Oriented3,
29    /// Caller-supplied coordinate hypotheses.
30    CoordinateHypotheses,
31}
32
33/// User-facing failure modes for projective-grid tasks.
34#[derive(Clone, Debug, Error, PartialEq, Eq)]
35#[non_exhaustive]
36pub enum GridError {
37    /// The requested task/lattice/evidence combination is intentionally not
38    /// implemented yet.
39    #[error("unsupported combination: task={task:?}, lattice={lattice:?}, evidence={evidence:?}")]
40    UnsupportedCombination {
41        /// Requested task.
42        task: GridTask,
43        /// Requested lattice family.
44        lattice: LatticeKind,
45        /// Supplied evidence kind.
46        evidence: EvidenceKind,
47    },
48    /// There is not enough evidence to run the requested task.
49    #[error("insufficient evidence")]
50    InsufficientEvidence,
51    /// Input slices disagree or contain duplicate/conflicting identifiers.
52    #[error("inconsistent input: {0}")]
53    InconsistentInput(String),
54    /// Geometry is degenerate, for example all model or image points are
55    /// collinear.
56    #[error("degenerate geometry")]
57    DegenerateGeometry,
58}
59
60/// Convenience result alias for this crate.
61pub type Result<T> = std::result::Result<T, GridError>;