quadtree/
error.rs

1use std::fmt;
2
3#[derive(Debug, Clone, Copy, PartialEq)]
4pub enum QuadtreeError {
5    InvalidRectangleDims {
6        width: f32,
7        height: f32,
8    },
9    InvalidCircleRadius {
10        radius: f32,
11    },
12    InvalidRectExtent {
13        min_x: f32,
14        min_y: f32,
15        max_x: f32,
16        max_y: f32,
17    },
18    RectExtentOutOfBounds {
19        min_x: f32,
20        min_y: f32,
21        max_x: f32,
22        max_y: f32,
23        bounds_min_x: f32,
24        bounds_min_y: f32,
25        bounds_max_x: f32,
26        bounds_max_y: f32,
27    },
28}
29
30pub type QuadtreeResult<T> = Result<T, QuadtreeError>;
31
32impl fmt::Display for QuadtreeError {
33    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34        match self {
35            QuadtreeError::InvalidRectangleDims { width, height } => {
36                write!(
37                    f,
38                    "rectangle width/height must be finite and non-negative (width: {}, height: {})",
39                    width, height
40                )
41            }
42            QuadtreeError::InvalidCircleRadius { radius } => {
43                write!(
44                    f,
45                    "circle radius must be finite and non-negative (radius: {})",
46                    radius
47                )
48            }
49            QuadtreeError::InvalidRectExtent {
50                min_x,
51                min_y,
52                max_x,
53                max_y,
54            } => {
55                write!(
56                    f,
57                    "rectangle extents must be finite with min <= max (min_x: {}, min_y: {}, max_x: {}, max_y: {})",
58                    min_x, min_y, max_x, max_y
59                )
60            }
61            QuadtreeError::RectExtentOutOfBounds {
62                min_x,
63                min_y,
64                max_x,
65                max_y,
66                bounds_min_x,
67                bounds_min_y,
68                bounds_max_x,
69                bounds_max_y,
70            } => {
71                write!(
72                    f,
73                    "rectangle extents must be within quadtree bounds (min_x: {}, min_y: {}, max_x: {}, max_y: {}, bounds_min_x: {}, bounds_min_y: {}, bounds_max_x: {}, bounds_max_y: {})",
74                    min_x,
75                    min_y,
76                    max_x,
77                    max_y,
78                    bounds_min_x,
79                    bounds_min_y,
80                    bounds_max_x,
81                    bounds_max_y
82                )
83            }
84        }
85    }
86}
87
88impl std::error::Error for QuadtreeError {}