use of org.eclipse.swt.graphics.Region in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Region method test_containsII.
@Test
public void test_containsII() {
Rectangle rect1 = new Rectangle(10, 10, 200, 100);
Point pointInRect1 = new Point(10, 10);
Rectangle rect2 = new Rectangle(50, 50, 1000, 1000);
Point pointInRect2 = new Point(1049, 1009);
Point pointNotInRect12 = new Point(49, 110);
Region reg = new Region(display);
reg.dispose();
try {
reg.contains(pointInRect1.x, pointInRect1.y);
fail("no exception thrown on disposed region");
} catch (Exception e) {
}
reg = new Region(display);
if (reg.contains(pointInRect1.x, pointInRect1.y)) {
reg.dispose();
fail("Empty region should not contain point");
}
reg.add(rect1);
if (!reg.contains(pointInRect1.x, pointInRect1.y)) {
reg.dispose();
fail("Region should contain point");
}
reg.add(rect2);
if (!reg.contains(pointInRect1.x, pointInRect1.y) || !reg.contains(pointInRect2.x, pointInRect2.y)) {
reg.dispose();
fail("Region should contain point");
}
if (reg.contains(pointNotInRect12.x, pointNotInRect12.y)) {
reg.dispose();
fail("Region should not contain point");
}
reg.dispose();
}
use of org.eclipse.swt.graphics.Region in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Region method test_containsLorg_eclipse_swt_graphics_Point.
@Test
public void test_containsLorg_eclipse_swt_graphics_Point() {
Rectangle rect1 = new Rectangle(10, 10, 200, 100);
Point pointInRect1 = new Point(10, 10);
Rectangle rect2 = new Rectangle(50, 50, 1000, 1000);
Point pointInRect2 = new Point(1049, 1009);
Point pointNotInRect12 = new Point(49, 110);
Region reg = new Region(display);
reg.dispose();
try {
reg.contains(pointInRect1);
fail("no exception thrown on disposed region");
} catch (Exception e) {
}
reg = new Region(display);
if (reg.contains(pointInRect1)) {
reg.dispose();
fail("Empty region should not contain point");
}
reg.add(rect1);
if (!reg.contains(pointInRect1)) {
reg.dispose();
fail("Region should contain point");
}
reg.add(rect2);
if (!reg.contains(pointInRect1) || !reg.contains(pointInRect2)) {
reg.dispose();
fail("Region should contain point");
}
if (reg.contains(pointNotInRect12)) {
reg.dispose();
fail("Region should not contain point");
}
reg.dispose();
}
use of org.eclipse.swt.graphics.Region in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Region method test_getBounds.
@Test
public void test_getBounds() {
Region reg = new Region(display);
reg.dispose();
try {
reg.getBounds();
fail("Region disposed should throw Exception");
} catch (Exception e) {
}
Rectangle rect1 = new Rectangle(10, 10, 50, 30);
Rectangle rect2 = new Rectangle(100, 100, 10, 10);
// the rectangle enclosing the two preceding rectangles
Rectangle rect12Bounds = new Rectangle(10, 10, 100, 100);
reg = new Region(display);
reg.add(rect1);
Rectangle rect1Bis = reg.getBounds();
if (rect1Bis.x != rect1.x || rect1Bis.y != rect1.y || rect1Bis.height != rect1.height || rect1Bis.width != rect1.width) {
reg.dispose();
fail("getBounds doesn't return the borders of the rectangle area which was set up");
}
reg.add(rect2);
Rectangle rect12 = reg.getBounds();
if (rect12.x != rect12Bounds.x || rect12.y != rect12Bounds.y || rect12.height != rect12Bounds.height || rect12.width != rect12Bounds.width) {
reg.dispose();
fail("getBounds doesn't return the borders of the resulting rectangle area which was set up");
}
reg.dispose();
}
use of org.eclipse.swt.graphics.Region in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Region method test_intersectLorg_eclipse_swt_graphics_Rectangle.
@Test
public void test_intersectLorg_eclipse_swt_graphics_Rectangle() {
Rectangle rect1 = new Rectangle(0, 0, 48, 24);
Rectangle rect2 = new Rectangle(0, 0, 48, 24);
Rectangle rect3 = new Rectangle(10, 10, 10, 10);
Rectangle rect4 = new Rectangle(48, 24, 10, 10);
Rectangle rect5 = new Rectangle(24, 20, 24, 10);
Region reg = new Region(display);
reg.dispose();
try {
reg.intersect(rect1);
fail("no exception thrown on disposed region");
} catch (SWTException e) {
}
reg = new Region(display);
reg.intersect(rect1);
if (!reg.isEmpty()) {
reg.dispose();
fail("intersect failed for empty region");
}
reg.add(rect1);
reg.intersect(rect2);
Rectangle box = reg.getBounds();
if (!box.equals(rect1)) {
reg.dispose();
fail("intersect failed 1");
}
reg.intersect(rect3);
box = reg.getBounds();
if (!box.equals(rect3)) {
reg.dispose();
fail("intersect failed 2");
}
reg.intersect(rect4);
if (!reg.isEmpty()) {
reg.dispose();
fail("intersect failed 3");
}
reg.add(rect1.union(rect4));
reg.intersect(rect5);
box = reg.getBounds();
if (!box.equals(rect5)) {
reg.dispose();
fail("intersect failed 4");
}
reg.dispose();
reg = new Region(display);
reg.add(rect1);
reg.add(rect4);
reg.intersect(rect5);
box = reg.getBounds();
if (!box.equals(new Rectangle(24, 20, 24, 4))) {
reg.dispose();
fail("intersect failed 5");
}
reg.dispose();
}
use of org.eclipse.swt.graphics.Region in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Region method test_subtractLorg_eclipse_swt_graphics_Region.
@Test
public void test_subtractLorg_eclipse_swt_graphics_Region() {
Region reg1 = new Region(display);
reg1.add(new Rectangle(0, 0, 50, 25));
Region reg = new Region(display);
reg.dispose();
try {
reg.subtract(reg1);
reg1.dispose();
fail("no exception thrown on disposed region");
} catch (SWTException e) {
}
reg = new Region(display);
reg.subtract(reg1);
if (!reg.isEmpty()) {
reg.dispose();
reg1.dispose();
fail("subtract failed for empty region");
}
Region reg2 = new Region(display);
reg2.add(new Rectangle(0, 0, 50, 25));
reg.add(reg1);
reg.subtract(reg2);
if (!reg.isEmpty()) {
reg.dispose();
reg1.dispose();
reg2.dispose();
fail("subtract failed 1");
}
reg2.dispose();
Region reg3 = new Region(display);
reg3.add(new Rectangle(10, 10, 10, 10));
reg.add(reg1);
reg.subtract(reg3);
Rectangle box = reg.getBounds();
if (!box.equals(reg1.getBounds())) {
reg.dispose();
reg1.dispose();
reg3.dispose();
fail("subtract failed 2");
}
reg3.dispose();
Region reg4 = new Region(display);
reg4.add(new Rectangle(50, 25, 10, 10));
reg.subtract(reg4);
box = reg.getBounds();
if (!box.equals(reg1.getBounds())) {
reg.dispose();
reg1.dispose();
reg4.dispose();
fail("subtract failed 3");
}
Region reg5 = new Region(display);
reg5.add(new Rectangle(0, 0, 60, 20));
reg.add(reg1.getBounds().union(reg4.getBounds()));
reg.subtract(reg5);
box = reg.getBounds();
if (!box.equals(new Rectangle(0, 20, 60, 15))) {
reg.dispose();
reg1.dispose();
reg4.dispose();
reg5.dispose();
fail("subtract failed 4");
}
reg.dispose();
reg = new Region(display);
reg.add(reg1);
reg.add(reg4);
reg.subtract(reg5);
box = reg.getBounds();
if (!box.equals(new Rectangle(0, 20, 60, 15))) {
reg.dispose();
reg1.dispose();
reg4.dispose();
reg5.dispose();
fail("subtract failed 5");
}
reg.dispose();
reg1.dispose();
reg4.dispose();
reg5.dispose();
}
Aggregations