Java check if two rectangles overlap at any point

后端 未结 9 2271
醉梦人生
醉梦人生 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 06:12

    Here's another simpler solution:

        // Left x 
        int leftX = Math.max(x1, x3);
        // Right x
        int rightX = Math.min(x2, x4);
        // Bottom y
        int botY = Math.max(y1, y3);
        // TopY
        int topY = Math.min(y2, y4);
    
        if (rightX > leftX && topY > botY)
           return true;
    

提交回复
热议问题