1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! Represents a margin around an axis-aligned rectangle.

use crate::vector2f::Vector2f;

/// Represents a margin around an axis-aligned rectangle.
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde_derive", derive(Serialize, Deserialize))]
#[repr(C)]
pub struct Thicknessf {
    /// Left x component
    pub left: f32,
    /// Top y component
    pub top: f32,
    /// Right x component
    pub right: f32,
    /// Bottom y component
    pub bottom: f32,
}

impl Thicknessf {
    /// Constructs the thickness from components.
    #[inline]
    pub fn new(left: f32, top: f32, right: f32, bottom: f32) -> Thicknessf {
        Thicknessf {
            left,
            top,
            right,
            bottom,
        }
    }
}

impl From<Vector2f> for Thicknessf {
    #[inline]
    fn from(vec: Vector2f) -> Thicknessf {
        (vec.x, vec.y).into()
    }
}

impl From<f32> for Thicknessf {
    #[inline]
    fn from(f: f32) -> Thicknessf {
        (f, f, f, f).into()
    }
}

impl From<(f32, f32)> for Thicknessf {
    #[inline]
    fn from((x, y): (f32, f32)) -> Thicknessf {
        (x, y, x, y).into()
    }
}

impl From<(f32, f32, f32, f32)> for Thicknessf {
    #[inline]
    fn from(values: (f32, f32, f32, f32)) -> Thicknessf {
        let (left, top, right, bottom) = values;
        Thicknessf {
            left,
            top,
            right,
            bottom,
        }
    }
}