Exemplo n.º 1
0
  public static Point2D.Double pointBetween(Point2D.Double p, Point2D.Double p2, double pos) {

    Point2D.Double n =
        new Point2D.Double(
            p.getX() * (1 - pos) + p2.getX() * (pos), p.getY() * (1 - pos) + p2.getY() * (pos));

    return n;
  }
Exemplo n.º 2
0
 /**
  * The mouse location changed during a drag, while this MapTool was the active tool.
  *
  * @param point The location of the mouse in world coordinates.
  * @param evt The original event.
  */
 @Override
 public void updateDrag(Point2D.Double point, MouseEvent evt) {
   // just in case we didn't get a mousePressed event
   if (dragStartPos == null) {
     dragStartPos = (Point2D.Double) point.clone();
   } else {
     double dx = dragStartPos.getX() - point.getX();
     double dy = dragStartPos.getY() - point.getY();
     mapComponent.offsetVisibleArea(dx, dy);
   }
 }
  public double getDistance(Vector<VivaeObject> objects) {
    GeneralPath thisPath = new GeneralPath(this.getTransformedShape());
    PathIntersection pi = new PathIntersection();
    Point2D.Double[] points;
    double dist = ray_length;
    double nd;
    for (VivaeObject vivaeObject : objects) {
      if (vivaeObject != this.owner) {
        GeneralPath gp = new GeneralPath(vivaeObject.getTransformedShape());
        points = pi.getIntersections(thisPath, gp);
        for (Point2D.Double point : points) {
          nd = pi.euclideanDistance(point.getX(), point.getY(), owner.getX(), owner.getY());
          if (nd < dist) {
            dist = nd;
          }
          // System.out.println(dist);
        }
      }
    }

    opacity = Math.max((float) (1d - (dist / ray_length)), opacity);
    opacityOfRay = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);

    return 1d - (dist / ray_length);
  }
 public boolean isInside(Point2D.Double point) {
   double x = point.getX();
   double y = point.getY();
   if ((x < center.getX() + radius && x > center.getX() - radius)
       && (y < center.getY() + radius && y > center.getY() - radius)) {
     return true;
   }
   return false;
 }
Exemplo n.º 5
0
  public static int closest(Point2D.Double[] BTS, Point2D.Double p) {

    double[] dist = new double[BTS.length];
    int min = 0;
    for (int i = 0; i < BTS.length; i++) {
      dist[i] = distanceSq(BTS[i].getX(), BTS[i].getY(), p.getX(), p.getY());
      if (dist[i] < dist[min]) min = i;
    }
    // System.out.println(dist[min] + " " + min);

    return min;
  }
Exemplo n.º 6
0
  /**
   * Method to get the coordinates of the enclosing rectangle after this transformation is applied
   * to the current picture
   *
   * @return the enclosing rectangle
   */
  public Rectangle2D getTransformEnclosingRect(AffineTransform trans) {
    int width = getWidth();
    int height = getHeight();
    double maxX = width - 1;
    double maxY = height - 1;
    double minX, minY;
    Point2D.Double p1 = new Point2D.Double(0, 0);
    Point2D.Double p2 = new Point2D.Double(maxX, 0);
    Point2D.Double p3 = new Point2D.Double(maxX, maxY);
    Point2D.Double p4 = new Point2D.Double(0, maxY);
    Point2D.Double result = new Point2D.Double(0, 0);
    Rectangle2D.Double rect = null;

    // get the new points and min x and y and max x and y
    trans.deltaTransform(p1, result);
    minX = result.getX();
    maxX = result.getX();
    minY = result.getY();
    maxY = result.getY();
    trans.deltaTransform(p2, result);
    minX = Math.min(minX, result.getX());
    maxX = Math.max(maxX, result.getX());
    minY = Math.min(minY, result.getY());
    maxY = Math.max(maxY, result.getY());
    trans.deltaTransform(p3, result);
    minX = Math.min(minX, result.getX());
    maxX = Math.max(maxX, result.getX());
    minY = Math.min(minY, result.getY());
    maxY = Math.max(maxY, result.getY());
    trans.deltaTransform(p4, result);
    minX = Math.min(minX, result.getX());
    maxX = Math.max(maxX, result.getX());
    minY = Math.min(minY, result.getY());
    maxY = Math.max(maxY, result.getY());

    // create the bounding rectangle to return
    rect = new Rectangle2D.Double(minX, minY, maxX - minX + 1, maxY - minY + 1);
    return rect;
  }
