| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #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;
- }
|