arsa  2.7
Public Member Functions | Public Attributes | List of all members
irr::core::dimension2d< T > Class Template Reference

Specifies a 2 dimensional size. More...

#include <dimension2d.h>

Public Member Functions

 dimension2d ()
 Default constructor for empty dimension. More...
 
 dimension2d (const T &width, const T &height)
 Constructor with width and height. More...
 
 dimension2d (const vector2d< T > &other)
 
template<class U >
 dimension2d (const dimension2d< U > &other)
 Use this constructor only where you are sure that the conversion is valid. More...
 
template<class U >
dimension2d< T > & operator= (const dimension2d< U > &other)
 
bool operator== (const dimension2d< T > &other) const
 Equality operator. More...
 
bool operator!= (const dimension2d< T > &other) const
 Inequality operator. More...
 
bool operator== (const vector2d< T > &other) const
 
bool operator!= (const vector2d< T > &other) const
 
dimension2d< T > & set (const T &width, const T &height)
 Set to new values. More...
 
dimension2d< T > & operator/= (const T &scale)
 Divide width and height by scalar. More...
 
dimension2d< T > operator/ (const T &scale) const
 Divide width and height by scalar. More...
 
dimension2d< T > & operator *= (const T &scale)
 Multiply width and height by scalar. More...
 
dimension2d< T > operator * (const T &scale) const
 Multiply width and height by scalar. More...
 
dimension2d< T > & operator+= (const dimension2d< T > &other)
 Add another dimension to this one. More...
 
dimension2d< T > operator+ (const dimension2d< T > &other) const
 Add two dimensions. More...
 
dimension2d< T > & operator-= (const dimension2d< T > &other)
 Subtract a dimension from this one. More...
 
dimension2d< T > operator- (const dimension2d< T > &other) const
 Subtract one dimension from another. More...
 
getArea () const
 Get area. More...
 
dimension2d< T > getOptimalSize (bool requirePowerOfTwo=true, bool requireSquare=false, bool larger=true, u32 maxValue=0) const
 Get the optimal size according to some properties. More...
 
dimension2d< T > getInterpolated (const dimension2d< T > &other, f32 d) const
 Get the interpolated dimension. More...
 

Public Attributes

Width
 Width of the dimension. More...
 
Height
 Height of the dimension. More...
 

Detailed Description

template<class T>
class irr::core::dimension2d< T >

Specifies a 2 dimensional size.

Definition at line 20 of file dimension2d.h.

Constructor & Destructor Documentation

◆ dimension2d() [1/4]

template<class T>
irr::core::dimension2d< T >::dimension2d ( )
inline

Default constructor for empty dimension.

Definition at line 24 of file dimension2d.h.

24 : Width(0), Height(0) {}
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206

◆ dimension2d() [2/4]

template<class T>
irr::core::dimension2d< T >::dimension2d ( const T &  width,
const T &  height 
)
inline

Constructor with width and height.

Definition at line 26 of file dimension2d.h.

27  : Width(width), Height(height) {}
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572

◆ dimension2d() [3/4]

template<class T>
irr::core::dimension2d< T >::dimension2d ( const vector2d< T > &  other)

Definition at line 413 of file vector2d.h.

413 : Width(other.X), Height(other.Y) { }
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206

◆ dimension2d() [4/4]

template<class T>
template<class U >
irr::core::dimension2d< T >::dimension2d ( const dimension2d< U > &  other)
inlineexplicit

Use this constructor only where you are sure that the conversion is valid.

Definition at line 33 of file dimension2d.h.

33  :
34  Width((T)other.Width), Height((T)other.Height) { }
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206

Member Function Documentation

◆ getArea()

template<class T>
T irr::core::dimension2d< T >::getArea ( ) const
inline

Get area.

Definition at line 130 of file dimension2d.h.

131  {
132  return Width*Height;
133  }
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206

◆ getInterpolated()

template<class T>
dimension2d<T> irr::core::dimension2d< T >::getInterpolated ( const dimension2d< T > &  other,
f32  d 
) const
inline

Get the interpolated dimension.

Parameters
otherOther dimension to interpolate with.
dValue between 0.0f and 1.0f. d=0 returns other, d=1 returns this, values between interpolate.
Returns
Interpolated dimension.

Definition at line 196 of file dimension2d.h.

197  {
198  f32 inv = (1.0f - d);
199  return dimension2d<T>( (T)(other.Width*inv + Width*d), (T)(other.Height*inv + Height*d));
200  }
float f32
32 bit floating point variable.
Definition: irrTypes.h:108
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206

◆ getOptimalSize()

template<class T>
dimension2d<T> irr::core::dimension2d< T >::getOptimalSize ( bool  requirePowerOfTwo = true,
bool  requireSquare = false,
bool  larger = true,
u32  maxValue = 0 
) const
inline

Get the optimal size according to some properties.

This is a function often used for texture dimension calculations. The function returns the next larger or smaller dimension which is a power-of-two dimension (2^n,2^m) and/or square (Width=Height).

Parameters
requirePowerOfTwoForces the result to use only powers of two as values.
requireSquareMakes width==height in the result
largerChoose whether the result is larger or smaller than the current dimension. If one dimension need not be changed it is kept with any value of larger.
maxValueMaximum texturesize. if value > 0 size is clamped to maxValue
Returns
The optimal dimension under the given constraints.

Definition at line 150 of file dimension2d.h.

