@Test public void testContains() { System.out.println("Check if a polygon A contains polygon B"); 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)); FreedomPoint inside = new FreedomPoint(25, 25); FreedomPoint onBorder = new FreedomPoint(25, 0); FreedomPoint outside = new FreedomPoint(200, 200); assertEquals(true, TopologyUtils.contains(source, inside)); assertEquals(false, TopologyUtils.contains(source, onBorder)); assertEquals(false, TopologyUtils.contains(source, outside)); }
public static boolean contains(FreedomShape fShape, FreedomPoint fPoint) { ArrayList<Float> lx = new ArrayList<Float>(); ArrayList<Float> ly = new ArrayList<Float>(); int verticesNum = 0; float px = fPoint.getX(); float py = fPoint.getY(); if (fShape instanceof FreedomPolygon) { FreedomPolygon poly = (FreedomPolygon) fShape; verticesNum = poly.getPoints().size(); for (int i = 0; i < poly.getPoints().size(); i++) { lx.add((float) poly.getPoints().get(i).getX()); ly.add((float) poly.getPoints().get(i).getY()); } } float[] x = new float[lx.size()]; for (int i = 0; i < lx.size(); i++) { Float f = lx.get(i); x[i] = ((f != null) ? f : Float.NaN); } float[] y = new float[ly.size()]; for (int i = 0; i < ly.size(); i++) { Float f = ly.get(i); y[i] = ((f != null) ? f : Float.NaN); } if (verticesNum < 3) { return false; } boolean oddNodes = false; float x2 = x[verticesNum - 1]; float y2 = y[verticesNum - 1]; float x1; float y1; for (int i = 0; i < verticesNum; x2 = x1, y2 = y1, ++i) { x1 = x[i]; y1 = y[i]; if (((y1 < py) && (y2 >= py)) || ((y1 >= py) && (y2 < py))) { if (((py - y1) / (y2 - y1) * (x2 - x1)) < (px - x1)) { oddNodes = !oddNodes; } } } return oddNodes; }
TopologyUtils { public static boolean contains(FreedomShape fShape, FreedomPoint fPoint) { ArrayList<Float> lx = new ArrayList<Float>(); ArrayList<Float> ly = new ArrayList<Float>(); int verticesNum = 0; float px = fPoint.getX(); float py = fPoint.getY(); if (fShape instanceof FreedomPolygon) { FreedomPolygon poly = (FreedomPolygon) fShape; verticesNum = poly.getPoints().size(); for (int i = 0; i < poly.getPoints().size(); i++) { lx.add((float) poly.getPoints().get(i).getX()); ly.add((float) poly.getPoints().get(i).getY()); } } float[] x = new float[lx.size()]; for (int i = 0; i < lx.size(); i++) { Float f = lx.get(i); x[i] = ((f != null) ? f : Float.NaN); } float[] y = new float[ly.size()]; for (int i = 0; i < ly.size(); i++) { Float f = ly.get(i); y[i] = ((f != null) ? f : Float.NaN); } if (verticesNum < 3) { return false; } boolean oddNodes = false; float x2 = x[verticesNum - 1]; float y2 = y[verticesNum - 1]; float x1; float y1; for (int i = 0; i < verticesNum; x2 = x1, y2 = y1, ++i) { x1 = x[i]; y1 = y[i]; if (((y1 < py) && (y2 >= py)) || ((y1 >= py) && (y2 < py))) { if (((py - y1) / (y2 - y1) * (x2 - x1)) < (px - x1)) { oddNodes = !oddNodes; } } } return oddNodes; } }
TopologyUtils { public static boolean contains(FreedomShape fShape, FreedomPoint fPoint) { ArrayList<Float> lx = new ArrayList<Float>(); ArrayList<Float> ly = new ArrayList<Float>(); int verticesNum = 0; float px = fPoint.getX(); float py = fPoint.getY(); if (fShape instanceof FreedomPolygon) { FreedomPolygon poly = (FreedomPolygon) fShape; verticesNum = poly.getPoints().size(); for (int i = 0; i < poly.getPoints().size(); i++) { lx.add((float) poly.getPoints().get(i).getX()); ly.add((float) poly.getPoints().get(i).getY()); } } float[] x = new float[lx.size()]; for (int i = 0; i < lx.size(); i++) { Float f = lx.get(i); x[i] = ((f != null) ? f : Float.NaN); } float[] y = new float[ly.size()]; for (int i = 0; i < ly.size(); i++) { Float f = ly.get(i); y[i] = ((f != null) ? f : Float.NaN); } if (verticesNum < 3) { return false; } boolean oddNodes = false; float x2 = x[verticesNum - 1]; float y2 = y[verticesNum - 1]; float x1; float y1; for (int i = 0; i < verticesNum; x2 = x1, y2 = y1, ++i) { x1 = x[i]; y1 = y[i]; if (((y1 < py) && (y2 >= py)) || ((y1 >= py) && (y2 < py))) { if (((py - y1) / (y2 - y1) * (x2 - x1)) < (px - x1)) { oddNodes = !oddNodes; } } } return oddNodes; } private  TopologyUtils(); }
TopologyUtils { public static boolean contains(FreedomShape fShape, FreedomPoint fPoint) { ArrayList<Float> lx = new ArrayList<Float>(); ArrayList<Float> ly = new ArrayList<Float>(); int verticesNum = 0; float px = fPoint.getX(); float py = fPoint.getY(); if (fShape instanceof FreedomPolygon) { FreedomPolygon poly = (FreedomPolygon) fShape; verticesNum = poly.getPoints().size(); for (int i = 0; i < poly.getPoints().size(); i++) { lx.add((float) poly.getPoints().get(i).getX()); ly.add((float) poly.getPoints().get(i).getY()); } } float[] x = new float[lx.size()]; for (int i = 0; i < lx.size(); i++) { Float f = lx.get(i); x[i] = ((f != null) ? f : Float.NaN); } float[] y = new float[ly.size()]; for (int i = 0; i < ly.size(); i++) { Float f = ly.get(i); y[i] = ((f != null) ? f : Float.NaN); } if (verticesNum < 3) { return false; } boolean oddNodes = false; float x2 = x[verticesNum - 1]; float y2 = y[verticesNum - 1]; float x1; float y1; for (int i = 0; i < verticesNum; x2 = x1, y2 = y1, ++i) { x1 = x[i]; y1 = y[i]; if (((y1 < py) && (y2 >= py)) || ((y1 >= py) && (y2 < py))) { if (((py - y1) / (y2 - y1) * (x2 - x1)) < (px - x1)) { oddNodes = !oddNodes; } } } return oddNodes; } 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); }
TopologyUtils { public static boolean contains(FreedomShape fShape, FreedomPoint fPoint) { ArrayList<Float> lx = new ArrayList<Float>(); ArrayList<Float> ly = new ArrayList<Float>(); int verticesNum = 0; float px = fPoint.getX(); float py = fPoint.getY(); if (fShape instanceof FreedomPolygon) { FreedomPolygon poly = (FreedomPolygon) fShape; verticesNum = poly.getPoints().size(); for (int i = 0; i < poly.getPoints().size(); i++) { lx.add((float) poly.getPoints().get(i).getX()); ly.add((float) poly.getPoints().get(i).getY()); } } float[] x = new float[lx.size()]; for (int i = 0; i < lx.size(); i++) { Float f = lx.get(i); x[i] = ((f != null) ? f : Float.NaN); } float[] y = new float[ly.size()]; for (int i = 0; i < ly.size(); i++) { Float f = ly.get(i); y[i] = ((f != null) ? f : Float.NaN); } if (verticesNum < 3) { return false; } boolean oddNodes = false; float x2 = x[verticesNum - 1]; float y2 = y[verticesNum - 1]; float x1; float y1; for (int i = 0; i < verticesNum; x2 = x1, y2 = y1, ++i) { x1 = x[i]; y1 = y[i]; if (((y1 < py) && (y2 >= py)) || ((y1 >= py) && (y2 < py))) { if (((py - y1) / (y2 - y1) * (x2 - x1)) < (px - x1)) { oddNodes = !oddNodes; } } } return oddNodes; } 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);  }