Calculating minimum size of rectangle that contains two smaller ones
For the moment, I'm assuming a typical graphics system with the origin at the top left. At the very least, the variable names I've used depend upon that to really make any sense. Anyway, I believe the logic you want can be embodied in code something like this (please forgive the sexist variable names):

Rectangle operator+(Rectangle &amp;o) {
    double my_left = std::min(x, x + a);
    double his_left = std::min(o.x, o.x + o.a);
    double left = std::min(my_left, his_left);

    double my_right = std::max(x, x + a);
    double his_right = std::max(o.x, o.x + o.a);
    double right = std::max(my_right, his_right);

    double my_top = std::min(y, y + b);
    double his_top = std::min(o.y, o.y + o.b);
    double top = std::min(my_top, his_top);

    double my_bottom = std::max(y, y + b);
    double his_bottom = std::max(o.y, o.y + o.b);
    double bottom = std::max(my_bottom, his_bottom);

    return Rectangle(left, top, right - left, bottom - top);
}


If you can be sure that a and b are non-negative, you can simplify that quite a bit to just:

Rectangle operator+(Rectangle &amp;o) {
    double left = std::min(x, o.x);
    double right = std::max(x + a, o.x + o.a);
    double top = std::min(y, o.y);
    double bottom = std::max(y + b, o.y + o.b);

    return Rectangle(left, top, right - left, bottom - top);
}


As for the rest of the code, I see two obvious things. First of all, the variable names aren't particularly helpful. I guess I can sort of keep things like x1 and x2 straight, but only just.

Second, the logic strikes me as almost a complete mess. I guess I can understand what it needs to do, and if I was willing to spend enough time on it I could verify that it works correctly--but it's not immediately obvious to me at first glance, and it would take some fairly exhaustive (and exhausting) analysis to be sure that it works for every possible case, not to mention being sure exactly how it works.

There's also one final caveat I feel obliged to add: an IEEE floating point number can be set to a NaN, which means all comparisons to that value will return false (even if (a == a) will yield false). If either of your rectangles contains a NaN, all of these will produce garbage results.