From fbdfc250c7ff63401218e06b0bf8db910de5041e Mon Sep 17 00:00:00 2001 From: deadprogram Date: Tue, 26 Dec 2017 09:02:14 +0100 Subject: [PATCH] imgproc: add round function to allow for floating point accuracy differences due to GPU usage. Signed-off-by: deadprogram --- helpers_test.go | 4 ++++ imgproc_test.go | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/helpers_test.go b/helpers_test.go index 1db8737d..83e99a03 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -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 +} diff --git a/imgproc_test.go b/imgproc_test.go index 8a657aa9..9d0ad773 100644 --- a/imgproc_test.go +++ b/imgproc_test.go @@ -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)) } } @@ -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)) } }