wlroots-hyprland/include/wlr/util/box.h

110 lines
2.9 KiB
C
Raw Normal View History

2021-07-01 22:36:01 +02:00
/*
2021-07-01 22:38:32 +02:00
* This is a stable interface of wlroots. Future changes will be limited to:
*
* - New functions
* - New struct members
* - New enum members
*
* Note that wlroots does not make an ABI compatibility promise - in the future,
* the layout and size of structs used by wlroots may change, requiring code
* depending on this header to be recompiled (but not edited).
*
* Breaking changes are announced in the release notes and follow a 1-year
* deprecation schedule.
2021-07-01 22:36:01 +02:00
*/
2021-07-01 22:38:32 +02:00
#ifndef WLR_UTIL_BOX_H
#define WLR_UTIL_BOX_H
2021-07-01 22:36:01 +02:00
#include <stdbool.h>
#include <wayland-server-protocol.h>
2021-07-01 22:38:32 +02:00
/**
* A box representing a rectangle region in a 2D space.
*
* The x and y coordinates are inclusive, and the width and height lengths are
* exclusive. In other words, the box starts from the coordinates (x, y), and
* goes up to but not including (x + width, y + height).
2021-07-01 22:38:32 +02:00
*/
2021-07-01 22:36:01 +02:00
struct wlr_box {
int x, y;
int width, height;
};
2021-07-01 22:38:32 +02:00
/**
* A floating-point box representing a rectangle region in a 2D space.
*
* struct wlr_fbox has the same semantics as struct wlr_box.
2021-07-01 22:38:32 +02:00
*/
2021-07-01 22:36:01 +02:00
struct wlr_fbox {
double x, y;
double width, height;
};
2021-07-01 22:38:32 +02:00
/**
* Finds the closest point within the box bounds.
*
* Returns NAN if the box is empty.
2021-07-01 22:38:32 +02:00
*/
2021-07-01 22:36:01 +02:00
void wlr_box_closest_point(const struct wlr_box *box, double x, double y,
double *dest_x, double *dest_y);
2021-07-01 22:38:32 +02:00
/**
* Gives the intersecting box between two struct wlr_box.
2021-07-01 22:38:32 +02:00
*
* Returns an empty box if the provided boxes don't intersect.
2021-07-01 22:38:32 +02:00
*/
2021-07-01 22:36:01 +02:00
bool wlr_box_intersection(struct wlr_box *dest, const struct wlr_box *box_a,
const struct wlr_box *box_b);
2021-07-01 22:38:32 +02:00
/**
* Verifies if a point is contained within the bounds of a given struct wlr_box.
2021-07-01 22:38:32 +02:00
*
* For example:
*
* - A point at (100, 50) is not contained in the box (0, 0, 100, 50).
* - A point at (10, 10) is contained in the box (10, 0, 50, 50).
2021-07-01 22:38:32 +02:00
*/
2021-07-01 22:36:01 +02:00
bool wlr_box_contains_point(const struct wlr_box *box, double x, double y);
2021-07-01 22:38:32 +02:00
/**
* Checks whether a box is empty or not.
*
* A box is considered empty if its width and/or height is zero or negative.
2021-07-01 22:38:32 +02:00
*/
2021-07-01 22:36:01 +02:00
bool wlr_box_empty(const struct wlr_box *box);
/**
2021-07-01 22:38:32 +02:00
* Transforms a box inside a (0, 0, width, height) box.
2021-07-01 22:36:01 +02:00
*/
void wlr_box_transform(struct wlr_box *dest, const struct wlr_box *box,
enum wl_output_transform transform, int width, int height);
/**
* Checks whether a box is empty or not.
*
* A box is considered empty if its width and/or height is zero or negative.
*/
bool wlr_fbox_empty(const struct wlr_fbox *box);
/**
* Transforms a floating-point box inside a (0, 0, width, height) box.
*/
void wlr_fbox_transform(struct wlr_fbox *dest, const struct wlr_fbox *box,
enum wl_output_transform transform, double width, double height);
2022-08-15 12:14:28 +02:00
#ifdef WLR_USE_UNSTABLE
/**
* Returns true if the two boxes are equal, false otherwise.
*/
bool wlr_box_equal(const struct wlr_box *a, const struct wlr_box *b);
2022-08-15 12:04:42 +02:00
/**
* Returns true if the two boxes are equal, false otherwise.
*/
bool wlr_fbox_equal(const struct wlr_fbox *a, const struct wlr_fbox *b);
2022-08-15 12:14:28 +02:00
#endif
2021-07-01 22:36:01 +02:00
#endif