size.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2016 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  {
56  public:
58  Sizex() : width(0), height(0) { return; }
59 
64  Sizex(Type width, Type height)
65  : width(width), height(height) { }
66 
71  : width(s.width), height(s.height) {}
72 
74  Type width;
75 
77  Type height;
78 
79  operator Vec2<Type>() const
80  {
81  return Vec2<Type>(width, height);
82  }
83 
86  {
87  width += s.width; height += s.height; return *this;
88  }
89 
92  {
93  width -= s.width; height -= s.height; return *this;
94  }
95 
98  {
99  return Sizex<Type>(width + s.width, height + s.height);
100  }
101 
104  {
105  return Sizex<Type>(width - s.width, height - s.height);
106  }
107 
109  Sizex<Type> &operator+=(const Type &s)
110  {
111  width += s; height += s; return *this;
112  }
113 
115  Sizex<Type> &operator-=(const Type &s)
116  {
117  width -= s; height -= s; return *this;
118  }
119 
121  Sizex<Type> &operator*=(const Type &s)
122  {
123  width *= s; height *= s; return *this;
124  }
125 
127  Sizex<Type> &operator/=(const Type &s)
128  {
129  width /= s; height /= s; return *this;
130  }
131 
133  Sizex<Type> operator+(const Type &s) const
134  {
135  return Sizex<Type>(width + s, height + s);
136  }
137 
139  Sizex<Type> operator-(const Type &s) const
140  {
141  return Sizex<Type>(width - s, height - s);
142  }
143 
145  Sizex<Type> operator*(const Type &s) const
146  {
147  return Sizex<Type>(width * s, height * s);
148  }
149 
151  Sizex<Type> operator/(const Type &s) const
152  {
153  return Sizex<Type>(width / s, height / s);
154  }
155 
157  bool operator==(const Sizex<Type> &s) const
158  {
159  return (width == s.width) && (height == s.height);
160  }
161 
163  bool operator!=(const Sizex<Type> &s) const
164  {
165  return (width != s.width) || (height != s.height);
166  }
167  };
168 
170  class Size : public Sizex<int>
171  {
172  public:
173  Size() : Sizex<int>() {}
174  Size(int width, int height) : Sizex<int>(width, height) {}
175  Size(const Sizex<int> &s) : Sizex<int>(s) {}
176  Size(const Vec2<int> &s) : Sizex<int>(s.x, s.y) {}
177 
178  explicit Size(const Sizex<float> &copy) { width = (int)(copy.width + 0.5f); height = (int)(copy.height + 0.5f); }
179  explicit Size(const Sizex<double> &copy) { width = (int)(copy.width + 0.5); height = (int)(copy.height + 0.5); }
180  };
181 
183  class Sizef : public Sizex<float>
184  {
185  public:
186  Sizef() : Sizex<float>() {}
187  Sizef(float width, float height) : Sizex<float>(width, height) {}
188  Sizef(const Sizex<float> &s) : Sizex<float>(s) {}
189  Sizef(const Vec2<float> &s) : Sizex<float>(s.x, s.y) {}
190 
191  Sizef(const Sizex<int> &copy) { width = (float)copy.width; height = (float)copy.height; }
192  explicit Sizef(const Sizex<double> &copy) { width = (float)copy.width; height = (float)copy.height; }
193  };
194 
196  class Sized : public Sizex<double>
197  {
198  public:
199  Sized() : Sizex<double>() {}
200  Sized(double width, double height) : Sizex<double>(width, height) {}
201  Sized(const Sizex<double> &s) : Sizex<double>(s) {}
202  Sized(const Vec2<double> &s) : Sizex<double>(s.x, s.y) {}
203 
204  Sized(const Sizex<int> &copy) { width = (double)copy.width; height = (double)copy.height; }
205  Sized(const Sizex<float> &copy) { width = (double)copy.width; height = (double)copy.height; }
206  };
207 
209 }
Size(const Vec2< int > &s)
Definition: size.h:176
Definition: clanapp.h:35
Sizef(const Sizex< int > &copy)
Definition: size.h:191
Sizef(const Vec2< float > &s)
Definition: size.h:189
Sizex< Type > operator+(const Sizex< Type > &s) const
Size + Size operator.
Definition: size.h:97
Sizex< Type > & operator/=(const Type &s)
Size /= operator.
Definition: size.h:127
4D vector
Definition: size.h:47
2D vector
Definition: line.h:46
bool operator!=(const Sizex< Type > &s) const
Size != Size operator (deep compare).
Definition: size.h:163
Sizex< Type > operator+(const Type &s) const
Size + operator.
Definition: size.h:133
Sizex(Type width, Type height)
Constructs a size structure.
Definition: size.h:64
Sizex< Type > & operator-=(const Sizex< Type > &s)
Size -= Size operator.
Definition: size.h:91
Sized(const Sizex< float > &copy)
Definition: size.h:205
Sizex()
Constructs a size structure.
Definition: size.h:58
Sizef()
Definition: size.h:186
Sizex< Type > operator-(const Type &s) const
Size - operator.
Definition: size.h:139
Sizex< Type > operator/(const Type &s) const
Size / operator.
Definition: size.h:151
Sizex< Type > operator*(const Type &s) const
Size * operator.
Definition: size.h:145
Sized()
Definition: size.h:199
Sized(const Sizex< double > &s)
Definition: size.h:201
Sizex< Type > & operator+=(const Type &s)
Size += operator.
Definition: size.h:109
Sizef(float width, float height)
Definition: size.h:187
Sizef(const Sizex< double > &copy)
Definition: size.h:192
2D (width,height) size structure - Double
Definition: size.h:196
Sizex(const Sizex< Type > &s)
Constructs a size structure.
Definition: size.h:70
Sizef(const Sizex< float > &s)
Definition: size.h:188
Size(const Sizex< double > &copy)
Definition: size.h:179
Size(const Sizex< float > &copy)
Definition: size.h:178
Sized(const Sizex< int > &copy)
Definition: size.h:204
Size()
Definition: size.h:173
Size(const Sizex< int > &s)
Definition: size.h:175
Type height
Size height.
Definition: size.h:77
Sizex< Type > & operator*=(const Type &s)
Size *= operator.
Definition: size.h:121
2D (width,height) size structure - Integer
Definition: size.h:170
Sizex< Type > & operator+=(const Sizex< Type > &s)
Size += Size operator.
Definition: size.h:85
Sizex< Type > & operator-=(const Type &s)
Size -= operator.
Definition: size.h:115
Sized(double width, double height)
Definition: size.h:200
Size(int width, int height)
Definition: size.h:174
2D (width,height) size structure.
Definition: size.h:54
Sized(const Vec2< double > &s)
Definition: size.h:202
Sizex< Type > operator-(const Sizex< Type > &s) const
Size - Size operator.
Definition: size.h:103
Type width
Size width.
Definition: size.h:74
bool operator==(const Sizex< Type > &s) const
Size == Size operator (deep compare).
Definition: size.h:157
2D (width,height) size structure - Float
Definition: size.h:183