From 7ff17453dd5fa7d865aadb7e548a4bef0b1c7aeb Mon Sep 17 00:00:00 2001 From: Viktor Ogeman Date: Thu, 25 Jun 2020 13:14:38 +0200 Subject: [PATCH] gpu: fix negative intersections Fixes a bug due to that f32.Rect.Intersect will not return the empty rectangle for non intersecting rectangles - but instead a swapped rectangle. By removing the .Canon() call in gpu.go we ensure that non overlapping clipping rects and paint rects will lead to no painting. The Canon() call is not needed since boundsForTransformedRect() was previously updated to always return a canonical rectangle. Test case added. Signed-off-by: Viktor --- gpu/gpu.go | 2 +- internal/rendertest/refs/TestNegativeOverlaps.png | Bin 0 -> 364 bytes internal/rendertest/render_test.go | 12 ++++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 internal/rendertest/refs/TestNegativeOverlaps.png diff --git a/gpu/gpu.go b/gpu/gpu.go index 48a6334d..321b2a89 100644 --- a/gpu/gpu.go +++ b/gpu/gpu.go @@ -768,7 +768,7 @@ loop: // the new bounding rectangle and the transformed original paint rectangle. trans, off := splitTransform(state.t) clipData, bnd, partialTrans := d.boundsForTransformedRect(op.Rect, trans) - clip := state.clip.Intersect(bnd.Add(off)).Canon() + clip := state.clip.Intersect(bnd.Add(off)) if clip.Empty() { continue } diff --git a/internal/rendertest/refs/TestNegativeOverlaps.png b/internal/rendertest/refs/TestNegativeOverlaps.png new file mode 100644 index 0000000000000000000000000000000000000000..9ed91358c5102f5423f4aee5bc3e241445ea011c GIT binary patch literal 364 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1SEZ8zRh7^U^Mo0aSW-L^X6h8=K%wTqX!IM z-T$<@=XZvmqeA*^@#ohW*Jm?aV_3r&!MuSjf%kw^gDJxZ7RUnz-2eZJSXdY~s>`MV OISihzelF{r5}E+9Ep1l- literal 0 HcmV?d00001 diff --git a/internal/rendertest/render_test.go b/internal/rendertest/render_test.go index 089ab24c..1078f492 100644 --- a/internal/rendertest/render_test.go +++ b/internal/rendertest/render_test.go @@ -182,3 +182,15 @@ func TestBuildOffscreen(t *testing.T) { r.expect(38, 38, colornames.White) })) } + +func TestNegativeOverlaps(t *testing.T) { + run(t, func(ops *op.Ops) { + clip.Rect{Rect: f32.Rect(50, 50, 100, 100)}.Add(ops) + paint.PaintOp{Rect: f32.Rect(0, 120, 100, 122)}.Add(ops) + }, func(r result) { + r.expect(60, 60, colornames.White) + r.expect(60, 110, colornames.White) + r.expect(60, 120, colornames.White) + r.expect(60, 122, colornames.White) + }) +}