From 7c1282df478a3b71d3f53561ef5a0de354fd6d1e Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Thu, 7 Jun 2018 19:28:58 +0200 Subject: [PATCH] Implemt Rect::from_size and From for Rect. --- src/rect.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/rect.rs b/src/rect.rs index 3fb6756..812816a 100644 --- a/src/rect.rs +++ b/src/rect.rs @@ -103,6 +103,19 @@ impl TypedRect { } } +impl TypedRect +where + T: Copy + Zero +{ + /// Creates a rect of the given size, at offset zero. + pub fn from_size(size: TypedSize2D) -> Self { + TypedRect { + origin: TypedPoint2D::zero(), + size, + } + } +} + impl TypedRect where T: Copy + Clone + Zero + PartialOrd + PartialEq + Add + Sub, @@ -550,6 +563,14 @@ impl TypedRect { } } +impl From> for TypedRect +where T: Copy + Zero +{ + fn from(size: TypedSize2D) -> Self { + Self::from_size(size) + } +} + /// Shorthand for `TypedRect::new(TypedPoint2D::new(x, y), TypedSize2D::new(w, h))`. pub fn rect(x: T, y: T, w: T, h: T) -> TypedRect { TypedRect::new(TypedPoint2D::new(x, y), TypedSize2D::new(w, h))