Determine if two rectangles overlap each other?

前端 未结 23 1191
礼貌的吻别
礼貌的吻别 2020-11-22 04:09

I am trying to write a C++ program that takes the following inputs from the user to construct rectangles (between 2 and 5): height, width, x-pos, y-pos. All of these rectang

23条回答
  •  没有蜡笔的小新
    2020-11-22 05:10

    Don't think of coordinates as indicating where pixels are. Think of them as being between the pixels. That way, the area of a 2x2 rectangle should be 4, not 9.

    bool bOverlap = !((A.Left >= B.Right || B.Left >= A.Right)
                   && (A.Bottom >= B.Top || B.Bottom >= A.Top));
    

提交回复
热议问题