| 25 | #include "SDL_assert.h" |
| 26 | |
| 27 | SDL_bool |
| 28 | SDL_HasIntersection(const SDL_Rect * A, const SDL_Rect * B) |
| 29 | { |
| 30 | int Amin, Amax, Bmin, Bmax; |
| 31 | |
| 32 | if (!A) { |
| 33 | SDL_InvalidParamError("A"); |
| 34 | return SDL_FALSE; |
| 35 | } |
| 36 | |
| 37 | if (!B) { |
| 38 | SDL_InvalidParamError("B"); |
| 39 | return SDL_FALSE; |
| 40 | } |
| 41 | |
| 42 | /* Special cases for empty rects */ |
| 43 | if (SDL_RectEmpty(A) || SDL_RectEmpty(B)) { |
| 44 | return SDL_FALSE; |
| 45 | } |
| 46 | |
| 47 | /* Horizontal intersection */ |
| 48 | Amin = A->x; |
| 49 | Amax = Amin + A->w; |
| 50 | Bmin = B->x; |
| 51 | Bmax = Bmin + B->w; |
| 52 | if (Bmin > Amin) |
| 53 | Amin = Bmin; |
| 54 | if (Bmax < Amax) |
| 55 | Amax = Bmax; |
| 56 | if (Amax <= Amin) |
| 57 | return SDL_FALSE; |
| 58 | |
| 59 | /* Vertical intersection */ |
| 60 | Amin = A->y; |
| 61 | Amax = Amin + A->h; |
| 62 | Bmin = B->y; |
| 63 | Bmax = Bmin + B->h; |
| 64 | if (Bmin > Amin) |
| 65 | Amin = Bmin; |
| 66 | if (Bmax < Amax) |
| 67 | Amax = Bmax; |
| 68 | if (Amax <= Amin) |
| 69 | return SDL_FALSE; |
| 70 | |
| 71 | return SDL_TRUE; |
| 72 | } |
| 73 | |
| 74 | SDL_bool |
| 75 | SDL_IntersectRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result) |