00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef HEADER_SUPERTUX_MATH_SIZE_HPP
00018 #define HEADER_SUPERTUX_MATH_SIZE_HPP
00019
00020 #include <iosfwd>
00021
00022 class Sizef;
00023
00024 class Size
00025 {
00026 public:
00027 Size() :
00028 width(0),
00029 height(0)
00030 {}
00031
00032 Size(int width_, int height_) :
00033 width(width_),
00034 height(height_)
00035 {}
00036
00037 Size(const Size& rhs) :
00038 width(rhs.width),
00039 height(rhs.height)
00040 {}
00041
00042 explicit Size(const Sizef& rhs);
00043
00044 Size& operator*=(int factor)
00045 {
00046 width *= factor;
00047 height *= factor;
00048 return *this;
00049 }
00050
00051 Size& operator/=(int divisor)
00052 {
00053 width /= divisor;
00054 height /= divisor;
00055 return *this;
00056 }
00057
00058 Size& operator+=(const Size& rhs)
00059 {
00060 width += rhs.width;
00061 height += rhs.height;
00062 return *this;
00063 }
00064
00065 Size& operator-=(const Size& rhs)
00066 {
00067 width -= rhs.width;
00068 height -= rhs.height;
00069 return *this;
00070 }
00071
00072 public:
00073 int width;
00074 int height;
00075 };
00076
00077 inline Size operator*(const Size& lhs, int factor)
00078 {
00079 return Size(lhs.width * factor,
00080 lhs.height * factor);
00081 }
00082
00083 inline Size operator*(int factor, const Size& rhs)
00084 {
00085 return Size(rhs.width * factor,
00086 rhs.height * factor);
00087 }
00088
00089 inline Size operator/(const Size& lhs, int divisor)
00090 {
00091 return Size(lhs.width / divisor,
00092 lhs.height / divisor);
00093 }
00094
00095 inline Size operator+(const Size& lhs, const Size& rhs)
00096 {
00097 return Size(lhs.width + rhs.width,
00098 lhs.height + rhs.height);
00099 }
00100
00101 inline Size operator-(const Size& lhs, const Size& rhs)
00102 {
00103 return Size(lhs.width - rhs.width,
00104 lhs.height - rhs.height);
00105 }
00106
00107 inline bool operator==(const Size& lhs, const Size& rhs)
00108 {
00109 return (lhs.width == rhs.width) && (lhs.height == rhs.height);
00110 }
00111
00112 inline bool operator!=(const Size& lhs, const Size& rhs)
00113 {
00114 return (lhs.width != rhs.width) || (lhs.height != rhs.height);
00115 }
00116
00117 std::ostream& operator<<(std::ostream& s, const Size& size);
00118
00119 #endif