From 4d0f41cc6b13754ff43b42013aaadc4763912e90 Mon Sep 17 00:00:00 2001 From: Thomas Friedel Date: Wed, 17 Apr 2019 13:01:38 +0200 Subject: [PATCH] more precise rasterization --- backend/software/triangles.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/software/triangles.go b/backend/software/triangles.go index cc61680..476ff31 100644 --- a/backend/software/triangles.go +++ b/backend/software/triangles.go @@ -19,10 +19,10 @@ func triangleLR(tri [][2]float64, y float64) (l, r float64, outside bool) { } // check general bounds - if y < a[1] { + if y <= a[1] { return a[0], a[0], true } - if y >= c[1] { + if y > c[1] { return c[0], c[0], true } @@ -73,6 +73,9 @@ func (b *SoftwareBackend) fillTriangle(tri [][2]float64, fn func(x, y int)) { } else if r > float64(b.w) { r = float64(b.w) } + if l >= r { + continue + } fl, cr := int(math.Floor(l)), int(math.Ceil(r)) for x := fl; x <= cr; x++ { fx := float64(x) + 0.5 @@ -127,6 +130,9 @@ func (b *SoftwareBackend) fillQuad(quad [4][2]float64, fn func(x, y int, sx, sy } else if r > float64(b.w) { r = float64(b.w) } + if l >= r { + continue + } v0 := [2]float64{float64(l) - quad[0][0], float64(y) - quad[0][1]} sx0 := topv[0]*v0[0] + topv[1]*v0[1]