-
-
Notifications
You must be signed in to change notification settings - Fork 665
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUG:
region.IsInside(zeroSizedRegion)
should always return false
As documented by commit a872710 "STYLE: Documenting the behavior of the IsInside() method when the argument region has zero size in any of its dimensions", by Luis Ibanez, 18 December 2009. Included GoogleTest unit tests for both zero-sized and one-sized regions as argument.
- Loading branch information
Showing
3 changed files
with
77 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/*========================================================================= | ||
* | ||
* Copyright NumFOCUS | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0.txt | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*=========================================================================*/ | ||
|
||
// First include the header file to be tested: | ||
#include "itkImageRegion.h" | ||
#include "itkIndexRange.h" | ||
#include <gtest/gtest.h> | ||
#include <type_traits> // For remove_const_t and remove_reference_t. | ||
|
||
|
||
// Tests that a zero-sized region is not considered to be inside of another region. | ||
TEST(ImageRegion, ZeroSizedRegionIsNotInside) | ||
{ | ||
using RegionType = itk::ImageRegion<2>; | ||
using IndexType = RegionType::IndexType; | ||
using SizeType = RegionType::SizeType; | ||
|
||
const RegionType region(SizeType::Filled(2)); | ||
|
||
for (const auto indexValue : { -1, 0, 1 }) | ||
{ | ||
const RegionType zeroSizedRegion{ IndexType::Filled(indexValue), SizeType{ { 0 } } }; | ||
|
||
EXPECT_FALSE(region.IsInside(zeroSizedRegion)); | ||
} | ||
} | ||
|
||
|
||
// Tests that regions of size 1 are considered to be inside of a region, if and only if ("iff") their index is inside of | ||
// this region. | ||
TEST(ImageRegion, OneSizedRegionIsInsideIffItsIndexIsInside) | ||
{ | ||
const auto check = [](const auto & region) { | ||
using RegionType = std::remove_const_t<std::remove_reference_t<decltype(region)>>; | ||
using SizeType = typename RegionType::SizeType; | ||
|
||
auto paddedRegion = region; | ||
paddedRegion.PadByRadius(1); | ||
|
||
for (const auto & index : itk::ImageRegionIndexRange<RegionType::ImageDimension>(paddedRegion)) | ||
{ | ||
const RegionType oneSizedRegion{ index, SizeType::Filled(1) }; | ||
|
||
// The one-sized region is inside this region if and only if its index is inside this region. | ||
EXPECT_EQ(region.IsInside(oneSizedRegion), region.IsInside(index)); | ||
} | ||
}; | ||
|
||
// Check for a 2D and a 3D image region. | ||
check(itk::ImageRegion<2>(itk::Size<2>::Filled(3))); | ||
check(itk::ImageRegion<3>(itk::MakeIndex(-1, 0, 1), itk::MakeSize(2, 3, 4))); | ||
} |