Skip to main content

hypergraph_rs/geometry/
error.rs

1//! The errors of the geometry module.
2
3/// What can go wrong in a geometry function.
4///
5/// In functions that take slices, `item` is the index written as `#<index>`; in functions that read a hypergraph it
6/// is the node or edge id.
7#[derive(Debug, Clone, PartialEq, thiserror::Error)]
8#[non_exhaustive]
9pub enum GeometryError {
10    /// A weight is negative or not finite.
11    #[error("weight {value} of {item} is negative or not finite")]
12    BadWeight {
13        /// The item the weight belongs to.
14        item: String,
15        /// The weight.
16        value: f64,
17    },
18    /// A position has a coordinate that is not finite.
19    #[error("position of {item} is not finite")]
20    NonFinitePosition {
21        /// The item the position belongs to.
22        item: String,
23    },
24    /// A parameter is out of its range.
25    #[error("parameter {name} = {value} is out of range")]
26    BadParameter {
27        /// The parameter's name.
28        name: &'static str,
29        /// The value given.
30        value: f64,
31    },
32    /// A row has the wrong count of numbers.
33    #[error("{item} has {found} numbers, expected {expected}")]
34    CountMismatch {
35        /// The item whose row is wrong.
36        item: String,
37        /// The count expected.
38        expected: usize,
39        /// The count found.
40        found: usize,
41    },
42    /// A hyperedge is not in the hypergraph.
43    #[error("edge {0} is not in the hypergraph")]
44    UnknownEdge(String),
45    /// A member has a positive weight but no position.
46    #[error("member {node} of edge {edge} has a weight but no position")]
47    NoPosition {
48        /// The edge.
49        edge: String,
50        /// The member without a position.
51        node: String,
52    },
53    /// A grid would hold more nodes than the limit allows.
54    #[error("a grid of {nodes} nodes exceeds the limit of {limit}")]
55    GridTooLarge {
56        /// The count of grid nodes asked for.
57        nodes: usize,
58        /// The limit.
59        limit: usize,
60    },
61}