indexing description: "[ Rectangle. Used for clipping and blitting. ]" date: "$Date$" revision: "$Revision$" class EM_BLITTING_RECTANGLE inherit SDL_RECT_STRUCT rename h as height, w as width, set_h as set_height, set_w as set_width end create make feature {NONE} -- Initialization make (an_x: INTEGER; an_y: INTEGER; a_width: INTEGER; a_height: INTEGER) is -- Create with `an_x' and `an_y' as upper left corner, `a_width' wide and `a_height' -- tall. do make_new_unshared set_x (an_x) set_y (an_y) set_width (a_width) set_height (a_height) end feature -- Status report intersects (other: like Current): BOOLEAN is -- Is the intersection between `current' and `other' not empty require other_not_void: other /= Void do Result := not ((x + width < other.x) or (y + height < other.y) or (x > other.x + other.width) or (y > other.y + other.height)) end inside (other: like Current): BOOLEAN is -- Is `current' completly inside `other'? require other_not_void: other /= Void do Result := (x >= other.x) and (x + width <= other.width + other.x) and (y >= other.y) and (y + height <= other.height + other.y) end feature -- Basic operations intersection (other: like Current): like Current is -- Intersection between `current' and `other' EM_BLITTING_RECTANGLE require other_not_void: other /= Void local pos: INTEGER do if intersects (other) then create Result.make (max (x, other.x), max (y, other.y), 0, 0) pos := min (x + width, other.x + other.width) Result.set_width (pos - Result.x) pos := min (y + height, other.y + other.height) Result.set_height (pos - Result.y) else create Result.make (0, 0, 0, 0) end end feature {NONE} -- Implementation min (a: INTEGER; b: INTEGER): INTEGER is -- Minumum of `a' and `b' do if a < b then Result := a else Result := b end end max (a: INTEGER; b: INTEGER): INTEGER is -- Maximum of `a' and `b' do if a > b then Result := a else Result := b end end end