aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/include/dimension2d.h
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/include/dimension2d.h')
-rw-r--r--libraries/irrlicht-1.8/include/dimension2d.h448
1 files changed, 224 insertions, 224 deletions
diff --git a/libraries/irrlicht-1.8/include/dimension2d.h b/libraries/irrlicht-1.8/include/dimension2d.h
index 13addb4..c9d0652 100644
--- a/libraries/irrlicht-1.8/include/dimension2d.h
+++ b/libraries/irrlicht-1.8/include/dimension2d.h
@@ -1,224 +1,224 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt 1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine". 2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h 3// For conditions of distribution and use, see copyright notice in irrlicht.h
4 4
5#ifndef __IRR_DIMENSION2D_H_INCLUDED__ 5#ifndef __IRR_DIMENSION2D_H_INCLUDED__
6#define __IRR_DIMENSION2D_H_INCLUDED__ 6#define __IRR_DIMENSION2D_H_INCLUDED__
7 7
8#include "irrTypes.h" 8#include "irrTypes.h"
9#include "irrMath.h" // for irr::core::equals() 9#include "irrMath.h" // for irr::core::equals()
10 10
11namespace irr 11namespace irr
12{ 12{
13namespace core 13namespace core
14{ 14{
15 template <class T> 15 template <class T>
16 class vector2d; 16 class vector2d;
17 17
18 //! Specifies a 2 dimensional size. 18 //! Specifies a 2 dimensional size.
19 template <class T> 19 template <class T>
20 class dimension2d 20 class dimension2d
21 { 21 {
22 public: 22 public:
23 //! Default constructor for empty dimension 23 //! Default constructor for empty dimension
24 dimension2d() : Width(0), Height(0) {} 24 dimension2d() : Width(0), Height(0) {}
25 //! Constructor with width and height 25 //! Constructor with width and height
26 dimension2d(const T& width, const T& height) 26 dimension2d(const T& width, const T& height)
27 : Width(width), Height(height) {} 27 : Width(width), Height(height) {}
28 28
29 dimension2d(const vector2d<T>& other); // Defined in vector2d.h 29 dimension2d(const vector2d<T>& other); // Defined in vector2d.h
30 30
31 //! Use this constructor only where you are sure that the conversion is valid. 31 //! Use this constructor only where you are sure that the conversion is valid.
32 template <class U> 32 template <class U>
33 explicit dimension2d(const dimension2d<U>& other) : 33 explicit dimension2d(const dimension2d<U>& other) :
34 Width((T)other.Width), Height((T)other.Height) { } 34 Width((T)other.Width), Height((T)other.Height) { }
35 35
36 template <class U> 36 template <class U>
37 dimension2d<T>& operator=(const dimension2d<U>& other) 37 dimension2d<T>& operator=(const dimension2d<U>& other)
38 { 38 {
39 Width = (T) other.Width; 39 Width = (T) other.Width;
40 Height = (T) other.Height; 40 Height = (T) other.Height;
41 return *this; 41 return *this;
42 } 42 }
43 43
44 44
45 //! Equality operator 45 //! Equality operator
46 bool operator==(const dimension2d<T>& other) const 46 bool operator==(const dimension2d<T>& other) const
47 { 47 {
48 return core::equals(Width, other.Width) && 48 return core::equals(Width, other.Width) &&
49 core::equals(Height, other.Height); 49 core::equals(Height, other.Height);
50 } 50 }
51 51
52 //! Inequality operator 52 //! Inequality operator
53 bool operator!=(const dimension2d<T>& other) const 53 bool operator!=(const dimension2d<T>& other) const
54 { 54 {
55 return ! (*this == other); 55 return ! (*this == other);
56 } 56 }
57 57
58 bool operator==(const vector2d<T>& other) const; // Defined in vector2d.h 58 bool operator==(const vector2d<T>& other) const; // Defined in vector2d.h
59 59
60 bool operator!=(const vector2d<T>& other) const 60 bool operator!=(const vector2d<T>& other) const
61 { 61 {
62 return !(*this == other); 62 return !(*this == other);
63 } 63 }
64 64
65 //! Set to new values 65 //! Set to new values
66 dimension2d<T>& set(const T& width, const T& height) 66 dimension2d<T>& set(const T& width, const T& height)
67 { 67 {
68 Width = width; 68 Width = width;
69 Height = height; 69 Height = height;
70 return *this; 70 return *this;
71 } 71 }
72 72
73 //! Divide width and height by scalar 73 //! Divide width and height by scalar
74 dimension2d<T>& operator/=(const T& scale) 74 dimension2d<T>& operator/=(const T& scale)
75 { 75 {
76 Width /= scale; 76 Width /= scale;
77 Height /= scale; 77 Height /= scale;
78 return *this; 78 return *this;
79 } 79 }
80 80
81 //! Divide width and height by scalar 81 //! Divide width and height by scalar
82 dimension2d<T> operator/(const T& scale) const 82 dimension2d<T> operator/(const T& scale) const
83 { 83 {
84 return dimension2d<T>(Width/scale, Height/scale); 84 return dimension2d<T>(Width/scale, Height/scale);
85 } 85 }
86 86
87 //! Multiply width and height by scalar 87 //! Multiply width and height by scalar
88 dimension2d<T>& operator*=(const T& scale) 88 dimension2d<T>& operator*=(const T& scale)
89 { 89 {
90 Width *= scale; 90 Width *= scale;
91 Height *= scale; 91 Height *= scale;
92 return *this; 92 return *this;
93 } 93 }
94 94
95 //! Multiply width and height by scalar 95 //! Multiply width and height by scalar
96 dimension2d<T> operator*(const T& scale) const 96 dimension2d<T> operator*(const T& scale) const
97 { 97 {
98 return dimension2d<T>(Width*scale, Height*scale); 98 return dimension2d<T>(Width*scale, Height*scale);
99 } 99 }
100 100
101 //! Add another dimension to this one. 101 //! Add another dimension to this one.
102 dimension2d<T>& operator+=(const dimension2d<T>& other) 102 dimension2d<T>& operator+=(const dimension2d<T>& other)
103 { 103 {
104 Width += other.Width; 104 Width += other.Width;
105 Height += other.Height; 105 Height += other.Height;
106 return *this; 106 return *this;
107 } 107 }
108 108
109 //! Add two dimensions 109 //! Add two dimensions
110 dimension2d<T> operator+(const dimension2d<T>& other) const 110 dimension2d<T> operator+(const dimension2d<T>& other) const
111 { 111 {
112 return dimension2d<T>(Width+other.Width, Height+other.Height); 112 return dimension2d<T>(Width+other.Width, Height+other.Height);
113 } 113 }
114 114
115 //! Subtract a dimension from this one 115 //! Subtract a dimension from this one
116 dimension2d<T>& operator-=(const dimension2d<T>& other) 116 dimension2d<T>& operator-=(const dimension2d<T>& other)
117 { 117 {
118 Width -= other.Width; 118 Width -= other.Width;
119 Height -= other.Height; 119 Height -= other.Height;
120 return *this; 120 return *this;
121 } 121 }
122 122
123 //! Subtract one dimension from another 123 //! Subtract one dimension from another
124 dimension2d<T> operator-(const dimension2d<T>& other) const 124 dimension2d<T> operator-(const dimension2d<T>& other) const
125 { 125 {
126 return dimension2d<T>(Width-other.Width, Height-other.Height); 126 return dimension2d<T>(Width-other.Width, Height-other.Height);
127 } 127 }
128 128
129 //! Get area 129 //! Get area
130 T getArea() const 130 T getArea() const
131 { 131 {
132 return Width*Height; 132 return Width*Height;
133 } 133 }
134 134
135 //! Get the optimal size according to some properties 135 //! Get the optimal size according to some properties
136 /** This is a function often used for texture dimension 136 /** This is a function often used for texture dimension
137 calculations. The function returns the next larger or 137 calculations. The function returns the next larger or
138 smaller dimension which is a power-of-two dimension 138 smaller dimension which is a power-of-two dimension
139 (2^n,2^m) and/or square (Width=Height). 139 (2^n,2^m) and/or square (Width=Height).
140 \param requirePowerOfTwo Forces the result to use only 140 \param requirePowerOfTwo Forces the result to use only
141 powers of two as values. 141 powers of two as values.
142 \param requireSquare Makes width==height in the result 142 \param requireSquare Makes width==height in the result
143 \param larger Choose whether the result is larger or 143 \param larger Choose whether the result is larger or
144 smaller than the current dimension. If one dimension 144 smaller than the current dimension. If one dimension
145 need not be changed it is kept with any value of larger. 145 need not be changed it is kept with any value of larger.
146 \param maxValue Maximum texturesize. if value > 0 size is 146 \param maxValue Maximum texturesize. if value > 0 size is
147 clamped to maxValue 147 clamped to maxValue
148 \return The optimal dimension under the given 148 \return The optimal dimension under the given
149 constraints. */ 149 constraints. */
150 dimension2d<T> getOptimalSize( 150 dimension2d<T> getOptimalSize(
151 bool requirePowerOfTwo=true, 151 bool requirePowerOfTwo=true,
152 bool requireSquare=false, 152 bool requireSquare=false,
153 bool larger=true, 153 bool larger=true,
154 u32 maxValue = 0) const 154 u32 maxValue = 0) const
155 { 155 {
156 u32 i=1; 156 u32 i=1;
157 u32 j=1; 157 u32 j=1;
158 if (requirePowerOfTwo) 158 if (requirePowerOfTwo)
159 { 159 {
160 while (i<(u32)Width) 160 while (i<(u32)Width)
161 i<<=1; 161 i<<=1;
162 if (!larger && i!=1 && i!=(u32)Width) 162 if (!larger && i!=1 && i!=(u32)Width)
163 i>>=1; 163 i>>=1;
164 while (j<(u32)Height) 164 while (j<(u32)Height)
165 j<<=1; 165 j<<=1;
166 if (!larger && j!=1 && j!=(u32)Height) 166 if (!larger && j!=1 && j!=(u32)Height)
167 j>>=1; 167 j>>=1;
168 } 168 }
169 else 169 else
170 { 170 {
171 i=(u32)Width; 171 i=(u32)Width;
172 j=(u32)Height; 172 j=(u32)Height;
173 } 173 }
174 174
175 if (requireSquare) 175 if (requireSquare)
176 { 176 {
177 if ((larger && (i>j)) || (!larger && (i<j))) 177 if ((larger && (i>j)) || (!larger && (i<j)))
178 j=i; 178 j=i;
179 else 179 else
180 i=j; 180 i=j;
181 } 181 }
182 182
183 if ( maxValue > 0 && i > maxValue) 183 if ( maxValue > 0 && i > maxValue)
184 i = maxValue; 184 i = maxValue;
185 185
186 if ( maxValue > 0 && j > maxValue) 186 if ( maxValue > 0 && j > maxValue)
187 j = maxValue; 187 j = maxValue;
188 188
189 return dimension2d<T>((T)i,(T)j); 189 return dimension2d<T>((T)i,(T)j);
190 } 190 }
191 191
192 //! Get the interpolated dimension 192 //! Get the interpolated dimension
193 /** \param other Other dimension to interpolate with. 193 /** \param other Other dimension to interpolate with.
194 \param d Value between 0.0f and 1.0f. 194 \param d Value between 0.0f and 1.0f.
195 \return Interpolated dimension. */ 195 \return Interpolated dimension. */
196 dimension2d<T> getInterpolated(const dimension2d<T>& other, f32 d) const 196 dimension2d<T> getInterpolated(const dimension2d<T>& other, f32 d) const
197 { 197 {
198 f32 inv = (1.0f - d); 198 f32 inv = (1.0f - d);
199 return dimension2d<T>( (T)(other.Width*inv + Width*d), (T)(other.Height*inv + Height*d)); 199 return dimension2d<T>( (T)(other.Width*inv + Width*d), (T)(other.Height*inv + Height*d));
200 } 200 }
201 201
202 202
203 //! Width of the dimension. 203 //! Width of the dimension.
204 T Width; 204 T Width;
205 //! Height of the dimension. 205 //! Height of the dimension.
206 T Height; 206 T Height;
207 }; 207 };
208 208
209 //! Typedef for an f32 dimension. 209 //! Typedef for an f32 dimension.
210 typedef dimension2d<f32> dimension2df; 210 typedef dimension2d<f32> dimension2df;
211 //! Typedef for an unsigned integer dimension. 211 //! Typedef for an unsigned integer dimension.
212 typedef dimension2d<u32> dimension2du; 212 typedef dimension2d<u32> dimension2du;
213 213
214 //! Typedef for an integer dimension. 214 //! Typedef for an integer dimension.
215 /** There are few cases where negative dimensions make sense. Please consider using 215 /** There are few cases where negative dimensions make sense. Please consider using
216 dimension2du instead. */ 216 dimension2du instead. */
217 typedef dimension2d<s32> dimension2di; 217 typedef dimension2d<s32> dimension2di;
218 218
219 219
220} // end namespace core 220} // end namespace core
221} // end namespace irr 221} // end namespace irr
222 222
223#endif 223#endif
224 224