Skip to content

Refactor image comparison region grouping#255

Open
Shourov735 wants to merge 2 commits into
romankh3:masterfrom
Shourov735:refactor/code-smell-fixes
Open

Refactor image comparison region grouping#255
Shourov735 wants to merge 2 commits into
romankh3:masterfrom
Shourov735:refactor/code-smell-fixes

Conversation

@Shourov735

Copy link
Copy Markdown

PR Details

Description

This PR refactors internal image comparison logic without changing the public API or expected comparison output.

Changes included:

  • Replace per-pixel new Point(x, y) exclusion checks with coordinate-based checks.
  • Move comparison-specific matrix and region counters out of ImageComparison instance fields.
  • Replace recursive region grouping with an iterative ArrayDeque traversal.
  • Replace algorithm magic numbers with named constants.
  • Express rectangle merging as "merge until stable" instead of calling mergeRectangles() twice.
  • Restore Graphics2D color state after filling rectangles.
  • Add regression tests for coordinate exclusion checks and large connected diff regions.

Related Issue

Closes #254

Motivation and Context

The comparison engine had some maintainability issues: temporary comparison state was stored on the ImageComparison instance, region grouping used recursion, excluded-area checks allocated a Point object for every pixel, and a few sentinel values were represented as magic numbers.

This refactor keeps the behavior unchanged while making the comparison flow easier to maintain and safer for large connected difference regions.

How Has This Been Tested

Tested locally with:

  • mvn clean test
  • mvn pmd:check
  • mvn pmd:cpd-check
  • mvn org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test

Results:

  • 66 tests passed with 0 failures, 0 errors, and 0 skipped.
  • PMD passed with 0 violations.
  • CPD passed with no duplicated-code failures.

I also generated mvn checkstyle:checkstyle. The repository still has existing broad Sun Checkstyle findings, so I did not include a full style-only rewrite in this focused refactor.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve maintainability of image comparison region grouping

1 participant