Example #1
0
  public List<waypoint> hatchfill() {
    List<LineLatLng> gridLines = generateGrid(poly.getWaypoints(), angle, lineDist);
    List<LineLatLng> hatchLines = trimGridLines(poly.getWaypoints(), gridLines);
    List<waypoint> gridPoints = waypointsFromHatch(lastLocation, altitude, hatchLines);

    return gridPoints;
  }
Example #2
0
  public Shape prune() {
    Polygon result = new Polygon();

    for (int i = 0; i < getPointCount(); i++) {
      int next = i + 1 >= getPointCount() ? 0 : i + 1;
      int prev = i - 1 < 0 ? getPointCount() - 1 : i - 1;

      float dx1 = getPoint(i)[0] - getPoint(prev)[0];
      float dy1 = getPoint(i)[1] - getPoint(prev)[1];
      float dx2 = getPoint(next)[0] - getPoint(i)[0];
      float dy2 = getPoint(next)[1] - getPoint(i)[1];

      float len1 = MathUtils.sqrt((dx1 * dx1) + (dy1 * dy1));
      float len2 = MathUtils.sqrt((dx2 * dx2) + (dy2 * dy2));
      dx1 /= len1;
      dy1 /= len1;
      dx2 /= len2;
      dy2 /= len2;

      if ((dx1 != dx2) || (dy1 != dy2)) {
        result.addPoint(getPoint(i)[0], getPoint(i)[1]);
      }
    }

    return result;
  }
  /** @param renderer */
  public final void renderRemaining(
      final PolygonRasterizer
          renderer /*,final int xmin, final int xmax, final int ymin, final int ymax*/) {
    // renderer.setWindow(xmin,xmax,ymin,ymax);
    //		for (int i = polygonCount; i > 0;) {
    //			renderer.renderPolygon(polygons[--i],vertexData,polygons[i].getShader().isOutline());
    //			polygons[i].setShader(null);
    //		}
    //		for (int i = 0; i < transparentPolygonCount; i++) {
    //
    //	renderer.renderPolygon(transparentPolygons[i],vertexData,transparentPolygons[i].getShader().isOutline());
    //			transparentPolygons[i].setShader(null);
    //		}
    // System.out.println("polys "+ polygonCount);

    // we render the polygons front to back in order to have less to do in setPixel. transparent
    // polys are
    // sorted in reverse order and at the beginning, so we know, that they are rendered last and in
    // back to front order.
    //		for (int i = polygonCount; i > 0;) {
    //			renderer.renderPolygon(polygons[--i],vertexData,polygons[i].getShader().isOutline());
    //			polygons[i].setShader(null);
    //		}

    for (int i = 0; i < (polygonCount); i++) {
      Polygon p = polygons[i];
      renderer.renderPolygon(p, vertexData, p.getShader().isOutline());
      p.setShader(null);
      // System.out.println("centerZ "+p.getCenterZ() );
    }
  }
