diff --git a/rectangle.go b/rectangle.go index 9cdbd89..6fc2a7b 100644 --- a/rectangle.go +++ b/rectangle.go @@ -16,6 +16,11 @@ func Rect(x0, y0, x1, y1 int) Rectangle { return Rectangle{Point{x0, y0}, Point{x1, y1}} } +// RectRel is a shorthand function to create a rectangle specifying its width and height instead of a second coordinate. +func RectRel(x, y, w, h int) Rectangle { + return Rectangle{Point{x, y}, Point{x + w, y + h}} +} + // Add translates rectangle r by point p. func (r Rectangle) Add(p Point) Rectangle { return Rectangle{ diff --git a/rectanglef.go b/rectanglef.go index 41b2248..b33d4b0 100644 --- a/rectanglef.go +++ b/rectanglef.go @@ -17,6 +17,11 @@ func RectF(x0, y0, x1, y1 float64) RectangleF { return RectangleF{PtF(x0, y0), PtF(x1, y1)} } +// RectRelF is a shorthand function to create a rectangle specifying its width and height instead of a second coordinate. +func RectRelF(x, y, w, h float64) RectangleF { + return RectangleF{PointF{x, y}, PointF{x + w, y + h}} +} + // Add translates rectangle r by point p. func (r RectangleF) Add(p PointF) RectangleF { return RectangleF{ diff --git a/rectanglef32.go b/rectanglef32.go index fab729a..e482fd7 100644 --- a/rectanglef32.go +++ b/rectanglef32.go @@ -17,6 +17,11 @@ func RectF32(x0, y0, x1, y1 float32) RectangleF32 { return RectangleF32{PtF32(x0, y0), PtF32(x1, y1)} } +// RectRelF32 is a shorthand function to create a rectangle specifying its width and height instead of a second coordinate. +func RectRelF32(x, y, w, h float32) RectangleF32 { + return RectangleF32{PointF32{x, y}, PointF32{x + w, y + h}} +} + // Add translates rectangle r by point p. func (r RectangleF32) Add(p PointF32) RectangleF32 { return RectangleF32{