00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00029 #ifndef _GG_PtRect_h_
00030 #define _GG_PtRect_h_
00031
00032 #include <GG/Base.h>
00033
00034 #include <boost/serialization/access.hpp>
00035 #include <boost/serialization/nvp.hpp>
00036
00037 #include <iosfwd>
00038
00039
00040 namespace GG {
00041
00043 struct GG_API Pt
00044 {
00046 Pt();
00047 Pt(int x_, int y_);
00048
00049
00051
00053 bool Less(const Pt& rhs) const {return x < rhs.x ? true : (x == rhs.x ? (y < rhs.y ? true : false) : false);}
00055
00057 void operator+=(const Pt& rhs) {x += rhs.x; y += rhs.y;}
00058 void operator-=(const Pt& rhs) {x -= rhs.x; y -= rhs.y;}
00059 Pt operator-() const {return Pt(-x, -y);}
00060
00061
00062 int x;
00063 int y;
00064
00065 private:
00066 friend class boost::serialization::access;
00067 template <class Archive>
00068 void serialize(Archive& ar, const unsigned int version);
00069 };
00070
00072 struct GG_API Rect
00073 {
00075 Rect();
00076 Rect(const Pt& pt1, const Pt& pt2);
00077 Rect(int x1, int y1, int x2, int y2);
00078
00079
00081 int Left() const {return ul.x;}
00082 int Right() const {return lr.x;}
00083 int Top() const {return ul.y;}
00084 int Bottom() const {return lr.y;}
00085 Pt UpperLeft() const {return ul;}
00086 Pt LowerRight() const {return lr;}
00087 int Width() const {return lr.x - ul.x;}
00088 int Height() const {return lr.y - ul.y;}
00089
00090 bool Contains(const Pt& pt) const;
00091
00092
00094 void operator+=(const Pt& pt) {ul += pt; lr += pt;}
00095 void operator-=(const Pt& pt) {ul -= pt; lr -= pt;}
00096
00097
00098 Pt ul;
00099 Pt lr;
00100
00101 private:
00102 friend class boost::serialization::access;
00103 template <class Archive>
00104 void serialize(Archive& ar, const unsigned int version);
00105 };
00106
00107 GG_API inline bool operator==(const Pt& lhs, const Pt& rhs) {return lhs.x == rhs.x && lhs.y == rhs.y;}
00108 GG_API inline bool operator!=(const Pt& lhs, const Pt& rhs) {return !(lhs == rhs);}
00109 GG_API inline bool operator<(const Pt& lhs, const Pt& rhs) {return lhs.x < rhs.x && lhs.y < rhs.y;}
00110 GG_API inline bool operator>(const Pt& lhs, const Pt& rhs) {return lhs.x > rhs.x && lhs.y > rhs.y;}
00111 GG_API inline bool operator<=(const Pt& lhs, const Pt& rhs) {return lhs.x <= rhs.x && lhs.y <= rhs.y;}
00112 GG_API inline bool operator>=(const Pt& lhs, const Pt& rhs) {return lhs.x >= rhs.x && lhs.y >= rhs.y;}
00113 GG_API inline Pt operator+(const Pt& lhs, const Pt& rhs) {return Pt(lhs.x + rhs.x, lhs.y + rhs.y);}
00114 GG_API inline Pt operator-(const Pt& lhs, const Pt& rhs) {return Pt(lhs.x - rhs.x, lhs.y - rhs.y);}
00115
00116 GG_API std::ostream& operator<<(std::ostream& os, const Pt& pt);
00117
00119 GG_API inline bool operator==(const Rect& lhs, const Rect& rhs) {return lhs.ul.x == rhs.ul.x && lhs.lr.x == rhs.lr.x && lhs.lr.x == rhs.lr.x && lhs.lr.y == rhs.lr.y;}
00120
00122 GG_API inline bool operator!=(const Rect& lhs, const Rect& rhs) {return !(lhs == rhs);}
00123
00124 GG_API inline Rect operator+(const Rect& rect, const Pt& pt) {return Rect(rect.ul + pt, rect.lr + pt);}
00125 GG_API inline Rect operator-(const Rect& rect, const Pt& pt) {return Rect(rect.ul - pt, rect.lr - pt);}
00126 GG_API inline Rect operator+(const Pt& pt, const Rect& rect) {return rect + pt;}
00127 GG_API inline Rect operator-(const Pt& pt, const Rect& rect) {return rect - pt;}
00128
00129 GG_API std::ostream& operator<<(std::ostream& os, const Rect& rect);
00130
00131 }
00132
00133
00134 template <class Archive>
00135 void GG::Pt::serialize(Archive& ar, const unsigned int version)
00136 {
00137 ar & BOOST_SERIALIZATION_NVP(x)
00138 & BOOST_SERIALIZATION_NVP(y);
00139 }
00140
00141 template <class Archive>
00142 void GG::Rect::serialize(Archive& ar, const unsigned int version)
00143 {
00144 ar & BOOST_SERIALIZATION_NVP(ul)
00145 & BOOST_SERIALIZATION_NVP(lr);
00146 }
00147
00148 #endif // _GG_PtRect_h_
00149