Example #4
0
  private void draw_horizon(int rad, Point center, int[] angles) {
    // Draw an arc
    int arc_angle =
        ((angles[0] > angles[1]) ? (360 - angles[0]) + angles[1] : (angles[1] - angles[0]));

    Polygon remainder = new Polygon();

    offgraphics_.setColor(GREEN);
    offgraphics_.fillArc(center.x - rad, center.y - rad, 2 * rad, 2 * rad, angles[0], arc_angle);

    if (pitch_ != 0) {
      if ((pitch_ > 0 && Math.abs(roll_) < 90) || (pitch_ < 0 && Math.abs(roll_) >= 90))
        offgraphics_.setColor(BLUE);

      int cover_angle = (angles[0] + arc_angle / 2 + ((arc_angle < 180) ? 180 : 0)) % 360;

      // System.out.println (points[0] + " " + points[1]);

      // System.out.println (accepted_point);

      remainder.addPoint(
          center.x + polar_to_rect_x(rad, cover_angle),
          center.y - polar_to_rect_y(rad, cover_angle));
      remainder.addPoint(
          center.x + polar_to_rect_x(rad, angles[0]), center.y - polar_to_rect_y(rad, angles[0]));
      remainder.addPoint(
          center.x + polar_to_rect_x(rad, angles[1]), center.y - polar_to_rect_y(rad, angles[1]));
      offgraphics_.fillPolygon(remainder);
      // offgraphics_.setColor (getBackground ());
      // offgraphics_.drawPolygon (remainder);
    }
  }
  public void testPolygon() throws Exception {
    Polygon polygon = new Polygon();

    {
      LineString lineString = new LineString();
      lineString.addPoint(new Point(1, 2));
      lineString.addPoint(new Point(3, 4));
      lineString.addPoint(new Point(5, 6));
      lineString.addPoint(new Point(1, 2));

      polygon.addLinearRing(lineString);
    }

    StringWriter sw = new StringWriter();
    JSONWriter jsonWriter = new JSONWriter(sw);

    GeoJsonGeometryWriter geoWriter = new GeoJsonGeometryWriter();

    geoWriter.writeGeometry(jsonWriter, polygon);

    if (false
        == "{\"type\":\"Polygon\",\"coordinates\":[[[1,2],[3,4],[5,6],[1,2]]]}"
            .equals(sw.toString())) {
      fail("Unexpected output");
    }
  }
Example #6
0
  /**
   * make new shape polygon
   *
   * @param p
   * @param polygon
   * @param intersectPoint
   */
  private Polygon reMakePolygonShape(Polygon p, Polygon polygon, List<Point2D> intersectPoint) {
    ConvexHull convexHull;

    List<Point> newPoints = new ArrayList<Point>();

    for (int j = 0; j < p.npoints; j++) {
      if (polygon.contains(p.xpoints[j], p.ypoints[j])) {
        newPoints.add(new Point(p.xpoints[j], p.ypoints[j]));
      }
    }

    for (Point2D point2D : intersectPoint) {
      newPoints.add(new Point((int) point2D.getX(), (int) point2D.getY()));
    }

    for (int i = 0; i < polygon.npoints; i++) {
      if (p.contains(polygon.xpoints[i], polygon.ypoints[i])) {
        Point point = new Point(polygon.xpoints[i], polygon.ypoints[i]);
        newPoints.add(point);
      }
    }

    convexHull = new ConvexHull();

    for (Point point : newPoints) {
      convexHull.addPoint((int) point.getX(), (int) point.getY());
    }

    Polygon polygon1 = convexHull.convex();
    //        newPoints.clear();

    return polygon1;
  }
Example #7
0
  private static void graph(Polygon[] finalPolygons) {
    int weiners = 0;
    String[] Starter = sPoint.split(",");
    String[] Ender = ePoint.split(",");
    int endx = Integer.parseInt(Ender[0]);
    int endy = Integer.parseInt(Ender[1]);
    int G = 40;
    for (int i = 0; i < G; i++) {
      for (int j = 0; j < G; j++) {
        int loketest = 0;
        if ((i == Startx && j == Starty) || i == endx && j == endy) {
          loketest = 2;
        }
        for (Polygon helpme : finalPolygons) {
          if (helpme.contains(i, j)) {
            loketest = 1;
          }
        }
        if (loketest == 1) {
          System.out.print("1");
        } else if (loketest == 2) {
          System.out.print("X");
        } else {
          System.out.print("0");
        }
      }

      System.out.println("     \t");
      weiners++;
    }
  }
  public static void main(String[] args) {
    Point p1 = new Point(1.1, 2.2, 3.3, 1);
    Point p2 = new Point(0.5, 1.5, 2.5, 2);
    Point p3 = new Point(9.4, 10.2, 1.1, 3);

    Triangle tr = new Triangle(p1, p2, p3);

    if (tr.isEmpty()) {
      System.out.println("empty");
    } else {
      System.out.println("not empty");
    }

    System.out.println("tr.vertex(2) coodinateDemension : " + tr.vertex(2).coordinateDimension());
    System.out.println("tr.vertex(2) demension : " + tr.vertex(2).dimension());
    System.out.println("tr.vertex(2) m : " + tr.vertex(2).m());

    Triangle tr2 = new Triangle(tr);
    System.out.println("tr2 = tr.reverse()");
    tr2.reverse();
    System.out.println("tr2.vertex(2) coodinateDemension : " + tr2.vertex(2).coordinateDimension());
    System.out.println("tr2.vertex(2) demension : " + tr2.vertex(2).dimension());
    System.out.println("tr2.vertex(2) m : " + tr2.vertex(2).m());

    Polygon polygon = tr.toPolygon();
    System.out.println("polygon.numRings() " + polygon.numRings());
  }
