Author: cjhopman
Date: Thu May  7 19:46:30 2009
New Revision: 35473

URL: http://svn.gna.org/viewcvs/wesnoth?rev=35473&view=rev
Log:
rewrite get_rect_union to return the smallest rectangle that contains the union.
rename get_rect_union to union_rects to be consistent with intersect_rects.

Modified:
    trunk/src/sdl_utils.cpp
    trunk/src/sdl_utils.hpp

Modified: trunk/src/sdl_utils.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/sdl_utils.cpp?rev=35473&r1=35472&r2=35473&view=diff
==============================================================================
--- trunk/src/sdl_utils.cpp (original)
+++ trunk/src/sdl_utils.cpp Thu May  7 19:46:30 2009
@@ -84,25 +84,15 @@
        return res;
 }
 
-SDL_Rect get_rect_union(const SDL_Rect& rect1, const SDL_Rect& rect2)
-{
-       const int left_side = std::max(rect1.x, rect2.x);
-       const int right_side = std::min(rect1.x + rect1.w, rect2.x + rect2.w);
-       if(left_side > right_side) {
-               return empty_rect;
-       }
-
-       const int top_side = std::max(rect1.y, rect2.y);
-       const int bottom_side = std::min(rect1.y + rect1.h, rect2.y + rect2.h);
-       if(top_side > bottom_side) {
-               return empty_rect;
-       }
-
-       SDL_Rect result = {
-                       left_side,
-                       top_side,
-                       right_side - left_side,
-                       bottom_side - top_side};
+SDL_Rect union_rects(const SDL_Rect& rect1, const SDL_Rect& rect2)
+{
+       SDL_Rect result;
+
+       result.x = std::min(rect1.x, rect2.x);
+       result.w = std::max(rect1.x + rect1.w, rect2.x + rect2.w) - result.x;
+
+       result.y = std::min(rect1.y, rect2.y);
+       result.h = std::max(rect1.y + rect1.h, rect2.y + rect2.h) - result.y;
 
        return result;
 }

Modified: trunk/src/sdl_utils.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/sdl_utils.hpp?rev=35473&r1=35472&r2=35473&view=diff
==============================================================================
--- trunk/src/sdl_utils.hpp (original)
+++ trunk/src/sdl_utils.hpp Thu May  7 19:46:30 2009
@@ -58,14 +58,14 @@
 SDL_Rect intersect_rects(SDL_Rect const &rect1, SDL_Rect const &rect2);
 
 /**
- * Returns the union of two rectangles.
+ * Returns the smallest rectangle containing the union of two rectangles.
  *
  * @param rect1                   The first rectangle.
  * @param rect2                   The second rectangle.
  *
- * @returns                       The union of rect1 and rect2.
- */
-SDL_Rect get_rect_union(const SDL_Rect& rect1, const SDL_Rect& rect2);
+ * @returns                       The smallest rectangle that contains both 
rect1 and rect2.
+ */
+SDL_Rect union_rects(const SDL_Rect& rect1, const SDL_Rect& rect2);
 
 /**
  *  Creates an empty SDL_Rect.


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to