Skip to main content

bunny_codec/obj/
error.rs

1use std::fmt;
2
3/// Error returned when an OBJ mesh cannot be parsed as the Bunny text profile.
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum ObjError {
6    /// The OBJ source contains no vertex records.
7    MissingVertices,
8    /// The OBJ source contains no face records.
9    MissingFaces,
10    /// A numeric vertex coordinate could not be parsed.
11    InvalidVertex,
12    /// A vertex coordinate is NaN or infinity.
13    NonFiniteVertex,
14    /// A face is not a triangle.
15    NonTriangularFace,
16    /// A face index is zero, negative, relative, or not a valid integer.
17    InvalidIndex,
18    /// An accessor index or face vertex reference is outside the parsed range.
19    IndexOutOfBounds,
20    /// The OBJ statement is not part of the supported Bunny mesh profile.
21    UnsupportedStatement,
22}
23
24impl fmt::Display for ObjError {
25    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26        let message = match self {
27            Self::MissingVertices => "OBJ source contains no vertex records",
28            Self::MissingFaces => "OBJ source contains no face records",
29            Self::InvalidVertex => "OBJ vertex coordinate is invalid",
30            Self::NonFiniteVertex => "OBJ vertex coordinate is not finite",
31            Self::NonTriangularFace => "OBJ face is not triangular",
32            Self::InvalidIndex => "OBJ face index is invalid",
33            Self::IndexOutOfBounds => "OBJ index is out of bounds",
34            Self::UnsupportedStatement => "OBJ statement is unsupported",
35        };
36        f.write_str(message)
37    }
38}
39
40impl std::error::Error for ObjError {}