Skip to content

BUG: Keep reverse region iterators inside the region after SetIndex - #7069

Merged
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:bug-reverse-region-span
Nov 5, 2026
Merged

hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:bug-reverse-region-span

Conversation

@hjmjohnson

@hjmjohnson hjmjohnson commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

ImageRegionReverseConstIterator sets its row span one pixel too far when placed with SetIndex() or converted from another iterator, so operator++ can walk outside a cropped region. This computes both span offsets in one helper that matches GoToBegin(), and adds a test.

Found while triaging #7065, where the same formula moved into InitializeSpans(). The bug is on main independently of that PR, so the fix is kept separate to keep #7065 small.

Reproduction and test

The test uses a 10 x 4 image and a region starting at (2, 1) with size (3, 2). It places a reverse iterator at (4, 2), the row's last pixel, and at (3, 2), mid-row, and steps each to the end. Both placements fail on main.

Path Visited on main
SetIndex((4, 2)) (4,2) (3,2) (2,2) (1,2) (0,2) (4,1) (3,1)
converted from an ImageRegionIterator at (4, 2) (4,2) (3,2) (2,2) (1,2) (4,1) (3,1) (2,1)
expected, both paths (4,2) (3,2) (2,2) (4,1) (3,1) (2,1)

The span began one past the row's last pixel. That put the span end on the row's first pixel instead of one before it. The converting constructors also computed m_SpanEndOffset in the member initializer list from a m_SpanBeginOffset that had not been assigned yet.

With the fix, both paths match the expected order. All 723 ITKCommon tests pass on macOS arm64 (clang 19, Release).

@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Core Issues affecting the Core module labels Nov 1, 2026
@hjmjohnson
hjmjohnson marked this pull request as ready for review November 1, 2026 19:57
@greptile-apps

greptile-apps Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues were found.

Summary

Fixes reverse region iterators that leave a cropped region after placement or conversion.

  • Reverse region iterators stay inside cropped rows after placement.

Reviews (2) · Last reviewed commit: "BUG: Keep reverse region iterators insid..." · Reviewed by Greptile

@hjmjohnson
hjmjohnson requested a review from N-Dekker November 1, 2026 20:00
ImageRegionReverseConstIterator set its row span one pixel too far when
placed by SetIndex() or built from another iterator: the span began one
past the row's last pixel, so the span end landed on the row's first pixel
instead of one before it. operator++ then wrapped one pixel early and could
walk outside a cropped region; for a region starting at (2, 1) of size
(3, 2), stepping back from (4, 2) visited (1, 2) and (0, 2). The converting
constructors also computed m_SpanEndOffset in the member initializer list
from a not-yet-assigned m_SpanBeginOffset.

Compute both offsets in one InitializeSpans() helper, matching GoToBegin().
@hjmjohnson
hjmjohnson force-pushed the bug-reverse-region-span branch from ccce300 to 5ce1939 Compare November 1, 2026 23:41
@hjmjohnson
hjmjohnson requested a review from dzenanz November 4, 2026 00:11

@dzenanz dzenanz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks good on a glance.

@hjmjohnson

Copy link
Copy Markdown
Member Author

@greptileai review

@hjmjohnson
hjmjohnson merged commit 2bd0bed into InsightSoftwareConsortium:main Nov 5, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants