diff --git a/include/wlr/util/box.h b/include/wlr/util/box.h index f6809e0c3..543447a5d 100644 --- a/include/wlr/util/box.h +++ b/include/wlr/util/box.h @@ -114,6 +114,13 @@ void wlr_fbox_transform(struct wlr_fbox *dest, const struct wlr_fbox *box, */ bool wlr_box_intersects(const struct wlr_box *a, const struct wlr_box *b); +/** + * Checks whether two boxes intersect. + * + * Returns false if either box is empty. + */ +bool wlr_fbox_intersects(const struct wlr_fbox *a, const struct wlr_fbox *b); + /** * Returns true if the two boxes are equal, false otherwise. */ diff --git a/util/box.c b/util/box.c index 62d405488..7221a710e 100644 --- a/util/box.c +++ b/util/box.c @@ -111,6 +111,15 @@ bool wlr_box_intersects(const struct wlr_box *a, const struct wlr_box *b) { a->y < b->y + b->height && b->y < a->y + a->height; } +bool wlr_fbox_intersects(const struct wlr_fbox *a, const struct wlr_fbox *b) { + if (wlr_fbox_empty(a) || wlr_fbox_empty(b)) { + return false; + } + + return a->x < b->x + b->width && b->x < a->x + a->width && + a->y < b->y + b->height && b->y < a->y + a->height; +} + void wlr_box_transform(struct wlr_box *dest, const struct wlr_box *box, enum wl_output_transform transform, int width, int height) { struct wlr_box src = {0};