Exemplo n.º 7
0
  private void scan(Graphics2D g, InputStream input) throws IOException {
    Set<String> unknownC = new HashSet<String>();
    Pattern tab = Pattern.compile("[\t]");
    LineIterator in = new LineIteratorImpl(LineReaderUtil.fromBufferedStream(input));
    while (in.hasNext()) {
      String line = in.next();
      String tokens[] = tab.split(line, 5);
      if (tokens.length < 4) {
        warning("Ignoring " + line);
        continue;
      }
      SAMSequenceRecord rec = this.context.getDictionary().getSequence(tokens[0]);
      if (rec == null) {
        warning("unknown chromosome " + tokens[0]);
        continue;
      }
      String country = tokens[3].toLowerCase().replaceAll("[ ]", "");
      Shape shape = this.country2shape.get(country);
      if (shape == null) {
        if (!unknownC.contains(country)) {
          unknownC.add(country);
          warning("unknown country " + country);
        }
        continue;
      }
      seen.incr(country);
      int midpos = (Integer.parseInt(tokens[1]) + Integer.parseInt(tokens[2])) / 2;
      // country center
      Point2D.Double pt1 =
          new Point2D.Double(shape.getBounds2D().getCenterX(), shape.getBounds2D().getCenterY());
      // circle point
      Point2D pt3 = this.context.convertPositionToPoint(tokens[0], midpos, getRadiusInt());
      double angle = this.context.convertPositionToRadian(rec, midpos);
      double angle2 = angle -= Math.PI / 10.0;

      double distance13 =
          context
              .getCenter()
              .distance(
                  new Point2D.Double(
                      (pt1.getX() + pt3.getX()) / 2.0, (pt1.getY() + pt3.getY()) / 2.0));
      // mid point
      Point2D pt2 =
          new Point2D.Double(
              context.getCenterX() + distance13 * Math.cos(angle2),
              context.getCenterX() + distance13 * Math.sin(angle2));

      Composite old = g.getComposite();
      Stroke olds = g.getStroke();
      g.setStroke(new BasicStroke(0.8f));
      g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.02f));
      g.setColor(Color.DARK_GRAY);
      GeneralPath p = new GeneralPath();
      p.moveTo(pt1.getX(), pt1.getY());
      p.quadTo(pt2.getX(), pt2.getY(), pt3.getX(), pt3.getY());
      p.closePath();
      g.draw(p);
      g.setComposite(old);
      g.setStroke(olds);
    }
    CloserUtil.close(in);
  }
Exemplo n.º 8
0
 /**
  * Write the given text string in the current font, centered at <location>.
  *
  * @param location the Point at the center of the text
  * @param s the text
  */
 public static void text(Point2D.Double location, String s) {
   text(location.getX(), location.getY(), s);
 }
Exemplo n.º 9
0
  /**
   * Draw a filled rectangle of given half width and half height, centred at <location> and rotated
   * by d degrees.
   *
   * @param location the Point at the centre of the rectangle
   * @param halfWidth is half the width of the rectangle
   * @param halfHeight is half the height of the rectangle
   * @param degrees is the rotation of the rectangle with 3 o'clock being 0 degrees and 12 o'clock
   *     being 270 degrees
   * @throws RuntimeException if halfWidth or halfHeight is negative
   */
  public static void filledAngledRectangle(
      Point2D.Double location, double halfWidth, double halfHeight, double degrees) {

    filledAngledRectangle(location.getX(), location.getY(), halfWidth, halfHeight, degrees);
  }
Exemplo n.º 10
0
 /**
  * Draw a filled diamond of side length 2r, centred at <location>.
  *
  * @param location the Point at the centre of the square
  * @param r radius is half the length of any side of the diamond
  * @throws RuntimeException if r is negative
  */
 public static void filledDiamond(Point2D.Double location, double r) {
   filledDiamond(location.getX(), location.getY(), r);
 }
Exemplo n.º 11
0
 /**
  * Draw a filled square of side length 2r, centred at <location>.
  *
  * @param location the Point at the centre of the square
  * @param r radius is half the length of any side of the square
  * @throws RuntimeException if r is negative
  */
 public static void filledSquare(Point2D.Double location, double r) {
   filledSquare(location.getX(), location.getY(), r);
 }
Exemplo n.º 12
0
 /**
  * Draw a circle of radius r, centred at <location>.
  *
  * @param location the Point at the centre of the circle
  * @param r the radius of the circle
  * @throws RuntimeException if the radius of the circle is negative
  */
 public static void circle(Point2D.Double location, double r) {
   circle(location.getX(), location.getY(), r);
 }
Exemplo n.º 13
0
 public Circle(Point2D.Double center, double radius, Color color) {
   super(center, radius, color);
   this.thisCircle = new Ellipse2D.Double(center.getX(), center.getY(), radius, radius);
 }