~eliasnaur/gio-patches

gpu: fix negative intersections v1 PROPOSED

Viktor Ogeman: 1
 gpu: fix negative intersections

 3 files changed, 13 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~eliasnaur/gio-patches/patches/11329/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] gpu: fix negative intersections Export this patch

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 <viktor.ogeman@gmail.com>
---
 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 48a6334..321b2a8 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 089ab24..1078f49 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)
	})
}
-- 
2.25.2
Thanks, merged.