Documented event.h and vector2d.h

This commit is contained in:
Ulysse Cura 2025-08-11 18:35:31 +02:00
parent 8d7813bb53
commit e8bad2bdf4
2 changed files with 53 additions and 42 deletions

View File

@ -4,9 +4,11 @@
#include <gint/keycodes.h> #include <gint/keycodes.h>
#include <stdbool.h> #include <stdbool.h>
/* event_t: Events struct /**
Store events for inputs * @brief Store events for inputs
@keys Addressable array containing boolean state of each key */ *
* @param keys Addressable array containing boolean state of each key
*/
typedef struct event_t { typedef struct event_t {
bool keys[0xa6]; bool keys[0xa6];
} event_t; } event_t;

View File

@ -10,22 +10,24 @@
#include <gint/defs/types.h> #include <gint/defs/types.h>
/* vector2d_t: A point in space /**
This struct is the base for storing 2D positions. * @brief Point struct.
*
@x X pos of the vector * @param x X pos
@y Y pos of the vector */ * @param y Y pos
*/
typedef struct vector2d_t { typedef struct vector2d_t {
float x, y; float x, y;
} vector2d_t; } vector2d_t;
/* vector2d_t: A point in space /**
This struct is the base for storing 2D positions. * @brief Rectangle struct.
*
@x X pos of the rectangle * @param x X pos
@y Y pos of the rectangle * @param y Y pos
@w Width of the rectangle * @param w Width
@h Height of the rectangle */ * @param h Height
*/
typedef struct rect_t { typedef struct rect_t {
float x, y; float x, y;
float w, h; float w, h;
@ -39,38 +41,45 @@ __attribute__((const)) float fabsf(float x);
#define is_not_zero(X) (fabsf(X) > EPSILON) #define is_not_zero(X) (fabsf(X) > EPSILON)
/* point_in_rect(): Verify if a point is in a rectangle /**
This function is useful for verify if a point is in a rectangle. * @brief Verify if a point is in a rectangle
*
@P A Vector2d * @param P Vector2d
@R A rectangle * @param R Rectangle
Return true if the condition is validated else false. */ *
* @return True if the point is in the rectangle, else false.
*/
#define point_in_rect(P, R) (((P)->x >= (R)->x) && ((P)->x < ((R)->x + (R)->w)) && \ #define point_in_rect(P, R) (((P)->x >= (R)->x) && ((P)->x < ((R)->x + (R)->w)) && \
((P)->y >= (R)->y) && ((P)->y < ((R)->y + (R)->h))) ((P)->y >= (R)->y) && ((P)->y < ((R)->y + (R)->h)))
/* rect_empty(): Verify if a rectangle is empty /**
This function is useful for verify if a rectangle exists. * @brief Verify if a rectangle is empty
*
@R A rectangle * @param R Rectangle
Return true if the condition is validated else false. */ *
* @return True if the rectangle is empty, else false.
*/
#define rect_empty(R) ((!(R)) || (is_equal_to_zero((R)->w)) || (is_equal_to_zero((R)->h))) #define rect_empty(R) ((!(R)) || (is_equal_to_zero((R)->w)) || (is_equal_to_zero((R)->h)))
/* has_intersection(): Verify if there is a intersction between two rectangles /**
This function is useful for verify intersection between two rectangles. * @brief Verify if there is a intersction between two rectangles
*
* @param A Rectangle A
* @param B Rectangle B
*
* @return True if there is an intersection, else false.
*/
bool has_intersection(const rect_t *A, const rect_t *B);
@A A rectangle /**
@B Another rectangle * @brief Verify if there is an intersection between two rectangles and get the intersection rectangle.
Return true if the condition is validated else false. */ *
bool has_intersection(const rect_t *, const rect_t *); * @param A Rectangle A
* @param B Rectangle B
/* intersect_rect(): Like has_intersection but has a result rectangle * @param result The intersection rectangle
This function is useful for verify intersection between two rectangles *
and get the intersection rectangle. * @return True if there is an intersection, else false.
*/
@A A rectangle bool intersect_rect(const rect_t *A, const rect_t *B, rect_t *result);
@B Another rectangle
@result The intersection rectangle
Return true if the condition is validated else false. */
bool intersect_rect(const rect_t *, const rect_t *, rect_t *);
#endif // VECTOR2D_H #endif // VECTOR2D_H