示例#1
0
  public Rectangle2D.Double layout(
      CompositeFigure compositeFigure, Point2D.Double anchor, Point2D.Double lead) {
    Rectangle2D.Double bounds = null;

    for (Figure child : compositeFigure.getChildren()) {
      Locator locator = getLocator(child);

      Rectangle2D.Double r;
      if (locator == null) {
        r = child.getBounds();
      } else {
        Point2D.Double p = locator.locate(compositeFigure, child);
        Dimension2DDouble d = child.getPreferredSize();
        r = new Rectangle2D.Double(p.x, p.y, d.width, d.height);
      }
      child.willChange();
      child.setBounds(
          new Point2D.Double(r.getMinX(), r.getMinY()),
          new Point2D.Double(r.getMaxX(), r.getMaxY()));
      child.changed();
      if (!r.isEmpty()) {
        if (bounds == null) {
          bounds = r;
        } else {
          bounds.add(r);
        }
      }
    }

    return (bounds == null) ? new Rectangle2D.Double() : bounds;
  }
示例#2
0
 @Override
 public Rectangle2D.Double getDrawingArea() {
   Rectangle2D.Double r =
       new Rectangle2D.Double(
           rec.getMinX() - 10, rec.getMinY() - 10, rec.getMaxX() + 10, rec.getMaxY() + 10);
   return r;
 }
示例#3
0
 // robot reference point is the origin
 public CSpace(Polygon robot, PolygonMap map) {
   Rectangle2D.Double worldRect = map.getWorldRect();
   constructor(
       robot, worldRect.getMinX(), worldRect.getMinY(), worldRect.getMaxX(), worldRect.getMaxY());
   for (PolygonObstacle obstacle : map.getObstacles()) {
     addObstacle(obstacle);
   }
 }
示例#4
0
  private void createLine() {
    if (lines == null) {
      lines = new ArrayList<Figure>();
      linesButt = new ArrayList<Figure>();
    }
    CurveFigure line0;
    CurveFigure line1;
    CurveFigure line2;
    CurveFigure line3;
    if (lines.isEmpty()) {
      line0 = new CurveFigure();
      line1 = new CurveFigure();
      line2 = new CurveFigure();
      line3 = new CurveFigure();
    } else {
      line0 = (CurveFigure) linesButt.get(0);
      line1 = (CurveFigure) lines.get(0);
      line2 = (CurveFigure) linesButt.get(1);
      line3 = (CurveFigure) lines.get(1);
    }
    line0.setStartPoint(new Point2D.Double(rec.getMinX(), rec.getMinY()));
    line0.setEndPoint(new Point2D.Double(rec.getMaxX(), rec.getMinY()));
    line0.setDirection(-1);

    line1.setStartPoint(new Point2D.Double(rec.getMaxX(), rec.getMinY()));
    line1.setEndPoint(new Point2D.Double(rec.getMaxX(), rec.getMaxY()));
    line1.setDirection(-1);

    line2.setStartPoint(new Point2D.Double(rec.getMaxX(), rec.getMaxY()));
    line2.setEndPoint(new Point2D.Double(rec.getMinX(), rec.getMaxY()));
    line2.setDirection(1);

    line3.setStartPoint(new Point2D.Double(rec.getMinX(), rec.getMaxY()));
    line3.setEndPoint(new Point2D.Double(rec.getMinX(), rec.getMinY()));
    line3.setDirection(-1);

    if (lines.isEmpty()) {
      linesButt.add(line0);
      lines.add(line1);
      linesButt.add(line2);
      lines.add(line3);
    }
  }
示例#5
0
 /**
  * Returns the distance from a point within a box to the edge of a box given the point and a
  * heading in robocode degrees.
  *
  * @param x x-coordinate of point inside box
  * @param y y-coordinate of point inside box
  * @param headingRoboDegrees heading from point in robocode degrees
  * @param box box containing point
  * @return distance between point and edge of box given heading
  */
 public static double getDistanceToIntersect(
     double x, double y, double headingRoboDegrees, Rectangle2D.Double box) {
   VelocityVector vv = new VelocityVector(headingRoboDegrees, 1);
   double endX = (vv.getX() > 0) ? box.getMaxX() : box.getMinX();
   double endY = (vv.getY() > 0) ? box.getMaxY() : box.getMinY();
   double timeToX = (endX - x) / vv.getX();
   double timeToY = (endY - y) / vv.getY();
   double timeToIntercept = Math.min(timeToX, timeToY);
   double x_i = x + timeToIntercept * vv.getX();
   double y_i = y + timeToIntercept * vv.getY();
   return getDistanceBetweenPoints(x, y, x_i, y_i);
 }
示例#6
0
 public CSpace(Polygon robot, Rectangle2D.Double worldRect) {
   constructor(
       robot, worldRect.getMinX(), worldRect.getMinY(), worldRect.getMaxX(), worldRect.getMaxY());
 }