00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __RECT_H_
00021 #define __RECT_H_
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include "config.h"
00025 #endif
00026
00027 #include <ostream>
00028
00033 class point {
00034 private:
00035 int _x;
00036 int _y;
00037 public:
00038 point() throw() : _x(0), _y(0) {};
00039 point(const point & p) throw() : _x(p.get_x()), _y(p.get_y()) {};
00040 explicit point(int x, int y) throw() : _x(x), _y(y) {};
00041 point & operator=(const point & p) throw() { _x = p.get_x(); _y = p.get_y(); return *this; };
00042 bool operator==(const point & p) const throw() { return _x == p.get_x() && _y == p.get_y(); };
00043 const int & get_x() const throw() { return _x; };
00044 const int & get_y() const throw() { return _y; };
00045 int & get_x() throw() { return _x; };
00046 int & get_y() throw() { return _y; };
00047 point operator+(const point & p) const throw() { return point(_x+p.get_x(), _y+p.get_y()); };
00048 point operator-(const point & p) const throw() { return point(_x-p.get_x(), _y-p.get_y()); };
00049 point & operator+=(const point & p) throw() { _x += p.get_x(); _y += p.get_y(); return *this; };
00050 point & operator-=(const point & p) throw() { _x -= p.get_x(); _y -= p.get_y(); return *this; };
00051 bool is_origin() const throw() { return *this == point(0, 0); };
00052 void set(int x, int y) throw() { _x = x; _y = y; }
00053 };
00054
00060 class rect {
00061 private:
00062 point _topleft;
00063 point _bottomright;
00064 protected:
00065 void check() throw(std::exception);
00066 public:
00067 rect() throw();
00068 rect(int x, int y) throw(std::exception);
00069 explicit rect(const point & size) throw(std::exception);
00070 rect(int x1, int y1, int x2, int y2) throw(std::exception);
00071 rect(const point & topleft, const point & bottomright) throw(std::exception);
00072 rect(const rect & r) throw();
00073 rect & operator=(const rect & r) throw();
00074 bool operator==(const rect & r) const throw();
00075 point size() const throw() { return (_bottomright - _topleft); };
00076 int width() const throw() { return size().get_x(); }
00077 int height() const throw() { return size().get_y(); }
00078 int left() const throw() { return _topleft.get_x(); }
00079 int right() const throw() { return _bottomright.get_x(); }
00080 int top() const throw() { return _topleft.get_y(); }
00081 int bottom() const throw() { return _bottomright.get_y(); }
00082 const point & topleft() const throw() { return _topleft; }
00083 const point & bottomright() const throw() { return _bottomright; }
00084
00092 bool is_inside(int x, int y) const throw();
00099 bool is_inside(const point & p) const throw();
00100 bool clip(rect & r) const throw(std::exception);
00101 };
00102
00103 extern std::ostream & operator<<(std::ostream & o, const rect & r);
00104 extern std::ostream & operator<<(std::ostream & o, const point & p);
00105
00106 #endif