Loading...
Searching...
No Matches
dimension2d.h
Go to the documentation of this file.
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __IRR_DIMENSION2D_H_INCLUDED__
#define __IRR_DIMENSION2D_H_INCLUDED__
#include "irrTypes.h"
#include "irrMath.h" // for irr::core::equals()
namespace irr
{
namespace core
{
template <class T>
class vector2d;
template <class T>
class dimension2d
{
public:
dimension2d() : Width(0), Height(0) {}
dimension2d(const T& width, const T& height)
: Width(width), Height(height) {}
dimension2d(const vector2d<T>& other); // Defined in vector2d.h
template <class U>
explicit dimension2d(const dimension2d<U>& other) :
Width((T)other.Width), Height((T)other.Height) { }
template <class U>
dimension2d<T>& operator=(const dimension2d<U>& other)
{
Width = (T) other.Width;
Height = (T) other.Height;
return *this;
}
bool operator==(const dimension2d<T>& other) const
{
return core::equals(Width, other.Width) &&
core::equals(Height, other.Height);
}
bool operator!=(const dimension2d<T>& other) const
{
return ! (*this == other);
}
bool operator==(const vector2d<T>& other) const; // Defined in vector2d.h
bool operator!=(const vector2d<T>& other) const
{
return !(*this == other);
}
dimension2d<T>& set(const T& width, const T& height)
{
Width = width;
Height = height;
return *this;
}
dimension2d<T>& operator/=(const T& scale)
{
Width /= scale;
Height /= scale;
return *this;
}
dimension2d<T> operator/(const T& scale) const
{
return dimension2d<T>(Width/scale, Height/scale);
}
dimension2d<T>& operator*=(const T& scale)
{
Width *= scale;
Height *= scale;
return *this;
}
dimension2d<T> operator*(const T& scale) const
{
return dimension2d<T>(Width*scale, Height*scale);
}
dimension2d<T>& operator+=(const dimension2d<T>& other)
{
Width += other.Width;
Height += other.Height;
return *this;
}
dimension2d<T> operator+(const dimension2d<T>& other) const
{
return dimension2d<T>(Width+other.Width, Height+other.Height);
}
dimension2d<T>& operator-=(const dimension2d<T>& other)
{
Width -= other.Width;
Height -= other.Height;
return *this;
}
dimension2d<T> operator-(const dimension2d<T>& other) const
{
return dimension2d<T>(Width-other.Width, Height-other.Height);
}
T getArea() const
{
return Width*Height;
}
dimension2d<T> getOptimalSize(
bool requirePowerOfTwo=true,
bool requireSquare=false,
bool larger=true,
u32 maxValue = 0) const
{
u32 i=1;
u32 j=1;
if (requirePowerOfTwo)
{
while (i<(u32)Width)
i<<=1;
if (!larger && i!=1 && i!=(u32)Width)
i>>=1;
while (j<(u32)Height)
j<<=1;
if (!larger && j!=1 && j!=(u32)Height)
j>>=1;
}
else
{
i=(u32)Width;
j=(u32)Height;
}
if (requireSquare)
{
if ((larger && (i>j)) || (!larger && (i<j)))
j=i;
else
i=j;
}
if ( maxValue > 0 && i > maxValue)
i = maxValue;
if ( maxValue > 0 && j > maxValue)
j = maxValue;
return dimension2d<T>((T)i,(T)j);
}
dimension2d<T> getInterpolated(const dimension2d<T>& other, f32 d) const
{
f32 inv = (1.0f - d);
return dimension2d<T>( (T)(other.Width*inv + Width*d), (T)(other.Height*inv + Height*d));
}
T Width;
T Height;
};
typedef dimension2d<f32> dimension2df;
typedef dimension2d<u32> dimension2du;
typedef dimension2d<s32> dimension2di;
} // end namespace core
} // end namespace irr
#endif
irr::core::dimension2d
Specifies a 2 dimensional size.
Definition dimension2d.h:21
irr::core::dimension2d::getOptimalSize
dimension2d< T > getOptimalSize(bool requirePowerOfTwo=true, bool requireSquare=false, bool larger=true, u32 maxValue=0) const
Get the optimal size according to some properties.
Definition dimension2d.h:150
irr::core::dimension2d< f32 >::Width
f32 Width
Definition dimension2d.h:204
irr::core::dimension2d::operator/
dimension2d< T > operator/(const T &scale) const
Divide width and height by scalar.
Definition dimension2d.h:82
irr::core::dimension2d::operator!=
bool operator!=(const vector2d< T > &other) const
Definition dimension2d.h:60
irr::core::dimension2d::operator/=
dimension2d< T > & operator/=(const T &scale)
Divide width and height by scalar.
Definition dimension2d.h:74
irr::core::dimension2d::operator==
bool operator==(const vector2d< T > &other) const
Definition vector2d.h:336
irr::core::dimension2d::getArea
T getArea() const
Get area.
Definition dimension2d.h:130
irr::core::dimension2d::dimension2d
dimension2d(const dimension2d< U > &other)
Use this constructor only where you are sure that the conversion is valid.
Definition dimension2d.h:33
irr::core::dimension2d::operator+
dimension2d< T > operator+(const dimension2d< T > &other) const
Add two dimensions.
Definition dimension2d.h:110
irr::core::dimension2d::set
dimension2d< T > & set(const T &width, const T &height)
Set to new values.
Definition dimension2d.h:66
irr::core::dimension2d::operator!=
bool operator!=(const dimension2d< T > &other) const
Inequality operator.
Definition dimension2d.h:53
irr::core::dimension2d< f32 >::Height
f32 Height
Definition dimension2d.h:206
irr::core::dimension2d::dimension2d
dimension2d(const T &width, const T &height)
Constructor with width and height.
Definition dimension2d.h:26
irr::core::dimension2d::dimension2d
dimension2d(const vector2d< T > &other)
Definition vector2d.h:333
irr::core::dimension2d::getInterpolated
dimension2d< T > getInterpolated(const dimension2d< T > &other, f32 d) const
Get the interpolated dimension.
Definition dimension2d.h:196
irr::core::dimension2d::operator-=
dimension2d< T > & operator-=(const dimension2d< T > &other)
Subtract a dimension from this one.
Definition dimension2d.h:116
irr::core::dimension2d::operator=
dimension2d< T > & operator=(const dimension2d< U > &other)
Definition dimension2d.h:37
irr::core::dimension2d::operator+=
dimension2d< T > & operator+=(const dimension2d< T > &other)
Add another dimension to this one.
Definition dimension2d.h:102
irr::core::dimension2d::operator==
bool operator==(const dimension2d< T > &other) const
Equality operator.
Definition dimension2d.h:46
irr::core::dimension2d::operator-
dimension2d< T > operator-(const dimension2d< T > &other) const
Subtract one dimension from another.
Definition dimension2d.h:124
irr::core::dimension2d::operator*
dimension2d< T > operator*(const T &scale) const
Multiply width and height by scalar.
Definition dimension2d.h:96
irr::core::dimension2d::dimension2d
dimension2d()
Default constructor for empty dimension.
Definition dimension2d.h:24
irr::core::dimension2d::operator*=
dimension2d< T > & operator*=(const T &scale)
Multiply width and height by scalar.
Definition dimension2d.h:88
irr::core::vector2d
2d vector template class with lots of operators and methods.
Definition vector2d.h:22
irrMath.h
irrTypes.h
irr::core
Basic classes such as vectors, planes, arrays, lists, and so on can be found in this namespace.
Definition aabbox3d.h:15
irr::core::equals
bool equals(const f64 a, const f64 b, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals b, taking possible rounding errors into account
Definition irrMath.h:185
irr::core::dimension2di
dimension2d< s32 > dimension2di
Typedef for an integer dimension.
Definition dimension2d.h:217
irr::core::dimension2du
dimension2d< u32 > dimension2du
Typedef for an unsigned integer dimension.
Definition dimension2d.h:212
irr::core::dimension2df
dimension2d< f32 > dimension2df
Typedef for an f32 dimension.
Definition dimension2d.h:210
irr
Everything in the Irrlicht Engine can be found in this namespace.
Definition aabbox3d.h:13
irr::f32
float f32
32 bit floating point variable.
Definition irrTypes.h:104
irr::u32
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58
- Irrlicht Engine Documentation © 2003-2012 by Nikolaus Gebhardt. Generated on for Irrlicht 3D Engine by Doxygen 1.15.0