Java check if two rectangles overlap at any point

后端 未结 9 2275
醉梦人生
醉梦人生 2020-11-29 05:12

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

9条回答
  •  甜味超标
    2020-11-29 05:45

    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;
    }
    

提交回复
热议问题