Make rectangle functions pub

This commit is contained in:
expectocode 2019-12-31 01:32:02 +00:00
parent 4d73035a4e
commit 8098d2e1bc
1 changed files with 13 additions and 13 deletions

View File

@ -77,7 +77,7 @@ impl PartialEq for Point {
impl Eq for Point {} impl Eq for Point {}
impl Rectangle { impl Rectangle {
fn from_corner_width_height(top_left: Point, width: u32, height: u32) -> Rectangle { pub fn from_corner_width_height(top_left: Point, width: u32, height: u32) -> Rectangle {
Rectangle { Rectangle {
top_left, top_left,
width, width,
@ -85,7 +85,7 @@ impl Rectangle {
} }
} }
fn from_corners(corner_a: Point, corner_b: Point) -> Rectangle { pub fn from_corners(corner_a: Point, corner_b: Point) -> Rectangle {
let left = corner_a.x().min(corner_b.x()); let left = corner_a.x().min(corner_b.x());
let top = corner_a.y().min(corner_b.y()); let top = corner_a.y().min(corner_b.y());
@ -95,19 +95,19 @@ impl Rectangle {
Rectangle::from_corner_width_height(Point::new(left, top), width, height) Rectangle::from_corner_width_height(Point::new(left, top), width, height)
} }
fn at_origin_with_size(width: u32, height: u32) -> Rectangle { pub fn at_origin_with_size(width: u32, height: u32) -> Rectangle {
Rectangle::from_corner_width_height(Point::origin(), width, height) Rectangle::from_corner_width_height(Point::origin(), width, height)
} }
fn width(&self) -> u32 { pub fn width(&self) -> u32 {
self.width self.width
} }
fn height(&self) -> u32 { pub fn height(&self) -> u32 {
self.height self.height
} }
fn with_width(&self, width: u32) -> Rectangle { pub fn with_width(&self, width: u32) -> Rectangle {
Rectangle { Rectangle {
top_left: self.top_left, top_left: self.top_left,
width, width,
@ -115,7 +115,7 @@ impl Rectangle {
} }
} }
fn with_height(&self, height: u32) -> Rectangle { pub fn with_height(&self, height: u32) -> Rectangle {
Rectangle { Rectangle {
top_left: self.top_left, top_left: self.top_left,
width: self.width, width: self.width,
@ -123,30 +123,30 @@ impl Rectangle {
} }
} }
fn top_left(&self) -> Point { pub fn top_left(&self) -> Point {
self.top_left self.top_left
} }
fn top_right(&self) -> Point { pub fn top_right(&self) -> Point {
Point::new(self.top_left.x() + self.width, self.top_left.y()) Point::new(self.top_left.x() + self.width, self.top_left.y())
} }
fn bottom_right(&self) -> Point { pub fn bottom_right(&self) -> Point {
Point::new( Point::new(
self.top_left.x() + self.width, self.top_left.x() + self.width,
self.top_left.y() + self.height, self.top_left.y() + self.height,
) )
} }
fn bottom_left(&self) -> Point { pub fn bottom_left(&self) -> Point {
Point::new(self.top_left.x(), self.top_left.y() + self.height) Point::new(self.top_left.x(), self.top_left.y() + self.height)
} }
fn area(&self) -> u32 { pub fn area(&self) -> u32 {
self.width * self.height self.width * self.height
} }
fn intersects(&self, other: &Rectangle) -> bool { pub fn intersects(&self, other: &Rectangle) -> bool {
!(self.top_left().right_of(&other.top_right()) !(self.top_left().right_of(&other.top_right())
|| self.top_left().below(&other.bottom_left()) || self.top_left().below(&other.bottom_left())
|| self.top_right().left_of(&other.top_left()) || self.top_right().left_of(&other.top_left())