Java check if two rectangles overlap at any point

后端 未结 9 2241
醉梦人生
醉梦人生 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:47

    If the first one implements RectangularShape and the second one is a Rectangle2D, you can simply use RectangularShape.intersects:

    selectionRectangle.intersects(otherRectangle)
    

    Tests if the interior of the Shape intersects the interior of a specified Rectangle2D

    From the Oracle Java docs

提交回复
热议问题