Refactor rectangle to use Point instead of x and y

master
expectocode 2019-12-31 00:23:21 +00:00
parent 12a50af544
commit 08def2bb42
1 changed files with 7 additions and 13 deletions

View File

@ -8,8 +8,7 @@ pub struct Point {
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct Rectangle { pub struct Rectangle {
x: u32, top_left: Point,
y: u32,
width: u32, width: u32,
height: u32, height: u32,
} }
@ -77,10 +76,9 @@ impl PartialEq for Point {
impl Eq for Point {} impl Eq for Point {}
impl Rectangle { impl Rectangle {
fn from_corner_width_height(corner: Point, width: u32, height: u32) -> Rectangle { fn from_corner_width_height(top_left: Point, width: u32, height: u32) -> Rectangle {
Rectangle { Rectangle {
x: corner.x(), top_left,
y: corner.y(),
width, width,
height, height,
} }
@ -94,8 +92,7 @@ impl Rectangle {
let height = (corner_a.y() as i64 - corner_b.y() as i64).abs() as u32; let height = (corner_a.y() as i64 - corner_b.y() as i64).abs() as u32;
Rectangle { Rectangle {
x: left, top_left: Point::new(left, top),
y: top,
width, width,
height, height,
} }
@ -103,8 +100,7 @@ impl Rectangle {
fn at_origin_with_size(width: u32, height: u32) -> Rectangle { fn at_origin_with_size(width: u32, height: u32) -> Rectangle {
Rectangle { Rectangle {
x: 0, top_left: Point::origin(),
y: 0,
width, width,
height, height,
} }
@ -120,8 +116,7 @@ impl Rectangle {
fn with_width(&self, width: u32) -> Rectangle { fn with_width(&self, width: u32) -> Rectangle {
Rectangle { Rectangle {
x: self.x, top_left: self.top_left,
y: self.y,
width, width,
height: self.height, height: self.height,
} }
@ -129,8 +124,7 @@ impl Rectangle {
fn with_height(&self, height: u32) -> Rectangle { fn with_height(&self, height: u32) -> Rectangle {
Rectangle { Rectangle {
x: self.x, top_left: self.top_left,
y: self.y,
width: self.width, width: self.width,
height, height,
} }