Skip to content

Commit

Permalink
imgproc: add round function to allow for floating point accuracy diff…
Browse files Browse the repository at this point in the history
…erences due to GPU usage.

Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Dec 26, 2017
1 parent 152d0b8 commit fbdfc25
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ func floatEquals(a, b float64) bool {
}
return false
}

func round(x, unit float64) float64 {
return float64(int64(x/unit+0.5)) * unit
}
9 changes: 5 additions & 4 deletions imgproc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,9 @@ func TestWarpAffine(t *testing.T) {
dst = src.Clone()
WarpAffine(src, dst, rot, image.Point{343, 400})
result = Norm(dst, NormL2)
if result != 111111.05612854195 {
t.Errorf("WarpAffine() = %v, want %v", result, 111111.05612854195)

if !floatEquals(round(result, 0.05), round(111111.05, 0.05)) {
t.Errorf("WarpAffine() = %v, want %v", round(result, 0.05), round(111111.05, 0.05))
}
}

Expand All @@ -528,8 +529,8 @@ func TestWarpAffineWithParams(t *testing.T) {
dst = src.Clone()
WarpAffineWithParams(src, dst, rot, image.Point{343, 400}, InterpolationLinear, BorderConstant, color.RGBA{0, 0, 0, 0})
result = Norm(dst, NormL2)
if !floatEquals(result, 111111.05612854195) {
t.Errorf("WarpAffineWithParams() = %v, want %v", result, 111111.05612854195)
if !floatEquals(round(result, 0.05), round(111111.05, 0.05)) {
t.Errorf("WarpAffine() = %v, want %v", round(result, 0.05), round(111111.05, 0.05))
}
}

Expand Down

0 comments on commit fbdfc25

Please sign in to comment.