Two Rectangles intersection

后端 未结 7 2116
北海茫月
北海茫月 2020-11-27 16:39

I have two rectangles characterized by 4 values each :

Left position X, top position Y, width W and height H:

7条回答
  •  佛祖请我去吃肉
    2020-11-27 17:04

    Should the two rectangles have the same dimensions you can do:

    if (abs (x1 - x2) < w && abs (y1 - y2) < h) {
        // overlaps
    }
    

提交回复
热议问题