geom.h (1274B)
1 #pragma once 2 3 #include <stuff/base.h> 4 5 typedef struct Point Point; 6 typedef struct Rectangle Rectangle; 7 8 struct Point { 9 int x, y; 10 }; 11 12 struct Rectangle { 13 Point min, max; 14 }; 15 16 enum Align { 17 North = 0x01, 18 East = 0x02, 19 South = 0x04, 20 West = 0x08, 21 NEast = North | East, 22 NWest = North | West, 23 SEast = South | East, 24 SWest = South | West, 25 Center = NEast | SWest, 26 }; 27 28 typedef enum Align Align; 29 30 #define Dx(r) ((r).max.x - (r).min.x) 31 #define Dy(r) ((r).max.y - (r).min.y) 32 #define Pt(x, y) ((Point){(x), (y)}) 33 #define Rpt(p, q) ((Rectangle){(p), (q)}) 34 #define Rect(x0, y0, x1, y1) Rpt(Pt(x0, y0), Pt(x1, y1)) 35 36 Point addpt(Point, Point); 37 Point divpt(Point, Point); 38 int eqpt(Point, Point); 39 int eqrect(Rectangle, Rectangle); 40 Rectangle gravitate(Rectangle dst, Rectangle src, Point grav); 41 Rectangle insetrect(Rectangle, int); 42 Point mulpt(Point p, Point q); 43 Rectangle rectaddpt(Rectangle, Point); 44 Rectangle rectsetorigin(Rectangle, Point); 45 Rectangle rectsubpt(Rectangle, Point); 46 Point subpt(Point, Point); 47 48 Align get_sticky(Rectangle src, Rectangle dst); 49 Align quadrant(Rectangle, Point); 50 bool rect_contains_p(Rectangle, Rectangle); 51 bool rect_haspoint_p(Rectangle, Point); 52 bool rect_intersect_p(Rectangle, Rectangle); 53 Rectangle rect_intersection(Rectangle, Rectangle); 54