src/video/SDL_rect.c
changeset 5950 36fa6d12784b
parent 5902 d3d839b15c2f
child 5953 fecf71a834ed
equal deleted inserted replaced
5949:b2668bd8c9dc 5950:36fa6d12784b
    31     if (!A || !B) {
    31     if (!A || !B) {
    32         // TODO error message
    32         // TODO error message
    33         return SDL_FALSE;
    33         return SDL_FALSE;
    34     }
    34     }
    35 
    35 
       
    36     /* Special cases for empty rects */
       
    37     if (SDL_RectEmpty(A) || SDL_RectEmpty(B)) {
       
    38         return SDL_FALSE;
       
    39     }
       
    40 
    36     /* Horizontal intersection */
    41     /* Horizontal intersection */
    37     Amin = A->x;
    42     Amin = A->x;
    38     Amax = Amin + A->w;
    43     Amax = Amin + A->w;
    39     Bmin = B->x;
    44     Bmin = B->x;
    40     Bmax = Bmin + B->w;
    45     Bmax = Bmin + B->w;
    68     if (!A || !B || !result) {
    73     if (!A || !B || !result) {
    69         // TODO error message
    74         // TODO error message
    70         return SDL_FALSE;
    75         return SDL_FALSE;
    71     }
    76     }
    72 
    77 
       
    78     /* Special cases for empty rects */
       
    79     if (SDL_RectEmpty(A) || SDL_RectEmpty(B)) {
       
    80         return SDL_FALSE;
       
    81     }
       
    82     
    73     /* Horizontal intersection */
    83     /* Horizontal intersection */
    74     Amin = A->x;
    84     Amin = A->x;
    75     Amax = Amin + A->w;
    85     Amax = Amin + A->w;
    76     Bmin = B->x;
    86     Bmin = B->x;
    77     Bmax = Bmin + B->w;
    87     Bmax = Bmin + B->w;
   104 
   114 
   105     if (!A || !B || !result) {
   115     if (!A || !B || !result) {
   106         return;
   116         return;
   107     }
   117     }
   108 
   118 
       
   119     /* Special cases for empty Rects */
       
   120     if (SDL_RectEmpty(A)) {
       
   121       if (SDL_RectEmpty(B)) {
       
   122        /* A and B empty */
       
   123        return;
       
   124       } else {
       
   125        /* A empty, B not empty */
       
   126        *result = *B;
       
   127        return;
       
   128       }
       
   129     } else {      
       
   130       if (SDL_RectEmpty(B)) {
       
   131        /* A not empty, B empty */
       
   132        *result = *A;
       
   133        return;
       
   134       } 
       
   135     }
       
   136     
   109     /* Horizontal union */
   137     /* Horizontal union */
   110     Amin = A->x;
   138     Amin = A->x;
   111     Amax = Amin + A->w;
   139     Amax = Amin + A->w;
   112     Bmin = B->x;
   140     Bmin = B->x;
   113     Bmax = Bmin + B->w;
   141     Bmax = Bmin + B->w;
   116     result->x = Amin;
   144     result->x = Amin;
   117     if (Bmax > Amax)
   145     if (Bmax > Amax)
   118         Amax = Bmax;
   146         Amax = Bmax;
   119     result->w = Amax - Amin;
   147     result->w = Amax - Amin;
   120 
   148 
   121     /* Vertical intersection */
   149     /* Vertical union */
   122     Amin = A->y;
   150     Amin = A->y;
   123     Amax = Amin + A->h;
   151     Amax = Amin + A->h;
   124     Bmin = B->y;
   152     Bmin = B->y;
   125     Bmax = Bmin + B->h;
   153     Bmax = Bmin + B->h;
   126     if (Bmin < Amin)
   154     if (Bmin < Amin)
   150         // TODO error message
   178         // TODO error message
   151         return SDL_FALSE;
   179         return SDL_FALSE;
   152     }
   180     }
   153 
   181 
   154     if (clip) {
   182     if (clip) {
       
   183         /* Special case for empty rectangle */
       
   184         if (SDL_RectEmpty(clip)) {
       
   185             return SDL_FALSE;
       
   186         }
       
   187         
   155         SDL_bool added = SDL_FALSE;
   188         SDL_bool added = SDL_FALSE;
   156         int clip_minx = clip->x;
   189         int clip_minx = clip->x;
   157         int clip_miny = clip->y;
   190         int clip_miny = clip->y;
   158         int clip_maxx = clip->x+clip->w-1;
   191         int clip_maxx = clip->x+clip->w-1;
   159         int clip_maxy = clip->y+clip->h-1;
   192         int clip_maxy = clip->y+clip->h-1;
   267     if (!rect || !X1 || !Y1 || !X2 || !Y2) {
   300     if (!rect || !X1 || !Y1 || !X2 || !Y2) {
   268         // TODO error message
   301         // TODO error message
   269         return SDL_FALSE;
   302         return SDL_FALSE;
   270     }
   303     }
   271 
   304 
       
   305     /* Special case for empty rect */
       
   306     if (SDL_RectEmpty(rect)) {
       
   307         return SDL_FALSE;
       
   308     }
       
   309     
   272     x1 = *X1;
   310     x1 = *X1;
   273     y1 = *Y1;
   311     y1 = *Y1;
   274     x2 = *X2;
   312     x2 = *X2;
   275     y2 = *Y2;
   313     y2 = *Y2;
   276     rectx1 = rect->x;
   314     rectx1 = rect->x;