Example usage for java.awt.geom Rectangle2D getMaxY

List of usage examples for java.awt.geom Rectangle2D getMaxY

Introduction

In this page you can find the example usage for java.awt.geom Rectangle2D getMaxY.

Prototype

public double getMaxY() 

Source Link

Document

Returns the largest Y coordinate of the framing rectangle of the Shape in double precision.

Usage

From source file:Main.java

/**
 * Returns a point based on (x, y) but constrained to be within the bounds
 * of a given rectangle./*from   w w  w .  j  a va2s  .c o  m*/
 *
 * @param x  the x-coordinate.
 * @param y  the y-coordinate.
 * @param area  the constraining rectangle (<code>null</code> not
 *              permitted).
 *
 * @return A point within the rectangle.
 *
 * @throws NullPointerException if <code>area</code> is <code>null</code>.
 */
public static Point2D getPointInRectangle(double x, double y, final Rectangle2D area) {

    x = Math.max(area.getMinX(), Math.min(x, area.getMaxX()));
    y = Math.max(area.getMinY(), Math.min(y, area.getMaxY()));
    return new Point2D.Double(x, y);

}

From source file:Main.java

public static Rectangle2D.Double fromSheetRect(Rectangle2D r, AffineTransform at) {
    Point2D.Double pSheet = new Point2D.Double(r.getX(), r.getY());
    Point2D.Double pSX = new Point2D.Double(r.getMaxX(), r.getMinY());
    Point2D.Double pSY = new Point2D.Double(r.getMinX(), r.getMaxY());
    Point2D.Double pScreen = new Point2D.Double();
    Point2D.Double pScreenX = new Point2D.Double();
    Point2D.Double pScreenY = new Point2D.Double();

    try {//  ww w.j  a  va 2 s .c o  m
        at.transform(pSheet, pScreen);
        at.transform(pSX, pScreenX);
        at.transform(pSY, pScreenY);
    } catch (Exception e) {
        System.err.print(e.getMessage());
    }

    Rectangle2D.Double res = new Rectangle2D.Double();
    res.setRect(pScreen.getX(), pScreen.getY(), pScreen.distance(pScreenX), pScreen.distance(pScreenY));

    return res;
}

From source file:Main.java

public static Rectangle2D.Double toSheetRect(Rectangle2D r, AffineTransform at) {
    Point2D.Double pSheet = toSheetPoint(new Point2D.Double(r.getX(), r.getY()), at);
    Point2D.Double pSheetX = toSheetPoint(new Point2D.Double(r.getMaxX(), r.getMinY()), at);
    Point2D.Double pSheetY = toSheetPoint(new Point2D.Double(r.getMinX(), r.getMaxY()), at);
    Rectangle2D.Double res = new Rectangle2D.Double();
    res.setRect(pSheet.getX(), pSheet.getY(), pSheet.distance(pSheetX), pSheet.distance(pSheetY));

    return res;/*w  w  w .j  a  va  2 s.c  om*/
}

From source file:GraphicsUtil.java

public static void drawImage(Graphics g, BufferedImage img, Rectangle2D bounds, ImageObserver observer) {
    Graphics2D g2 = (Graphics2D) g;
    g2.drawImage(img, // what to draw
            (int) bounds.getMinX(), // dest left
            (int) bounds.getMinY(), // dest top
            (int) bounds.getMaxX(), // dest right
            (int) bounds.getMaxY(), // dest bottom
            0, // src left
            0, // src top
            img.getWidth(), // src right
            img.getHeight(), // src bottom
            observer // to notify of image updates
    );//from  w w  w. j a  v  a  2s. c  om
}

From source file:de.bund.bfr.knime.gis.GisUtils.java

public static Polygon createBorderPolygon(Rectangle2D rect, double d) {
    Coordinate[] outerRing = new Coordinate[] { new Coordinate(rect.getMinX() - d, rect.getMinY() - d),
            new Coordinate(rect.getMaxX() + d, rect.getMinY() - d),
            new Coordinate(rect.getMaxX() + d, rect.getMaxY() + d),
            new Coordinate(rect.getMinX() - d, rect.getMaxY() + d),
            new Coordinate(rect.getMinX() - d, rect.getMinY() - d) };
    Coordinate[] innerRing = new Coordinate[] { new Coordinate(rect.getMinX(), rect.getMinY()),
            new Coordinate(rect.getMaxX(), rect.getMinY()), new Coordinate(rect.getMaxX(), rect.getMaxY()),
            new Coordinate(rect.getMinX(), rect.getMaxY()), new Coordinate(rect.getMinX(), rect.getMinY()) };

    return FACTORY.createPolygon(FACTORY.createLinearRing(outerRing),
            new LinearRing[] { FACTORY.createLinearRing(innerRing) });
}

From source file:LineUtilities.java

/**
 * Clips the specified line to the given rectangle.
 *
 * @param line  the line (<code>null</code> not permitted).
 * @param rect  the clipping rectangle (<code>null</code> not permitted).
 *
 * @return <code>true</code> if the clipped line is visible, and
 *     <code>false</code> otherwise.
 *//*from ww w.j a  v  a  2s.c om*/
public static boolean clipLine(Line2D line, Rectangle2D rect) {

    double x1 = line.getX1();
    double y1 = line.getY1();
    double x2 = line.getX2();
    double y2 = line.getY2();

    double minX = rect.getMinX();
    double maxX = rect.getMaxX();
    double minY = rect.getMinY();
    double maxY = rect.getMaxY();

    int f1 = rect.outcode(x1, y1);
    int f2 = rect.outcode(x2, y2);

    while ((f1 | f2) != 0) {
        if ((f1 & f2) != 0) {
            return false;
        }
        double dx = (x2 - x1);
        double dy = (y2 - y1);
        // update (x1, y1), (x2, y2) and f1 and f2 using intersections
        // then recheck
        if (f1 != 0) {
            // first point is outside, so we update it against one of the
            // four sides then continue
            if ((f1 & Rectangle2D.OUT_LEFT) == Rectangle2D.OUT_LEFT && dx != 0.0) {
                y1 = y1 + (minX - x1) * dy / dx;
                x1 = minX;
            } else if ((f1 & Rectangle2D.OUT_RIGHT) == Rectangle2D.OUT_RIGHT && dx != 0.0) {
                y1 = y1 + (maxX - x1) * dy / dx;
                x1 = maxX;
            } else if ((f1 & Rectangle2D.OUT_BOTTOM) == Rectangle2D.OUT_BOTTOM && dy != 0.0) {
                x1 = x1 + (maxY - y1) * dx / dy;
                y1 = maxY;
            } else if ((f1 & Rectangle2D.OUT_TOP) == Rectangle2D.OUT_TOP && dy != 0.0) {
                x1 = x1 + (minY - y1) * dx / dy;
                y1 = minY;
            }
            f1 = rect.outcode(x1, y1);
        } else if (f2 != 0) {
            // second point is outside, so we update it against one of the
            // four sides then continue
            if ((f2 & Rectangle2D.OUT_LEFT) == Rectangle2D.OUT_LEFT && dx != 0.0) {
                y2 = y2 + (minX - x2) * dy / dx;
                x2 = minX;
            } else if ((f2 & Rectangle2D.OUT_RIGHT) == Rectangle2D.OUT_RIGHT && dx != 0.0) {
                y2 = y2 + (maxX - x2) * dy / dx;
                x2 = maxX;
            } else if ((f2 & Rectangle2D.OUT_BOTTOM) == Rectangle2D.OUT_BOTTOM && dy != 0.0) {
                x2 = x2 + (maxY - y2) * dx / dy;
                y2 = maxY;
            } else if ((f2 & Rectangle2D.OUT_TOP) == Rectangle2D.OUT_TOP && dy != 0.0) {
                x2 = x2 + (minY - y2) * dx / dy;
                y2 = minY;
            }
            f2 = rect.outcode(x2, y2);
        }
    }

    line.setLine(x1, y1, x2, y2);
    return true; // the line is visible - if it wasn't, we'd have
                 // returned false from within the while loop above

}

From source file:RectUtils.java

/**
 * Unions the pair of source <code>Rectangle2D</code> objects and puts the
 * result into the returned <code>Rectangle2D</code> object. This method
 * extends the Rectangle2D version by checking for null parameters, the
 * returned value will also be <code>null</code> if the two input
 * rectangles are <code>null</code>
 * /* ww  w . ja  va 2 s. com*/
 * @param src1
 *            the first of a pair of <code>Rectangle2D</code> objects to
 *            be combined with each other
 * @param src2
 *            the second of a pair of <code>Rectangle2D</code> objects to
 *            be combined with each other
 * 
 */
