3 ** Copyright (c) 1997-2005 The ClanLib Team
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
27 ** (if your name is missing here, please add it)
33 #ifndef HEADER_WINDSTILLE_MATH_SIZE_HPP
34 #define HEADER_WINDSTILLE_MATH_SIZE_HPP
44 //: 2D (width,height) size structure.
51 //: Constructs a size structure.
52 //param width: Initial width of size structure.
53 //param height: Initial height of size structure.
54 //param size: Size structure to construct this one from.
59 Size(int width_, int height_)
60 : width(width_), height(height_)
68 explicit Size(const Sizef& s);
80 //: Size += Size operator.
81 Size &operator+=(const Size &s)
82 { width += s.width; height += s.height; return *this; }
84 //: Size -= Size operator.
85 Size &operator-=(const Size &s)
86 { width -= s.width; height -= s.height; return *this; }
88 //: Size + Size operator.
89 Size operator+(const Size &s) const
90 { return Size(width + s.width, height + s.height); }
92 //: Size - Size operator.
93 Size operator-(const Size &s) const
94 { return Size(width - s.width, height - s.height); }
96 //: Size == Size operator (deep compare).
97 bool operator==(const Size &s) const
98 { return (width == s.width) && (height == s.height); }
100 //: Size != Size operator (deep compare).
101 bool operator!=(const Size &s) const
102 { return (width != s.width) || (height != s.height); }
105 //: 2D (width,height) floating point size structure.
110 //: Constructs a size structure.
111 //param width: Initial width of size structure.
112 //param height: Initial height of size structure.
113 //param size: Size structure to construct this one from.
120 : width(static_cast<float>(s.width)),
121 height(static_cast<float>(s.height))
124 Sizef(float width_, float height_)
129 Sizef(const Sizef &s)
144 //: Size += Size operator.
145 Sizef &operator+=(const Sizef &s)
146 { width += s.width; height += s.height; return *this; }
148 //: Size -= Size operator.
149 Sizef &operator-=(const Sizef &s)
150 { width -= s.width; height -= s.height; return *this; }
152 //: Size + Size operator.
153 Sizef operator+(const Sizef &s) const
154 { return Sizef(width + s.width, height + s.height); }
156 //: Size - Size operator.
157 Sizef operator-(const Sizef &s) const
158 { return Sizef(width - s.width, height - s.height); }
160 //: Size == Size operator (deep compare).
161 bool operator==(const Sizef &s) const
162 { return (width == s.width) && (height == s.height); }
164 //: Size != Size operator (deep compare).
165 bool operator!=(const Size &s) const
166 { return (width != s.width) || (height != s.height); }
169 inline Size::Size(const Sizef& s)
170 : width(static_cast<int>(s.width)),
171 height(static_cast<int>(s.height))
174 inline std::ostream& operator<<(std::ostream& s, const Size& size)
176 return s << "Size(" << size.width << ", " << size.height << ")";