### Question:
TopologyUtils { public static boolean intersects(FreedomPolygon source, FreedomPolygon target) { for (FreedomPoint edge : source.getPoints()) { if (contains(target, edge)) { return true; } } for (FreedomPoint edge : target.getPoints()) { if (contains(source, edge)) { return true; } } return false; } private  TopologyUtils(); static Shape convertToAWT(FreedomShape input); static Shape convertToAWT(FreedomShape input, double xScale, double yScale); static Color convertColorToAWT(FreedomColor color); static FreedomPolygon translate(FreedomShape input, int xoffset, int yoffset); static FreedomPolygon rotate(FreedomPolygon input, int degrees); static boolean intersects(FreedomPolygon source, FreedomPolygon target); static boolean contains(FreedomShape fShape, FreedomPoint fPoint);  }### Answer:
@Test public void testIntersects() { System.out.println("Intersects a copy of itself (expected true)"); FreedomPolygon source = new FreedomPolygon(); source.append(new FreedomPoint(0, 0)); source.append(new FreedomPoint(100, 0)); source.append(new FreedomPoint(100, 50)); source.append(new FreedomPoint(0, 50)); FreedomPolygon target = new FreedomPolygon(); target.append(new FreedomPoint(0, 0)); target.append(new FreedomPoint(100, 0)); target.append(new FreedomPoint(100, 50)); target.append(new FreedomPoint(0, 50)); boolean expResult = true; boolean result = TopologyUtils.intersects(source, target); assertEquals(expResult, result); }
@Test public void testIntersects2() { System.out.println("Intersects with a rotated copy (90°) of itself (expected true)"); FreedomPolygon source = new FreedomPolygon(); source.append(new FreedomPoint(0, 0)); source.append(new FreedomPoint(100, 0)); source.append(new FreedomPoint(100, 50)); source.append(new FreedomPoint(0, 50)); FreedomPolygon target = new FreedomPolygon(); target.append(new FreedomPoint(0, 0)); target.append(new FreedomPoint(0, 100)); target.append(new FreedomPoint(-50, 100)); target.append(new FreedomPoint(-50, 0)); boolean expResult = true; boolean result = TopologyUtils.intersects(source, target); assertEquals(expResult, result); }
@Test public void testIntersects3() { System.out.println("Intersects overlapping polygins with no edge collision (expected true)"); FreedomPolygon source = new FreedomPolygon(); source.append(new FreedomPoint(0, 0)); source.append(new FreedomPoint(100, 0)); source.append(new FreedomPoint(100, 50)); source.append(new FreedomPoint(0, 50)); FreedomPolygon target = new FreedomPolygon(); target.append(new FreedomPoint(50, -25)); target.append(new FreedomPoint(75, -25)); target.append(new FreedomPoint(75, 75)); target.append(new FreedomPoint(50, 75)); boolean expResult = true; boolean result = TopologyUtils.intersects(source, target); }
@Test public void testIntersects4() { System.out.println("Intersects overlapping polygins with edge collision (expected true)"); FreedomPolygon source = new FreedomPolygon(); source.append(new FreedomPoint(0, 0)); source.append(new FreedomPoint(100, 0)); source.append(new FreedomPoint(100, 50)); source.append(new FreedomPoint(0, 50)); FreedomPolygon target = new FreedomPolygon(); target.append(new FreedomPoint(5, 5)); target.append(new FreedomPoint(75, -25)); target.append(new FreedomPoint(75, 75)); target.append(new FreedomPoint(50, 75)); boolean expResult = true; boolean result = TopologyUtils.intersects(source, target); assertEquals(expResult, result); }