Exemplo n.º 1
0
 private static boolean contains(CubicCurve2D.Double cubic, Rectangle2D... rects) {
   for (Rectangle2D r : rects) {
     if (r.contains(cubic.getP1()) && r.contains(cubic.getP2())) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 2
0
  public ResizeInfo getResizeInfo(int x, int y, int screenWidth, int screenHeight) {
    Rectangle2D r = getBounds(screenWidth, screenHeight);
    if (!r.contains(x, y)) {
      return null;
    }
    x -= r.getX();
    y -= r.getY();

    final int gap = 10;

    boolean north = y < gap;
    boolean west = x < gap;
    boolean south = y >= r.getHeight() - gap;
    boolean east = x >= r.getWidth() - gap;

    if (north) {
      if (west) {
        return new ResizeInfo(this, DragDirection.NORTH_WEST);
      }
      if (east) {
        return new ResizeInfo(this, DragDirection.NORTH_EAST);
      }
    } else if (south) {
      if (west) {
        return new ResizeInfo(this, DragDirection.SOUTH_WEST);
      }
      if (east) {
        return new ResizeInfo(this, DragDirection.SOUTH_EAST);
      }
    }

    return null;
  }
Exemplo n.º 3
0
 private static boolean contains(Point2D.Double point, Rectangle2D... rects) {
   for (Rectangle2D r : rects) {
     if (r.contains(point)) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 4
0
 public Variable getVariableAt(Point2D p) {
   Point2D q = new Point2D.Double();
   getParentToLocalTransform().transform(p, q);
   for (Rectangle2D rect : variableBBs.keySet()) {
     if (rect.contains(q)) return variableBBs.get(rect);
   }
   return null;
 }
Exemplo n.º 5
0
 /**
  * Обнаруживает первый квадрат, содержащий заданную точку
  *
  * @param p Точка
  * @return Первый квадрат, содержащий точку p
  */
 public Rectangle2D find(Point2D p) {
   for (Rectangle2D r : squares) {
     if (r.contains(p)) {
       return r;
     }
   }
   return null;
 }
Exemplo n.º 6
0
 /**
  * Handles a 'click' on the plot by updating the anchor values.
  *
  * @param x x-coordinate, where the click occured.
  * @param y y-coordinate, where the click occured.
  * @param info object containing information about the plot dimensions.
  */
 public void handleClick(int x, int y, PlotRenderingInfo info) {
   Rectangle2D dataArea = info.getDataArea();
   if (dataArea.contains(x, y)) {
     for (int i = 0; i < this.subplots.size(); i++) {
       XYPlot subplot = (XYPlot) this.subplots.get(i);
       PlotRenderingInfo subplotInfo = info.getSubplotInfo(i);
       subplot.handleClick(x, y, subplotInfo);
     }
   }
 }
Exemplo n.º 7
0
 /**
  * Checks whether the given render pass accepts the drag. When the render pass accepts the drag
  * everything is set up properly.
  *
  * @param r The render pass to check.
  * @param position The position in canvas coordinates.
  * @param e The mouse event.
  * @return Whether the drag was accepted.
  * @see #acceptDrag(Point2D, MouseEvent)
  */
 private boolean acceptDrag(final Renderpass r, final Point2D position, final MouseEvent e) {
   if (!r.isVisible()) return false;
   final Rectangle2D bbox = new Rectangle2D.Double();
   r.getBoundingBox(bbox);
   final Point2D pos = RenderpassPainter.getPositionFromCanvas(r, position);
   if (!bbox.contains(pos)) return false;
   if (!r.acceptDrag(pos, e)) return false;
   start = pos;
   dragging = r;
   return true;
 }
Exemplo n.º 8
0
 /**
  * @see prefuse.render.Renderer#locatePoint(java.awt.geom.Point2D, prefuse.visual.VisualItem)
  */
 @Override
 public boolean locatePoint(Point2D p, VisualItem item) {
   Shape s = getShape(item);
   if (s == null) {
     return false;
   } else if (s == m_box && m_box.contains(p)) {
     return true;
   } else {
     double width = Math.max(2, item.getSize());
     double halfWidth = width / 2.0;
     return s.intersects(p.getX() - halfWidth, p.getY() - halfWidth, width, width);
   }
 }
Exemplo n.º 9
0
  /**
   * Check if the user is close enough the parent entity of the slot. If the user is too far away
   * the window should not be opened, and it should be closed if it was already open.
   *
   * @param x x coordinate of the user
   * @param y y coordinate of the user
   * @return <code>true</code> if the user is close enough to have the window open, <code>false
   *     </code> otherwise.
   */
  private boolean isCloseEnough(final double x, final double y) {
    final int px = (int) x;
    final int py = (int) y;

    final Rectangle2D orig = parent.getArea();
    orig.setRect(
        orig.getX() - MAX_DISTANCE,
        orig.getY() - MAX_DISTANCE,
        orig.getWidth() + MAX_DISTANCE * 2,
        orig.getHeight() + MAX_DISTANCE * 2);

    return orig.contains(px, py);
  }
Exemplo n.º 10
0
 public void wallSmoothing(double absBearing) {
   double goalDirection = absBearing - Math.PI / 2 * moveDirection;
   Rectangle2D fieldRect =
       new Rectangle2D.Double(18, 18, getBattleFieldWidth() - 36, getBattleFieldHeight() - 36);
   while (!fieldRect.contains(
       getX() + Math.sin(goalDirection) * 120, getY() + Math.cos(goalDirection) * 120)) {
     goalDirection += moveDirection * .1;
   }
   double turn = robocode.util.Utils.normalRelativeAngle(goalDirection - getHeadingRadians());
   if (Math.abs(turn) > Math.PI / 2) {
     turn = robocode.util.Utils.normalRelativeAngle(turn + Math.PI);
     setBack(100);
   } else setAhead(100);
   setTurnRightRadians(turn);
 }
Exemplo n.º 11
0
 /**
  * Picks a layouted render pass.
  *
  * @param position The position.
  * @return The render pass at the given position or <code>null</code> if there is none.
  */
 protected Renderpass pickLayouted(final Point2D position) {
   final Rectangle2D bbox = new Rectangle2D.Double();
   for (final RenderpassPosition<T> p : reverseArray(members())) {
     final Renderpass r = p.pass;
     if (!r.isVisible()) {
       continue;
     }
     r.getBoundingBox(bbox);
     final Point2D pos = RenderpassPainter.getPositionFromCanvas(r, position);
     if (!bbox.contains(pos)) {
       continue;
     }
     return r;
   }
   return null;
 }
Exemplo n.º 12
0
 /**
  * Check if the connector may cross this point Optionally, returns a shape that defines the
  * boundaries of the area around this point that the connector may not cross. This method can be
  * used for advanced connectors that route along other objects on the drawing
  *
  * @return A shape that defines the boundaries of the area around this point that the connector
  *     may not cross. Returning null is allowed for implementing classes.
  */
 public Shape mayCross(Point2D point) {
   Pathway parent = getParent();
   Rectangle2D rect = null;
   if (parent != null) {
     for (PathwayElement e : parent.getDataObjects()) {
       ObjectType ot = e.getObjectType();
       if (ot == ObjectType.SHAPE || ot == ObjectType.DATANODE || ot == ObjectType.LABEL) {
         Rectangle2D b = e.getMBounds();
         if (b.contains(point)) {
           if (rect == null) rect = b;
           else rect.add(b);
         }
       }
     }
   }
   return rect;
 }
Exemplo n.º 13
0
 @Override
 public boolean click(final Camera cam, final Point2D position, final MouseEvent e) {
   if (RenderpassPainter.click(nlFront, cam, position, e)) return true;
   final Rectangle2D bbox = new Rectangle2D.Double();
   for (final RenderpassPosition<T> p : reverseArray(members())) {
     final Renderpass r = p.pass;
     if (!r.isVisible()) {
       continue;
     }
     r.getBoundingBox(bbox);
     final Point2D pos = RenderpassPainter.getPositionFromCanvas(r, position);
     if (!bbox.contains(pos)) {
       continue;
     }
     if (r.click(cam, pos, e)) return true;
   }
   return RenderpassPainter.click(nlBack, cam, position, e);
 }
Exemplo n.º 14
0
 @Override
 public String getTooltip(final Point2D position) {
   final String tt = RenderpassPainter.getTooltip(nlFront, position);
   if (tt != null) return tt;
   final Rectangle2D bbox = new Rectangle2D.Double();
   for (final RenderpassPosition<T> p : reverseArray(members())) {
     final Renderpass r = p.pass;
     if (!r.isVisible()) {
       continue;
     }
     r.getBoundingBox(bbox);
     final Point2D pos = RenderpassPainter.getPositionFromCanvas(r, position);
     if (!bbox.contains(pos)) {
       continue;
     }
     final String tooltip = r.getTooltip(pos);
     if (tooltip != null) return tooltip;
   }
   return RenderpassPainter.getTooltip(nlBack, position);
 }
Exemplo n.º 15
0
 /**
  * Determines if a node lies within the bounding box.
  *
  * @param boundingBox The bounding box.
  * @param node The node to be checked.
  * @return True if the node lies within the box.
  */
 private boolean isNodeInsideBox(Rectangle2D boundingBox, Node node) {
   return boundingBox.contains(node.getLongitude(), node.getLatitude());
 }
Exemplo n.º 16
0
 @Override
 public boolean hitTestInLocalSpace(Point2D p) {
   return getContentsBoundingBox().contains(p)
       || getLabelBB().contains(p)
       || ((encodingBB != null) && encodingBB.contains(p));
 }
Exemplo n.º 17
0
 public static boolean intersects(Rectangle2D r, Point2D p) {
   return r.contains(p);
 }
Exemplo n.º 18
0
 public void mouseClicked(MouseEvent e) {
   if (hoverArea.contains(e.getPoint())) skillToggle = !skillToggle;
 }
Exemplo n.º 19
0
 @Override
 public void repaint(Graphics2D g) {
   drawProgressBar(g, skill, x, y, width, height, (skillToggle || hoverArea.contains(m)));
 }
 boolean contains(Point p) {
   return bbPos.contains(p);
 }
Exemplo n.º 21
0
  /**
   * Draws an item label. This method is provided as an alternative to {@link
   * #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int, double, double, boolean)} so
   * that the bar can be used to calculate the label anchor point.
   *
   * @param g2 the graphics device.
   * @param dataset the dataset.
   * @param series the series index.
   * @param item the item index.
   * @param plot the plot.
   * @param generator the label generator ({@code null} permitted, in which case the method does
   *     nothing, just returns).
   * @param bar the bar.
   * @param negative a flag indicating a negative value.
   */
  protected void drawItemLabel(
      Graphics2D g2,
      XYDataset dataset,
      int series,
      int item,
      XYPlot plot,
      XYItemLabelGenerator generator,
      Rectangle2D bar,
      boolean negative) {

    if (generator == null) {
      return; // nothing to do
    }
    String label = generator.generateLabel(dataset, series, item);
    if (label == null) {
      return; // nothing to do
    }

    Font labelFont = getItemLabelFont(series, item);
    g2.setFont(labelFont);
    Paint paint = getItemLabelPaint(series, item);
    g2.setPaint(paint);

    // find out where to place the label...
    ItemLabelPosition position;
    if (!negative) {
      position = getPositiveItemLabelPosition(series, item);
    } else {
      position = getNegativeItemLabelPosition(series, item);
    }

    // work out the label anchor point...
    Point2D anchorPoint =
        calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation());

    if (isInternalAnchor(position.getItemLabelAnchor())) {
      Shape bounds =
          TextUtilities.calculateRotatedStringBounds(
              label,
              g2,
              (float) anchorPoint.getX(),
              (float) anchorPoint.getY(),
              position.getTextAnchor(),
              position.getAngle(),
              position.getRotationAnchor());

      if (bounds != null) {
        if (!bar.contains(bounds.getBounds2D())) {
          if (!negative) {
            position = getPositiveItemLabelPositionFallback();
          } else {
            position = getNegativeItemLabelPositionFallback();
          }
          if (position != null) {
            anchorPoint =
                calculateLabelAnchorPoint(
                    position.getItemLabelAnchor(), bar, plot.getOrientation());
          }
        }
      }
    }

    if (position != null) {
      TextUtilities.drawRotatedString(
          label,
          g2,
          (float) anchorPoint.getX(),
          (float) anchorPoint.getY(),
          position.getTextAnchor(),
          position.getAngle(),
          position.getRotationAnchor());
    }
  }
Exemplo n.º 22
0
 /**
  * Tests if the shape contains a point.
  *
  * @param p coord point
  * @return true if shape contains p
  */
 public boolean contains(Point2D p) {
   Rectangle2D rect = new Rectangle2D.Double(point.getX(), point.getY(), width, height);
   return rect.contains(p);
 }
Exemplo n.º 23
-1
  private void doShooting() {
    PositionFinder p = new PositionFinder(enemies, this);
    en = p.findNearest();
    if (en == null) return;

    Point2D myPos = new Point2D.Double(getX(), getY());

    if (HoT) {
      /* Perform head on target for gun movement */
      aimingPoint = new Point2D.Double(en.getX(), en.getY());
      double turnGunAmt = (getHeadingRadians() + en.getBearingRadians() - getGunHeadingRadians());
      turnGunAmt = Utils.normalRelativeAngle(turnGunAmt);
      setTurnGunRightRadians(turnGunAmt);
    } else {
      /* Perform circular targeting */
      Rectangle2D battlefield =
          new Rectangle2D.Double(0, 0, getBattleFieldWidth(), getBattleFieldHeight());
      long when = calcTimeToReachEnemy();
      aimingPoint = org.pattern.utils.Utils.getFuturePoint(en, when);
      if (!battlefield.contains(aimingPoint)) {
        HoT = true;
        return;
      }
      double theta =
          Utils.normalAbsoluteAngle(
              Math.atan2(aimingPoint.getX() - getX(), aimingPoint.getY() - getY()));
      setTurnGunRightRadians(Utils.normalRelativeAngle(theta - getGunHeadingRadians()));
    }

    if (getGunHeat() == 0) {
      double firePower = 3.0;
      fire(firePower);
    }
  }