Skip to content

[BUG] Rectangle Fills are Incorrect #243

@MikeMCrank

Description

@MikeMCrank

Describe the bug
The fill rectangles call does not apply the correct x/y offsets. (uses x and y -1 instead of +1)
com.github.romankh3.image.comparison.ImageComparison.fillRectangles(Graphics2D, List, double)

To Reproduce
Set the excluded area color, set an excluded area, set draw excluded rectangles and then get a comparison image.

Screenshots
Current behavior
fill rectangle does not cover the full exclusion area
image

Expected Behavior
fill rectangle fully covers the exclusion area
image

Fix
current code:

   private void fillRectangles(Graphics2D graphics, List<Rectangle> rectangles, double percentOpacity) {

        graphics.setColor(new Color(graphics.getColor().getRed(),
                graphics.getColor().getGreen(),
                graphics.getColor().getBlue(),
                (int) (percentOpacity / 100 * 255)
        ));
        rectangles.forEach(rectangle -> graphics.fillRect(
                rectangle.getMinPoint().x - 1,
                rectangle.getMinPoint().y - 1,
                rectangle.getWidth() - 2,
                rectangle.getHeight() - 2)
        );
    }

fixed code:

   private void fillRectangles(Graphics2D graphics, List<Rectangle> rectangles, double percentOpacity) {

        graphics.setColor(new Color(graphics.getColor().getRed(),
                graphics.getColor().getGreen(),
                graphics.getColor().getBlue(),
                (int) (percentOpacity / 100 * 255)
        ));
        rectangles.forEach(rectangle -> graphics.fillRect(
                rectangle.getMinPoint().x + 1,
                rectangle.getMinPoint().y + 1,
                rectangle.getWidth() - 2,
                rectangle.getHeight() - 2)
        );
    }

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions