public void test020() {
    final int width = 200;
    final Point2D.Float zero = new Point2D.Float(0, 0);
    final Point2D.Float ch = new Point2D.Float(0, Ice.HOG_2_TEE);
    final Point2D.Float cb = new Point2D.Float(0, -Ice.BACK_2_TEE);
    final float h = ch.y - cb.y;
    final float sca = width / h;

    AffineTransform mat = new AffineTransform();
    mat.translate(0, (cb.y + ch.y) / 2);
    mat.scale(sca, sca);
    // mat.rotate(Math.PI / 2);
    // mat.translate(width / 2, height / 2);

    final Point2D.Float cht = new Point2D.Float(0, 0);
    final Point2D.Float cbt = new Point2D.Float(0, 0);
    final Point2D.Float zerot = new Point2D.Float(0, 0);
    mat.transform(ch, cht);
    mat.transform(cb, cbt);
    mat.transform(zero, zerot);
    print("Hog :", cht);
    print("Back:", cbt);
    print("0,0 :", zerot);

    // assertEquals("", (float) 0, p.x, (float) 1e-1);
    // assertEquals("", (float) 0, p.y, (float) 1e-1);
  }
Exemplo n.º 2
0
  public static BufferedImage rotateImage(BufferedImage image, double theta) {
    int degrees = (int) Math.abs(Math.toDegrees(theta));
    double xCenter = image.getWidth() / 2;
    double yCenter = image.getHeight() / 2;
    AffineTransform rotateTransform = AffineTransform.getRotateInstance(-theta, xCenter, yCenter);

    // Translation adjustments so image still centered after rotate width/height changes
    if (image.getHeight() != image.getWidth() && degrees != 180 && degrees != 0) {
      Point2D origin = new Point2D.Double(0.0, 0.0);
      origin = rotateTransform.transform(origin, null);
      double yTranslate = origin.getY();

      Point2D yMax = new Point2D.Double(0, image.getHeight());
      yMax = rotateTransform.transform(yMax, null);
      double xTranslate = yMax.getX();

      AffineTransform translationAdjustment =
          AffineTransform.getTranslateInstance(-xTranslate, -yTranslate);
      rotateTransform.preConcatenate(translationAdjustment);
    }

    AffineTransformOp op = new AffineTransformOp(rotateTransform, AffineTransformOp.TYPE_BILINEAR);
    // Have to recopy image because of JDK bug #4723021, AffineTransformationOp throwing exception
    // sometimes
    image = copyImage(image, BufferedImage.TYPE_INT_ARGB);

    // Need to create filter dest image ourselves since AffineTransformOp's own dest image creation
    // throws exceptions in some cases.
    Rectangle bounds = op.getBounds2D(image).getBounds();
    BufferedImage finalImage =
        new BufferedImage(
            (int) bounds.getWidth(), (int) bounds.getHeight(), BufferedImage.TYPE_INT_ARGB);

    return op.filter(image, finalImage);
  }
Exemplo n.º 3
0
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and ellipse.
  *
  * @return Returns true, if the circle is inside of the image bounds.
  */
 private boolean writeCircleAttributes(IXMLElement elem, SVGFigure f, Ellipse2D.Double ellipse) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType() &&
             ellipse.width == ellipse.height
             ) {
         
         Point2D.Double start = new Point2D.Double(ellipse.x, ellipse.y);
         Point2D.Double end = new Point2D.Double(ellipse.x + ellipse.width, ellipse.y + ellipse.height);
         t.transform(start, start);
         t.transform(end, end);
         ellipse.x = Math.min(start.x, end.x);
         ellipse.y = Math.min(start.y, end.y);
         ellipse.width = Math.abs(start.x - end.x);
         ellipse.height = Math.abs(start.y - end.y);
         
         elem.setAttribute("shape", "circle");
         elem.setAttribute("coords",
                 (int) (ellipse.x + ellipse.width / 2d)+","+
                 (int) (ellipse.y + ellipse.height / 2d)+","+
                 (int) (ellipse.width / 2d)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(ellipse.getBounds());
     } else {
         return writePolyAttributes(elem, f, (Shape) ellipse);
     }
 }
  public void test110_ZoomShift() {
    // final double s = 1.0 / RockLocationDisplayBase.SCALE;
    final double[] flat = new double[6];
    final Point2D dst = new Point2D.Double();
    final Point2D src = new Point2D.Double();
    final AffineTransform mat = new AffineTransform();
    final Rectangle2D wc = new Rectangle2D.Double(1, 2, 3, 4);
    Rectangle dc = new Rectangle(-1, -2, 3, 4);
    final Point2D fix = new Point2D.Double(1, 2);
    ZoomerFixPoint zom = new ZoomerFixPoint("1:1", wc, fix);

    mat.setToIdentity();
    zom.computeWc2Dc(dc, Orientation.N, true, false, mat);
    mat.getMatrix(flat);
    assertEquals("", -0.0010, flat[0], 1e-9);
    assertEquals("", 0, flat[1], 1e-9);
    assertEquals("", 0, flat[2], 1e-9);
    assertEquals("", -0.0010, flat[3], 1e-9);
    assertEquals("", 1.0, flat[4], 1e-9);
    assertEquals("", 6, flat[5], 1e-9);
    src.setLocation(fix);
    mat.transform(src, dst);
    assertEquals(new Point2D.Double(0.999, 5.998), dst);
    src.setLocation(3, 4);
    mat.transform(src, dst);
    assertEquals(new Point2D.Double(0.997, 5.996), dst);
  }
Exemplo n.º 5
0
  /**
   * WhiteboardShapeRect constructor.
   *
   * @param id String that uniquely identifies this WhiteboardShapeRect
   * @param thickness number of pixels that this object (or its border) should be thick
   * @param color WhiteboardShapeRect's color (or rather it's border)
   * @param point coordinates of this object.
   * @param width width value of this object (in pixel)
   * @param height height value of this object (in pixel)
   * @param fill True is filled, false is unfilled
   * @param transform 2D affine transformation
   */
  public WhiteboardShapeRect(
      String id,
      int thickness,
      Color color,
      WhiteboardPoint point,
      double width,
      double height,
      boolean fill,
      AffineTransform transform) {
    super(id);

    Point2D v0 = new Point2D.Double(point.getX(), point.getY());
    Point2D w0 = transform.transform(v0, null);

    double x = w0.getX();
    double y = w0.getY();

    point.setX(x);
    point.setY(y);

    Point2D v1 = new Point2D.Double(x + width, y + height);
    Point2D w1 = transform.transform(v1, null);

    double transformedWidth = w1.getX() - x;
    double transformedHeight = w1.getY() - y;

    this.initShape(thickness, color, point, transformedWidth, transformedHeight, fill);
  }
Exemplo n.º 6
0
  /**
   * Code to paint the WhiteboardShapeRect.
   *
   * @param g graphics context
   * @param t 2D affine transformation
   */
  public void paintShape(Graphics2D g, AffineTransform t) {
    double x = point.getX();
    double y = point.getY();

    g.setStroke(new BasicStroke(this.getThickness(), BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND));

    Point2D w0 = new Point2D.Double(x, y);
    Point2D v0 = t.transform(w0, null);

    int x0 = (int) v0.getX();
    int y0 = (int) v0.getY();

    Point2D w1 = new Point2D.Double(x + width, y + height);
    Point2D v1 = t.transform(w1, null);

    int xWidth = (int) v1.getX() - x0;
    int yHeight = (int) v1.getY() - y0;

    g.setColor(Color.getColor("", this.getColor()));
    if (fill) {
      g.fillRect(x0, y0, xWidth, yHeight);
    } else {
      g.drawRect(x0, y0, xWidth, yHeight);
    }
  }
Exemplo n.º 7
0
  /**
   * Compute the position of a sprite if it is not attached.
   *
   * @param sprite The sprite.
   * @param pos Where to stored the computed position, if null, the position is created.
   * @param units The units the computed position must be given into.
   * @return The same instance as pos, or a new one if pos was null.
   */
  protected Point2D.Double getSpritePositionFree(
      GraphicSprite sprite, Point2D.Double pos, Units units) {
    if (pos == null) pos = new Point2D.Double();

    if (sprite.getUnits() == units) {
      pos.x = sprite.getX();
      pos.y = sprite.getY();
    } else if (units == Units.GU && sprite.getUnits() == Units.PX) {
      pos.x = sprite.getX();
      pos.y = sprite.getY();

      xT.transform(pos, pos);
    } else if (units == Units.PX && sprite.getUnits() == Units.GU) {
      pos.x = sprite.getX();
      pos.y = sprite.getY();

      Tx.transform(pos, pos);
    } else if (units == Units.GU && sprite.getUnits() == Units.PERCENTS) {
      pos.x = metrics.lo.x + (sprite.getX() / 100f) * metrics.graphWidthGU();
      pos.y = metrics.lo.y + (sprite.getY() / 100f) * metrics.graphHeightGU();
    } else if (units == Units.PX && sprite.getUnits() == Units.PERCENTS) {
      pos.x = (sprite.getX() / 100f) * metrics.viewport[2];
      pos.y = (sprite.getY() / 100f) * metrics.viewport[3];
    } else {
      throw new RuntimeException("Unhandled yet sprite positioning.");
    }

    return pos;
  }
Exemplo n.º 8
0
  @SuppressWarnings("deprecation")
  private void doOverlayImage(GC gc) {
    Point2D lowerLeft = new Point2D.Double(overlayEnvelope.getMinX(), overlayEnvelope.getMinY());
    worldToScreen.transform(lowerLeft, lowerLeft);

    Point2D upperRight = new Point2D.Double(overlayEnvelope.getMaxX(), overlayEnvelope.getMaxY());
    worldToScreen.transform(upperRight, upperRight);

    Rectangle bounds = overlayImage.getBounds();
    if (overlayDoXor) {
      gc.setXORMode(true);
    }

    gc.drawImage(
        overlayImage, //
        0, //
        0, //
        bounds.width, //
        bounds.height, //
        (int) lowerLeft.getX(), //
        (int) upperRight.getY(), //
        (int) (upperRight.getX() - lowerLeft.getX()), //
        (int) Math.abs(upperRight.getY() - lowerLeft.getY()) //
        );
    if (overlayDoXor) {
      gc.setXORMode(false);
    }
  }
Exemplo n.º 9
0
  @Test
  public void drawWithClipAndTransform() throws Exception {
    graphics.setPaint(Color.BLACK);
    graphics.fill(imageBounds);

    AffineTransform tr =
        AffineTransform.getRotateInstance(
            Math.PI / 4,
            image.getMinX() + image.getWidth() / 2,
            image.getMinY() + image.getHeight() / 2);

    graphics.transform(tr);
    graphics.clip(midRect);

    graphics.setPaint(Color.RED);
    graphics.fill(imageBounds);

    showImage("drawWithClipAndTransform");

    // Outside transformed clip region
    Rectangle outer = new Rectangle(midRect);
    outer.grow(5, 5);
    Point2D[] corners = getCorners(outer);
    Point2D[] trPoints = new Point2D[corners.length];
    tr.transform(corners, 0, trPoints, 0, corners.length);
    assertColor(Color.BLACK, trPoints);

    // Inside transformed clip region
    Rectangle inner = new Rectangle(midRect);
    inner.grow(-5, -5);
    corners = getCorners(inner);
    tr.transform(corners, 0, trPoints, 0, corners.length);
    assertColor(Color.RED, trPoints);
  }
Exemplo n.º 10
0
 @Override
 public void transform(AffineTransform tx) {
   Point2D.Double anchor = getStartPoint();
   Point2D.Double lead = getEndPoint();
   tx.transform(anchor, anchor);
   tx.transform(lead, lead);
   setBounds(anchor, lead);
 }
Exemplo n.º 11
0
  /**
   * @param drop
   * @param i
   * @return
   */
  public static BufferedImage rotate(final BufferedImage src, final int degree) {
    final int w = src.getWidth(null);
    final int h = src.getHeight(null);

    // final Graphics2D g = image.createGraphics();
    // g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    // RenderingHints.VALUE_ANTIALIAS_ON);

    final AffineTransform at = new AffineTransform();
    at.rotate(degree * Math.PI / 180.0);
    Point2D p2din, p2dout;

    p2din = new Point2D.Double(0.0, 0.0);
    p2dout = at.transform(p2din, null);
    double ytrans = p2dout.getY();
    double xtrans = p2dout.getX();
    p2din = new Point2D.Double(0, h);
    p2dout = at.transform(p2din, null);
    ytrans = Math.min(ytrans, p2dout.getY());
    xtrans = Math.min(xtrans, p2dout.getX());
    p2din = new Point2D.Double(w, h);
    p2dout = at.transform(p2din, null);
    ytrans = Math.min(ytrans, p2dout.getY());
    xtrans = Math.min(xtrans, p2dout.getX());
    p2din = new Point2D.Double(w, 0);
    p2dout = at.transform(p2din, null);
    ytrans = Math.min(ytrans, p2dout.getY());
    xtrans = Math.min(xtrans, p2dout.getX());

    final AffineTransform tat = new AffineTransform();
    tat.translate(-xtrans, -ytrans);

    at.preConcatenate(tat);
    final AffineTransformOp bio = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);

    final Rectangle r = bio.getBounds2D(src).getBounds();

    BufferedImage image = new BufferedImage(r.width, r.height, BufferedImage.TYPE_INT_ARGB);

    image = bio.filter(src, image);
    // final Graphics g = image.getGraphics();
    // g.setColor(Color.RED);
    // g.drawRect(0, 0, image.getWidth() - 1, image.getHeight() - 1);
    // g.dispose();
    // try {
    // Dialog.getInstance().showConfirmDialog(0, "", "", new
    // ImageIcon(image), null, null);
    // } catch (final DialogClosedException e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // } catch (final DialogCanceledException e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // }
    return image;
  }
Exemplo n.º 12
0
  /**
   * Transforms an envelope in map units to image units
   *
   * @param geographicEnvelope The {@link Envelope} in map units.
   * @return Rectangle2DDouble The envelope in image units as a {@link Rectangle2DDouble}.
   */
  public Rectangle2DDouble toPixel(Envelope geographicEnvelope) {
    final Point2D lowerRight =
        new Point2D.Double(geographicEnvelope.getMaxX(), geographicEnvelope.getMinY());
    final Point2D upperLeft =
        new Point2D.Double(geographicEnvelope.getMinX(), geographicEnvelope.getMaxY());

    final Point2D ul = trans.transform(upperLeft, null);
    final Point2D lr = trans.transform(lowerRight, null);

    return new Rectangle2DDouble(
        ul.getX(), ul.getY(), lr.getX() - ul.getX(), lr.getY() - ul.getY());
  }
Exemplo n.º 13
0
  /* (non-Javadoc)
   * @see java.awt.geom.PathIterator#currentSegment(float[])
   */
  public int currentSegment(float[] coords) {
    coords[0] = (float) p.getX();
    coords[1] = (float) p.getY();
    at.transform(coords, 0, coords, 0, 1);

    return PathIterator.SEG_MOVETO;
  }
Exemplo n.º 14
0
  /**
   * Renders an image on the device
   *
   * @param tx the image location on the screen, x coordinate
   * @param ty the image location on the screen, y coordinate
   * @param img the image
   * @param rotation the image rotatation
   */
  private static void renderImage(
      Graphics2D graphics, double x, double y, Image image, double rotation, float opacity) {
    AffineTransform temp = graphics.getTransform();
    AffineTransform markAT = new AffineTransform();
    Point2D mapCentre = new java.awt.geom.Point2D.Double(x, y);
    Point2D graphicCentre = new java.awt.geom.Point2D.Double();
    temp.transform(mapCentre, graphicCentre);
    markAT.translate(graphicCentre.getX(), graphicCentre.getY());

    double shearY = temp.getShearY();
    double scaleY = temp.getScaleY();

    double originalRotation = Math.atan(shearY / scaleY);

    markAT.rotate(rotation);
    graphics.setTransform(markAT);
    graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));

    // we moved the origin to the centre of the image.
    graphics.drawImage(image, -image.getWidth(null) / 2, -image.getHeight(null) / 2, null);

    graphics.setTransform(temp);

    return;
  }
