size.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib Team
4 **
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.
8 **
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:
12 **
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.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Kenneth Gangstoe
28 */
29 
30 
31 #pragma once
32 
33 #include "vec2.h"
34 
35 namespace clan
36 {
39 
40 template<typename Type>
41 class Vec2;
42 
43 template<typename Type>
44 class Vec3;
45 
46 template<typename Type>
47 class Vec4;
48 
53 template<typename Type>
54 class Sizex
55 {
58 
59 public:
61  Sizex() : width(0), height(0) { return; }
62 
67  Sizex(Type width, Type height)
68  : width(width), height(height) { }
69 
73  Sizex(const Sizex<Type> &s)
74  : width(s.width), height(s.height) {}
75 
79 
80 public:
82  Type width;
83 
85  Type height;
86 
90 
91 public:
92  operator Vec2<Type>() const
93  {
94  return Vec2<Type>(width, height);
95  }
96 
99  { width += s.width; height += s.height; return *this; }
100 
103  { width -= s.width; height -= s.height; return *this; }
104 
107  { return Sizex<Type>(width + s.width, height + s.height); }
108 
111  { return Sizex<Type>(width - s.width, height - s.height); }
112 
114  Sizex<Type> &operator+=(const Type &s)
115  { width += s; height += s; return *this; }
116 
118  Sizex<Type> &operator-=(const Type &s)
119  { width -= s; height -= s; return *this; }
120 
122  Sizex<Type> &operator*=(const Type &s)
123  { width *= s; height *= s; return *this; }
124 
126  Sizex<Type> &operator/=(const Type &s)
127  { width /= s; height /= s; return *this; }
128 
130  Sizex<Type> operator+(const Type &s) const
131  { return Sizex<Type>(width + s, height + s); }
132 
134  Sizex<Type> operator-(const Type &s) const
135  { return Sizex<Type>(width - s, height - s); }
136 
138  Sizex<Type> operator*(const Type &s) const
139  { return Sizex<Type>(width * s, height * s); }
140 
142  Sizex<Type> operator/(const Type &s) const
143  { return Sizex<Type>(width / s, height / s); }
144 
146  bool operator==(const Sizex<Type> &s) const
147  { return (width == s.width) && (height == s.height); }
148 
150  bool operator!=(const Sizex<Type> &s) const
151  { return (width != s.width) || (height != s.height); }
153 };
154 
156 class Size : public Sizex<int>
157 {
158 public:
159  Size() : Sizex<int>() {}
160  Size(int width, int height) : Sizex<int>(width, height) {}
161  Size(const Sizex<int> &s) : Sizex<int>(s) {}
162  Size(const Vec2<int> &s) : Sizex<int>(s.x, s.y) {}
163 
164  explicit Size(const Sizex<float> &copy) { width = (int)(copy.width+0.5f); height = (int)(copy.height+0.5f); }
165  explicit Size(const Sizex<double> &copy) { width = (int)(copy.width+0.5); height = (int)(copy.height+0.5); }
166 };
167 
169 class Sizef : public Sizex<float>
170 {
171 public:
172  Sizef() : Sizex<float>() {}
173  Sizef(float width, float height) : Sizex<float>(width, height) {}
174  Sizef(const Sizex<float> &s) : Sizex<float>(s) {}
175  Sizef(const Vec2<float> &s) : Sizex<float>(s.x, s.y) {}
176 
177  Sizef(const Sizex<int> &copy) { width = (float)copy.width; height = (float)copy.height; }
178  explicit Sizef(const Sizex<double> &copy) { width = (float)copy.width; height = (float)copy.height; }
179 };
180 
182 class Sized : public Sizex<double>
183 {
184 public:
185  Sized() : Sizex<double>() {}
186  Sized(double width, double height) : Sizex<double>(width, height) {}
187  Sized(const Sizex<double> &s) : Sizex<double>(s) {}
188  Sized(const Vec2<double> &s) : Sizex<double>(s.x, s.y) {}
189 
190  Sized(const Sizex<int> &copy) { width = (double)copy.width; height = (double)copy.height; }
191  Sized(const Sizex<float> &copy) { width = (double)copy.width; height = (double)copy.height; }
192 };
193 
194 }
195 
Sizex< Type > operator*(const Type &s) const
Size * operator.
Definition: size.h:138
Sizex< Type > operator/(const Type &s) const
Size / operator.
Definition: size.h:142
Sizex< Type > & operator+=(const Type &s)
Size += operator.
Definition: size.h:114
Size(const Sizex< double > &copy)
Definition: size.h:165
Sizex< Type > & operator-=(const Type &s)
Size -= operator.
Definition: size.h:118
Sized(const Sizex< double > &s)
Definition: size.h:187
Sizex< Type > operator-(const Type &s) const
Size - operator.
Definition: size.h:134
Sizex< Type > & operator/=(const Type &s)
Size /= operator.
Definition: size.h:126
Sizef(float width, float height)
Definition: size.h:173
Sized(const Sizex< float > &copy)
Definition: size.h:191
Sizef(const Vec2< float > &s)
Definition: size.h:175
Sizex()
Constructs a size structure.
Definition: size.h:61
Sizex< Type > & operator*=(const Type &s)
Size *= operator.
Definition: size.h:122
2D (width,height) size structure - Double
Definition: size.h:183
Sized(const Sizex< int > &copy)
Definition: size.h:190
Size(int width, int height)
Definition: size.h:160
Sizef(const Sizex< int > &copy)
Definition: size.h:177
Sizex< Type > & operator-=(const Sizex< Type > &s)
Size -= Size operator.
Definition: size.h:102
Sizef(const Sizex< float > &s)
Definition: size.h:174
Sizef()
Definition: size.h:172
2D vector
Definition: line.h:48
Size(const Sizex< int > &s)
Definition: size.h:161
Sizex(const Sizex< Type > &s)
Constructs a size structure.
Definition: size.h:73
Size(const Vec2< int > &s)
Definition: size.h:162
Sizef(const Sizex< double > &copy)
Definition: size.h:178
Sizex< Type > operator+(const Sizex< Type > &s) const
Size + Size operator.
Definition: size.h:106
4D vector
Definition: size.h:47
Sized(double width, double height)
Definition: size.h:186
Definition: clanapp.h:36
Sized(const Vec2< double > &s)
Definition: size.h:188
Sized()
Definition: size.h:185
Type width
Size width.
Definition: size.h:82
bool operator!=(const Sizex< Type > &s) const
Size != Size operator (deep compare).
Definition: size.h:150
bool operator==(const Sizex< Type > &s) const
Size == Size operator (deep compare).
Definition: size.h:146
Type height
Size height.
Definition: size.h:85
Sizex< Type > operator-(const Sizex< Type > &s) const
Size - Size operator.
Definition: size.h:110
2D (width,height) size structure - Integer
Definition: size.h:157
2D (width,height) size structure - Float
Definition: size.h:170
Size()
Definition: size.h:159
2D (width,height) size structure.
Definition: size.h:55
Sizex(Type width, Type height)
Constructs a size structure.
Definition: size.h:67
Sizex< Type > operator+(const Type &s) const
Size + operator.
Definition: size.h:130
Size(const Sizex< float > &copy)
Definition: size.h:164
Sizex< Type > & operator+=(const Sizex< Type > &s)
Size += Size operator.
Definition: size.h:98