@@ -74,10 +74,12 @@ func TestImage(t *testing.T) {
74
74
b .Min .X += 10
75
75
b .Max .Y /= 2
76
76
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 }
81
83
m .Draw (ptTopLeft , ptTopRight , ptBottomLeft , b )
82
84
83
85
// For unknown reasons, a windowless OpenGL context on darwin
@@ -158,7 +160,7 @@ func drawCross(m *image.RGBA, x, y int) {
158
160
}
159
161
160
162
func eqEpsilon (x , y uint8 ) bool {
161
- const epsilon = 5
163
+ const epsilon = 8
162
164
return x - y < epsilon || y - x < epsilon
163
165
}
164
166
@@ -172,13 +174,15 @@ func imageEq(m0, m1 *image.RGBA) bool {
172
174
if b0 != b1 {
173
175
return false
174
176
}
177
+ badPx := 0
175
178
for y := b0 .Min .Y ; y < b0 .Max .Y ; y ++ {
176
179
for x := b0 .Min .X ; x < b0 .Max .X ; x ++ {
177
180
c0 , c1 := m0 .At (x , y ).(color.RGBA ), m1 .At (x , y ).(color.RGBA )
178
181
if ! colorEq (c0 , c1 ) {
179
- return false
182
+ badPx ++
180
183
}
181
184
}
182
185
}
183
- return true
186
+ badFrac := float64 (badPx ) / float64 (b0 .Dx ()* b0 .Dy ())
187
+ return badFrac < 0.01
184
188
}
0 commit comments