Beispiel #1
0
 public FGEArea getAllowedHorizontalConnectorLocationFromWest2() {
   double maxY = Double.NEGATIVE_INFINITY;
   double minY = Double.POSITIVE_INFINITY;
   for (ControlPoint cp : getControlPoints()) {
     FGEPoint p = cp.getPoint();
     FGEHalfLine hl = new FGEHalfLine(p.x, p.y, p.x - 1, p.y);
     FGEArea inters = getShape().intersect(hl);
     System.out.println("inters=" + inters);
     if (inters instanceof FGEPoint || inters instanceof FGEEmptyArea) {
       // Consider this point
       if (p.y > maxY) {
         maxY = p.y;
       }
       if (p.y < minY) {
         minY = p.y;
       }
     }
   }
   FGEHalfLine north = new FGEHalfLine(0, minY, -1, minY);
   FGEHalfLine south = new FGEHalfLine(0, maxY, -1, maxY);
   /*
    * FGEHalfLine north = new FGEHalfLine(0,0,-1,0); FGEHalfLine south =
    * new FGEHalfLine(0,1,-1,1);
    */
   if (north.overlap(south)) {
     System.out.println("Return a " + north.intersect(south));
     return north.intersect(south);
   }
   return new FGEHalfBand(north, south);
 }
  /**
   * Return nearest point from point "from" following supplied orientation
   *
   * <p>Returns null if no intersection was found
   *
   * @param from point from which we are coming to area
   * @param orientation orientation we are coming from
   * @return
   */
  @Override
  public FGEPoint nearestPointFrom(FGEPoint from, SimplifiedCardinalDirection orientation) {
    FGEHalfLine hl = FGEHalfLine.makeHalfLine(from, orientation);

    FGEArea intersection = computeLineIntersection(hl);
    if (intersection instanceof FGEEmptyArea) {
      return null;
    } else if (intersection instanceof FGEPoint) {
      return (FGEPoint) intersection;
    } else if (intersection instanceof FGEUnionArea) {
      double minimalDistanceSq = java.lang.Double.POSITIVE_INFINITY;
      FGEPoint returned = null;
      for (FGEArea a : ((FGEUnionArea) intersection).getObjects()) {
        if (a instanceof FGEPoint) {
          double distSq = FGEPoint.distanceSq(from, (FGEPoint) a);
          if (distSq < minimalDistanceSq) {
            returned = (FGEPoint) a;
            minimalDistanceSq = distSq;
          }
        }
      }
      return returned;
    } else if (intersection instanceof FGESegment) {
      FGEPoint p1, p2;
      p1 = ((FGESegment) intersection).getP1();
      p2 = ((FGESegment) intersection).getP2();
      if (FGEPoint.distanceSq(from, p1) < FGEPoint.distanceSq(from, p2)) {
        return p1;
      } else {
        return p2;
      }
    } else {
      logger.warning("Unexpected area: " + intersection);
      return null;
    }

    /*if (getNorthWestRoundBounds().contains(returned)) {
    	//System.out.println("outlineIntersect() in NW");
    	return getNorthWestRound().nearestPointFrom(returned,orientation);
    }

    if (getSouthWestRoundBounds().contains(returned)) {
    	//System.out.println("outlineIntersect() in SW");
    	return getSouthWestRound().nearestPointFrom(returned,orientation);
    }

    if (getNorthEastRoundBounds().contains(returned)) {
    	//System.out.println("outlineIntersect() in NE");
    	return getNorthEastRound().nearestPointFrom(returned,orientation);
    }


    if (getSouthEastRoundBounds().contains(returned)) {
    	//System.out.println("outlineIntersect() in SE");
    	return getSouthEastRound().nearestPointFrom(returned,orientation);
    }*/

    // return returned;
  }