From 0bf6de6cfad3c716567df99dfa1f9dbb058fb487 Mon Sep 17 00:00:00 2001 From: Wagner Riffel Date: Wed, 13 May 2020 07:06:55 -0300 Subject: [PATCH] f32: add package Rect shorthand function Signed-off-by: Wagner Riffel --- f32/f32.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/f32/f32.go b/f32/f32.go index 8062055d..70229f2b 100644 --- a/f32/f32.go +++ b/f32/f32.go @@ -33,6 +33,19 @@ func (r Rectangle) String() string { return r.Min.String() + "-" + r.Max.String() } +// Rect is a shorthand to Rectangle{Point{x0, y0}, Point{x1, y1}}. +// The returned Rectangle has x0 and y0 swapped if necessary so that +// it's correctly formed +func Rect(x0, y0, x1, y1 float32) Rectangle { + if x0 > x1 { + x0, x1 = x1, x0 + } + if y0 > y1 { + y0, y1 = y1, y0 + } + return Rectangle{Point{x0, y0}, Point{x1, y1}} +} + // Add return the point p+p2. func (p Point) Add(p2 Point) Point { return Point{X: p.X + p2.X, Y: p.Y + p2.Y}