Skip to main content

sightloom_core/
error.rs

1//! Non-allocating core error definitions.
2
3use core::fmt;
4
5/// An error produced by a core processing operation.
6#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7pub enum CoreError {
8    /// A numeric input is NaN or infinite.
9    NonFinite,
10    /// Caller-owned storage has no room for another value.
11    InsufficientCapacity,
12    /// A suppression threshold is non-finite or outside `0.0..=1.0`.
13    InvalidThreshold,
14    /// Caller-owned NMS scratch is shorter than the detections slice.
15    InsufficientScratch,
16    /// A media time has a zero timescale.
17    InvalidMediaTime,
18}
19
20impl fmt::Display for CoreError {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        f.write_str(match self {
23            Self::NonFinite => "non-finite numeric value",
24            Self::InsufficientCapacity => "insufficient capacity",
25            Self::InvalidThreshold => "invalid threshold",
26            Self::InsufficientScratch => "insufficient NMS scratch",
27            Self::InvalidMediaTime => "invalid media time (zero timescale)",
28        })
29    }
30}
31
32#[cfg(feature = "std")]
33impl std::error::Error for CoreError {}
34
35/// An error produced while constructing validated geometry.
36#[derive(Clone, Copy, Debug, Eq, PartialEq)]
37pub enum GeometryError {
38    /// At least one coordinate is NaN or infinite.
39    NonFinite,
40    /// A rectangle's right or bottom edge precedes its opposite edge.
41    InvertedBounds,
42    /// A line segment's endpoints are identical.
43    DegenerateSegment,
44    /// A polygon has fewer than three supplied points.
45    TooFewPoints,
46}
47
48impl fmt::Display for GeometryError {
49    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50        f.write_str(match self {
51            Self::NonFinite => "non-finite geometry coordinate",
52            Self::InvertedBounds => "inverted rectangle bounds",
53            Self::DegenerateSegment => "degenerate line segment",
54            Self::TooFewPoints => "polygon has too few points",
55        })
56    }
57}
58
59#[cfg(feature = "std")]
60impl std::error::Error for GeometryError {}