]> git.lizzy.rs Git - nothing.git/blob - src/math/rect.h
(#647) fix max_int64
[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 {
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;
16
17 typedef struct Rect {
18     float x, y, w, h;
19 } Rect;
20
21 typedef struct Line {
22     Point p1;
23     Point p2;
24 } Line;
25
26 Rect rect(float x, float y, float w, float h);
27 Rect rect_from_vecs(Point position, Vec size);
28 Rect rect_from_sdl(const SDL_Rect *rect);
29
30 Rect rects_overlap_area(Rect rect1, Rect rect2);
31
32 int rect_contains_point(Rect rect, Point p);
33
34 int rects_overlap(Rect rect1, Rect rect2);
35
36 void rect_object_impact(Rect object,
37                         Rect obstacle,
38                         int *sides);
39
40 Line rect_side(Rect rect, Rect_side side);
41
42 Rect rect_from_point(Point p, float w, float h);
43
44 float line_length(Line line);
45
46 SDL_Rect rect_for_sdl(Rect rect);
47
48 Vec rect_center(Rect rect);
49
50 Rect rect_snap(Rect pivot, Rect rect);
51 void rect_impulse(Rect *r1, Rect *r2);
52
53 #endif  // RECT_H_