From 3322e211c921fd47f312f28694670855dd10115f Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 8 Apr 2021 18:53:21 +0200 Subject: [PATCH] f32: handle empty rectangles in Union and Intersect The old renderer depends on the old behaviour of Union, so change that reference to a copy. Signed-off-by: Elias Naur --- f32/f32.go | 9 +++++++++ gpu/clip.go | 19 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/f32/f32.go b/f32/f32.go index 69745ba2..e4a7f328 100644 --- a/f32/f32.go +++ b/f32/f32.go @@ -101,11 +101,20 @@ func (r Rectangle) Intersect(s Rectangle) Rectangle { if r.Max.Y > s.Max.Y { r.Max.Y = s.Max.Y } + if r.Empty() { + return Rectangle{} + } return r } // Union returns the union of r and s. func (r Rectangle) Union(s Rectangle) Rectangle { + if r.Empty() { + return s + } + if s.Empty() { + return r + } if r.Min.X > s.Min.X { r.Min.X = s.Min.X } diff --git a/gpu/clip.go b/gpu/clip.go index 57c03a4f..8ae25b53 100644 --- a/gpu/clip.go +++ b/gpu/clip.go @@ -93,5 +93,22 @@ func (qs *quadSplitter) splitAndEncode(quad stroke.QuadSegment) { } } - qs.bounds = qs.bounds.Union(cbnd) + qs.bounds = unionRect(qs.bounds, cbnd) +} + +// Union is like f32.Rectangle.Union but ignores empty rectangles. +func unionRect(r, s f32.Rectangle) f32.Rectangle { + if r.Min.X > s.Min.X { + r.Min.X = s.Min.X + } + if r.Min.Y > s.Min.Y { + r.Min.Y = s.Min.Y + } + if r.Max.X < s.Max.X { + r.Max.X = s.Max.X + } + if r.Max.Y < s.Max.Y { + r.Max.Y = s.Max.Y + } + return r }