Surface->h problem?

I am using simple clipping such as this:

/* We have to do some clipping so UpdateRects works */
if (Y1 < 0) Y1 = 0;
if (Y1 > Surface->h) Y1 = Surface->h;
if (Y2 < 0) Y2 = 0;
if (Y2 > Surface->h) Y2 = Surface->h;

if (X < 0) X = 0;
if (X > Surface->w) X = Surface->w;

The above is from a vertical line drawer. The problem is although the X
clipping works fine in both this and the horizontal line drawer, the Y
clipping fails in both. Obviously if I call UpdateRects and the values
are out of range the program will crash, but if Y1 is out of range it
should be set to Surface->h which is in range, right?

I am using simple clipping such as this:

/* We have to do some clipping so UpdateRects works */
if (Y1 < 0) Y1 = 0;
if (Y1 > Surface->h) Y1 = Surface->h;
if (Y2 < 0) Y2 = 0;
if (Y2 > Surface->h) Y2 = Surface->h;

if (X < 0) X = 0;
if (X > Surface->w) X = Surface->w;

The above is from a vertical line drawer. The problem is although the X
clipping works fine in both this and the horizontal line drawer, the Y
clipping fails in both. Obviously if I call UpdateRects and the values
are out of range the program will crash, but if Y1 is out of range it
should be set to Surface->h which is in range, right?

Actually, often (depending on your code) when you’re translating between
x,y,w,h and x1,y1,x2,y2, x,y,w,h gets translated to x1,y1, x1+w-1,y1+h-1.

So, you probably want Surface->w-1 and Surface->h-1 as the bounds.

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

Thanks again.

By the way, I didn’t realize you were part of Loki, keep up the good work
all us Linux users appreciate it!

Sam Lantinga wrote:> > I am using simple clipping such as this:

/* We have to do some clipping so UpdateRects works */
if (Y1 < 0) Y1 = 0;
if (Y1 > Surface->h) Y1 = Surface->h;
if (Y2 < 0) Y2 = 0;
if (Y2 > Surface->h) Y2 = Surface->h;

if (X < 0) X = 0;
if (X > Surface->w) X = Surface->w;

The above is from a vertical line drawer. The problem is although the X
clipping works fine in both this and the horizontal line drawer, the Y
clipping fails in both. Obviously if I call UpdateRects and the values
are out of range the program will crash, but if Y1 is out of range it
should be set to Surface->h which is in range, right?

Actually, often (depending on your code) when you’re translating between
x,y,w,h and x1,y1,x2,y2, x,y,w,h gets translated to x1,y1, x1+w-1,y1+h-1.

So, you probably want Surface->w-1 and Surface->h-1 as the bounds.

    -Sam Lantinga                           (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software

“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec