From c7d6629d16095c940469beed25257c5778c7124a Mon Sep 17 00:00:00 2001 From: Loukas Agorgianitis Date: Mon, 14 Apr 2025 11:42:06 +0200 Subject: [PATCH] util/box: introduce wlr_fbox_contains_box Signed-off-by: Loukas Agorgianitis --- include/wlr/util/box.h | 8 ++++++++ util/box.c | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/wlr/util/box.h b/include/wlr/util/box.h index 7da693e5c..277d3dd23 100644 --- a/include/wlr/util/box.h +++ b/include/wlr/util/box.h @@ -87,6 +87,14 @@ bool wlr_box_contains_point(const struct wlr_box *box, double x, double y); */ bool wlr_box_contains_box(const struct wlr_box *bigger, const struct wlr_box *smaller); +/** + * Verifies that a box is fully contained within another box. + * + * Returns true if the "smaller" box is fully contained within the "bigger" box. + * If either of the boxes are empty, false is returned. + */ +bool wlr_fbox_contains_box(const struct wlr_fbox *bigger, const struct wlr_fbox *smaller); + /** * Checks whether a box is empty or not. * diff --git a/util/box.c b/util/box.c index 34834d340..30caedcd4 100644 --- a/util/box.c +++ b/util/box.c @@ -130,6 +130,17 @@ bool wlr_box_contains_box(const struct wlr_box *bigger, const struct wlr_box *sm smaller->y + smaller->height <= bigger->y + bigger->height; } +bool wlr_fbox_contains_box(const struct wlr_fbox *bigger, const struct wlr_fbox *smaller) { + if (wlr_fbox_empty(bigger) || wlr_fbox_empty(smaller)) { + return false; + } + + return smaller->x >= bigger->x && + smaller->x + smaller->width <= bigger->x + bigger->width && + smaller->y >= bigger->y && + smaller->y + smaller->height <= bigger->y + bigger->height; +} + bool wlr_box_intersects(const struct wlr_box *a, const struct wlr_box *b) { if (wlr_box_empty(a) || wlr_box_empty(b)) { return false;