hui_shared/rect/
corners.rs

1/// Represents 4 corners of a rectangular shape.
2#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
3pub struct Corners<T> {
4  pub top_left: T,
5  pub top_right: T,
6  pub bottom_left: T,
7  pub bottom_right: T,
8}
9
10impl<T: Clone> Corners<T> {
11  #[inline]
12  pub fn all(value: T) -> Self {
13    Self {
14      top_left: value.clone(),
15      top_right: value.clone(),
16      bottom_left: value.clone(),
17      bottom_right: value,
18    }
19  }
20
21  #[inline]
22  pub fn top_bottom(top: T, bottom: T) -> Self {
23    Self {
24      top_left: top.clone(),
25      top_right: top,
26      bottom_left: bottom.clone(),
27      bottom_right: bottom,
28    }
29  }
30
31  #[inline]
32  pub fn left_right(left: T, right: T) -> Self {
33    Self {
34      top_left: left.clone(),
35      top_right: right.clone(),
36      bottom_left: left,
37      bottom_right: right,
38    }
39  }
40}
41
42impl <T: Ord + Clone> Corners<T> {
43  pub fn max(&self) -> T {
44    self.top_left.clone()
45      .max(self.top_right.clone())
46      .max(self.bottom_left.clone())
47      .max(self.bottom_right.clone())
48      .clone()
49  }
50}
51
52impl Corners<f32> {
53  pub fn max_f32(&self) -> f32 {
54    self.top_left
55      .max(self.top_right)
56      .max(self.bottom_left)
57      .max(self.bottom_right)
58  }
59}
60
61impl Corners<f64> {
62  pub fn max_f64(&self) -> f64 {
63    self.top_left
64      .max(self.top_right)
65      .max(self.bottom_left)
66      .max(self.bottom_right)
67  }
68}
69
70impl<T: Clone> From<T> for Corners<T> {
71  fn from(value: T) -> Self {
72    Self::all(value)
73  }
74}
75
76impl<T> From<(T, T, T, T)> for Corners<T> {
77  fn from((top_left, top_right, bottom_left, bottom_right): (T, T, T, T)) -> Self {
78    Self {
79      top_left,
80      top_right,
81      bottom_left,
82      bottom_right,
83    }
84  }
85}