From cac351f290dff8d4c2b517327c74676ccd2e33cb Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Wed, 1 Nov 2017 11:24:33 +0100 Subject: [PATCH] Added methods to calculate width & height for RectangleF. --- rectanglef.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rectanglef.go b/rectanglef.go index c5c24ba..734194e 100644 --- a/rectanglef.go +++ b/rectanglef.go @@ -16,7 +16,17 @@ func RectF(x0, y0, x1, y1 float64) RectangleF { return RectangleF{PtF(x0, y0), PtF(x1, y1)} } +// Dx returns the width of r. +func (r RectangleF) Dx() float64 { + return r.Max.X - r.Min.X +} + +// Dy returns the height of r. +func (r RectangleF) Dy() float64 { + return r.Max.Y - r.Min.Y +} + // Size returns the size of the rectangle. func (r RectangleF) Size() PointF { - return PtF(r.Max.X-r.Min.X, r.Max.Y-r.Min.Y) + return PointF{r.Max.X - r.Min.X, r.Max.Y - r.Min.Y} }