Fix including empty range

There was a bug where if you included an empty range into another range,
the range suddenly became infinite. This is because empty ranges have
the max at -infinity and the min at infinity. If you just include the
endpoints independently (which is what include does), then the min gets
-infinity and the max gets infinity. This gets a check to make sure that
empty ranges are ignored.
This commit is contained in:
Kenneth Moreland 2018-02-19 10:13:07 -07:00
parent 39c4aacce2
commit e7e39e9ed6
3 changed files with 18 additions and 2 deletions

@ -144,8 +144,11 @@ struct Range
VTKM_EXEC_CONT
void Include(const vtkm::Range& range)
{
this->Include(range.Min);
this->Include(range.Max);
if (range.IsNonEmpty())
{
this->Include(range.Min);
this->Include(range.Max);
}
}
/// \b Return the union of this and another range.

@ -33,6 +33,13 @@ void TestBounds()
vtkm::Bounds emptyBounds;
VTKM_TEST_ASSERT(!emptyBounds.IsNonEmpty(), "Non empty bounds not empty.");
vtkm::Bounds emptyBounds2;
VTKM_TEST_ASSERT(!emptyBounds2.IsNonEmpty(), "2nd empty bounds not empty.");
VTKM_TEST_ASSERT(!emptyBounds.Union(emptyBounds2).IsNonEmpty(),
"Union of empty bounds not empty.");
emptyBounds2.Include(emptyBounds);
VTKM_TEST_ASSERT(!emptyBounds2.IsNonEmpty(), "Include empty in empty is not empty.");
std::cout << "Single value bounds." << std::endl;
vtkm::Bounds singleValueBounds(1.0, 1.0, 2.0, 2.0, 3.0, 3.0);
VTKM_TEST_ASSERT(singleValueBounds.IsNonEmpty(), "Empty?");

@ -32,6 +32,12 @@ void TestRange()
VTKM_TEST_ASSERT(!emptyRange.IsNonEmpty(), "Non empty range not empty.");
VTKM_TEST_ASSERT(test_equal(emptyRange.Length(), 0.0), "Bad length.");
vtkm::Range emptyRange2;
VTKM_TEST_ASSERT(!emptyRange2.IsNonEmpty(), "2nd empty range not empty.");
VTKM_TEST_ASSERT(!emptyRange.Union(emptyRange2).IsNonEmpty(), "Union of empty ranges not empty.");
emptyRange2.Include(emptyRange);
VTKM_TEST_ASSERT(!emptyRange2.IsNonEmpty(), "Include empty in empty is not empty.");
std::cout << "Single value range." << std::endl;
vtkm::Range singleValueRange(5.0, 5.0);
VTKM_TEST_ASSERT(singleValueRange.IsNonEmpty(), "Empty?");