Exemplo n.º 15
0
 /**
  * Transforms the figure.
  *
  * @param tx the transformation.
  */
 public void transform(AffineTransform tx) {
   if (TRANSFORM.get(this) != null
       || tx.getType() != (tx.getType() & AffineTransform.TYPE_TRANSLATION)) {
     if (TRANSFORM.get(this) == null) {
       TRANSFORM.basicSet(this, (AffineTransform) tx.clone());
     } else {
       AffineTransform t = TRANSFORM.getClone(this);
       t.preConcatenate(tx);
       TRANSFORM.basicSet(this, t);
     }
   } else {
     for (int i = 0; i < coordinates.length; i++) {
       tx.transform(coordinates[i], coordinates[i]);
     }
     if (FILL_GRADIENT.get(this) != null && !FILL_GRADIENT.get(this).isRelativeToFigureBounds()) {
       Gradient g = FILL_GRADIENT.getClone(this);
       g.transform(tx);
       FILL_GRADIENT.basicSet(this, g);
     }
     if (STROKE_GRADIENT.get(this) != null
         && !STROKE_GRADIENT.get(this).isRelativeToFigureBounds()) {
       Gradient g = STROKE_GRADIENT.getClone(this);
       g.transform(tx);
       STROKE_GRADIENT.basicSet(this, g);
     }
   }
   invalidate();
 }
Exemplo n.º 16
0
  /** @see java.awt.geom.PathIterator#currentSegment(double[]) */
  public int currentSegment(double[] coords) {
    if (currentCoord == 0) {
      coords[0] = (double) coordinates.getX(0);
      coords[1] = (double) coordinates.getY(0);
      at.transform(coords, 0, coords, 0, 1);
      return SEG_MOVETO;
    } else if ((currentCoord == coordinateCount) && isClosed) {
      return SEG_CLOSE;
    } else {
      coords[0] = coordinates.getX(currentCoord);
      coords[1] = coordinates.getY(currentCoord);
      at.transform(coords, 0, coords, 0, 1);

      return SEG_LINETO;
    }
  }
 public void transform(AffineTransform af) {
   int size = pathPoints.size();
   for (int i = 0; i < size; i++) {
     PathPoint p = (PathPoint) pathPoints.get(i);
     af.transform(p, p);
   }
 }
Exemplo n.º 18
0
  /**
   * Code to paint the specific shape
   *
   * @param w2v 2D affine transform
   * @param g graphics context
   */
  public void paintShape(Graphics2D g, AffineTransform w2v) {
    double x = startPoint.getX();
    double y = startPoint.getY();
    double xEnd = endPoint.getX();
    double yEnd = endPoint.getY();

    g.setStroke(new BasicStroke(this.getThickness(), BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND));

    Point2D v0 = w2v.transform(new Point2D.Double(x, y), null);
    int ix = (int) v0.getX();
    int iy = (int) v0.getY();

    Point2D v1 = w2v.transform(new Point2D.Double(xEnd, yEnd), null);

    g.drawLine(ix, iy, (int) v1.getX(), (int) v1.getY());
  }
Exemplo n.º 19
0
 /**
  * Return the raster coordinate denoted by the given world coordinate. This method is CENTER and
  * OUTER aware.
  *
  * @param worldX x position in the world coordinate system, for which raster coordinates should be
  *     calculated.
  * @param worldY y position in the world coordinate system, for which raster coordinates should be
  *     calculated.
  * @return the (rounded) raster coordinate which the given world coordinate maps to.
  */
 public int[] getRasterCoordinate(double worldX, double worldY) {
   Point2D rslt = invTransform.transform(new Point2D.Double(worldX, worldY), null);
   if (location == CENTER) {
     return new int[] {(int) round(rslt.getX()), (int) round(rslt.getY())};
   }
   return new int[] {(int) floor(rslt.getX()), (int) floor(rslt.getY())};
 }
Exemplo n.º 20
0
  public AffineRed(CachableRed src, AffineTransform src2me, RenderingHints hints) {
    super(); // We _must_ call init...

    this.src2me = src2me;
    this.hints = hints;

    try {
      me2src = src2me.createInverse();
    } catch (NoninvertibleTransformException nite) {
      me2src = null;
    }

    // Calculate my bounds by applying the affine transform to
    // my input data..codec/
    Rectangle srcBounds = src.getBounds();
    // srcBounds.grow(-1,-1);
    Rectangle myBounds;
    myBounds = src2me.createTransformedShape(srcBounds).getBounds();

    // If the output buffer is not premultiplied in certain cases it
    // fails to properly divide out the Alpha (it always does
    // the affine on premultiplied data), hence you get ugly
    // back aliasing effects...
    ColorModel cm = fixColorModel(src);

    // fix my sample model so it makes sense given my size.
    SampleModel sm = fixSampleModel(src, cm, myBounds);

    Point2D pt = new Point2D.Float(src.getTileGridXOffset(), src.getTileGridYOffset());
    pt = src2me.transform(pt, null);

    // Finish initializing our base class...
    init(src, myBounds, cm, sm, (int) pt.getX(), (int) pt.getY(), null);
  }
