From 9ce97352d9355d3565b020c3a7e3b681edb4018e Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Mon, 12 Jul 2021 07:08:33 -0600 Subject: [PATCH] Fix divide-by-zero in UnitTestCellInterpolate --- vtkm/exec/testing/UnitTestCellInterpolate.cxx | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/vtkm/exec/testing/UnitTestCellInterpolate.cxx b/vtkm/exec/testing/UnitTestCellInterpolate.cxx index 097ed1db1..5c951b161 100644 --- a/vtkm/exec/testing/UnitTestCellInterpolate.cxx +++ b/vtkm/exec/testing/UnitTestCellInterpolate.cxx @@ -59,6 +59,11 @@ struct TestInterpolateFunctor void DoTestWithField(CellShapeTag shape, const FieldVecType& fieldValues) const { vtkm::IdComponent numPoints = fieldValues.GetNumberOfComponents(); + if (numPoints < 1) + { + return; + } + FieldType averageValue = vtkm::TypeTraits::ZeroInitialization(); for (vtkm::IdComponent pointIndex = 0; pointIndex < numPoints; pointIndex++) { @@ -77,16 +82,13 @@ struct TestInterpolateFunctor "Interpolation at point not point value."); } - if (numPoints > 0) - { - vtkm::Vec3f pcoord; - CHECK_CALL(vtkm::exec::ParametricCoordinatesCenter(numPoints, shape, pcoord)); - FieldType interpolatedValue; - CHECK_CALL(vtkm::exec::CellInterpolate(fieldValues, pcoord, shape, interpolatedValue)); + vtkm::Vec3f pcoord; + CHECK_CALL(vtkm::exec::ParametricCoordinatesCenter(numPoints, shape, pcoord)); + FieldType interpolatedValue; + CHECK_CALL(vtkm::exec::CellInterpolate(fieldValues, pcoord, shape, interpolatedValue)); - VTKM_TEST_ASSERT(test_equal(averageValue, interpolatedValue), - "Interpolation at center not average value."); - } + VTKM_TEST_ASSERT(test_equal(averageValue, interpolatedValue), + "Interpolation at center not average value."); } template