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