summaryrefslogtreecommitdiffstats
path: root/Common/interface
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-12-08 19:45:19 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-12-08 19:45:19 +0000
commit143d8e78437336136bf397b05e02410ccde185a4 (patch)
tree944ed69d6488a50d1b8c35c468f2fdc27c648f60 /Common/interface
parentFixed minor issue with IDynamicTextureAtlas::GetAtlasDesc not being pure virtual (diff)
downloadDiligentCore-143d8e78437336136bf397b05e02410ccde185a4.tar.gz
DiligentCore-143d8e78437336136bf397b05e02410ccde185a4.zip
MathLib: added CheckBox2DBox2DOverlap function
Diffstat (limited to 'Common/interface')
-rw-r--r--Common/interface/AdvancedMath.hpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/Common/interface/AdvancedMath.hpp b/Common/interface/AdvancedMath.hpp
index 8d1119e5..11af8e34 100644
--- a/Common/interface/AdvancedMath.hpp
+++ b/Common/interface/AdvancedMath.hpp
@@ -935,6 +935,38 @@ void RasterizeTriangle(Vector2<T> V0,
}
}
+
+/// Checks if two 2D-boxes overlap.
+
+/// \tparam [in] AllowTouch - Whether to consider two boxes overlapping if
+/// they only touch at their boundaries or corners.
+/// \tparam [in] T - Component type.
+///
+/// \param [in] Box0Min - Min corner of the first box.
+/// \param [in] Box0Max - Max corner of the first box.
+/// \param [in] Box1Min - Min corner of the second box.
+/// \param [in] Box1Max - Max corner of the second box.
+///
+/// \return true if the bounding boxes overlap, and false otherwise.
+template <bool AllowTouch, typename T>
+bool CheckBox2DBox2DOverlap(const Vector2<T>& Box0Min,
+ const Vector2<T>& Box0Max,
+ const Vector2<T>& Box1Min,
+ const Vector2<T>& Box1Max)
+{
+ VERIFY_EXPR(Box0Max.x >= Box0Min.x && Box0Max.y >= Box0Min.y &&
+ Box1Max.x >= Box1Min.x && Box1Max.y >= Box1Min.y);
+ if (AllowTouch)
+ {
+ return !(Box0Min.x > Box1Max.x || Box1Min.x > Box0Max.x || Box0Min.y > Box1Max.y || Box1Min.y > Box0Max.y);
+ }
+ else
+ {
+ return !(Box0Min.x >= Box1Max.x || Box1Min.x >= Box0Max.x || Box0Min.y >= Box1Max.y || Box1Min.y >= Box0Max.y);
+ }
+}
+
+
} // namespace Diligent
namespace std