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

Max Horn max at quendi.de
Tue Oct 5 14:07:20 CEST 2004


Am 05.10.2004 um 12:25 schrieb Eugene Sandulenko:

> Max Horn writes:
>> 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.	
>
>> Now, of course you still can use Commonn::Rect either way.
> Sorry, if I sound dumb then I am, but what do you mean?
>
> How can you use it either way? If I'll use bigger right and bottom
> coordinates then I should expect my code to fail. From the other hand
> if it works in all cases then it should use correct approach, right?
>
> Please, give some references to the code when the usage is wrong.
>
First off, as I said, there is no such thing as "wrong", rather it 
would be "misuse" of the rect class. Let me first give an example of 
the code in question: From charset.cpp, line 1318 following:

...
	clip.top = clip.left = 0;
	clip.right = vs->w - 1;
	clip.bottom = vs->h - 1;

	dst.left = _left;
	dst.top = _top;
	dst.right = dst.left + width;
	dst.bottom = dst.top + height;

	dst.clip(clip);
...

Some general remarks: The way some of the HE/WizImage code uses it, 
methods like height(), contains(), intersects() etc. will yield wrong 
results.
Furthermore, you'll run into problems once you start calling other 
methods (like markRectAsDirty) which expect rects to follow the 
"bottom-right-is-*not*-contained" logic.

So in the excerpt above, you set clip to a rect using the 
"bottom-right-is-contained" method; then you set dst using the 
"bottom-right-is-*not*-contained" logic. So far so good, but then it 
gets really wrong, because you clip "dst" by "clip", which will yield 
incorrect results in certain cases. That would happen if dst covers the 
whole screen; you will loose the bottom most row, as well as the right 
most column.



Bye,

Max





More information about the Scummvm-devel mailing list