155  {
156  u32 i=1;
157  u32 j=1;
158  if (requirePowerOfTwo)
159  {
160  while (i<(u32)Width)
161  i<<=1;
162  if (!larger && i!=1 && i!=(u32)Width)
163  i>>=1;
164  while (j<(u32)Height)
165  j<<=1;
166  if (!larger && j!=1 && j!=(u32)Height)
167  j>>=1;
168  }
169  else
170  {
171  i=(u32)Width;
172  j=(u32)Height;
173  }
174 
175  if (requireSquare)
176  {
177  if ((larger && (i>j)) || (!larger && (i<j)))
178  j=i;
179  else
180  i=j;
181  }
182 
183  if ( maxValue > 0 && i > maxValue)
184  i = maxValue;
185 
186  if ( maxValue > 0 && j > maxValue)
187  j = maxValue;
188 
189  return dimension2d<T>((T)i,(T)j);
190  }
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206

◆ operator *()

template<class T>
dimension2d<T> irr::core::dimension2d< T >::operator * ( const T &  scale) const
inline

Multiply width and height by scalar.

Definition at line 96 of file dimension2d.h.

97  {
98  return dimension2d<T>(Width*scale, Height*scale);
99  }
GLenum GLenum GLenum GLenum GLenum scale
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206

◆ operator *=()

template<class T>
dimension2d<T>& irr::core::dimension2d< T >::operator *= ( const T &  scale)
inline

Multiply width and height by scalar.

Definition at line 88 of file dimension2d.h.

89  {
90  Width *= scale;
91  Height *= scale;
92  return *this;
93  }
GLenum GLenum GLenum GLenum GLenum scale
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206

◆ operator!=() [1/2]

template<class T>
bool irr::core::dimension2d< T >::operator!= ( const dimension2d< T > &  other) const
inline

Inequality operator.

Definition at line 53 of file dimension2d.h.

54  {
55  return ! (*this == other);
56  }

◆ operator!=() [2/2]

template<class T>
bool irr::core::dimension2d< T >::operator!= ( const vector2d< T > &  other) const
inline

Definition at line 60 of file dimension2d.h.

61  {
62  return !(*this == other);
63  }

◆ operator+()

template<class T>
dimension2d<T> irr::core::dimension2d< T >::operator+ ( const dimension2d< T > &  other) const
inline

Add two dimensions.

Definition at line 110 of file dimension2d.h.

111  {
112  return dimension2d<T>(Width+other.Width, Height+other.Height);
113  }
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206

◆ operator+=()

template<class T>
dimension2d<T>& irr::core::dimension2d< T >::operator+= ( const dimension2d< T > &  other)
inline

Add another dimension to this one.

Definition at line 102 of file dimension2d.h.

103  {
104  Width += other.Width;
105  Height += other.Height;
106  return *this;
107  }
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206

◆ operator-()

template<class T>
dimension2d<T> irr::core::dimension2d< T >::operator- ( const dimension2d< T > &  other) const
inline

Subtract one dimension from another.

Definition at line 124 of file dimension2d.h.

125  {
126  return dimension2d<T>(Width-other.Width, Height-other.Height);
127  }
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206

◆ operator-=()

template<class T>
dimension2d<T>& irr::core::dimension2d< T >::operator-= ( const dimension2d< T > &  other)
inline

Subtract a dimension from this one.

Definition at line 116 of file dimension2d.h.

117  {
118  Width -= other.Width;
119  Height -= other.Height;
120  return *this;
121  }
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206

◆ operator/()

template<class T>
dimension2d<T> irr::core::dimension2d< T >::operator/ ( const T &  scale) const
inline

Divide width and height by scalar.

Definition at line 82 of file dimension2d.h.

83  {
84  return dimension2d<T>(Width/scale, Height/scale);
85  }
GLenum GLenum GLenum GLenum GLenum scale
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206

◆ operator/=()

template<class T>
dimension2d<T>& irr::core::dimension2d< T >::operator/= ( const T &  scale)
inline

Divide width and height by scalar.

Definition at line 74 of file dimension2d.h.

75  {
76  Width /= scale;
77  Height /= scale;
78  return *this;
79  }
GLenum GLenum GLenum GLenum GLenum scale
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206

◆ operator=()

template<class T>
template<class U >
dimension2d<T>& irr::core::dimension2d< T >::operator= ( const dimension2d< U > &  other)
inline

Definition at line 37 of file dimension2d.h.

38  {
39  Width = (T) other.Width;
40  Height = (T) other.Height;
41  return *this;
42  }
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206

◆ operator==() [1/2]

template<class T>
bool irr::core::dimension2d< T >::operator== ( const dimension2d< T > &  other) const
inline

Equality operator.

Definition at line 46 of file dimension2d.h.

47  {
48  return core::equals(Width, other.Width) &&
49  core::equals(Height, other.Height);
50  }
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
Definition: irrMath.h:246
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206

◆ operator==() [2/2]

template<class T>
bool irr::core::dimension2d< T >::operator== ( const vector2d< T > &  other) const

Definition at line 416 of file vector2d.h.

416 { return Width == other.X && Height == other.Y; }
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206

◆ set()

template<class T>
dimension2d<T>& irr::core::dimension2d< T >::set ( const T &  width,
const T &  height 
)
inline

Set to new values.

Definition at line 66 of file dimension2d.h.

67  {
68  Width = width;
69  Height = height;
70  return *this;
71  }
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
T Width
Width of the dimension.
Definition: dimension2d.h:204
T Height
Height of the dimension.
Definition: dimension2d.h:206
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572

Member Data Documentation

◆ Height

template<class T>
T irr::core::dimension2d< T >::Height

Height of the dimension.

Definition at line 206 of file dimension2d.h.

◆ Width

template<class T>
T irr::core::dimension2d< T >::Width

Width of the dimension.

Definition at line 204 of file dimension2d.h.


The documentation for this class was generated from the following files: