smesh/smesh/
error.rs

1use crate::prelude::model::mesh_elements::{FaceId, HalfedgeId, VertexId};
2use std::fmt::{Display, Formatter};
3use thiserror::Error;
4
5#[derive(Error, Debug, Clone, Copy, PartialEq)]
6pub enum SMeshError {
7    /// Query errors
8    #[error("A Vertex with id `{0}` could not be found")]
9    VertexNotFound(VertexId),
10    #[error("Vertex with id `{0}` has no associated halfedge")]
11    VertexHasNoHalfEdge(VertexId),
12    #[error("Halfedge with id `{0}` could not be found")]
13    HalfedgeNotFound(HalfedgeId),
14    #[error("Halfedge with id `{0}` has no associated face")]
15    HalfedgeHasNoFace(HalfedgeId),
16    #[error("Halfedge with id `{0}` has no next halfedge")]
17    HalfedgeHasNoNext(HalfedgeId),
18    #[error("Halfedge with id `{0}` has no prev halfedge")]
19    HalfedgeHasNoPrev(HalfedgeId),
20    #[error("Halfedge with id `{0}` has no opposite halfedge")]
21    HalfedgeHasNoOpposite(HalfedgeId),
22    #[error("A Face with id `{0}` could not be found")]
23    FaceNotFound(FaceId),
24    #[error("Face with id `{0}` has no associated halfedge")]
25    FaceHasNoHalfEdge(FaceId),
26    /// Topology
27    #[error("Invalid mesh topology for this operation")]
28    TopologyError,
29    /// Other
30    #[error("Unsupported Operation")]
31    UnsupportedOperation,
32    #[error("Default SMesh Error")]
33    DefaultError,
34    #[error("Error: `{0}`")]
35    CustomError(&'static str),
36}
37
38pub type SMeshResult<T> = Result<T, SMeshError>;
39
40#[macro_export]
41macro_rules! bail {
42    ($error:ident) => {
43        return Err(SMeshError::$error)
44    };
45    ($error:ident, $value:expr) => {
46        return Err(SMeshError::$error($value))
47    };
48    ($value:expr) => {
49        return Err(SMeshError::CustomError($value))
50    };
51}
52
53impl Display for VertexId {
54    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
55        write!(f, "{:?}", self)
56    }
57}
58impl Display for HalfedgeId {
59    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
60        write!(f, "{:?}", self)
61    }
62}
63impl Display for FaceId {
64    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
65        write!(f, "{:?}", self)
66    }
67}