Good day for everyone! So, I have a case like this one. I need to write a method, that says if the rectangles overlap each other. Inputs are the following: height, width, x-pos and y-pos and rectangles are parallel to the x and the y axis. I used the solution from the questio, to which I gave a link, but it doesn't work properly. It tells that rectangles overlap even if they don't! Am I missing something important?
Code itself:
public static bool AreIntersected(Rectangle r1, Rectangle r2)
{
return (!(r1.Left > r2.Left + r2.Width) || !(r1.Left + r1.Width < r2.Left) || !(r1.Top < r2.Top - r2.Height)|| !(r1.Top - r1.Height > r2.Top));
}
Many thanks for your help!