mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-03-13 05:34:13 -04:00
util/box: Use integer min/max for intersection
wlr_box_intersection only operates on integers, so we shouldn't use fmin/fmax. Do the usual and add a local integer min/max helper.
This commit is contained in:
parent
9a931d9ffa
commit
285cee5f3a
1 changed files with 12 additions and 4 deletions
16
util/box.c
16
util/box.c
|
|
@ -4,6 +4,14 @@
|
||||||
#include <wlr/util/box.h>
|
#include <wlr/util/box.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
|
||||||
|
static int max(int a, int b) {
|
||||||
|
return a > b ? a : b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int min(int a, int b) {
|
||||||
|
return a < b ? a : b;
|
||||||
|
}
|
||||||
|
|
||||||
void wlr_box_closest_point(const struct wlr_box *box, double x, double y,
|
void wlr_box_closest_point(const struct wlr_box *box, double x, double y,
|
||||||
double *dest_x, double *dest_y) {
|
double *dest_x, double *dest_y) {
|
||||||
// if box is empty, then it contains no points, so no closest point either
|
// if box is empty, then it contains no points, so no closest point either
|
||||||
|
|
@ -56,10 +64,10 @@ bool wlr_box_intersection(struct wlr_box *dest, const struct wlr_box *box_a,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int x1 = fmax(box_a->x, box_b->x);
|
int x1 = max(box_a->x, box_b->x);
|
||||||
int y1 = fmax(box_a->y, box_b->y);
|
int y1 = max(box_a->y, box_b->y);
|
||||||
int x2 = fmin(box_a->x + box_a->width, box_b->x + box_b->width);
|
int x2 = min(box_a->x + box_a->width, box_b->x + box_b->width);
|
||||||
int y2 = fmin(box_a->y + box_a->height, box_b->y + box_b->height);
|
int y2 = min(box_a->y + box_a->height, box_b->y + box_b->height);
|
||||||
|
|
||||||
dest->x = x1;
|
dest->x = x1;
|
||||||
dest->y = y1;
|
dest->y = y1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue