#include "rect.hpp" /******************************************************************************* ** RectCreate *******************************************************************************/ Rect RectCreate(int x1, int y1, int x2, int y2) { Rect rect; rect.x1 = x1; rect.y1 = y1; rect.x2 = x2; rect.y2 = y2; return rect; } /******************************************************************************* ** RectInflate *******************************************************************************/ void RectInflate(Rect* dst, int x, int y) { dst->x1 -= x; dst->y1 -= y; dst->x2 += x; dst->y2 += y; } /******************************************************************************* ** RectSetWH *******************************************************************************/ void RectSetWH(Rect* dst, int x, int y, int w, int h) { dst->x1 = x; dst->y1 = y; dst->x2 = x + w; dst->y2 = y + h; } /******************************************************************************* ** RectWidth *******************************************************************************/ int RectWidth(Rect* dst) { return dst->x2 - dst->x1; } /******************************************************************************* ** RectHeight *******************************************************************************/ int RectHeight(Rect* dst) { return dst->y2 - dst->y1; } /******************************************************************************* ** RectAND *******************************************************************************/ void RectAND(Rect* dst, Rect* a, Rect* b) { dst->x1 = Max(a->x1, b->x1); dst->y1 = Max(a->y1, b->y1); dst->x2 = Min(a->x2, b->x2); dst->y2 = Min(a->y2, b->y2); } /******************************************************************************* ** RectContains *******************************************************************************/ int RectContains(Rect* r, int x, int y) { return x >= r->x1 && x < r->x2 && y >= r->y1 && y < r->y2; } /******************************************************************************* ** RectIsVisible *******************************************************************************/ int RectIsVisible(Rect* r) { return (r->x2 - r->x1) > 0 && (r->y2 - r->y1) > 0; }