summaryrefslogtreecommitdiff
path: root/src/helpers/Box.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/helpers/Box.cpp')
-rw-r--r--src/helpers/Box.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/helpers/Box.cpp b/src/helpers/Box.cpp
index 8470b509..77406ecf 100644
--- a/src/helpers/Box.cpp
+++ b/src/helpers/Box.cpp
@@ -121,7 +121,7 @@ CBox& CBox::noNegativeSize() {
return *this;
}
-CBox CBox::intersection(const CBox other) const {
+CBox CBox::intersection(const CBox& other) const {
const float newX = std::max(x, other.x);
const float newY = std::max(y, other.y);
const float newBottom = std::min(y + h, other.y + other.h);
@@ -137,6 +137,14 @@ CBox CBox::intersection(const CBox other) const {
return {newX, newY, newW, newH};
}
+bool CBox::overlaps(const CBox& other) const {
+ return (other.x + other.w >= x) && (x + w >= other.x) && (other.y + other.h >= y) && (y + h >= other.y);
+}
+
+bool CBox::inside(const CBox& bound) const {
+ return bound.x < x && bound.y < y && x + w < bound.x + bound.w && y + h < bound.y + bound.h;
+}
+
CBox CBox::roundInternal() {
float newW = x + w - std::floor(x);
float newH = y + h - std::floor(y);
@@ -156,6 +164,16 @@ Vector2D CBox::size() const {
return {w, h};
}
+Vector2D CBox::closestPoint(const Vector2D& vec) const {
+ if (containsPoint(vec))
+ return vec;
+
+ Vector2D nv = vec;
+ nv.x = std::clamp(nv.x, x, x + w);
+ nv.y = std::clamp(nv.y, y, y + h);
+ return nv;
+}
+
SWindowDecorationExtents CBox::extentsFrom(const CBox& small) {
return {{small.x - x, small.y - y}, {w - small.w - (small.x - x), h - small.h - (small.y - y)}};
}