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))