| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#pragma once |
| 27 |
|
| 28 |
#include <math.h> |
| 29 |
|
| 30 |
#include "mathc/mathc.h" |
| 31 |
#include "utils.h" |
| 32 |
|
| 33 |
#define CHEBYSHEV_DISTANCE(x1, y1, x2, y2) \ |
| 34 |
MAX(fabsf((x1) - (x2)), fabsf((y1) - (y2))) |
| 35 |
|
| 36 |
struct vec2i svec2i_scale_divide(const struct vec2i v, const mint_t scale); |
| 37 |
|
| 38 |
struct vec2i Vec2iToTile(struct vec2i v); |
| 39 |
struct vec2i Vec2iCenterOfTile(struct vec2i v); |
| 40 |
struct vec2i Vec2ToTile(const struct vec2 v); |
| 41 |
struct vec2 Vec2CenterOfTile(const struct vec2i v); |
| 42 |
|
| 43 |
|
| 44 |
#define CENTER_X(_pos, _size, _w) ((_pos).x + ((_size).x - (_w)) / 2) |
| 45 |
#define CENTER_Y(_pos, _size, _h) ((_pos).y + ((_size).y - (_h)) / 2) |
| 46 |
|
| 47 |
typedef struct |
| 48 |
{ |
| 49 |
struct vec2i Pos; |
| 50 |
struct vec2i Size; |
| 51 |
} Rect2i; |
| 52 |
|
| 53 |
#define RECT_FOREACH(_r) \ |
| 54 |
{ \ |
| 55 |
struct vec2i _v; \ |
| 56 |
for (_v.y = _r.Pos.y; _v.y < _r.Pos.y + _r.Size.y; _v.y++) \ |
| 57 |
{ \ |
| 58 |
for (_v.x = _r.Pos.x; _v.x < _r.Pos.x + _r.Size.x; _v.x++) \ |
| 59 |
{ \ |
| 60 |
const int _i = _v.x + _v.y * _r.Size.x; \ |
| 61 |
UNUSED(_i); |
| 62 |
#define RECT_FOREACH_END() \ |
| 63 |
} \ |
| 64 |
} \ |
| 65 |
} |
| 66 |
|
| 67 |
Rect2i Rect2iNew(const struct vec2i pos, const struct vec2i size); |
| 68 |
Rect2i Rect2iZero(void); |
| 69 |
bool Rect2iIsZero(const Rect2i r); |
| 70 |
bool Rect2iIsAtEdge(const Rect2i r, const struct vec2i v); |
| 71 |
bool Rect2iIsInside(const Rect2i r, const struct vec2i v); |
| 72 |
bool Rect2iOverlap(const Rect2i r1, const Rect2i r2); |
| 73 |
struct vec2i Rect2iCenter(const Rect2i r); |