]> git.lizzy.rs Git - nothing.git/blobdiff - src/math/rect.h
(#886) Make RectLayer display the ids
[nothing.git] / src / math / rect.h
index 1a75d4c4f20baabea232d47bf5e3e5ce1152a032..16334410ab14cc234e08c4e841463062e7ba8c76 100644 (file)
@@ -1,48 +1,68 @@
 #ifndef RECT_H_
 #define RECT_H_
 
-#include <SDL2/SDL.h>
+#include <SDL.h>
 
 #include "math/point.h"
 
-typedef enum rect_side_t {
+typedef enum Rect_side {
     RECT_SIDE_LEFT = 0,
     RECT_SIDE_RIGHT,
     RECT_SIDE_TOP,
     RECT_SIDE_BOTTOM,
 
     RECT_SIDE_N
-} rect_side_t;
+} Rect_side;
 
-typedef struct rect_t {
+typedef struct Rect {
     float x, y, w, h;
-} rect_t;
+} Rect;
 
-typedef struct line_t {
-    point_t p1;
-    point_t p2;
-} line_t;
+typedef struct Line {
+    Point p1;
+    Point p2;
+} Line;
 
-rect_t rect(float x, float y, float w, float h);
-rect_t rect_from_vecs(point_t position, vec_t size);
-rect_t rect_from_sdl(const SDL_Rect *rect);
+Rect rect(float x, float y, float w, float h);
+Rect rect_from_vecs(Point position, Vec size);
+Rect rect_from_points(Point p1, Point p2);
+Rect rect_from_sdl(const SDL_Rect *rect);
 
-rect_t rects_overlap_area(rect_t rect1, rect_t rect2);
+Rect rects_overlap_area(Rect rect1, Rect rect2);
 
-int rect_contains_point(rect_t rect, point_t p);
+static inline Point rect_position(Rect rect)
+{
+    return vec(rect.x, rect.y);
+}
 
-int rects_overlap(rect_t rect1, rect_t rect2);
+static inline Rect rect_scale(Rect rect, float d)
+{
+    rect.x -= d;
+    rect.y -= d;
+    rect.w += d * 2.0f;
+    rect.h += d * 2.0f;
+    return rect;
+}
 
-void rect_object_impact(const rect_t *object,
-                        const rect_t *obstacle,
+int rect_contains_point(Rect rect, Point p);
+
+int rects_overlap(Rect rect1, Rect rect2);
+
+void rect_object_impact(Rect object,
+                        Rect obstacle,
                         int *sides);
 
-line_t rect_side(rect_t rect, rect_side_t side);
+Line rect_side(Rect rect, Rect_side side);
+
+Rect rect_from_point(Point p, float w, float h);
+
+float line_length(Line line);
 
-rect_t rect_from_point(point_t p, float w, float h);
+SDL_Rect rect_for_sdl(Rect rect);
 
-float line_length(line_t line);
+Vec rect_center(Rect rect);
 
-SDL_Rect rect_for_sdl(rect_t rect);
+Vec rect_snap(Rect pivot, Rect *rect);
+Vec rect_impulse(Rect *r1, Rect *r2);
 
 #endif  // RECT_H_