Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package org.eclipse.swt.graphics;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.win32.*;
Expand Down Expand Up @@ -55,4 +57,31 @@ public void testRegionMustBeScaledOnHandleOfScaledZoomLevel() {
assertEquals("scaled region's y position should be double of unscaled region", bounds.y * scalingFactor, scaledBounds.y);
}


@Test
public void testRegionMustIntersectProperlyOn175Zoom() {
Display display = Display.getDefault();
Shell shell = new Shell(display);
DPITestUtil.changeDPIZoom(shell, 150);

Region region = new Region(display);
region.add(0, 0, 100, 51);
boolean intersectWhenOverlapping = region.intersects(0, 50, 100, 50);
assertTrue(intersectWhenOverlapping);

region = new Region(display);
region.add(0, 0, 100, 50);
boolean dontIntersectWhenNotOverlapping = region.intersects(0, 50, 100, 50);
assertFalse(dontIntersectWhenNotOverlapping);

region = new Region(display);
// 58 * 150 equals to 87
region.add(0, 58, 100, 20);
// (27 + 31) should equal to 87, but will be 88 if 27 and 31 will
// be rounded independently
boolean shouldNotIntersect = region.intersects(0, 27, 100, 31);
assertFalse(shouldNotIntersect);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public void intersect (Region region) {
*/
public boolean intersects (int x, int y, int width, int height) {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return intersectsInPixels(DPIUtil.scaleUp(x, initialZoom), DPIUtil.scaleUp(y, initialZoom), DPIUtil.scaleUp(width, initialZoom), DPIUtil.scaleUp(height, initialZoom));
return intersects(new Rectangle(x, y, width, height));
}

boolean intersectsInPixels (int x, int y, int width, int height) {
Expand Down
Loading