Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members | Tutorials
dimension2d.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2010 Nikolaus Gebhardt
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
4 
5 #ifndef __IRR_DIMENSION2D_H_INCLUDED__
6 #define __IRR_DIMENSION2D_H_INCLUDED__
7 
8 #include "irrTypes.h"
9 #include "irrMath.h" // for irr::core::equals()
10 
11 namespace irr
12 {
13 namespace core
14 {
15  template <class T>
16  class vector2d;
17 
19  template <class T>
21  {
22  public:
24  dimension2d() : Width(0), Height(0) {}
26  dimension2d(const T& width, const T& height)
27  : Width(width), Height(height) {}
28 
29  dimension2d(const vector2d<T>& other); // Defined in vector2d.h
30 
32  template <class U>
33  explicit dimension2d(const dimension2d<U>& other) :
34  Width((T)other.Width), Height((T)other.Height) { }
35 
36  template <class U>
38  {
39  Width = (T) other.Width;
40  Height = (T) other.Height;
41  return *this;
42  }
43 
44 
46  bool operator==(const dimension2d<T>& other) const
47  {
48  return core::equals(Width, other.Width) &&
49  core::equals(Height, other.Height);
50  }
51 
53  bool operator!=(const dimension2d<T>& other) const
54  {
55  return ! (*this == other);
56  }
57 
58  bool operator==(const vector2d<T>& other) const; // Defined in vector2d.h
59 
60  bool operator!=(const vector2d<T>& other) const
61  {
62  return !(*this == other);
63  }
64 
66  dimension2d<T>& set(const T& width, const T& height)
67  {
68  Width = width;
69  Height = height;
70  return *this;
71  }
72 
74  dimension2d<T>& operator/=(const T& scale)
75  {
76  Width /= scale;
77  Height /= scale;
78  return *this;
79  }
80 
82  dimension2d<T> operator/(const T& scale) const
83  {
84  return dimension2d<T>(Width/scale, Height/scale);
85  }
86 
88  dimension2d<T>& operator*=(const T& scale)
89  {
90  Width *= scale;
91  Height *= scale;
92  return *this;
93  }
94 
96  dimension2d<T> operator*(const T& scale) const
97  {
98  return dimension2d<T>(Width*scale, Height*scale);
99  }
100 
103  {
104  Width += other.Width;
105  Height += other.Height;
106  return *this;
107  }
108 
111  {
112  Width -= other.Width;
113  Height -= other.Height;
114  return *this;
115  }
116 
117 
120  {
121  return dimension2d<T>(Width+other.Width, Height+other.Height);
122  }
123 
125  T getArea() const
126  {
127  return Width*Height;
128  }
129 
131 
146  bool requirePowerOfTwo=true,
147  bool requireSquare=false,
148  bool larger=true,
149  u32 maxValue = 0) const
150  {
151  u32 i=1;
152  u32 j=1;
153  if (requirePowerOfTwo)
154  {
155  while (i<(u32)Width)
156  i<<=1;
157  if (!larger && i!=1 && i!=(u32)Width)
158  i>>=1;
159  while (j<(u32)Height)
160  j<<=1;
161  if (!larger && j!=1 && j!=(u32)Height)
162  j>>=1;
163  }
164  else
165  {
166  i=(u32)Width;
167  j=(u32)Height;
168  }
169 
170  if (requireSquare)
171  {
172  if ((larger && (i>j)) || (!larger && (i<j)))
173  j=i;
174  else
175  i=j;
176  }
177 
178  if ( maxValue > 0 && i > maxValue)
179  i = maxValue;
180 
181  if ( maxValue > 0 && j > maxValue)
182  j = maxValue;
183 
184  return dimension2d<T>((T)i,(T)j);
185  }
186 
188 
192  {
193  f32 inv = (1.0f - d);
194  return dimension2d<T>( (T)(other.Width*inv + Width*d), (T)(other.Height*inv + Height*d));
195  }
196 
197 
199  T Width;
202  };
203 
208 
210 
213 
214 
215 } // end namespace core
216 } // end namespace irr
217 
218 #endif
219 

The Irrlicht Engine
The Irrlicht Engine Documentation © 2003-2010 by Nikolaus Gebhardt. Generated on Tue Jun 5 2012 17:57:10 by Doxygen (1.8.1)