Skip to content

Commit

Permalink
STYLE: Remove local cropPossible variable from ImageRegion::Crop
Browse files Browse the repository at this point in the history
Directly returned `false`, as soon as it would appear that we cannot crop.
  • Loading branch information
N-Dekker authored and dzenanz committed Nov 14, 2023
1 parent 1b57648 commit fc17f0b
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions Modules/Core/Common/include/itkImageRegion.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -189,31 +189,20 @@ ImageRegion<VImageDimension>::Crop(const Self & region)
{
OffsetValueType crop;
unsigned int i;
bool cropPossible = true;

// Can we crop?
for (i = 0; i < VImageDimension && cropPossible; ++i)
for (i = 0; i < VImageDimension; ++i)
{
// Is left edge of current region to the right of the right edge
// of the region to crop with? (if so, we cannot crop)
if (m_Index[i] >= region.m_Index[i] + static_cast<OffsetValueType>(region.m_Size[i]))
{
cropPossible = false;
}
// If right edge of the current region to the left of the left
// edge of the region to crop with? (if so, we cannot crop)
if (m_Index[i] + static_cast<OffsetValueType>(m_Size[i]) <= region.m_Index[i])
// Is the left edge of current region to the right of the right edge of the region to crop with? Or is the right
// edge of the current region to the left of the left edge of the region to crop with? (if so, we cannot crop)
if (m_Index[i] >= region.m_Index[i] + static_cast<OffsetValueType>(region.m_Size[i]) ||
m_Index[i] + static_cast<OffsetValueType>(m_Size[i]) <= region.m_Index[i])
{
cropPossible = false;
// if we cannot crop, return without changing anything
return false;
}
}

// if we cannot crop, return without changing anything
if (!cropPossible)
{
return cropPossible;
}

// we can crop, so crop
for (i = 0; i < VImageDimension; ++i)
{
Expand All @@ -240,7 +229,7 @@ ImageRegion<VImageDimension>::Crop(const Self & region)
}
}

return cropPossible;
return true;
}

template <unsigned int VImageDimension>
Expand Down

0 comments on commit fc17f0b

Please sign in to comment.