[ create a new paste ] login | about

Link: http://codepad.org/FMVzUAWO    [ raw code | output | fork ]

sehe - C++, pasted on Jul 12:
// MODIFIED VERSION (Bounding Box)

#include <iostream>

struct R
{
    int x1,y1,x2,y2;
    int height() const { return y2-y1; }
    int width() const  { return y2-y1; }
};

R combined(R const& a, R const& b)
{
    R r;
    r.x1 = min(a.x1, b.x1);
    r.y1 = min(a.y1, b.y1);
    r.x2 = max(a.x2, b.x2);
    r.y2 = max(a.y2, b.y2);
    return r;
}

std::ostream& operator<<(std::ostream &os, R const& r)
{
    return os << '(' << r.x1 << "," << r.y1 << ")-(" << r.x2 << ',' << r.y2 << ')';
}

int main()
{
	{
		std::cout << "sample from original question" << std::endl;
		R a = { 0, 0,   320, 119 };
		R b = { 0, 120, 320, 239 };

		std::cout << "a: " << a << "\t b: " << b << std::endl;
		std::cout << "r: " << combined(a,b) << std::endl;
	}
	{
		std::cout << "sample from the comment" << std::endl;
		R a = { 0, 0, 1, 320 }; // width=320, height=1
		R b = { 0, 0, 2, 320 }; // width=320, height=1

		std::cout << "a: " << a << "\t b: " << b << std::endl;
		std::cout << "r: " << combined(a,b) << std::endl;
	}
}


Output:
1
2
3
4
5
6
sample from original question
a: (0,0)-(320,119)	 b: (0,120)-(320,239)
r: (0,0)-(320,239)
sample from the comment
a: (0,0)-(1,320)	 b: (0,0)-(2,320)
r: (0,0)-(2,320)


Create a new paste based on this one


Comments: