BUG: Fix float-precision division in BresenhamLine::BuildLine#6057
Merged
hjmjohnson merged 1 commit intoInsightSoftwareConsortium:mainfrom Apr 14, 2026
Merged
Conversation
Add explicit static_cast<double>() on both operands of the division computing euclideanLineLen. Because LType = Vector<float>, the expression `IdentifierType / float` previously evaluated in float precision; the double result was only a widened float quotient. Assisted-by: Greptile — identified float-precision division in BuildLine
Contributor
|
| Filename | Overview |
|---|---|
| Modules/Core/Common/include/itkBresenhamLine.hxx | Adds explicit static_cast<double>() on both operands of the division to ensure double-precision arithmetic instead of float-precision. LType = Vector<float>, so without the cast the division was IdentifierType / float → float, then implicitly widened to double with precision already lost. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["mainDirectionLen\n(IdentifierType / integer)"]
B["Direction[maxDistanceDimension]\n(float, from LType = Vector<float>)"]
C["itk::Math::Absolute(...)"]
subgraph before["Before fix (float precision)"]
D["integer ÷ float\n→ float result"]
E["Implicit widen to double\n(precision already lost)"]
D --> E
end
subgraph after["After fix (double precision)"]
F["static_cast<double>(mainDirectionLen)"]
G["static_cast<double>(Absolute(...))"]
H["double ÷ double\n→ double result (full precision)"]
F --> H
G --> H
end
A --> D
B --> C --> D
A --> F
B --> C --> G
E --> R1["euclideanLineLen (degraded)"]
H --> R2["euclideanLineLen (correct)"]
Reviews (1): Last reviewed commit: "BUG: Fix float-precision division in Bre..." | Re-trigger Greptile
dzenanz
approved these changes
Apr 14, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix float-precision division in
BuildLine(Direction, length). The expressionIdentifierType / floatwas evaluating in float precision despite storing the result in adouble. Adds explicitstatic_cast<double>()on both operands.Companion to the release-5.4 backport in #6054 where this was caught by Greptile review.