rect_lib/
basic_rectangle.rs1use crate::Rectangle;
2
3#[derive(Clone, Copy, Debug, PartialEq)]
6pub struct BasicRectangle {
7 x: i32,
8 y: i32,
9 width: i32,
10 height: i32,
11}
12
13impl Rectangle for BasicRectangle {
14 type Unit = i32;
15
16 fn left(&self) -> i32 {
17 self.x
18 }
19
20 fn right(&self) -> i32 {
21 self.x + self.width - 1
22 }
23
24 fn top(&self) -> i32 {
25 self.y
26 }
27
28 fn bottom(&self) -> i32 {
29 self.y - self.height + 1
30 }
31
32 fn new_from_sides(left: i32, right: i32, top: i32, bottom: i32) -> Self {
33 Self {
34 x: left,
35 y: top,
36 width: right - left + 1,
37 height: top - bottom + 1,
38 }
39 }
40}