Skip to content

Commit 2003fb4

Browse files
slavusthjmjohnson
authored andcommitted
BUG: BresenhamLine - use double precision floats for ending index computation
Use explicit static_cast<double>() on both operands of the division computing euclideanLineLen so the division evaluates in double precision, not float (LType = Vector<float>). Assisted-by: Greptile — identified float-precision division in BuildLine (cherry picked from commit b7248b1)
1 parent ac5652b commit 2003fb4

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

Modules/Core/Common/include/itkBresenhamLine.hxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ BresenhamLine<VDimension>::BuildLine(LType Direction, IdentifierType length) ->
3535
// The dimension with the largest absolute component
3636
const unsigned int maxDistanceDimension = std::distance(
3737
Direction.Begin(), std::max_element(Direction.Begin(), Direction.End(), [](const auto a, const auto b) {
38-
return itk::Math::Absolute(a) < itk::Math::Absolute(b);
38+
return itk::Math::abs(a) < itk::Math::abs(b);
3939
}));
4040

4141
// compute actual line length because the shorter distance
4242
// the larger deviation due to rounding to integers
4343
const IdentifierType mainDirectionLen = length - 1;
44-
const float euclideanLineLen = mainDirectionLen / itk::Math::Absolute(Direction[maxDistanceDimension]);
44+
const double euclideanLineLen =
45+
static_cast<double>(mainDirectionLen) / static_cast<double>(itk::Math::abs(Direction[maxDistanceDimension]));
4546

4647
// we are going to start at 0
4748
constexpr IndexType StartIndex{ 0 };
@@ -81,7 +82,7 @@ BresenhamLine<VDimension>::BuildLine(IndexType p0, IndexType p1) -> IndexArray
8182
{
8283
const IndexValueType delta = p1[i] - p0[i];
8384
step[i] = (delta >= 0) ? 1 : -1;
84-
absDeltas[i] = static_cast<IndexValueType>(itk::Math::Absolute(delta));
85+
absDeltas[i] = static_cast<IndexValueType>(itk::Math::abs(delta));
8586

8687
if (absDeltas[i] > maxAbsDelta)
8788
{

0 commit comments

Comments
 (0)