List of utility methods to do Rectangle Intersect
Rectangle | getMaxIntersection(List get Max Intersection int maxIntersection = 0; Rectangle result = null; for (Rectangle targetRect : targetRects) { int intersection = getIntersection(targetRect, rect); if (maxIntersection < intersection) { maxIntersection = intersection; result = targetRect; return result; |
Rectangle | intersect(Rectangle r1, Rectangle r2, Rectangle result) More efficient version of Sun's Rectangle intersection() method int x1 = max(r1.x, r2.x); int x2 = min(r1.x + r1.width, r2.x + r2.width); int y1 = max(r1.y, r2.y); int y2 = min(r1.y + r1.height, r2.y + r2.height); if (((x2 - x1) < 0) || ((y2 - y1) < 0)) result.x = result.y = result.width = result.height = 0; else { result.x = x1; ... |
boolean | intersect(Rectangle rect1, Rectangle rect2) Returns true if the two specified rectangles intersect. return rect1.intersects(rect2);
|
Line2D.Double | intersection(Line2D.Double line, Rectangle2D.Double bounds) intersection Point2D.Double bottom = computeSegmentIntersection(line.x1, line.y1, line.x2, line.y2, bounds.getMinX(), bounds.getMaxY(), bounds.getMaxX(), bounds.getMaxY()); Point2D.Double right = computeSegmentIntersection(line.x1, line.y1, line.x2, line.y2, bounds.getMaxX(), bounds.getMaxY(), bounds.getMaxX(), bounds.getMinY()); Point2D.Double top = computeSegmentIntersection(line.x1, line.y1, line.x2, line.y2, bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(), bounds.getMinY()); Point2D.Double left = computeSegmentIntersection(line.x1, line.y1, line.x2, line.y2, bounds.getMinX(), bounds.getMinY(), bounds.getMinX(), bounds.getMaxY()); ... |
boolean | intersection(Rectangle r1, Rectangle r2, Rectangle out) intersection int xmin = Math.max(r1.x, r2.x); int xmax1 = r1.x + r1.width; int xmax2 = r2.x + r2.width; int xmax = Math.min(xmax1, xmax2); if (xmax > xmin) { int ymin = Math.max(r1.y, r2.y); int ymax1 = r1.y + r1.height; int ymax2 = r2.y + r2.height; ... |
void | intersection(Rectangle rectangle, Rectangle rectangle1, Rectangle rectangle2) intersection int i = rectangle.x; int j = rectangle.y; int k = rectangle1.x; int l = rectangle1.y; int i1 = i; i1 += rectangle.width; int j1 = j; j1 += rectangle.height; ... |
boolean | intersectRect(double x1, double y1, double w1, double h1, double x2, double y2, double w2, double h2) intersect Rect return intersectRange(x1, x1 + w1, x2, x2 + w2) && intersectRange(y1, y1 + h1, y2, y2 + h2);
|
boolean | intersects(double oldx, double oldy, double oldwidth, double oldheight, double oldx2, double oldy2, double oldwidth2, double oldheight2) intersects double x, y, width, height, x2, y2, width2, height2; x = oldx; y = oldy; width = oldwidth; height = oldheight; if (oldwidth < 0) { width = oldx + oldwidth; x -= Math.abs(oldwidth); ... |
boolean | intersects(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) Tests four points to see if a line from the first to the second would intersect a line from the third to the fourth. return (((x1 == x3) && (y1 == y3)) || ((x1 == x4) && (y1 == y4)) || ((x2 == x3) && (y2 == y3))
|| ((x2 == x4) && (y2 == y4)) || (((CCW(x1, y1, x2, y2, x3, y3) * CCW(x1, y1, x2, y2, x4, y4)) <= 0)
&& ((CCW(x3, y3, x4, y4, x1, y1) * CCW(x3, y3, x4, y4, x2, y2)) <= 0)));
|
boolean | intersects(final float x, final float y, final float z, final int sx, final int sy, final int sz) intersects if (x >= 0 && y >= 0 && z >= 0 && x < sx && y < sy && z < sz) return true; else return false; |