Skip to main content

stipple_geometry/
insets.rs

1/// Edge insets (padding/margin) in logical pixels.
2#[derive(Clone, Copy, Debug, Default, PartialEq)]
3pub struct Insets {
4    pub top: f64,
5    pub right: f64,
6    pub bottom: f64,
7    pub left: f64,
8}
9
10impl Insets {
11    pub const ZERO: Self = Self {
12        top: 0.0,
13        right: 0.0,
14        bottom: 0.0,
15        left: 0.0,
16    };
17
18    #[inline]
19    pub const fn new(top: f64, right: f64, bottom: f64, left: f64) -> Self {
20        Self {
21            top,
22            right,
23            bottom,
24            left,
25        }
26    }
27
28    /// The same inset on all four edges.
29    #[inline]
30    pub const fn uniform(v: f64) -> Self {
31        Self {
32            top: v,
33            right: v,
34            bottom: v,
35            left: v,
36        }
37    }
38
39    /// Independent horizontal (left/right) and vertical (top/bottom) insets.
40    #[inline]
41    pub const fn symmetric(horizontal: f64, vertical: f64) -> Self {
42        Self {
43            top: vertical,
44            right: horizontal,
45            bottom: vertical,
46            left: horizontal,
47        }
48    }
49
50    /// Total inset along the horizontal axis (`left + right`).
51    #[inline]
52    pub fn horizontal(self) -> f64 {
53        self.left + self.right
54    }
55
56    /// Total inset along the vertical axis (`top + bottom`).
57    #[inline]
58    pub fn vertical(self) -> f64 {
59        self.top + self.bottom
60    }
61}