Exemplo n.º 21
0
 /**
  * Transforms an image coordinate in pixels into a map coordinate
  *
  * @param i The x ordinate of the point in the image
  * @param j The y ordinate of the point in the image
  * @return The Point2D instance on the map computed from the given coordinates.
  */
 public Point2D toMapPoint(int i, int j) {
   if (transInv != null) {
     return transInv.transform(new Point2D.Double(i, j), null);
   } else {
     throw new RuntimeException("NonInvertibleMatrix");
   }
 }
Exemplo n.º 22
0
 @Override
 public void rotate(Point2D point, double theta) {
   final AffineTransform transform = new AffineTransform();
   transform.rotate(theta, point.getX(), point.getY());
   Point2D point2D = transform.transform(getLocation(), null);
   setLocation(point2D);
 }
Exemplo n.º 23
0
 protected Point rotateAboutCentre(Point target, double radians) {
   Point result = new Point();
   AffineTransform rotation = new AffineTransform(); // 'tis affine transform, cap'n
   rotation.rotate(radians, this.centre.x, this.centre.y);
   rotation.transform(target, result);
   return result;
 }
Exemplo n.º 24
0
  public synchronized void paint(Graphics gin) {
    Graphics2D g = (Graphics2D) gin;

    if (im == null) return;

    int height = getHeight();
    int width = getWidth();

    if (fit) {
      t = new AffineTransform();
      double scale = Math.min(((double) width) / im.getWidth(), ((double) height) / im.getHeight());
      // we'll re-center the transform in a moment.
      t.scale(scale, scale);
    }

    // if the image (in either X or Y) is smaller than the view port, then center
    // the image with respect to that axis.
    double mwidth = im.getWidth() * t.getScaleX();
    double mheight = im.getHeight() * t.getScaleY();
    if (mwidth < width)
      t.preConcatenate(
          AffineTransform.getTranslateInstance((width - mwidth) / 2.0 - t.getTranslateX(), 0));
    if (mheight < height)
      t.preConcatenate(
          AffineTransform.getTranslateInstance(0, (height - mheight) / 2.0 - t.getTranslateY()));

    // if we're allowing panning (because only a portion of the image is visible),
    // don't allow translations that show less information that is possible.
    Point2D topleft = t.transform(new Point2D.Double(0, 0), null);
    Point2D bottomright = t.transform(new Point2D.Double(im.getWidth(), im.getHeight()), null);

    if (mwidth > width) {
      if (topleft.getX() > 0)
        t.preConcatenate(AffineTransform.getTranslateInstance(-topleft.getX(), 0));
      if (bottomright.getX() < width)
        t.preConcatenate(AffineTransform.getTranslateInstance(width - bottomright.getX(), 0));
      //		    t.translate(width-bottomright.getX(), 0);
    }
    if (mheight > height) {
      if (topleft.getY() > 0)
        t.preConcatenate(AffineTransform.getTranslateInstance(0, -topleft.getY()));
      if (bottomright.getY() < height)
        t.preConcatenate(AffineTransform.getTranslateInstance(0, height - bottomright.getY()));
    }

    g.drawImage(im, t, null);
  }
  private static MeshCoords transformSector(AffineTransform transform, Sector sector) {
    java.awt.geom.Point2D p = new java.awt.geom.Point2D.Double();
    java.awt.geom.Point2D ll = new java.awt.geom.Point2D.Double();
    java.awt.geom.Point2D ur = new java.awt.geom.Point2D.Double();

    p.setLocation(sector.getMinLongitude().degrees, sector.getMinLatitude().degrees);
    transform.transform(p, ll);

    p.setLocation(sector.getMaxLongitude().degrees, sector.getMaxLatitude().degrees);
    transform.transform(p, ur);

    return new MeshCoords(
        (float) ur.getY(), // Top
        (float) ll.getX(), // Left
        (float) ll.getY(), // Bottom
        (float) ur.getX()); // Right
  }
 void calcPos(AffineTransform w2n) {
   w2n.transform(worldPos, screenPos); // work in normalized coordinate space
   bbPos.setRect(
       screenPos.getX() + bb.getX(),
       screenPos.getY() + bb.getY(),
       bb.getWidth(),
       bb.getHeight());
 }
