#include "rectangle.h" Rect::Rect( int x1, int y1, int x2, int y2 ) { if ( x1 < x2 ) { left = x1; right = x2; } else { left = x2; right = x1; } if ( y1 < y2 ) { top = y1; bottom = y2; } else { top = y2; bottom = y1; } } Rect::Rect( const Point& p1, const Point& p2 ) { if ( p1.x < p2.x ) { left = p1.x; right = p2.x; } else { left = p2.x; right = p1.x; } if ( p1.y < p2.y ) { top = p1.y; bottom = p2.y; } else { top = p2.y; bottom = p1.y; } } Rect::Rect( const Rect& other ) : left( other.left ), top( other.top ), right( other.right ), bottom( other.bottom ) { } Rect::~Rect() { } Point Rect::TopLeft() { Point p( left, top ); return p; } Point Rect::BottomRight() { Point p( right, bottom ); return p; } Point Rect::CenterPoint() { Point p( ( right - left ) / 2, ( bottom - top ) / 2 ); return p; } int Rect::Width() { return right - left + 1; } int Rect::Height() { return bottom - top + 1; }