public static Rectangle2D union(Rectangle2D src1, Rectangle2D src2) {
    Rectangle2D result = null;
    if (src1 == null && src2 == null) {
        result = null;
    } else if (src1 != null && src2 != null) {
        double x1 = Math.min(src1.getMinX(), src2.getMinX());
        double y1 = Math.min(src1.getMinY(), src2.getMinY());
        double x2 = Math.max(src1.getMaxX(), src2.getMaxX());
        double y2 = Math.max(src1.getMaxY(), src2.getMaxY());
        result = new Rectangle2D.Double();
        result.setFrameFromDiagonal(x1, y1, x2, y2);
    } else if (src1 != null) {
        double x1 = src1.getMinX();
        double y1 = src1.getMinY();
        double x2 = src1.getMaxX();
        double y2 = src1.getMaxY();
        result = new Rectangle2D.Double();
        result.setFrameFromDiagonal(x1, y1, x2, y2);
    } else {
        // only src2 is non-null
        double x1 = src2.getMinX();
        double y1 = src2.getMinY();
        double x2 = src2.getMaxX();
        double y2 = src2.getMaxY();
        result = new Rectangle2D.Double();
        result.setFrameFromDiagonal(x1, y1, x2, y2);
    }
    return result;
}

From source file:org.jax.maanova.plot.PlotUtil.java

/**
 * Rescales the XY plot to match the viewing area
 * @param viewArea/*from  w w  w .  jav  a2  s.  co  m*/
 *          the viewing area (null means we should use autorange)
 * @param plot
 *          the plot to rescale
 */
public static void rescaleXYPlot(final Rectangle2D viewArea, final XYPlot plot) {
    if (viewArea == null) {
        plot.getDomainAxis().setAutoRange(true);
        plot.getRangeAxis().setAutoRange(true);
    } else {
        plot.getDomainAxis().setRange(new Range(viewArea.getMinX(), viewArea.getMaxX()), true, false);
        plot.getRangeAxis().setRange(new Range(viewArea.getMinY(), viewArea.getMaxY()), true, true);
    }
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

public static Abstract2DMask translateChartRectangle(Abstract2DMask mask, Rectangle2D imageArea,
        JFreeChart chart) {/* w  ww .  j a v  a2s .  co  m*/
    Rectangle2D bound = mask.getRectangleFrame();
    Point2D start = new Point2D.Double(bound.getMinX(), bound.getMinY());
    Point2D end = new Point2D.Double(bound.getMaxX(), bound.getMaxY());
    Point2D screenStart = translateChartPoint(start, imageArea, chart);
    Point2D screenEnd = translateChartPoint(end, imageArea, chart);
    Abstract2DMask imageMask = mask.clone();
    imageMask.setRectangleFrame(new Rectangle2D.Double(Math.min(screenStart.getX(), screenEnd.getX()),
            Math.min(screenStart.getY(), screenEnd.getY()), Math.abs(screenStart.getX() - screenEnd.getX()),
            Math.abs(screenStart.getY() - screenEnd.getY())));
    return imageMask;
}

From source file:org.logisticPlanning.utils.graphics.chart.impl.jfree._JFCLineChart2D.java

/**
 * Creates a rectangle that is aligned to the frame.
 *
 * @param dimensions//from   w ww . j  av a 2 s .  c  o  m
 *          the dimensions for the rectangle.
 * @param frame
 *          the frame to align to.
 * @param hAlign
 *          the horizontal alignment.
 * @param vAlign
 *          the vertical alignment.
 * @return A rectangle.
 */
private static final Rectangle2D __createAlignedRectangle2D(final Size2D dimensions, final Rectangle2D frame,
        final HorizontalAlignment hAlign, final VerticalAlignment vAlign) {
    double x, y;

    x = y = Double.NaN;

    if (hAlign == HorizontalAlignment.LEFT) {
        x = frame.getX();
    } else if (hAlign == HorizontalAlignment.CENTER) {
        x = frame.getCenterX() - (dimensions.width / 2.0);
    } else if (hAlign == HorizontalAlignment.RIGHT) {
        x = frame.getMaxX() - dimensions.width;
    }
    if (vAlign == VerticalAlignment.TOP) {
        y = frame.getY();
    } else if (vAlign == VerticalAlignment.CENTER) {
        y = frame.getCenterY() - (dimensions.height / 2.0);
    } else if (vAlign == VerticalAlignment.BOTTOM) {
        y = frame.getMaxY() - dimensions.height;
    }

    return new Rectangle2D.Double(x, y, dimensions.width, dimensions.height);
}