Example #9
0
 /** @param args the command line arguments */
 public static void main(String[] args) {
   // TODO code application logic here
   JBrushWindow appWindow;
   appWindow = new JBrushWindow("JBrush");
   appWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   appWindow.setSize(1024, 768);
   appWindow.setVisible(true);
   Camera cam = new Camera(200, 100, 100, appWindow.getWidth() / 2, appWindow.getHeight() / 2, 5);
   Polygon poly =
       new Polygon(
           new Vertex(500, 800, 800),
           new Vertex(500, 800, 500),
           new Vertex(800, 800, 500),
           new Vertex(800, 800, 800));
   poly.scanlineFill();
   ArrayList<Point2D> pixelBuffer = new ArrayList<>();
   for (Pixel_3D pixel : poly.pixelBuffer) {
     Point2D projectedPixel = cam.project(pixel);
     Graphics g = appWindow.getGraphics();
     g.setColor(Color.GRAY);
     g.fillRect(
         (int) projectedPixel.x,
         (int) projectedPixel.y,
         (int) projectedPixel.x + 1,
         (int) projectedPixel.y + 1);
     appWindow.paint(g);
   }
 }
Example #10
0
 /** NOTE: the connection from java to matlab */
 public RCvalue java2Matlab() throws EvalException {
   if (rc == null) {
     if (poly != null) {
       Value[] v = new Value[poly.degree()];
       for (int i = 0; i < v.length; i++) {
         Point pt = poly.point(i);
         assert pt.type() == CohoDouble.type
             : "The result type is not CohoDouble, it is " + pt.type();
         //					if(pt.type()!=CohoDouble.type){
         //					throw new RuntimeException("The result type is not CohoDouble, it is "+pt.type() );
         //					}
         v[i] =
             RCvalue.factory()
                 .create(
                     new Value[] {
                       DoubleValue.factory()
                           .create(new Double(((CohoDouble) pt.x()).doubleValue()), null),
                       DoubleValue.factory()
                           .create(new Double(((CohoDouble) pt.y()).doubleValue()), null)
                     },
                     false);
       }
       rc = (RCvalue) (RCvalue.factory().create(v, true));
     } else { // empty polygon
       rc = (RCvalue) (RCvalue.factory().create(new Value[0], true));
     }
   }
   return (rc);
 }
Example #11
0
  private Polygon editPolygon(Polygon polygon, GeometryEditorOperation operation) {
    Polygon newPolygon = (Polygon) operation.edit(polygon, factory);
    // create one if needed
    if (newPolygon == null) newPolygon = factory.createPolygon((CoordinateSequence) null);
    if (newPolygon.isEmpty()) {
      // RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino]
      return newPolygon;
    }

    LinearRing shell = (LinearRing) edit(newPolygon.getExteriorRing(), operation);
    if (shell == null || shell.isEmpty()) {
      // RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino]
      return factory.createPolygon(null, null);
    }

    ArrayList holes = new ArrayList();
    for (int i = 0; i < newPolygon.getNumInteriorRing(); i++) {
      LinearRing hole = (LinearRing) edit(newPolygon.getInteriorRingN(i), operation);
      if (hole == null || hole.isEmpty()) {
        continue;
      }
      holes.add(hole);
    }

    return factory.createPolygon(shell, (LinearRing[]) holes.toArray(new LinearRing[] {}));
  }
