Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Rectangle Fills are Incorrect #243

Open
MikeMCrank opened this issue Jun 5, 2023 · 0 comments
Open

[BUG] Rectangle Fills are Incorrect #243

MikeMCrank opened this issue Jun 5, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@MikeMCrank
Copy link

MikeMCrank commented Jun 5, 2023

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)
        );
    }
@MikeMCrank MikeMCrank added the bug Something isn't working label Jun 5, 2023
@MikeMCrank MikeMCrank changed the title [BUG] [BUG] Rectangle Fills are Incorrect Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants