image-comparison
image-comparison copied to clipboard
[BUG] Rectangle Fills are Incorrect
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<Rectangle>, 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
Expected Behavior
fill rectangle fully covers the exclusion area
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)
);
}