From 16193730622e84f5510ab8a007a6f7f7d3c06cb4 Mon Sep 17 00:00:00 2001 From: faiface <faiface@ksp.sk> Date: Fri, 5 May 2017 15:43:24 +0200 Subject: [PATCH] add Rect.Union --- geometry.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/geometry.go b/geometry.go index e494712..fc0f9be 100644 --- a/geometry.go +++ b/geometry.go @@ -272,6 +272,16 @@ func (r Rect) Contains(u Vec) bool { return r.Min.X() <= u.X() && u.X() <= r.Max.X() && r.Min.Y() <= u.Y() && u.Y() <= r.Max.Y() } +// Union returns a minimal Rect which covers both r and s. Rects r and s should be normalized. +func (r Rect) Union(s Rect) Rect { + return R( + math.Min(r.Min.X(), s.Min.X()), + math.Min(r.Min.Y(), s.Min.Y()), + math.Max(r.Max.X(), s.Max.X()), + math.Max(r.Max.Y(), s.Max.Y()), + ) +} + // Matrix is a 3x3 transformation matrix that can be used for all kinds of spacial transforms, such // as movement, scaling and rotations. // -- GitLab