Skip to content

Commit e30edec

Browse files
author
Marc Modat
committed
#128 fixed spline test tolerance
1 parent 9b6558d commit e30edec

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

reg-test/reg_test_getDeformationField.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,18 @@ TEST_CASE_METHOD(GetDeformationFieldTest, "Deformation Field from B-spline Grid"
211211
const float resVal = resPtr[i];
212212
const float expVal = expPtr[i];
213213
const float diff = abs(resVal - expVal);
214-
if (diff > 0) {
214+
// The deformation is a float cubic B-spline weighted sum, so it reproduces the
215+
// affine (grid) transformation only to float precision, not bit-exactly. The
216+
// rounding is relative to the coordinate magnitude (~1 ULP), so the tolerance
217+
// scales with the expected value.
218+
const float tol = EPS * (std::abs(expVal) > 1.f ? std::abs(expVal) : 1.f);
219+
if (diff > tol) {
215220
NR_COUT << "[i]=" << i;
216221
NR_COUT << " | diff=" << diff;
217222
NR_COUT << " | Result=" << resVal;
218223
NR_COUT << " | Expected=" << expVal << std::endl;
219224
}
220-
REQUIRE(diff == 0);
225+
REQUIRE(diff <= tol);
221226
}
222227
}
223228
}

0 commit comments

Comments
 (0)