mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-02-09 10:06:44 -05:00
util/box: introduce wlr_fbox_intersection
Signed-off-by: Loukas Agorgianitis <loukas@agorgianitis.com>
This commit is contained in:
parent
62234c5133
commit
72c31255c3
2 changed files with 36 additions and 0 deletions
|
|
@ -61,6 +61,14 @@ void wlr_box_closest_point(const struct wlr_box *box, double x, double y,
|
|||
bool wlr_box_intersection(struct wlr_box *dest, const struct wlr_box *box_a,
|
||||
const struct wlr_box *box_b);
|
||||
|
||||
/**
|
||||
* Gives the intersecting box between two struct wlr_fbox.
|
||||
*
|
||||
* Returns an empty box if the provided boxes don't intersect.
|
||||
*/
|
||||
bool wlr_fbox_intersection(struct wlr_fbox *dest, const struct wlr_fbox *box_a,
|
||||
const struct wlr_fbox *box_b);
|
||||
|
||||
/**
|
||||
* Verifies if a point is contained within the bounds of a given struct wlr_box.
|
||||
*
|
||||
|
|
|
|||
28
util/box.c
28
util/box.c
|
|
@ -74,6 +74,34 @@ bool wlr_box_intersection(struct wlr_box *dest, const struct wlr_box *box_a,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool wlr_fbox_intersection(struct wlr_fbox *dest, const struct wlr_fbox *box_a,
|
||||
const struct wlr_fbox *box_b) {
|
||||
bool a_empty = wlr_fbox_empty(box_a);
|
||||
bool b_empty = wlr_fbox_empty(box_b);
|
||||
|
||||
if (a_empty || b_empty) {
|
||||
*dest = (struct wlr_fbox){0};
|
||||
return false;
|
||||
}
|
||||
|
||||
double x1 = fmax(box_a->x, box_b->x);
|
||||
double y1 = fmax(box_a->y, box_b->y);
|
||||
double x2 = fmin(box_a->x + box_a->width, box_b->x + box_b->width);
|
||||
double y2 = fmin(box_a->y + box_a->height, box_b->y + box_b->height);
|
||||
|
||||
dest->x = x1;
|
||||
dest->y = y1;
|
||||
dest->width = x2 - x1;
|
||||
dest->height = y2 - y1;
|
||||
|
||||
if (wlr_fbox_empty(dest)) {
|
||||
*dest = (struct wlr_fbox){0};
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wlr_box_contains_point(const struct wlr_box *box, double x, double y) {
|
||||
if (wlr_box_empty(box)) {
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue