Improved [Box|Rect]::Intersect performances
Allowed early returns Former-commit-id: 59001afdd9734666640d440cb8b87b5a426973ce
This commit is contained in:
parent
ad3c70bbc8
commit
a1624af969
|
|
@ -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;
|
||||
|
|
@ -265,9 +271,6 @@ bool NzBox<T>::Intersect(const NzBox& box, NzBox* intersection) const
|
|||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
|
|||
|
|
@ -166,24 +166,24 @@ template<typename T>
|
|||
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);
|
||||
T top = std::max(y, rect.y);
|
||||
T bottom = std::min(y+height, rect.y+rect.height);
|
||||
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;
|
||||
intersection->y = top;
|
||||
intersection->width = right-left;
|
||||
intersection->height = bottom-top;
|
||||
intersection->width = right - left;
|
||||
intersection->height = bottom - top;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
|
|||
Loading…
Reference in New Issue