use core::fmt;
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MeshValidationError {
IncompleteTriangle { index_count: usize },
PositionIndexOutOfRange { index: u32, position_count: usize },
NormalCount { expected: usize, actual: usize },
NormalIndexCount { expected: usize, actual: usize },
NormalIndexOutOfRange { index: u32, normal_count: usize },
AttributeCount {
name: String,
expected: usize,
actual: usize,
},
AttributeZeroWidth {
name: String,
},
AttributeDuplicateName {
name: String,
},
}
impl fmt::Display for MeshValidationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::IncompleteTriangle { index_count } => {
write!(f, "index count {index_count} is not divisible by three")
}
Self::PositionIndexOutOfRange {
index,
position_count,
} => write!(
f,
"position index {index} exceeds {position_count} positions"
),
Self::NormalCount { expected, actual } => {
write!(f, "expected {expected} normals, found {actual}")
}
Self::NormalIndexCount { expected, actual } => {
write!(f, "expected {expected} normal indices, found {actual}")
}
Self::NormalIndexOutOfRange {
index,
normal_count,
} => write!(f, "normal index {index} exceeds {normal_count} normals"),
Self::AttributeCount {
name,
expected,
actual,
} => write!(
f,
"attribute channel {name} covers {actual} vertices, mesh has {expected}"
),
Self::AttributeZeroWidth { name } => {
write!(f, "attribute channel {name} declares a zero tuple width")
}
Self::AttributeDuplicateName { name } => {
write!(f, "attribute channel name {name} is used more than once")
}
}
}
}
impl std::error::Error for MeshValidationError {}