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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use super::Vector2;

/// Defines the coordinates of the corners of a rectangle.
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Rect {
    /// The top of the rectangle.
    pub top: u16,
    /// The bottom of the rectangle.
    pub bottom: u16,
    /// The left of the rectangle.
    pub left: u16,
    /// The right of the rectangle.
    pub right: u16,
}

impl Rect {
    /**
    Creates a new Rect.
    */
    pub fn new(top: u16, left: u16, right: u16, bottom: u16) -> Rect {
        Rect {
            top,
            bottom,
            left,
            right,
        }
    }

    /**
    Returns a Vector representing the bottom-left corner of the rectangle.

    # Examples
    ```
    # extern crate winconsole;
    # use winconsole::console::{Rect, Vector2};
    # fn main() {
    let rect = Rect::new(0, 10, 20, 30);
    let bottom_left = rect.bottom_left();
    assert_eq!(bottom_left, Vector2::new(10, 30))
    # }
    ```
    */
    pub fn bottom_left(self) -> Vector2<u16> {
        Vector2::new(self.left, self.bottom)
    }
    /**
    Returns a Vector representing the bottom-right corner of the rectangle.

    # Examples
    ```
    # extern crate winconsole;
    # use winconsole::console::{Rect, Vector2};
    # fn main() {
    let rect = Rect::new(0, 10, 20, 30);
    let bottom_right = rect.bottom_right();
    assert_eq!(bottom_right, Vector2::new(20, 30))
    # }
    ```
    */
    pub fn bottom_right(self) -> Vector2<u16> {
        Vector2::new(self.right, self.bottom)
    }
    /**
    Returns a Vector representing the top-left corner of the rectangle.

    # Examples
    ```
    # extern crate winconsole;
    # use winconsole::console::{Rect, Vector2};
    # fn main() {
    let rect = Rect::new(0, 10, 20, 30);
    let top_left = rect.top_left();
    assert_eq!(top_left, Vector2::new(10, 0));
    # }
    ```
    */
    pub fn top_left(self) -> Vector2<u16> {
        Vector2::new(self.left, self.top)
    }
    /**
    Returns a Vector representing the top-right corner of the rectangle.

    # Examples
    ```
    # extern crate winconsole;
    # use winconsole::console::{Rect, Vector2};
    # fn main() {
    let rect = Rect::new(0, 10, 20, 30);
    let top_right = rect.top_right();
    assert_eq!(top_right, Vector2::new(20, 0));
    # }
    ```
    */
    pub fn top_right(self) -> Vector2<u16> {
        Vector2::new(self.right, self.top)
    }
}