public Polygon2D(double[] x, double[] y) { if (x.length != y.length) { throw new RuntimeException("Unbalanced arrays"); } if (x[0] != x[x.length - 1] && y[0] != y[y.length - 1]) { double[] newX = new double[x.length + 1]; double[] newY = new double[y.length + 1]; System.arraycopy(x, 0, newX, 0, x.length); System.arraycopy(y, 0, newY, 0, y.length); newX[x.length] = x[0]; newY[y.length] = y[0]; this.x = newX; this.y = newY; } else { this.x = x; this.y = y; } length = this.x.length - 1; }
public NewPolygon2D clip(Rectangle2D boundingBox) { Area thisArea = new Area(path); thisArea.intersect(new Area(boundingBox)); PathIterator iterator = thisArea.getPathIterator(null); double[] v = new double[2]; while (!iterator.isDone()) { int type = iterator.currentSegment(v); System.err.println(":" + v[0] + v[1] + "\n"); iterator.next(); } System.exit(-1); GeneralPath path = new GeneralPath(thisArea); path.closePath(); NewPolygon2D newPolygon = new NewPolygon2D(path); newPolygon.setFillValue(this.getFillValue()); return newPolygon; }