Example #12
0
  protected Geometry transformPolygon(Polygon geom, Geometry parent) {
    boolean isAllValidLinearRings = true;
    Geometry shell = transformLinearRing((LinearRing) geom.getExteriorRing(), geom);

    if (shell == null || !(shell instanceof LinearRing) || shell.isEmpty())
      isAllValidLinearRings = false;
    // return factory.createPolygon(null, null);

    ArrayList holes = new ArrayList();
    for (int i = 0; i < geom.getNumInteriorRing(); i++) {
      Geometry hole = transformLinearRing((LinearRing) geom.getInteriorRingN(i), geom);
      if (hole == null || hole.isEmpty()) {
        continue;
      }
      if (!(hole instanceof LinearRing)) isAllValidLinearRings = false;

      holes.add(hole);
    }

    if (isAllValidLinearRings)
      return factory.createPolygon(
          (LinearRing) shell, (LinearRing[]) holes.toArray(new LinearRing[] {}));
    else {
      List components = new ArrayList();
      if (shell != null) components.add(shell);
      components.addAll(holes);
      return factory.buildGeometry(components);
    }
  }
Example #13
0
 @Override
 public boolean isInBounds(Bounds bounds) {
   // TODO there is no float polygon, so I have to think about s.th. else (or leave it the way it
   // is now)
   int x[] = new int[nodes.length];
   int y[] = new int[nodes.length];
   int i = 0;
   for (Node node : nodes) {
     x[i] = (int) (node.getPos().getLongitude() * 1000); // 1000 is a random factor, can be changed
     i++;
   }
   i = 0;
   for (Node node : nodes) {
     y[i] = (int) (node.getPos().getLatitude() * 1000);
     i++;
   }
   Polygon area = new Polygon(x, y, nodes.length);
   Rectangle2D.Double box =
       new Rectangle2D.Double(
           bounds.getLeft() * 1000 - 1,
           bounds.getTop() * 1000 - 1,
           bounds.getWidth() * 1000 + 1,
           bounds.getHeight() * 1000 + 1);
   boolean inside = false;
   for (Node node : nodes) {
     if (node.isInBounds(bounds)) {
       inside = true;
     }
   }
   return inside || area.contains(box) || area.intersects(box);
 }
Example #14
0
  /**
   * Draw the LineSelection at its current location. It is the responsibility of the
   * applet/application to draw the LineSelection at the appropriate times, e.g., inside the
   * component's update() and/or paint() method. This gives maximum flexibility for double
   * buffering, etc.
   *
   * @param g The Graphics context to use for drawing.
   */
  public void draw(Graphics g) {

    if (!isVisible()) {
      return;
    }

    Color saveColor = g.getColor();
    g.setColor(color);
    if (thickness > 1) {
      double ratio = ((double) thickness) / ((double) length());
      double txdb = ratio * ((double) height) / 2.0;
      int tx = txdb > 0 ? ((int) Math.ceil(txdb)) : ((int) Math.floor(txdb));
      double tydb = -ratio * ((double) width) / 2.0;
      int ty = tydb > 0 ? ((int) Math.ceil(tydb)) : ((int) Math.floor(tydb));
      Point[] poly = new Point[4];
      for (int i = 0; i < 4; i++) poly[i] = new Point(x, y);
      poly[0].translate(tx, ty);
      poly[1].translate(-tx, -ty);
      poly[2].translate(width, height);
      poly[2].translate(-tx, -ty);
      poly[3].translate(width, height);
      poly[3].translate(tx, ty);
      Polygon polygon = new Polygon();
      for (int i = 0; i < 4; i++) polygon.addPoint(poly[i].x, poly[i].y);
      g.fillPolygon(polygon);
    } else g.drawLine(x, y, x + width, y + height);
    g.setColor(saveColor);
  } // end draw
 @Test
 public void testPolygon() throws SQLException {
   logger.trace("void testPolygon()");
   logger.info(plg_str);
   Polygon plg = new Polygon(plg_str);
   logger.info(plg.toString());
 }
