コード例 #1
0
ファイル: NewPolygon2D.java プロジェクト: 4ment/beast-mcmc
  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;
  }
コード例 #2
0
ファイル: NewPolygon2D.java プロジェクト: 4ment/beast-mcmc
        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;
        }
コード例 #3
0
ファイル: NewPolygon2D.java プロジェクト: 4ment/beast-mcmc
  public static void main(String[] args) {
    NewPolygon2D polygon = new NewPolygon2D();
    polygon.moveTo(new Point2D.Double(-10, -10));
    polygon.lineTo(new Point2D.Double(-10, 50));
    polygon.lineTo(new Point2D.Double(10, 50));
    polygon.lineTo(new Point2D.Double(10, -10));
    polygon.lineTo(new Point2D.Double(-10, -10));
    //        polygon.closePath();
    System.out.println(polygon);
    System.out.println("");
    //        System.exit(-1);

    Point2D pt = new Point2D.Double(0, 0);
    System.out.println("polygon contains " + pt + ": " + polygon.contains(pt));
    pt = new Point2D.Double(100, 100);
    System.out.println("polygon contains " + pt + ": " + polygon.contains(pt));
    System.out.println("");

    Rectangle2D boundingBox =
        new Rectangle2D.Double(0, 0, 100, 100); // defines lower-left corner and width/height
    System.out.println(boundingBox);
    NewPolygon2D myClip = polygon.clip(boundingBox);
    System.out.println(myClip);
  }