]> git.lizzy.rs Git - nothing.git/blob - src/rect.h
Merge pull request #124 from tsoding/117
[nothing.git] / src / rect.h
1 #ifndef RECT_H_
2 #define RECT_H_
3
4 #include "./point.h"
5
6 typedef struct SDL_Rect SDL_Rect;
7
8 typedef enum rect_side_t {
9     RECT_SIDE_LEFT = 0,
10     RECT_SIDE_RIGHT,
11     RECT_SIDE_TOP,
12     RECT_SIDE_BOTTOM,
13
14     RECT_SIDE_N
15 } rect_side_t;
16
17 typedef struct rect_t {
18     float x, y, w, h;
19 } rect_t;
20
21 typedef struct line_t {
22     point_t p1;
23     point_t p2;
24 } line_t;
25
26 rect_t rect(float x, float y, float w, float h);
27 rect_t rect_from_vecs(point_t position, vec_t size);
28
29 rect_t rects_overlap_area(rect_t rect1, rect_t rect2);
30
31 int rect_contains_point(rect_t rect, point_t p);
32
33 int rects_overlap(rect_t rect1, rect_t rect2);
34
35 void rect_object_impact(const rect_t *object,
36                         const rect_t *obstacle,
37                         int *sides);
38
39 line_t rect_side(rect_t rect, rect_side_t side);
40
41 rect_t rect_from_point(point_t p, float w, float h);
42
43 float line_length(line_t line);
44
45 SDL_Rect rect_for_sdl(rect_t rect);
46
47 #endif  // RECT_H_