Exemplo n.º 27
0
        /** @param mouseLoc the mouse location, relative to the panel (pre-transform) */
        private Selection getSelection(ShapeCreationPanel scp, Point2D mouseLoc) {
          AffineTransform tx = scp.getTransform();

          CubicPath[] paths = getCubicPaths(scp);
          Integer shapeIntersection = null;
          int r = scp.getHandleSize() / 2;
          Active active = scp.getHandlesActive();
          for (int shapeIndex = paths.length - 1; shapeIndex >= 0; shapeIndex--) {
            if (active.supports(scp, shapeIndex)) {
              CubicPath path = paths[shapeIndex];
              for (int nodeIndex = 0; nodeIndex < path.getNodeCount(); nodeIndex++) {
                Point2D p2 = path.getPrevControlForNode(nodeIndex, null);
                if (p2 != null) {
                  tx.transform(p2, p2);
                  if (hit(scp, mouseLoc, p2)) {
                    return new Selection(shapeIndex, nodeIndex, Handle.PREVIOUS_CONTROL);
                  }
                }
                p2 = path.getNode(nodeIndex, null);
                if (p2 != null) {
                  tx.transform(p2, p2);
                  if (hit(scp, mouseLoc, p2)) {
                    return new Selection(shapeIndex, nodeIndex, Handle.PRIMARY);
                  }
                }
                p2 = path.getNextControlForNode(nodeIndex, null);
                if (p2 != null) {
                  tx.transform(p2, p2);
                  if (hit(scp, mouseLoc, p2)) {
                    return new Selection(shapeIndex, nodeIndex, Handle.NEXT_CONTROL);
                  }
                }
              }
              if (shapeIntersection == null) {
                Shape outline =
                    new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)
                        .createStrokedShape(path);
                if (outline.intersects(mouseLoc.getX() - r, mouseLoc.getY() - r, 2 * r, 2 * r)) {
                  shapeIntersection = shapeIndex;
                }
              }
            }
          }

          return getSelectedShape(scp, mouseLoc);
        }
Exemplo n.º 28
0
 public Vector copy(AffineTransform transform) {
   double[] pts =
       new double[] {
         x, y, x + w, y + h,
       };
   transform.transform(pts, 0, pts, 0, 2);
   return new Rectangle(pts[0], pts[1], pts[2] - pts[0], pts[3] - pts[1], fill);
 }
Exemplo n.º 29
0
  /**
   * DOCUMENT ME!
   *
   * @param at DOCUMENT ME!
   */
  public void transform(AffineTransform at) {
    Point2D center =
        new Point2D.Double((init.getX() + end.getX()) / 2, (init.getY() + end.getY()) / 2);
    Point2D pdist = UtilFunctions.getPerpendicularPoint(init, end, center, ydist);
    Point2D aux1 = new Point2D.Double();
    at.transform(init, aux1);
    init = aux1;
    Point2D aux2 = new Point2D.Double();
    at.transform(end, aux2);
    end = aux2;

    center = new Point2D.Double((init.getX() + end.getX()) / 2, (init.getY() + end.getY()) / 2);

    Point2D aux3 = new Point2D.Double();
    at.transform(pdist, aux3);
    ydist = center.distance(aux3);
    gp.transform(at);
  }
Exemplo n.º 30
0
 public float getFontSize() {
   //   return FONT_SIZE.get(this).floatValue();
   Point2D.Double p = new Point2D.Double(0, FONT_SIZE.get(this));
   AffineTransform tx = TRANSFORM.get(this);
   if (tx != null) {
     tx.transform(p, p);
     Point2D.Double p0 = new Point2D.Double(0, 0);
     tx.transform(p0, p0);
     p.y -= p0.y;
     /*
     try {
         tx.inverseTransform(p, p);
     } catch (NoninvertibleTransformException ex) {
         ex.printStackTrace();
     }*/
   }
   return (float) Math.abs(p.y);
 }