README: mention SDL2 backend
[rofl0r-concol.git] / rect.h
blobbc27caf956eddda34370fadd69636fce7c57a868
1 #ifndef RECT_H
2 #define RECT_H
4 #include "point.h"
6 typedef struct {
7 point topleft;
8 point bottomright;
9 } rect;
11 #define rect_zero {{0,0},{0,0}}
13 #define width_from_rect(RECT_PTR) ((RECT_PTR)->bottomright.x + 1 - (RECT_PTR)->topleft.x)
14 #define height_from_rect(RECT_PTR) ((RECT_PTR)->bottomright.y + 1 - (RECT_PTR)->topleft.y)
15 #define make_rect(RECT_PTR, X1, Y1, X2, Y2) do { (RECT_PTR)->topleft.x = X1; (RECT_PTR)->topleft.y = Y1; \
16 (RECT_PTR)->bottomright.x = X2; (RECT_PTR)->bottomright.y = Y2; } while(0)
17 #define point_in_rect(POINT_PTR, RECT_PTR) ((POINT_PTR)->x >= (RECT_PTR)->topleft.x && \
18 (POINT_PTR)->x <= (RECT_PTR)->bottomright.x && \
19 (POINT_PTR)->y >= (RECT_PTR)->topleft.y && \
20 (POINT_PTR)->y <= (RECT_PTR)->bottomright.y )
21 #define point_member_in_rect(POINT_PTR, RECT_PTR, IS_X) (\
22 ((IS_X) ? ( \
23 (POINT_PTR)->x >= (RECT_PTR)->topleft.x && \
24 (POINT_PTR)->x <= (RECT_PTR)->bottomright.x \
25 ) : ( \
26 (POINT_PTR)->y >= (RECT_PTR)->topleft.y && \
27 (POINT_PTR)->y <= (RECT_PTR)->bottomright.y \
28 )))
30 #endif