Java 检查两个矩形是否在任何一点重叠

问题描述:

我有多个矩形和一个特殊的矩形:选择矩形.我想检查每个矩形是否包含至少一个位于选择矩形内的点.为了清楚起见,这是一张图片:

I have multiple rectangles and one special rectangle: the selection rect. I want to check for each rectangle if the rectangle contains at least one point which is inside the selection rectangle. Here is an image for clarity:

这将查找矩形是否与另一个矩形重叠:

This will find if the rectangle is overlapping another rectangle:

public boolean overlaps (Rectangle r) {
    return x < r.x + r.width && x + width > r.x && y < r.y + r.height && y + height > r.y;
}