update SDL3 to latest commit

This commit is contained in:
Sasha Szpakowski
2024-10-06 20:30:44 -03:00
parent 1b0fdc338b
commit 9e5eb1b018
1426 changed files with 242456 additions and 103496 deletions
+103 -75
View File
@@ -19,23 +19,40 @@
3. This notice may not be removed or altered from any source distribution.
*/
/* This file is #included twice to support int and float versions with the same code. */
// This file is #included twice to support int and float versions with the same code.
SDL_bool SDL_HASINTERSECTION(const RECTTYPE *A, const RECTTYPE *B)
static bool SDL_RECT_CAN_OVERFLOW(const RECTTYPE *rect)
{
if (rect->x <= (SCALARTYPE)(SDL_MIN_SINT32 / 2) ||
rect->x >= (SCALARTYPE)(SDL_MAX_SINT32 / 2) ||
rect->y <= (SCALARTYPE)(SDL_MIN_SINT32 / 2) ||
rect->y >= (SCALARTYPE)(SDL_MAX_SINT32 / 2) ||
rect->w >= (SCALARTYPE)(SDL_MAX_SINT32 / 2) ||
rect->h >= (SCALARTYPE)(SDL_MAX_SINT32 / 2)) {
return true;
}
return false;
}
bool SDL_HASINTERSECTION(const RECTTYPE *A, const RECTTYPE *B)
{
SCALARTYPE Amin, Amax, Bmin, Bmax;
if (!A) {
SDL_InvalidParamError("A");
return SDL_FALSE;
return false;
} else if (!B) {
SDL_InvalidParamError("B");
return SDL_FALSE;
return false;
} else if (SDL_RECT_CAN_OVERFLOW(A) ||
SDL_RECT_CAN_OVERFLOW(B)) {
SDL_SetError("Potential rect math overflow");
return false;
} else if (SDL_RECTEMPTY(A) || SDL_RECTEMPTY(B)) {
return SDL_FALSE; /* Special cases for empty rects */
return false; // Special cases for empty rects
}
/* Horizontal intersection */
// Horizontal intersection
Amin = A->x;
Amax = Amin + A->w;
Bmin = B->x;
@@ -46,10 +63,10 @@ SDL_bool SDL_HASINTERSECTION(const RECTTYPE *A, const RECTTYPE *B)
if (Bmax < Amax) {
Amax = Bmax;
}
if (Amax <= Amin) {
return SDL_FALSE;
if ((Amax - ENCLOSEPOINTS_EPSILON) < Amin) {
return false;
}
/* Vertical intersection */
// Vertical intersection
Amin = A->y;
Amax = Amin + A->h;
Bmin = B->y;
@@ -60,32 +77,36 @@ SDL_bool SDL_HASINTERSECTION(const RECTTYPE *A, const RECTTYPE *B)
if (Bmax < Amax) {
Amax = Bmax;
}
if (Amax <= Amin) {
return SDL_FALSE;
if ((Amax - ENCLOSEPOINTS_EPSILON) < Amin) {
return false;
}
return SDL_TRUE;
return true;
}
SDL_bool SDL_INTERSECTRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result)
bool SDL_INTERSECTRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result)
{
SCALARTYPE Amin, Amax, Bmin, Bmax;
if (!A) {
SDL_InvalidParamError("A");
return SDL_FALSE;
return false;
} else if (!B) {
SDL_InvalidParamError("B");
return SDL_FALSE;
return false;
} else if (SDL_RECT_CAN_OVERFLOW(A) ||
SDL_RECT_CAN_OVERFLOW(B)) {
SDL_SetError("Potential rect math overflow");
return false;
} else if (!result) {
SDL_InvalidParamError("result");
return SDL_FALSE;
} else if (SDL_RECTEMPTY(A) || SDL_RECTEMPTY(B)) { /* Special cases for empty rects */
return false;
} else if (SDL_RECTEMPTY(A) || SDL_RECTEMPTY(B)) { // Special cases for empty rects
result->w = 0;
result->h = 0;
return SDL_FALSE;
return false;
}
/* Horizontal intersection */
// Horizontal intersection
Amin = A->x;
Amax = Amin + A->w;
Bmin = B->x;
@@ -99,7 +120,7 @@ SDL_bool SDL_INTERSECTRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *resul
}
result->w = Amax - Amin;
/* Vertical intersection */
// Vertical intersection
Amin = A->y;
Amax = Amin + A->h;
Bmin = B->y;
@@ -116,7 +137,7 @@ SDL_bool SDL_INTERSECTRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *resul
return !SDL_RECTEMPTY(result);
}
int SDL_UNIONRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result)
bool SDL_UNIONRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result)
{
SCALARTYPE Amin, Amax, Bmin, Bmax;
@@ -124,21 +145,24 @@ int SDL_UNIONRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result)
return SDL_InvalidParamError("A");
} else if (!B) {
return SDL_InvalidParamError("B");
} else if (SDL_RECT_CAN_OVERFLOW(A) ||
SDL_RECT_CAN_OVERFLOW(B)) {
return SDL_SetError("Potential rect math overflow");
} else if (!result) {
return SDL_InvalidParamError("result");
} else if (SDL_RECTEMPTY(A)) { /* Special cases for empty Rects */
if (SDL_RECTEMPTY(B)) { /* A and B empty */
} else if (SDL_RECTEMPTY(A)) { // Special cases for empty Rects
if (SDL_RECTEMPTY(B)) { // A and B empty
SDL_zerop(result);
} else { /* A empty, B not empty */
} else { // A empty, B not empty
*result = *B;
}
return 0;
} else if (SDL_RECTEMPTY(B)) { /* A not empty, B empty */
return true;
} else if (SDL_RECTEMPTY(B)) { // A not empty, B empty
*result = *A;
return 0;
return true;
}
/* Horizontal union */
// Horizontal union
Amin = A->x;
Amax = Amin + A->w;
Bmin = B->x;
@@ -152,7 +176,7 @@ int SDL_UNIONRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result)
}
result->w = Amax - Amin;
/* Vertical union */
// Vertical union
Amin = A->y;
Amax = Amin + A->h;
Bmin = B->y;
@@ -165,11 +189,10 @@ int SDL_UNIONRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result)
Amax = Bmax;
}
result->h = Amax - Amin;
return 0;
return true;
}
SDL_bool SDL_ENCLOSEPOINTS(const POINTTYPE *points, int count, const RECTTYPE *clip,
RECTTYPE *result)
bool SDL_ENCLOSEPOINTS(const POINTTYPE *points, int count, const RECTTYPE *clip, RECTTYPE *result)
{
SCALARTYPE minx = 0;
SCALARTYPE miny = 0;
@@ -180,22 +203,22 @@ SDL_bool SDL_ENCLOSEPOINTS(const POINTTYPE *points, int count, const RECTTYPE *c
if (!points) {
SDL_InvalidParamError("points");
return SDL_FALSE;
return false;
} else if (count < 1) {
SDL_InvalidParamError("count");
return SDL_FALSE;
return false;
}
if (clip) {
SDL_bool added = SDL_FALSE;
bool added = false;
const SCALARTYPE clip_minx = clip->x;
const SCALARTYPE clip_miny = clip->y;
const SCALARTYPE clip_maxx = clip->x + clip->w - 1;
const SCALARTYPE clip_maxy = clip->y + clip->h - 1;
const SCALARTYPE clip_maxx = clip->x + clip->w - ENCLOSEPOINTS_EPSILON;
const SCALARTYPE clip_maxy = clip->y + clip->h - ENCLOSEPOINTS_EPSILON;
/* Special case for empty rectangle */
// Special case for empty rectangle
if (SDL_RECTEMPTY(clip)) {
return SDL_FALSE;
return false;
}
for (i = 0; i < count; ++i) {
@@ -207,15 +230,15 @@ SDL_bool SDL_ENCLOSEPOINTS(const POINTTYPE *points, int count, const RECTTYPE *c
continue;
}
if (!added) {
/* Special case: if no result was requested, we are done */
// Special case: if no result was requested, we are done
if (!result) {
return SDL_TRUE;
return true;
}
/* First point added */
// First point added
minx = maxx = x;
miny = maxy = y;
added = SDL_TRUE;
added = true;
continue;
}
if (x < minx) {
@@ -230,15 +253,15 @@ SDL_bool SDL_ENCLOSEPOINTS(const POINTTYPE *points, int count, const RECTTYPE *c
}
}
if (!added) {
return SDL_FALSE;
return false;
}
} else {
/* Special case: if no result was requested, we are done */
// Special case: if no result was requested, we are done
if (!result) {
return SDL_TRUE;
return true;
}
/* No clipping, always add the first point */
// No clipping, always add the first point
minx = maxx = points[0].x;
miny = maxy = points[0].y;
@@ -262,13 +285,13 @@ SDL_bool SDL_ENCLOSEPOINTS(const POINTTYPE *points, int count, const RECTTYPE *c
if (result) {
result->x = minx;
result->y = miny;
result->w = (maxx - minx) + 1;
result->h = (maxy - miny) + 1;
result->w = (maxx - minx) + ENCLOSEPOINTS_EPSILON;
result->h = (maxy - miny) + ENCLOSEPOINTS_EPSILON;
}
return SDL_TRUE;
return true;
}
/* Use the Cohen-Sutherland algorithm for line clipping */
// Use the Cohen-Sutherland algorithm for line clipping
static int COMPUTEOUTCODE(const RECTTYPE *rect, SCALARTYPE x, SCALARTYPE y)
{
int code = 0;
@@ -285,7 +308,7 @@ static int COMPUTEOUTCODE(const RECTTYPE *rect, SCALARTYPE x, SCALARTYPE y)
return code;
}
SDL_bool SDL_INTERSECTRECTANDLINE(const RECTTYPE *rect, SCALARTYPE *X1, SCALARTYPE *Y1, SCALARTYPE *X2, SCALARTYPE *Y2)
bool SDL_INTERSECTRECTANDLINE(const RECTTYPE *rect, SCALARTYPE *X1, SCALARTYPE *Y1, SCALARTYPE *X2, SCALARTYPE *Y2)
{
SCALARTYPE x = 0;
SCALARTYPE y = 0;
@@ -299,21 +322,24 @@ SDL_bool SDL_INTERSECTRECTANDLINE(const RECTTYPE *rect, SCALARTYPE *X1, SCALARTY
if (!rect) {
SDL_InvalidParamError("rect");
return SDL_FALSE;
return false;
} else if (SDL_RECT_CAN_OVERFLOW(rect)) {
SDL_SetError("Potential rect math overflow");
return false;
} else if (!X1) {
SDL_InvalidParamError("X1");
return SDL_FALSE;
return false;
} else if (!Y1) {
SDL_InvalidParamError("Y1");
return SDL_FALSE;
return false;
} else if (!X2) {
SDL_InvalidParamError("X2");
return SDL_FALSE;
return false;
} else if (!Y2) {
SDL_InvalidParamError("Y2");
return SDL_FALSE;
return false;
} else if (SDL_RECTEMPTY(rect)) {
return SDL_FALSE; /* Special case for empty rect */
return false; // Special case for empty rect
}
x1 = *X1;
@@ -322,22 +348,22 @@ SDL_bool SDL_INTERSECTRECTANDLINE(const RECTTYPE *rect, SCALARTYPE *X1, SCALARTY
y2 = *Y2;
rectx1 = rect->x;
recty1 = rect->y;
rectx2 = rect->x + rect->w - 1;
recty2 = rect->y + rect->h - 1;
rectx2 = rect->x + rect->w - ENCLOSEPOINTS_EPSILON;
recty2 = rect->y + rect->h - ENCLOSEPOINTS_EPSILON;
/* Check to see if entire line is inside rect */
// Check to see if entire line is inside rect
if (x1 >= rectx1 && x1 <= rectx2 && x2 >= rectx1 && x2 <= rectx2 &&
y1 >= recty1 && y1 <= recty2 && y2 >= recty1 && y2 <= recty2) {
return SDL_TRUE;
return true;
}
/* Check to see if entire line is to one side of rect */
// Check to see if entire line is to one side of rect
if ((x1 < rectx1 && x2 < rectx1) || (x1 > rectx2 && x2 > rectx2) ||
(y1 < recty1 && y2 < recty1) || (y1 > recty2 && y2 > recty2)) {
return SDL_FALSE;
return false;
}
if (y1 == y2) { /* Horizontal line, easy to clip */
if (y1 == y2) { // Horizontal line, easy to clip
if (x1 < rectx1) {
*X1 = rectx1;
} else if (x1 > rectx2) {
@@ -348,10 +374,10 @@ SDL_bool SDL_INTERSECTRECTANDLINE(const RECTTYPE *rect, SCALARTYPE *X1, SCALARTY
} else if (x2 > rectx2) {
*X2 = rectx2;
}
return SDL_TRUE;
return true;
}
if (x1 == x2) { /* Vertical line, easy to clip */
if (x1 == x2) { // Vertical line, easy to clip
if (y1 < recty1) {
*Y1 = recty1;
} else if (y1 > recty2) {
@@ -362,15 +388,15 @@ SDL_bool SDL_INTERSECTRECTANDLINE(const RECTTYPE *rect, SCALARTYPE *X1, SCALARTY
} else if (y2 > recty2) {
*Y2 = recty2;
}
return SDL_TRUE;
return true;
}
/* More complicated Cohen-Sutherland algorithm */
// More complicated Cohen-Sutherland algorithm
outcode1 = COMPUTEOUTCODE(rect, x1, y1);
outcode2 = COMPUTEOUTCODE(rect, x2, y2);
while (outcode1 || outcode2) {
if (outcode1 & outcode2) {
return SDL_FALSE;
return false;
}
if (outcode1) {
@@ -392,23 +418,23 @@ SDL_bool SDL_INTERSECTRECTANDLINE(const RECTTYPE *rect, SCALARTYPE *X1, SCALARTY
outcode1 = COMPUTEOUTCODE(rect, x, y);
} else {
if (outcode2 & CODE_TOP) {
SDL_assert(y2 != y1); /* if equal: division by zero. */
SDL_assert(y2 != y1); // if equal: division by zero.
y = recty1;
x = (SCALARTYPE) (x1 + ((BIGSCALARTYPE)(x2 - x1) * (y - y1)) / (y2 - y1));
} else if (outcode2 & CODE_BOTTOM) {
SDL_assert(y2 != y1); /* if equal: division by zero. */
SDL_assert(y2 != y1); // if equal: division by zero.
y = recty2;
x = (SCALARTYPE) (x1 + ((BIGSCALARTYPE)(x2 - x1) * (y - y1)) / (y2 - y1));
} else if (outcode2 & CODE_LEFT) {
/* If this assertion ever fires, here's the static analysis that warned about it:
http://buildbot.libsdl.org/sdl-static-analysis/sdl-macosx-static-analysis/sdl-macosx-static-analysis-1101/report-b0d01a.html#EndPath */
SDL_assert(x2 != x1); /* if equal: division by zero. */
SDL_assert(x2 != x1); // if equal: division by zero.
x = rectx1;
y = (SCALARTYPE) (y1 + ((BIGSCALARTYPE)(y2 - y1) * (x - x1)) / (x2 - x1));
} else if (outcode2 & CODE_RIGHT) {
/* If this assertion ever fires, here's the static analysis that warned about it:
http://buildbot.libsdl.org/sdl-static-analysis/sdl-macosx-static-analysis/sdl-macosx-static-analysis-1101/report-39b114.html#EndPath */
SDL_assert(x2 != x1); /* if equal: division by zero. */
SDL_assert(x2 != x1); // if equal: division by zero.
x = rectx2;
y = (SCALARTYPE) (y1 + ((BIGSCALARTYPE)(y2 - y1) * (x - x1)) / (x2 - x1));
}
@@ -421,7 +447,7 @@ SDL_bool SDL_INTERSECTRECTANDLINE(const RECTTYPE *rect, SCALARTYPE *X1, SCALARTY
*Y1 = y1;
*X2 = x2;
*Y2 = y2;
return SDL_TRUE;
return true;
}
#undef RECTTYPE
@@ -429,6 +455,8 @@ SDL_bool SDL_INTERSECTRECTANDLINE(const RECTTYPE *rect, SCALARTYPE *X1, SCALARTY
#undef SCALARTYPE
#undef BIGSCALARTYPE
#undef COMPUTEOUTCODE
#undef ENCLOSEPOINTS_EPSILON
#undef SDL_RECT_CAN_OVERFLOW
#undef SDL_HASINTERSECTION
#undef SDL_INTERSECTRECT
#undef SDL_RECTEMPTY