]> git.lizzy.rs Git - nothing.git/blob - src/math/rect.h
Merge pull request #228 from tsoding/222
[nothing.git] / src / math / rect.h
1 #ifndef RECT_H_
2 #define RECT_H_
3
4 #include <SDL2/SDL.h>
5
6 #include "math/point.h"
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 rect_t rect_from_sdl(const SDL_Rect *rect);
29
30 rect_t rects_overlap_area(rect_t rect1, rect_t rect2);
31
32 int rect_contains_point(rect_t rect, point_t p);
33
34 int rects_overlap(rect_t rect1, rect_t rect2);
35
36 void rect_object_impact(rect_t object,
37                         rect_t obstacle,
38                         int *sides);
39
40 line_t rect_side(rect_t rect, rect_side_t side);
41
42 rect_t rect_from_point(point_t p, float w, float h);
43
44 float line_length(line_t line);
45
46 SDL_Rect rect_for_sdl(rect_t rect);
47
48 #endif  // RECT_H_