(Rect|Cube) Fixed ExtendTo method (Close #6)

Former-commit-id: 066d87f52361d1c30ec6521b637308ee4541bba1
This commit is contained in:
Lynix 2013-01-03 19:17:04 +01:00
parent db86cc4dc3
commit 962c330390
2 changed files with 28 additions and 10 deletions

View File

@ -63,12 +63,17 @@ bool NzCube<T>::Contains(const NzCube<T>& cube) const
template<typename T>
NzCube<T>& NzCube<T>::ExtendTo(const NzVector3<T>& point)
{
width = std::max(x + width, point.x);
height = std::max(y + height, point.y);
depth = std::max(z + depth, point.z);
x = std::min(x, point.x);
y = std::min(y, point.y);
z = std::min(z, point.z);
width = std::max(x + width, point.x) - x;
height = std::max(y + height, point.y) - y;
depth = std::max(z + depth, point.z) - z;
width -= x;
height -= y;
depth -= z;
return *this;
}
@ -76,12 +81,17 @@ NzCube<T>& NzCube<T>::ExtendTo(const NzVector3<T>& point)
template<typename T>
NzCube<T>& NzCube<T>::ExtendTo(const NzCube& cube)
{
width = std::max(x + width, cube.x + cube.width);
height = std::max(y + height, cube.y + cube.height);
depth = std::max(z + depth, cube.z + cube.depth);
x = std::min(x, cube.x);
y = std::min(y, cube.y);
z = std::min(z, cube.z);
width = std::max(x + width, cube.x + cube.width) - x;
height = std::max(y + height, cube.y + cube.height) - y;
depth = std::max(z + depth, cube.z + cube.depth) - z;
width -= x;
height -= y;
depth -= z;
return *this;
}

View File

@ -56,10 +56,14 @@ bool NzRect<T>::Contains(const NzRect<T>& rect) const
template<typename T>
NzRect<T>& NzRect<T>::ExtendTo(const NzVector2<T>& point)
{
width = std::max(x + width, point.x);
height = std::max(y + height, point.y);
x = std::min(x, point.x);
y = std::min(y, point.y);
width = std::max(x + width, point.x) - x;
height = std::max(y + height, point.y) - y;
width -= x;
height -= y;
return *this;
}
@ -67,10 +71,14 @@ NzRect<T>& NzRect<T>::ExtendTo(const NzVector2<T>& point)
template<typename T>
NzRect<T>& NzRect<T>::ExtendTo(const NzRect& rect)
{
width = std::max(x + width, rect.x + rect.width);
height = std::max(y + height, rect.y + rect.height);
x = std::min(x, rect.x);
y = std::min(y, rect.y);
width = std::max(x + width, rect.x + rect.width) - x;
height = std::max(x + height, rect.y + rect.height) - y;
width -= x;
height -= y;
return *this;
}