Skip to content

Commit b208e91

Browse files
committed
go.mobile/gl/glutil: take advantage of new degree of freedom in test
LGTM=nigeltao R=nigeltao CC=golang-codereviews https://golang.org/cl/166030043
1 parent 970a0a0 commit b208e91

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

gl/glutil/glimage_test.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ func TestImage(t *testing.T) {
7474
b.Min.X += 10
7575
b.Max.Y /= 2
7676

77-
ptTopLeft := geom.Point{3, 15}
78-
ptTopRight := geom.Point{48, 15}
79-
ptBottomLeft := geom.Point{3, 46}
80-
ptBottomRight := geom.Point{48, 46}
77+
// All-integer right-angled triangles offsetting the
78+
// box: 24-32-40, 12-16-20.
79+
ptTopLeft := geom.Point{0, 24}
80+
ptTopRight := geom.Point{32, 0}
81+
ptBottomLeft := geom.Point{12, 24 + 16}
82+
ptBottomRight := geom.Point{12 + 32, 16}
8183
m.Draw(ptTopLeft, ptTopRight, ptBottomLeft, b)
8284

8385
// For unknown reasons, a windowless OpenGL context on darwin
@@ -158,7 +160,7 @@ func drawCross(m *image.RGBA, x, y int) {
158160
}
159161

160162
func eqEpsilon(x, y uint8) bool {
161-
const epsilon = 5
163+
const epsilon = 8
162164
return x-y < epsilon || y-x < epsilon
163165
}
164166

@@ -172,13 +174,15 @@ func imageEq(m0, m1 *image.RGBA) bool {
172174
if b0 != b1 {
173175
return false
174176
}
177+
badPx := 0
175178
for y := b0.Min.Y; y < b0.Max.Y; y++ {
176179
for x := b0.Min.X; x < b0.Max.X; x++ {
177180
c0, c1 := m0.At(x, y).(color.RGBA), m1.At(x, y).(color.RGBA)
178181
if !colorEq(c0, c1) {
179-
return false
182+
badPx++
180183
}
181184
}
182185
}
183-
return true
186+
badFrac := float64(badPx) / float64(b0.Dx()*b0.Dy())
187+
return badFrac < 0.01
184188
}

testdata/testpattern-window.png

4.46 KB
Loading

0 commit comments

Comments
 (0)