Improved [Box|Rect]::Intersect performances

Allowed early returns


Former-commit-id: 59001afdd9734666640d440cb8b87b5a426973ce
This commit is contained in:
Lynix 2015-01-03 22:15:15 +01:00
parent ad3c70bbc8
commit a1624af969
2 changed files with 36 additions and 33 deletions

View File

@ -247,13 +247,19 @@ bool NzBox<T>::Intersect(const NzBox& box, NzBox* intersection) const
{
T left = std::max(x, box.x);
T right = std::min(x + width, box.x + box.width);
if (left >= right)
return false;
T top = std::max(y, box.y);
T bottom = std::min(y + height, box.y + box.height);
if (top >= bottom)
return false;
T up = std::max(z, box.z);
T down = std::min(z + depth, box.z + box.depth);
if (up >= down)
return false;
if (left < right && top < bottom && up < down)
{
if (intersection)
{
intersection->x = left;
@ -266,9 +272,6 @@ bool NzBox<T>::Intersect(const NzBox& box, NzBox* intersection) const
return true;
}
else
return false;
}
template<typename T>
bool NzBox<T>::IsValid() const

View File

@ -167,11 +167,14 @@ bool NzRect<T>::Intersect(const NzRect& rect, NzRect* intersection) const
{
T left = std::max(x, rect.x);
T right = std::min(x + width, rect.x + rect.width);
if (left >= right)
return false;
T top = std::max(y, rect.y);
T bottom = std::min(y + height, rect.y + rect.height);
if (top >= bottom)
return false;
if (left < right && top < bottom)
{
if (intersection)
{
intersection->x = left;
@ -182,9 +185,6 @@ bool NzRect<T>::Intersect(const NzRect& rect, NzRect* intersection) const
return true;
}
else
return false;
}
template<typename T>
bool NzRect<T>::IsValid() const