[Scummvm-devel] About Rect's, and the bottom right point

Max Horn max at quendi.de
Tue Oct 5 01:20:47 CEST 2004


Yo folks,

recently a lot of code has been checked in to the SCUMM engine (esp. 
for HE code) which uses the Common::Rect class differently than the 
existing code. I actually already documented this particular thing in 
common/rect.h, so I am just going to quote myself first:

	This small class is an helper for rectangles.
	Note: This implementation is built around the assumption that 
(top,left) is
	part of the rectangle, but (bottom,right) is not! This is reflected in
	various methods, including contains(), intersects() and others.
	
	Another very wide spread approach to rectangle classes treats 
(bottom,right)
	also as a part of the rectangle.
	
	Coneptually, both are sound, but the approach we use saves many 
intermediate
	computations (like computing the height in our case is done by doing 
this:
	  height = bottom - top;
	while in the alternate system, it would be
	  height = bottom - top + 1;
	
	When writing code using our Rect class, always keep this principle in 
mind!


Now, of course you still can use Commonn::Rect either way. However, by 
not using it consistenly, we introduce a lot of potential for 
confusion, and make it very likely that off-by-one errors creep in. 
Hence I would strongly suggest that all the SCUMM code make use of the 
Rect convention as described above.

For other engines it probably would be nice if they followed the 
convention, too, but the reasons are far less compelling; as long as 
it's used consistently within each module, that should be fine. The bad 
things just start to happen when you mix the two notions.


Cheers,

max





More information about the Scummvm-devel mailing list