]> git.lizzy.rs Git - nothing.git/blob - src/math/rect.h
(#694) Fix box pushing mechanics
[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_points(Point p1, Point p2);
29 Rect rect_from_sdl(const SDL_Rect *rect);
30
31 Rect rects_overlap_area(Rect rect1, Rect rect2);
32
33 int rect_contains_point(Rect rect, Point p);
34
35 int rects_overlap(Rect rect1, Rect rect2);
36
37 void rect_object_impact(Rect object,
38                         Rect obstacle,
39                         int *sides);
40
41 Line rect_side(Rect rect, Rect_side side);
42
43 Rect rect_from_point(Point p, float w, float h);
44
45 float line_length(Line line);
46
47 SDL_Rect rect_for_sdl(Rect rect);
48
49 Vec rect_center(Rect rect);
50
51 Vec rect_snap(Rect pivot, Rect *rect);
52 Vec rect_impulse(Rect *r1, Rect *r2);
53
54 #endif  // RECT_H_