The answer that you linked actually "intersects" the rectangles as polygons, as polygonal sets of points on the plane, and returns lower-left and upper-right corners of the resultant rectangle (as a polygonal set). The two returned points actually trivially define all four corners of the resultant rectangle. So, no it does not "return two points". It actually returns four points.
In order to solve your problem you have to decide which ones of these four points to keep and which to discard. The rule is pretty simple: you have to keep only those points that do not coincide with corresponding vertices of the original rectangles. You can simply check this directly, in trivial and tedious fashion. Eight checks (if I'm not missing any) and you are done.
Or you can use a slightly more tricky approach.
Let's say we have two rectangles: (x11, y11)-(x12, y12)
and (x21, y21)-(x22, y22)
. The rectangles are normalized (as defined at the link). We still use the same min-max technique when calculating the overlap rectangle, but at the same time we also memorize which original rectangle(s) supplied the extreme values
int x1 = max(x11, x21);
unsigned flags_x1 = (x1 == x11) | ((x1 == x21) << 1);
int y1 = max(y11, y21);
unsigned flags_y1 = (y1 == y11) | ((y1 == y21) << 1);
int x2 = min(x12, x22);
unsigned flags_x2 = (x2 == x12) | ((x2 == x22) << 1);
int y2 = min(y12, y22);
unsigned flags_y2 = (y2 == y12) | ((y2 == y22) << 1);
Now we check whether these rectangles even have a proper overlap
if (x1 >= x2 || y1 >= y2)
/* No overlap. Done */;
But if overlap exists, we use our flags_...
variables to output only those points that are formed by extreme values that came from two different rectangles
/* Lower-left */
if ((flags_x1 & flags_y1) == 0)
/* Output (x1, y1) as intersection point */;
/* Lower-right */
if ((flags_x2 & flags_y1) == 0)
/* Output (x2, y1) as intersection point */;
/* Upper-left */
if ((flags_x1 & flags_y2) == 0)
/* Output (x1, y2) as intersection point */;
/* Upper-right */
if ((flags_x2 & flags_y2) == 0)
/* Output (x2, y2) as intersection point */;
Note that if one rectangle lies completely inside another rectangle the no-overlap test above will pass (since rectangles actually do overlap), but the flags_...
tests will discard all four vertices.
As usual, extra effort might be needed (or not) to properly process boundary cases, such as touching rectangles (inside or outside touch).