Example #1
0
  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;
  }
Example #2
0
        public Object parseXMLObject(XMLObject xo) throws XMLParseException {

          KMLCoordinates coordinates = (KMLCoordinates) xo.getChild(KMLCoordinates.class);
          boolean closed = xo.getAttribute(CLOSED, false);

          if ((!closed && coordinates.length < 3) || (closed && coordinates.length < 4))
            throw new XMLParseException(
                "Insufficient points in polygon '" + xo.getId() + "' to define a polygon in 2D");

          NewPolygon2D polygon = new NewPolygon2D();
          polygon.moveTo(new Point2D.Double(coordinates.x[0], coordinates.y[0]));
          int length = coordinates.length;
          if (closed) length--;
          for (int i = 1; i < length; i++)
            polygon.lineTo(new Point2D.Double(coordinates.x[i], coordinates.y[i]));
          polygon.lineTo(new Point2D.Double(coordinates.x[0], coordinates.y[0]));
          //            polygon.closePath();

          polygon.setFillValue(xo.getAttribute(FILL_VALUE, 0.0));

          return polygon;
        }