Rectangle have area inside of another - Proof I was trying forever to write a simple program that showed if one rectangle has any area inside of another. It turns out it's very simple. Can somebody show me a proof to this mathematically? If not, could someone break it down. It hurts my brain to understand why this works.
Let (x1, y1, x2, y2) and (X1, Y1, X2, Y2).

public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
    int x1 = rec1[0], y1 = rec1[1], x2 = rec1[2], y2 = rec1[3];
    int X1 = rec2[0], Y1 = rec2[1], X2 = rec2[2], Y2 = rec2[3];

    return x1 < X2 
            && y1 < Y2
            && x2 > X1
            && y2 > Y1;
}

returns if a rect is inside of another.
I drew a picture, but I don't understand how it proves this case to the right here (where the rectangle on the right has no vertices inside of the other rectangle)
 A: On the coordinate plane, let:
Coordinates for Rectangle A:
(X1, Y1)
(X2, Y2)
(X3, Y3)
(X4, Y4)

Coordinates for Rectangle A:
(X5, Y5)
(X6, Y6)
(X7, Y7)
(X8, Y8)

If any value of X5 is less than or equal to X1 and any value of X7 is less than or equal to X3, the vertical dimensions will overlap because segment containing points X5 and X7 are within segment with points X1 and X3. The same is true for the other pair of x-coordinates.
Similary apply the pattern to the y-coordinates.
Hopefully this explantion suites you well. Comment further for clarification.
A: Let's think of the one-dimensional case first (intervals instead of rectangles). I will assume $x_1<x_2$ and $X_1<X_2$.
We will divide the proof into two cases. First, we will show that if the intervals intersect, then the code returns true. Second, we will show that if the code returns true, then the intervals intersect.
By definition, the intervals $(x_1,x_2)$ and $(X_1,X_2)$ intersect iff there's a number $p$ in both intervals, that is, a number $p$ satisfying $x_1<p<x_2$ and $X_1<p<X_2$. But then $x_1<p<X_2$ and $X_1<p<x_2$, which is what the code checks for. So if the intervals intersect then your code will return true.
Conversely, suppose your code returns true; we want to find a $p$ in both intervals, proving they intersect. Let$$p=\frac{\max\{x_1,X_1\}+\min\{x_2,X_2\}}2.$$Since your code returns true, everything in $\{x_1,X_1\}$ is less than everything in $\{x_2,X_2\}$, and $p$, being an average, lies between them. But then$$x_1,X_1\le\max\{x_1,X_1\}<p<\min\{x_2,X_2\}\le x_2,X_2$$and so $p$ lies in both intervals.
For the two-dimensional case, run the test on each coordinate.
