Viewport { public boolean intersects(int x, int y, int width, int height) { return this.width > 0 && this.height > 0 && width > 0 && height > 0 && this.x < (x + width) && x < (this.x + this.width) && this.y < (y + height) && y < (this.y + this.height); } Viewport();  Viewport(int x, int y, int width, int height);  Viewport(Viewport viewport); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); Viewport set(int x, int y, int width, int height); Viewport set(Viewport viewport); Viewport setEmpty(); boolean isEmpty(); boolean intersects(int x, int y, int width, int height); @SuppressWarnings("UnnecessaryLocalVariable") boolean intersects(Viewport viewport); boolean intersect(int x, int y, int width, int height); @SuppressWarnings("UnnecessaryLocalVariable") boolean intersect(Viewport viewport); boolean contains(int x, int y); public int x; public int y; public int width; public int height; }
@Test public void testIntersects() throws Exception { Viewport a = new Viewport(30, 100, 3, 3); Viewport copy = new Viewport(a); assertTrue("inside", a.intersects(new Viewport(31, 101, 1, 1))); assertTrue("overlap east", a.intersects(new Viewport(31, 102, 1, 2))); assertTrue("overlap west", a.intersects(new Viewport(31, 99, 1, 2))); assertTrue("overlap north", a.intersects(new Viewport(32, 101, 2, 1))); assertTrue("overlap south", a.intersects(new Viewport(29, 101, 2, 1))); assertEquals("no mutation", copy, a); }
@Test public void testIntersects_Empty() throws Exception { Viewport a = new Viewport(30, 100, 3, 3); assertFalse("empty", a.intersects(new Viewport())); assertFalse("no dimension", a.intersects(new Viewport(31, 101, 0, 0))); assertFalse("no width", a.intersects(new Viewport(31, 101, 5, 0))); assertFalse("no height", a.intersects(new Viewport(31, 101, 0, 5))); }
@Test public void testIntersects_Coincident() throws Exception { Viewport a = new Viewport(30, 100, 1, 1); assertTrue("coincident", a.intersects(new Viewport(30, 100, 1, 1))); assertFalse("coincident east edge", a.intersects(new Viewport(30, 101, 1, 1))); assertFalse("coincident west edge", a.intersects(new Viewport(30, 99, 1, 1))); assertFalse("coincident north edge", a.intersects(new Viewport(31, 100, 1, 1))); assertFalse("coincident south edge", a.intersects(new Viewport(29, 100, 1, 1))); assertFalse("coincident ne point", a.intersects(new Viewport(31, 101, 1, 1))); assertFalse("coincident se point", a.intersects(new Viewport(29, 101, 1, 1))); assertFalse("coincident nw point", a.intersects(new Viewport(31, 99, 1, 1))); assertFalse("coincident sw point", a.intersects(new Viewport(29, 99, 1, 1))); }
@Test public void testIntersects_Doubles() throws Exception { Viewport a = new Viewport(30, 100, 3, 3); Viewport copy = new Viewport(a); assertTrue("inside", a.intersects(31, 101, 1, 1)); assertTrue("overlap east", a.intersects(31, 102, 1, 2)); assertTrue("overlap west", a.intersects(31, 99, 1, 2)); assertTrue("overlap north", a.intersects(32, 101, 2, 1)); assertTrue("overlap south", a.intersects(29, 101, 2, 1)); assertEquals("no mutation", copy, a); }
@Test public void testIntersects_DoublesEmpty() throws Exception { Viewport a = new Viewport(30, 100, 3, 3); assertFalse("empty", a.intersects(0, 0, 0, 0)); assertFalse("no dimension", a.intersects(31, 101, 0, 0)); assertFalse("no width", a.intersects(31, 101, 5, 0)); assertFalse("no height", a.intersects(31, 101, 0, 5)); }
@Test public void testIntersects_DoublesCoincident() throws Exception { Viewport a = new Viewport(30, 100, 1, 1); assertTrue("coincident", a.intersects(30, 100, 1, 1)); assertFalse("coincident east edge", a.intersects(30, 101, 1, 1)); assertFalse("coincident west edge", a.intersects(30, 99, 1, 1)); assertFalse("coincident north edge", a.intersects(31, 100, 1, 1)); assertFalse("coincident south edge", a.intersects(29, 100, 1, 1)); assertFalse("coincident ne point", a.intersects(31, 101, 1, 1)); assertFalse("coincident se point", a.intersects(29, 101, 1, 1)); assertFalse("coincident nw point", a.intersects(31, 99, 1, 1)); assertFalse("coincident sw point", a.intersects(29, 99, 1, 1)); }