(Rect|Cube) Fixed ExtendTo method (Close #6)
Former-commit-id: 066d87f52361d1c30ec6521b637308ee4541bba1
This commit is contained in:
parent
db86cc4dc3
commit
962c330390
|
|
@ -63,12 +63,17 @@ bool NzCube<T>::Contains(const NzCube<T>& cube) const
|
||||||
template<typename T>
|
template<typename T>
|
||||||
NzCube<T>& NzCube<T>::ExtendTo(const NzVector3<T>& point)
|
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);
|
x = std::min(x, point.x);
|
||||||
y = std::min(y, point.y);
|
y = std::min(y, point.y);
|
||||||
z = std::min(z, point.z);
|
z = std::min(z, point.z);
|
||||||
width = std::max(x + width, point.x) - x;
|
|
||||||
height = std::max(y + height, point.y) - y;
|
width -= x;
|
||||||
depth = std::max(z + depth, point.z) - z;
|
height -= y;
|
||||||
|
depth -= z;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
@ -76,12 +81,17 @@ NzCube<T>& NzCube<T>::ExtendTo(const NzVector3<T>& point)
|
||||||
template<typename T>
|
template<typename T>
|
||||||
NzCube<T>& NzCube<T>::ExtendTo(const NzCube& cube)
|
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);
|
x = std::min(x, cube.x);
|
||||||
y = std::min(y, cube.y);
|
y = std::min(y, cube.y);
|
||||||
z = std::min(z, cube.z);
|
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;
|
width -= x;
|
||||||
depth = std::max(z + depth, cube.z + cube.depth) - z;
|
height -= y;
|
||||||
|
depth -= z;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,10 +56,14 @@ bool NzRect<T>::Contains(const NzRect<T>& rect) const
|
||||||
template<typename T>
|
template<typename T>
|
||||||
NzRect<T>& NzRect<T>::ExtendTo(const NzVector2<T>& point)
|
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);
|
x = std::min(x, point.x);
|
||||||
y = std::min(y, point.y);
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
@ -67,10 +71,14 @@ NzRect<T>& NzRect<T>::ExtendTo(const NzVector2<T>& point)
|
||||||
template<typename T>
|
template<typename T>
|
||||||
NzRect<T>& NzRect<T>::ExtendTo(const NzRect& rect)
|
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);
|
x = std::min(x, rect.x);
|
||||||
y = std::min(y, rect.y);
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue