Exemplo n.º 1
0
 private Pair<Point2D, Point2D> getAPointInReachblePartEdges(Area area, Edge relatedEdge) {
   Point2D point = null;
   Edge rEdge = null;
   if (area instanceof Road) {
     Road road = (Road) area;
     FOR:
     for (SOSArea reachablePart : road.getReachableParts()) {
       for (Edge edge : reachablePart.getEdges()) {
         if (edge.getReachablityIndex() >= 0
             && area.getEdges().get(edge.getReachablityIndex()).equals(relatedEdge)) {
           point = edge.getMidPoint();
           rEdge = edge;
           break FOR;
         }
       }
     }
   }
   if (point == null) {
     point = relatedEdge.getMidPoint();
     rEdge = relatedEdge;
   }
   ArrayList<Point2D> twoPointForCheckContain =
       Utility.get2PointsAroundAPointOutOfLine(rEdge.getStart(), rEdge.getEnd(), point, 10);
   ArrayList<Point2D> twoPoint =
       Utility.get2PointsAroundAPointOutOfLine(rEdge.getStart(), rEdge.getEnd(), point, 3000);
   if (area.getShape().contains(twoPointForCheckContain.get(0).toGeomPoint()))
     return new Pair<Point2D, Point2D>(twoPoint.get(0), twoPoint.get(1));
   else return new Pair<Point2D, Point2D>(twoPoint.get(1), twoPoint.get(0));
 }
Exemplo n.º 2
0
  private void computeCenter(int[] apexes) {

    rescuecore2.geometry.Point2D p = SOSGeometryTools.computeCentroid(apexes);
    centerX = (int) p.getX();
    centerY = (int) p.getY();
    if (apexes.length < 6) return;
    try {
      Point2D point1 = null, point2 = null, middlePoint = null;
      ArrayList<rescuecore2.geometry.Point2D> twoPointOutOfLine = null;
      if (!contains(centerX, centerY)) { // if the point is not inside the polygon
        /////////////////////// finding a point inside polygon////////////////
        FOR:
        for (int i = 0; i < apexes.length - 2; i += 2) {
          point1 = new rescuecore2.geometry.Point2D(apexes[i], apexes[i + 1]);
          point2 = new rescuecore2.geometry.Point2D(apexes[i + 2], apexes[i + 3]);
          middlePoint =
              new rescuecore2.geometry.Point2D(
                  (apexes[i] + apexes[i + 2]) / 2, (apexes[i + 1] + apexes[i + 3]) / 2);
          twoPointOutOfLine =
              Utility.get2PointsAroundAPointOutOfLine(point1, point2, middlePoint, 2);
          for (rescuecore2.geometry.Point2D point2d : twoPointOutOfLine) {
            if (contains(point2d.getX(), point2d.getY())) {
              centerX = (int) point2d.getX();
              centerY = (int) point2d.getY();
              break FOR;
            }
          }
        }
        /*
        if (!contains(centerX, centerY)) {
        	debug.show("SOS Shape", new ShapeDebugFrame.AWTShapeInfo(this, "apexes=" + Arrays.toString(apexes), Color.blue, false),
        			new ShapeDebugFrame.Point2DShapeInfo(point1, "Point 1", Color.red, true),
        			new ShapeDebugFrame.Point2DShapeInfo(point2, "Point 2", Color.green, true),
        			new ShapeDebugFrame.Point2DShapeInfo(middlePoint, "middlePoint", Color.pink, true),
        			new ShapeDebugFrame.Point2DShapeInfo(twoPointOutOfLine.get(0), "twoPointOutOfLine 1", Color.magenta, true),
        			new ShapeDebugFrame.Point2DShapeInfo(twoPointOutOfLine.get(1), "twoPointOutOfLine 2", Color.black, true),
        			new ShapeDebugFrame.DetailInfo("area:" + SOSGeometryTools.computeAreaUnsigned(apexes))
        			);
        }
        */
        ///////////////////////////////////////////////////////////////////////
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.err.println(this.getClass().getSimpleName() + " have error" + e.getMessage());
    }
  }