List of utility methods to do Rectangle Fit
void | fitRectangle(Rectangle rect, Dimension d) fit Rectangle fitRectangle(rect, d.width, d.height); |
void | fitRectangle(Rectangle rect, Rectangle target) fit Rectangle if (rect.width > target.width) { rect.width = target.width; if (rect.height > target.height) { rect.height = target.height; if (rect.x < target.x) { rect.x = target.x; ... |
Rectangle | fitRectangles(Dimension imageSize, Dimension size) fit Rectangles double aspectX = (double) size.width / imageSize.width; double aspectY = (double) size.height / imageSize.height; double aspect = Math.min(aspectX, aspectY); int paintedWidth = (int) (imageSize.width * aspect); int paintedHeight = (int) (imageSize.height * aspect); int x = (size.width - paintedWidth) / 2; int y = (size.height - paintedHeight) / 2; return new Rectangle(x, y, paintedWidth, paintedHeight); ... |
Point | fitRectInRect(Rectangle rect, Rectangle bounds) Returns the most reasonable position for the specified rectangle to be placed at so as to maximize its containment by the specified bounding rectangle while still placing it as near its original coordinates as possible. return new Point(Math.min(bounds.x + bounds.width - rect.width, Math.max(rect.x, bounds.x)), Math.min(bounds.y + bounds.height - rect.height, Math.max(rect.y, bounds.y))); |
boolean | fits(Rectangle r) fits boolean ret = false; final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); if (((r.x + r.width) <= screenSize.width) && ((r.y + r.height) <= screenSize.height)) { ret = true; return ret; |
boolean | fits(Rectangle2D o1, Rectangle2D o2) Takes two rectangles and check if the first fits into the second return (o1.getHeight() <= o2.getHeight() && o1.getWidth() <= o2.getWidth());
|
boolean | fitsInside(Dimension2D dim, Rectangle2D rect) fits Inside return rect.getWidth() >= dim.getWidth() && rect.getHeight() >= dim.getHeight();
|
boolean | fitsRotated(Rectangle2D o1, Rectangle2D o2) fits Rotated return (o1.getHeight() <= o2.getWidth() && o1.getWidth() <= o2.getHeight());
|
Rectangle | reScale(Rectangle rect, int oldScale, int newScale) re Scale Rectangle res = new Rectangle(); res.x = reScale(rect.x, oldScale, newScale); res.y = reScale(rect.y, oldScale, newScale); res.width = reScale(rect.width, oldScale, newScale); res.height = reScale(rect.height, oldScale, newScale); return res; |
Rectangle | shrinkToFit(Rectangle container, Rectangle item) shrink To Fit double scale = scaleProportional(container, item); if (scale > 1) { return item; } else { return new Rectangle((int) (item.width * scale), (int) (item.height * scale)); |