List of utility methods to do Rectangle
Rectangle | interpolate(Rectangle r1, Rectangle r2, float f) interpolate Rectangle out = new Rectangle(); interpolate(r1, r2, f, out); return out; |
Set | mergeRects(Set merge Rects Set<Rectangle> unmerged = new HashSet<Rectangle>(prev); if (!prev.isEmpty() && !current.isEmpty()) { Rectangle[] pr = prev.toArray(new Rectangle[prev.size()]); Rectangle[] cr = current.toArray(new Rectangle[current.size()]); int ipr = 0; int icr = 0; while (ipr < pr.length && icr < cr.length) { while (cr[icr].x < pr[ipr].x) { ... |
void | normalizeRect(Rectangle rect) normalize Rect if (rect.width < 0) { rect.width = -rect.width; rect.x -= rect.width; if (rect.height < 0) { rect.height = -rect.height; rect.y -= rect.height; |
Rectangle | randomRectangle(int minW, int maxW, int minH, int maxH) Returns a rectangle with the given min/max width and height. int w = random(minW, maxW); int h = random(minH, maxH); return new Rectangle(w, h); |
Rectangle | randomSquare(int minW, int maxW) Returns a square with the given min/max side length. int w = random(minW, maxW); return new Rectangle(w, w); |
Rectangle | rectangleResize(Rectangle rect, int width, int height) rectangle Resize return new Rectangle(rect.x + (rect.width - width) / 2, rect.y + (rect.height - height) / 2, width, height); |
boolean | rectCollide(final Rectangle a, final Rectangle b) rect Collide if (a.x > b.x + b.width || a.y > b.y + b.height || a.x + a.width < b.x || a.y + a.height < b.y) { return false; return true; |
int | rectDistance(final Rectangle r, final Rectangle q) rect Distance if (rectOverlaps(r, q)) { return 0; int r_x0 = r.x; int r_x1 = r.x + r.width; int r_y0 = r.y; int r_y1 = r.y + r.height; int q_x0 = q.x; ... |
void | rectFromArray(Rectangle2D aRectangle, double[] pts) rect From Array double minX = pts[0]; double minY = pts[1]; double maxX = pts[0]; double maxY = pts[1]; double x; double y; for (int i = 1; i < 4; i++) { x = pts[2 * i]; ... |
Rectangle | rectFromRect2D(Rectangle2D rect) Make a Rectangle from a Rectangle2D (Rectangle is subclass of Rectangle2D) return ((rect == null) ? null : new Rectangle((int) rect.getX(), (int) rect.getY(), (int) rect.getWidth(), (int) rect.getHeight())); |