From 5d5e60a5cc647b3227f78e1f3a3b31b2c27a3cc7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 28 Apr 2020 04:39:59 +0200 Subject: Implement `Rectangle::new` --- core/src/rectangle.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'core/src') diff --git a/core/src/rectangle.rs b/core/src/rectangle.rs index db8ebfc8..b9d0d5d2 100644 --- a/core/src/rectangle.rs +++ b/core/src/rectangle.rs @@ -17,6 +17,21 @@ pub struct Rectangle { } impl Rectangle { + /// Creates a new [`Rectangle`] with its top-left corner in the given + /// [`Point`] and with the provided [`Size`]. + /// + /// [`Rectangle`]: struct.Rectangle.html + /// [`Point`]: struct.Point.html + /// [`Size`]: struct.Size.html + pub fn new(top_left: Point, size: Size) -> Self { + Self { + x: top_left.x, + y: top_left.y, + width: size.width, + height: size.height, + } + } + /// Returns the [`Point`] at the center of the [`Rectangle`]. /// /// [`Point`]: struct.Point.html -- cgit