Example #16
0
 public static void drawPolygon(
     Graphics g,
     int x1,
     int y1,
     int x2,
     int y2,
     int x3,
     int y3,
     int x4,
     int y4,
     int x5,
     int y5,
     int x6,
     int y6,
     int x7,
     int y7,
     int x8,
     int y8) {
   Polygon myPoly = new Polygon();
   myPoly.addPoint(x1, y1);
   myPoly.addPoint(x2, y2);
   myPoly.addPoint(x3, y3);
   myPoly.addPoint(x4, y4);
   myPoly.addPoint(x5, y5);
   myPoly.addPoint(x6, y6);
   myPoly.addPoint(x7, y7);
   myPoly.addPoint(x8, y8);
   g.drawPolygon(myPoly);
 }
Example #17
0
  /** make new shape polygon */
  private void reMakePolygonShape() {
    ConvexHull convexHull;

    List<Point> newPoints = new ArrayList<Point>();

    for (int j = 0; j < polygon.npoints; j++) {

      if (mainClusterShape.contains(polygon.xpoints[j], polygon.ypoints[j])) {
        newPoints.add(new Point(polygon.xpoints[j], polygon.ypoints[j]));
      }
    }

    for (Point2D point2D : getIntersectPoint()) {
      newPoints.add(new Point((int) point2D.getX(), (int) point2D.getY()));
    }

    for (int i = 0; i < mainClusterShape.npoints; i++) {
      if (polygon.contains(mainClusterShape.xpoints[i], mainClusterShape.ypoints[i])) {
        Point point = new Point(mainClusterShape.xpoints[i], mainClusterShape.ypoints[i]);
        newPoints.add(point);
      }
    }

    convexHull = new ConvexHull();

    for (Point point : newPoints) {
      convexHull.addPoint((int) point.getX(), (int) point.getY());
    }

    setPolygon(convexHull.convex());
    newPoints.clear();
  }
 private Seq<PolygonwithHoles> buildMultipolygons(
     Hashtable<Long, Point2D> nodes,
     Hashtable<Long, List<Long>> multipolygonWays,
     List<List<Tuple2<WayRole, Long>>> multipolygonWayRefs) {
   return Seq.seq(multipolygonWayRefs)
       .map(
           waysOfPoly -> {
             try {
               // I know this not how should assemble them, but parsing OSM wasn't our objective.
               List<Polygon> holes = new ArrayList<>();
               Polygon outer = null;
               for (Tuple2<WayRole, Long> way : waysOfPoly) {
                 WayRole role = way.v1;
                 long wayRef = way.v2;
                 List<Long> nodeRefs = multipolygonWays.get(wayRef);
                 Polygon p = buildPolygonFromWayRefs(nodeRefs, nodes);
                 if (role == WayRole.OUTER && outer == null && p.GetPointsNumber() > 0) {
                   outer = p;
                 } else if (role == WayRole.INNER && p.GetPointsNumber() > 0) {
                   holes.add(p);
                 } else {
                   LOG.warn("Could not process a way");
                 }
               }
               return new PolygonwithHoles(outer, holes);
             } catch (Exception ex) {
               // System.out.println("Failed to build a certain multipolygon");
             }
             return null;
           })
       .filter(p -> p != null);
 }
