636416a56a74eb330da14c6c1d0a2e9c93978bdb
[supertux.git] / src / math / sizef.hpp
1 //  SuperTux
2 //  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmail.com>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #ifndef HEADER_SUPERTUX_MATH_SIZEF_HPP
18 #define HEADER_SUPERTUX_MATH_SIZEF_HPP
19
20 #include <iosfwd>
21
22 class Size;
23
24 class Sizef
25 {
26 public:
27   Sizef() :
28     width(0.0f),
29     height(0.0f)
30   {}
31
32   Sizef(float width_, float height_) :
33     width(width_),
34     height(height_)
35   {}
36
37   Sizef(const Sizef& rhs) :
38     width(rhs.width),
39     height(rhs.height)
40   {}
41
42   Sizef(const Size& rhs);
43
44   Sizef& operator*=(float factor)
45   {
46     width  *= factor;
47     height *= factor;
48     return *this;
49   }
50
51   Sizef& operator/=(float divisor)
52   {
53     width  /= divisor;
54     height /= divisor;
55     return *this;
56   }
57
58   Sizef& operator+=(const Sizef& rhs)
59   {
60     width  += rhs.width;
61     height += rhs.height;
62     return *this;
63   }
64
65   Sizef& operator-=(const Sizef& rhs)
66   {
67     width  -= rhs.width;
68     height -= rhs.height;
69     return *this;
70   }
71
72 public:
73   float width;
74   float height;
75 };
76
77 inline Sizef operator*(const Sizef& lhs, float factor)
78 {
79   return Sizef(lhs.width  * factor,
80                lhs.height * factor);
81 }
82
83 inline Sizef operator*(float factor, const Sizef& rhs)
84 {
85   return Sizef(rhs.width  * factor,
86                rhs.height * factor);
87 }
88
89 inline Sizef operator/(const Sizef& lhs, float divisor)
90 {
91   return Sizef(lhs.width  / divisor,
92                lhs.height / divisor);
93 }
94
95 inline Sizef operator+(const Sizef& lhs, const Sizef& rhs)
96 {
97   return Sizef(lhs.width  + rhs.width,
98                lhs.height + rhs.height);
99 }
100
101 inline Sizef operator-(const Sizef& lhs, const Sizef& rhs)
102 {
103   return Sizef(lhs.width  - rhs.width,
104                lhs.height - rhs.height);
105 }
106
107 inline bool operator==(const Sizef& lhs, const Sizef& rhs)
108 {
109   return (lhs.width == rhs.width) && (rhs.height == rhs.height);
110 }
111
112 inline bool operator!=(const Sizef& lhs, const Sizef& rhs)
113 {
114   return (lhs.width != rhs.width) || (lhs.height != rhs.height);
115 }
116
117 std::ostream& operator<<(std::ostream& s, const Sizef& size);
118
119 #endif
120
121 /* EOF */