module sdl3::sdl; struct Point { int x; int y; } struct FPoint { float x; float y; } struct Rect { int x, y; int w, h; } struct FRect { float x; float y; float w; float h; } macro void rect_to_f_rect(Rect* rect, FRect* frect) { frect.x = (float)rect.x; frect.y = (float)rect.y; frect.w = (float)rect.w; frect.h = (float)rect.h; } macro bool point_in_rect(Point* p, Rect* r) { return ( p && r && (p.x >= r.x) && (p.x < (r.x + r.w)) && (p.y >= r.y) && (p.y < (r.y + r.h)) ) ? true : false; } macro bool rect_empty(Rect* r) { return ((!r) || (r.w <= 0) || (r.h <= 0)) ? true : false; } macro bool rects_equal(Rect* a, Rect* b) { return (a && b && (a.x == b.x) && (a.y == b.y) && (a.w == b.w) && (a.h == b.h)) ? true : false; } extern fn bool has_rect_intersection(Rect* a , Rect* b) @extern("SDL_HasRectIntersection"); extern fn bool get_rect_intersection(Rect* a , Rect* b, Rect* result) @extern("SDL_GetRectIntersection"); extern fn bool get_rect_union(Rect* a , Rect* b, Rect* result) @extern("SDL_GetRectUnion"); extern fn bool get_rect_enclosing_points(Point* points, int count, Rect* clip, Rect* result) @extern("SDL_GetRectEnclosingPoints"); extern fn bool get_rect_and_line_intersection(Rect* rect, int* x1, int* y1, int* x2, int* y2) @extern("SDL_GetRectAndLineIntersection"); macro bool point_in_rect_float(FPoint* p, FRect *r) { return ( p && r && (p.x >= r.x) && (p.x <= (r.x + r.w)) && (p.y >= r.y) && (p.y <= (r.y + r.h)) ) ? true : false; } macro bool rect_empty_float(FRect* r) { return ((!r) || (r.w < 0.0f) || (r.h < 0.0f)) ? true : false; } macro bool rects_equal_epsilon(FRect* a, FRect* b, float epsilon) { return (a && b && ((a == b) || ((fabsf(a.x - b.x) <= epsilon) && (fabsf(a.y - b.y) <= epsilon) && (fabsf(a.w - b.w) <= epsilon) && (fabsf(a.h - b.h) <= epsilon)))) ? true : false; } macro bool rects_equal_float(FRect* a, FRect* b) => rects_equal_epsilon(a, b, FLT_EPSILON); extern fn bool has_rect_intersection_float(FRect* a , FRect* b) @extern("SDL_HasRectIntersectionFloat"); extern fn bool get_rect_intersection_float(FRect* a , FRect* b, FRect* result) @extern("SDL_GetRectIntersectionFloat"); extern fn bool get_rect_union_float(FRect* a , FRect* b, FRect* result) @extern("SDL_GetRectUnionFloat"); extern fn bool get_rect_enclosing_points_float(FPoint* points, int count, FRect* clip, FRect* result) @extern("SDL_GetRectEnclosingPointsFloat"); extern fn bool get_rect_and_line_intersection_float(FRect* rect, float* x1, float* y1, float* x2, float* y2) @extern("SDL_GetRectAndLineIntersectionFloat");