Example #19
0
  /*
   * (non-Javadoc)
   *
   * @see com.sun.syndication.io.ModuleParser#parse(org.jdom.Element)
   */
  public Module parse(Element element) {
    GeoRSSModule geoRSSModule = null;
    new SimpleModuleImpl();

    Element pointElement = element.getChild("point", GeoRSSModule.SIMPLE_NS);
    Element lineElement = element.getChild("line", GeoRSSModule.SIMPLE_NS);
    Element polygonElement = element.getChild("polygon", GeoRSSModule.SIMPLE_NS);
    Element boxElement = element.getChild("box", GeoRSSModule.SIMPLE_NS);
    if (pointElement != null) {
      geoRSSModule = new SimpleModuleImpl();
      String coordinates = pointElement.getText();
      String[] coord = coordinates.trim().split(" ");
      Position pos = new Position(Double.parseDouble(coord[1]), Double.parseDouble(coord[0]));
      geoRSSModule.setGeometry(new Point(pos));
    } else if (lineElement != null) {
      geoRSSModule = new SimpleModuleImpl();
      PositionList posList = parsePosList(lineElement);
      geoRSSModule.setGeometry(new LineString(posList));
    } else if (polygonElement != null) {
      geoRSSModule = new SimpleModuleImpl();
      PositionList posList = parsePosList(polygonElement);
      Polygon poly = new Polygon();
      poly.setExterior(new LinearRing(posList));
      geoRSSModule.setGeometry(poly);
    } else {
      geoRSSModule = (GeoRSSModule) GMLParser.parseGML(element);
    }

    return geoRSSModule;
  }
Example #20
0
 /**
  * Draws a solid "filled-in" irregular polygon using between 3 and 12 sets of provided
  * coordinates. <br>
  * Examples: <br>
  * Expo.fillPolygon(g,100,300,200,100,300,300); // for a triangle
  * Expo.fillPolygon(g,525,300,600,250,650,250,725,300,725,350,650,400); // for a hexagon
  */
 public static void fillPolygon(Graphics g, int x1, int y1, int x2, int y2, int x3, int y3) {
   Polygon myPoly = new Polygon();
   myPoly.addPoint(x1, y1);
   myPoly.addPoint(x2, y2);
   myPoly.addPoint(x3, y3);
   g.fillPolygon(myPoly);
 }
Example #21
0
          public Value eval(RCvalue args) throws EvalException {
            if ((args.size() < 0) || (3 < args.size()))
              throw new EvalException("usage: reduce(polygon, [errtol,[edgeReducible] ] ])");
            if (!(args.value(0) instanceof PolygonValue))
              throw new EvalException("reduce: first operand must be a polygon");

            double errtol = defaultErrtol;
            if (args.size() >= 2) { // get error tolerance
              if (!(args.value(1) instanceof DoubleValue))
                throw new EvalException("reduce: second operand must be an integer");
              errtol = ((DoubleValue) (args.value(1))).value();
            }
            boolean edgeReducible = true;
            if (args.size() >= 3) {
              double temp = ((DoubleValue) (args.value(2))).value();
              edgeReducible = (temp > 0); // temp = 1, edge reducible, otherwise, not
            }

            Polygon.EndCondition ec = new Polygon.CostEndCondition(errtol);
            if (errtol >= 3) {
              int maxV = (int) Math.round(errtol);
              ec = new Polygon.DegreeEndCondition(maxV);
            }
            PolygonValue p = (PolygonValue) (args.value(0));
            Polygon poly = p.polygon();
            if (poly instanceof ConvexPolygon) { // NOTE: connection for reduce
              if (edgeReducible) return new PolygonValue(((ConvexPolygon) poly).reduce(ec));
              else return p; // can't reduce because convex polygon can only reduce edge
            } else {
              return new PolygonValue(poly.reduce(ec, true, edgeReducible));
            }
          }
Example #22
0
  @Test
  public void testSetPointsWithExceptions() {
    ArrayList<Point> points = new ArrayList<Point>();

    // Kein Punkt
    try {
      poly.setPoints(points);
      fail("setPoints mit 0 Punkten sollte eine PolygonShapeException auslösen");
    } catch (PolygonShapeException e) {
    }

    // Ein Punkt
    points.add(new Point(12, 34));
    try {
      poly.setPoints(points);
      fail("setPoints mit 1 Punkt sollte eine PolygonShapeException auslösen");
    } catch (PolygonShapeException e) {
    }

    // Zwei Punkte
    points.add(new Point(12, 34));
    try {
      poly.setPoints(points);
    } catch (PolygonShapeException e) {
      fail("setPoints mit 2 Punkten sollte keine PolygonShapeException auslösen");
    }
  }
Example #23
0
 public void printLoop(int n, float x[], float y[]) {
   // Need to swap the y component
   Polygon P = new Polygon();
   for (int i = 0; i < n; i++) P.addPoint(Math.round(x[i]), Math.round(height - y[i]));
   poly_draw.add(P);
   poly_draw_color.add(curColor);
 }
 private int getPolygonSize(Polygon geom) {
   // to hold the number of linear rings
   int size = ByteBuffer.UINT_SIZE;
   // for each linear ring, a UINT holds the number of points
   size += geom.isEmpty() ? 0 : ByteBuffer.UINT_SIZE * (geom.getNumInteriorRing() + 1);
   size += getPointByteSize(geom) * geom.getNumPoints();
   return size;
 }
Example #25
0
 public MutableQuad[][] bisect(Plane p) {
   Polygon poly = new Polygon(this);
   BisectedPolygon bi = poly.bisect(p);
   MutableQuad[][] quads = {{}, {}};
   if (bi.towards != null) quads[0] = bi.towards.toQuads();
   if (bi.away != null) quads[1] = bi.away.toQuads();
   return quads;
 }
Example #26
0
 public Value eval(RCvalue args) throws EvalException {
   if (args.size() != 1) throw new EvalException("usage: hull(polygon)");
   if (!(args.value(0) instanceof PolygonValue))
     throw new EvalException("hull: argument must be a polygon");
   PolygonValue pv = (PolygonValue) (args.value(0));
   Polygon poly = pv.polygon();
   return new PolygonValue(poly.convexHull()); // NOTE: connection for convex hull
 }
Example #27
0
 public Polygon addHole(Polygon poly, LinearRing hole) {
   int nOrigHoles = poly.getNumInteriorRing();
   LinearRing[] newHoles = new LinearRing[nOrigHoles + 1];
   for (int i = 0; i < nOrigHoles; i++) {
     newHoles[i] = (LinearRing) poly.getInteriorRingN(i);
   }
   newHoles[nOrigHoles] = hole;
   return geomFactory.createPolygon((LinearRing) poly.getExteriorRing(), newHoles);
 }
Example #28
0
 public static void drawPolygon(
     Graphics g, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
   Polygon myPoly = new Polygon();
   myPoly.addPoint(x1, y1);
   myPoly.addPoint(x2, y2);
   myPoly.addPoint(x3, y3);
   myPoly.addPoint(x4, y4);
   g.drawPolygon(myPoly);
 }
  /**
   * Tests whether a geometry consists of a single polygon with no holes.
   *
   * @return true if the geometry is a single polygon with no holes
   */
  private boolean isSingleShell(Geometry geom) {
    // handles single-element MultiPolygons, as well as Polygons
    if (geom.getNumGeometries() != 1) return false;

    Polygon poly = (Polygon) geom.getGeometryN(0);
    int numHoles = poly.getNumInteriorRing();
    if (numHoles == 0) return true;
    return false;
  }
 @Override
 public void visit(PolyHedralSurface geom) {
   writeByteOrder(output);
   DimensionalFlag dimension = DimensionalFlag.valueOf(geom.is3D(), geom.isMeasured());
   writeTypeCodeAndSrid(geom, dimension, output);
   output.putUInt(geom.getNumPatches());
   for (Polygon pg : geom) {
     pg.accept(this);
   }
 }