Skip to content

Quality: RegionExt::clamp returns spurious 1×1 crop when region is entirely outside image bounds - #826

Open
kumburovicbranko682-boop wants to merge 1 commit into
mayocream:mainfrom
kumburovicbranko682-boop:contribai/improve/quality/regionext-clamp-returns-spurious-1-1-cro
Open

Quality: RegionExt::clamp returns spurious 1×1 crop when region is entirely outside image bounds#826
kumburovicbranko682-boop wants to merge 1 commit into
mayocream:mainfrom
kumburovicbranko682-boop:contribai/improve/quality/regionext-clamp-returns-spurious-1-1-cro

Conversation

@kumburovicbranko682-boop

Copy link
Copy Markdown

✨ Code Quality

Problem

When a Region is completely outside the image (e.g., self.x=100 on a 50-wide image), the clamp method incorrectly returns Some((49, y0, 1, h)) — a 1-pixel strip at the boundary — instead of None. This happens because x0 is capped at width-1 (49), then x1 is computed as max(..., x0)=50, yielding w=1. The caller has no way to know the region was entirely out-of-bounds and will silently crop a wrong sliver of the image.

Severity: high
File: koharu-app/src/utils.rs

Solution

Add an early-exit check for fully out-of-bounds regions before the min/max calculations:

Changes

  • koharu-app/src/utils.rs (modified)

Testing

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced


🤖 About this PR

This pull request was generated by ContribAI, an AI agent
that helps improve open source projects. The change was:

  1. Discovered by automated code analysis
  2. Generated by AI with context-aware code generation
  3. Self-reviewed by AI quality checks

If you have questions or feedback about this PR, please comment below.
We appreciate your time reviewing this contribution!

Closes #825

…ntirely outside image bounds

When a Region is completely outside the image (e.g., self.x=100 on a 50-wide image), the clamp method incorrectly returns Some((49, y0, 1, h)) — a 1-pixel strip at the boundary — instead of None. This happens because x0 is capped at width-1 (49), then x1 is computed as max(..., x0)=50, yielding w=1. The caller has no way to know the region was entirely out-of-bounds and will silently crop a wrong sliver of the image.


Affected files: utils.rs

Signed-off-by: kumburovicbranko682-boop <295886834+kumburovicbranko682-boop@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: regionext::clamp returns spurious 1×1 crop when region is entirely outside image bounds

1 participant