mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-15 14:26:01 +00:00
Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base. In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted. The script I ran for the src directory is added as build-scripts/clang-format-src.sh This fixes: #6592 #6593 #6594
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
/* 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)
|
||||
SDL_HASINTERSECTION(const RECTTYPE *A, const RECTTYPE *B)
|
||||
{
|
||||
SCALARTYPE Amin, Amax, Bmin, Bmax;
|
||||
|
||||
@@ -33,7 +33,7 @@ SDL_HASINTERSECTION(const RECTTYPE * A, const RECTTYPE * B)
|
||||
SDL_InvalidParamError("B");
|
||||
return SDL_FALSE;
|
||||
} else if (SDL_RECTEMPTY(A) || SDL_RECTEMPTY(B)) {
|
||||
return SDL_FALSE; /* Special cases for empty rects */
|
||||
return SDL_FALSE; /* Special cases for empty rects */
|
||||
}
|
||||
|
||||
/* Horizontal intersection */
|
||||
@@ -68,7 +68,7 @@ SDL_HASINTERSECTION(const RECTTYPE * A, const RECTTYPE * B)
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
SDL_INTERSECTRECT(const RECTTYPE * A, const RECTTYPE * B, RECTTYPE * result)
|
||||
SDL_INTERSECTRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result)
|
||||
{
|
||||
SCALARTYPE Amin, Amax, Bmin, Bmax;
|
||||
|
||||
@@ -81,7 +81,7 @@ SDL_INTERSECTRECT(const RECTTYPE * A, const RECTTYPE * B, RECTTYPE * result)
|
||||
} else if (result == NULL) {
|
||||
SDL_InvalidParamError("result");
|
||||
return SDL_FALSE;
|
||||
} else if (SDL_RECTEMPTY(A) || SDL_RECTEMPTY(B)) { /* Special cases for empty rects */
|
||||
} else if (SDL_RECTEMPTY(A) || SDL_RECTEMPTY(B)) { /* Special cases for empty rects */
|
||||
result->w = 0;
|
||||
result->h = 0;
|
||||
return SDL_FALSE;
|
||||
@@ -118,8 +118,7 @@ SDL_INTERSECTRECT(const RECTTYPE * A, const RECTTYPE * B, RECTTYPE * result)
|
||||
return !SDL_RECTEMPTY(result);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_UNIONRECT(const RECTTYPE * A, const RECTTYPE * B, RECTTYPE * result)
|
||||
void SDL_UNIONRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result)
|
||||
{
|
||||
SCALARTYPE Amin, Amax, Bmin, Bmax;
|
||||
|
||||
@@ -132,16 +131,16 @@ SDL_UNIONRECT(const RECTTYPE * A, const RECTTYPE * B, RECTTYPE * result)
|
||||
} else if (result == NULL) {
|
||||
SDL_InvalidParamError("result");
|
||||
return;
|
||||
} 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;
|
||||
} else if (SDL_RECTEMPTY(B)) { /* A not empty, B empty */
|
||||
*result = *A;
|
||||
return;
|
||||
} else if (SDL_RECTEMPTY(B)) { /* A not empty, B empty */
|
||||
*result = *A;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Horizontal union */
|
||||
@@ -173,8 +172,8 @@ SDL_UNIONRECT(const RECTTYPE * A, const RECTTYPE * B, RECTTYPE * result)
|
||||
result->h = Amax - Amin;
|
||||
}
|
||||
|
||||
SDL_bool SDL_ENCLOSEPOINTS(const POINTTYPE * points, int count, const RECTTYPE * clip,
|
||||
RECTTYPE * result)
|
||||
SDL_bool SDL_ENCLOSEPOINTS(const POINTTYPE *points, int count, const RECTTYPE *clip,
|
||||
RECTTYPE *result)
|
||||
{
|
||||
SCALARTYPE minx = 0;
|
||||
SCALARTYPE miny = 0;
|
||||
@@ -195,8 +194,8 @@ SDL_bool SDL_ENCLOSEPOINTS(const POINTTYPE * points, int count, const RECTTYPE *
|
||||
SDL_bool added = SDL_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 - 1;
|
||||
const SCALARTYPE clip_maxy = clip->y + clip->h - 1;
|
||||
|
||||
/* Special case for empty rectangle */
|
||||
if (SDL_RECTEMPTY(clip)) {
|
||||
@@ -267,15 +266,14 @@ SDL_bool SDL_ENCLOSEPOINTS(const POINTTYPE * points, int count, const RECTTYPE *
|
||||
if (result) {
|
||||
result->x = minx;
|
||||
result->y = miny;
|
||||
result->w = (maxx-minx)+1;
|
||||
result->h = (maxy-miny)+1;
|
||||
result->w = (maxx - minx) + 1;
|
||||
result->h = (maxy - miny) + 1;
|
||||
}
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
/* Use the Cohen-Sutherland algorithm for line clipping */
|
||||
static int
|
||||
COMPUTEOUTCODE(const RECTTYPE * rect, SCALARTYPE x, SCALARTYPE y)
|
||||
static int COMPUTEOUTCODE(const RECTTYPE *rect, SCALARTYPE x, SCALARTYPE y)
|
||||
{
|
||||
int code = 0;
|
||||
if (y < rect->y) {
|
||||
@@ -292,7 +290,7 @@ COMPUTEOUTCODE(const RECTTYPE * rect, SCALARTYPE x, SCALARTYPE y)
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
SDL_INTERSECTRECTANDLINE(const RECTTYPE * rect, SCALARTYPE *X1, SCALARTYPE *Y1, SCALARTYPE *X2,
|
||||
SDL_INTERSECTRECTANDLINE(const RECTTYPE *rect, SCALARTYPE *X1, SCALARTYPE *Y1, SCALARTYPE *X2,
|
||||
SCALARTYPE *Y2)
|
||||
{
|
||||
SCALARTYPE x = 0;
|
||||
@@ -321,7 +319,7 @@ SDL_INTERSECTRECTANDLINE(const RECTTYPE * rect, SCALARTYPE *X1, SCALARTYPE *Y1,
|
||||
SDL_InvalidParamError("Y2");
|
||||
return SDL_FALSE;
|
||||
} else if (SDL_RECTEMPTY(rect)) {
|
||||
return SDL_FALSE; /* Special case for empty rect */
|
||||
return SDL_FALSE; /* Special case for empty rect */
|
||||
}
|
||||
|
||||
x1 = *X1;
|
||||
@@ -345,7 +343,7 @@ SDL_INTERSECTRECTANDLINE(const RECTTYPE * rect, SCALARTYPE *X1, SCALARTYPE *Y1,
|
||||
return SDL_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) {
|
||||
@@ -359,7 +357,7 @@ SDL_INTERSECTRECTANDLINE(const RECTTYPE * rect, SCALARTYPE *X1, SCALARTYPE *Y1,
|
||||
return SDL_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) {
|
||||
@@ -400,23 +398,23 @@ SDL_INTERSECTRECTANDLINE(const RECTTYPE * rect, SCALARTYPE *X1, SCALARTYPE *Y1,
|
||||
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 = x1 + ((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 = x1 + ((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 = y1 + ((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 = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user