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