Made Cube/Rect more user-friendly

Former-commit-id: 13ac0b9f6428059596c98f636caf61afd2a436b7
This commit is contained in:
Lynix 2013-05-30 03:02:43 +02:00
parent e0229ab390
commit c99ab36ebe
4 changed files with 99 additions and 0 deletions

View File

@ -19,9 +19,11 @@ class NzCube
{
public:
NzCube() = default;
NzCube(T Width, T Height, T Depth);
NzCube(T X, T Y, T Z, T Width, T Height, T Depth);
NzCube(const T cube[6]);
NzCube(const NzRect<T>& rect);
NzCube(const NzVector3<T>& size);
NzCube(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> explicit NzCube(const NzCube<U>& cube);
NzCube(const NzCube& cube) = default;
@ -51,10 +53,12 @@ class NzCube
NzCube& MakeZero();
NzCube& Set(T Width, T Height, T Depth);
NzCube& Set(T X, T Y, T Z, T Width, T Height, T Depth);
NzCube& Set(const T cube[6]);
NzCube& Set(const NzCube& cube);
NzCube& Set(const NzRect<T>& rect);
NzCube& Set(const NzVector3<T>& size);
NzCube& Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> NzCube& Set(const NzCube<U>& cube);
@ -66,8 +70,10 @@ class NzCube
T operator[](unsigned int i) const;
NzCube operator*(T scalar) const;
NzCube operator*(const NzVector3<T>& vec) const;
NzCube& operator*=(T scalar);
NzCube& operator*=(const NzVector3<T>& vec);
bool operator==(const NzCube& cube) const;
bool operator!=(const NzCube& cube) const;

View File

@ -10,6 +10,12 @@
#define F(a) static_cast<T>(a)
template<typename T>
NzCube<T>::NzCube(T Width, T Height, T Depth)
{
Set(Width, Height, Depth);
}
template<typename T>
NzCube<T>::NzCube(T X, T Y, T Z, T Width, T Height, T Depth)
{
@ -22,6 +28,12 @@ NzCube<T>::NzCube(const NzRect<T>& rect)
Set(rect);
}
template<typename T>
NzCube<T>::NzCube(const NzVector3<T>& size)
{
Set(size);
}
template<typename T>
NzCube<T>::NzCube(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{
@ -258,6 +270,19 @@ NzCube<T>& NzCube<T>::MakeZero()
return *this;
}
template<typename T>
NzCube<T>& NzCube<T>::Set(T Width, T Height, T Depth)
{
x = F(0.0);
y = F(0.0);
z = F(0.0);
width = Width;
height = Height;
depth = Depth;
return *this;
}
template<typename T>
NzCube<T>& NzCube<T>::Set(T X, T Y, T Z, T Width, T Height, T Depth)
{
@ -305,6 +330,12 @@ NzCube<T>& NzCube<T>::Set(const NzRect<T>& rect)
return *this;
}
template<typename T>
NzCube<T>& NzCube<T>::Set(const NzVector3<T>& size)
{
return Set(size.x, size.y, size.z);
}
template<typename T>
NzCube<T>& NzCube<T>::Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{
@ -393,6 +424,12 @@ NzCube<T> NzCube<T>::operator*(T scalar) const
return NzCube(x, y, z, width*scalar, height*scalar, depth*scalar);
}
template<typename T>
NzCube<T> NzCube<T>::operator*(const NzVector3<T>& vec) const
{
return NzCube(x, y, z, width*vec.x, height*vec.y, depth*vec.z);
}
template<typename T>
NzCube<T>& NzCube<T>::operator*=(T scalar)
{
@ -401,6 +438,14 @@ NzCube<T>& NzCube<T>::operator*=(T scalar)
depth *= scalar;
}
template<typename T>
NzCube<T>& NzCube<T>::operator*=(const NzVector3<T>& vec)
{
width *= vec.x;
height *= vec.y;
depth *= vec.z;
}
template<typename T>
bool NzCube<T>::operator==(const NzCube& cube) const
{

View File

@ -15,8 +15,10 @@ class NzRect
{
public:
NzRect() = default;
NzRect(T Width, T Height);
NzRect(T X, T Y, T Width, T Height);
NzRect(const T rect[4]);
NzRect(const NzVector2<T>& size);
NzRect(const NzVector2<T>& vec1, const NzVector2<T>& vec2);
template<typename U> explicit NzRect(const NzRect<U>& rect);
NzRect(const NzRect& rect) = default;
@ -42,9 +44,11 @@ class NzRect
NzRect& MakeZero();
NzRect& Set(T Width, T Height);
NzRect& Set(T X, T Y, T Width, T Height);
NzRect& Set(const T rect[4]);
NzRect& Set(const NzRect<T>& rect);
NzRect& Set(const NzVector2<T>& size);
NzRect& Set(const NzVector2<T>& vec1, const NzVector2<T>& vec2);
template<typename U> NzRect& Set(const NzRect<U>& rect);
@ -54,8 +58,10 @@ class NzRect
T operator[](unsigned int i) const;
NzRect operator*(T scalar) const;
NzRect operator*(const NzVector2<T>& vec) const;
NzRect& operator*=(T scalar);
NzRect& operator*=(const NzVector2<T>& vec);
bool operator==(const NzRect& rect) const;
bool operator!=(const NzRect& rect) const;

View File

@ -10,6 +10,12 @@
#define F(a) static_cast<T>(a)
template<typename T>
NzRect<T>::NzRect(T Width, T Height)
{
Set(Width, Height);
}
template<typename T>
NzRect<T>::NzRect(T X, T Y, T Width, T Height)
{
@ -22,6 +28,12 @@ NzRect<T>::NzRect(const T vec[4])
Set(vec);
}
template<typename T>
NzRect<T>::NzRect(const NzVector2<T>& size)
{
Set(size);
}
template<typename T>
NzRect<T>::NzRect(const NzVector2<T>& vec1, const NzVector2<T>& vec2)
{
@ -178,6 +190,17 @@ NzRect<T>& NzRect<T>::MakeZero()
return *this;
}
template<typename T>
NzRect<T>& NzRect<T>::Set(T Width, T Height)
{
x = F(0.0);
y = F(0.0);
width = Width;
height = Height;
return *this;
}
template<typename T>
NzRect<T>& NzRect<T>::Set(T X, T Y, T Width, T Height)
{
@ -208,6 +231,12 @@ NzRect<T>& NzRect<T>::Set(const NzRect<T>& rect)
return *this;
}
template<typename T>
NzRect<T>& NzRect<T>::Set(const NzVector2<T>& size)
{
return Set(size.x, size.y);
}
template<typename T>
NzRect<T>& NzRect<T>::Set(const NzVector2<T>& vec1, const NzVector2<T>& vec2)
{
@ -279,6 +308,12 @@ NzRect<T> NzRect<T>::operator*(T scalar) const
return NzRect(x, y, width*scalar, height*scalar);
}
template<typename T>
NzRect<T> NzRect<T>::operator*(const NzVector2<T>& vec) const
{
return NzRect(x, y, width*vec.x, height*vec.y);
}
template<typename T>
NzRect<T>& NzRect<T>::operator*=(T scalar)
{
@ -286,6 +321,13 @@ NzRect<T>& NzRect<T>::operator*=(T scalar)
height *= scalar;
}
template<typename T>
NzRect<T>& NzRect<T>::operator*=(const NzVector2<T>& vec)
{
width *= vec.x;
height *= vec.y;
}
template<typename T>
bool NzRect<T>::operator==(const NzRect& rect) const
{