SDL_GetRectA...rsectionFloat(3)
π SDL_GetRectAndLineIntersectionFloat π
okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, this one's a banger π
β¨ NAME β¨
SDL_GetRectAndLineIntersectionFloat β figure out where a rectangle and a line segment actually cross, but make it float precision π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_rect.h>
bool SDL_GetRectAndLineIntersectionFloat(const SDL_FRect *rect, float *X1, float *Y1, float *X2, float *Y2);
π¦ DESCRIPTION π¦
so the whole vibe here is clipping a line segment to a rectangle. that's it, that's the job π«Ά
here's the tea tho, three possible outcomes and they're all lowkey different:
- a line segment that's fully inside the rectangle? untouched. unchanged. no notes. π
- a line segment that doesn't intersect at all? also just chillin', stays exactly how it was π
- a line segment that crosses the rectangle at either or both ends? that one gets clipped to the boundary of the rectangle, and the new coordinates get saved into
X1,Y1,X2, and/orY2as necessary β¨
like it's giving "we trimmed your line, you're welcome" π
π FUNCTION PARAMETERS π
rectβ anSDL_FRectstructure representing the rectangle you wanna intersect with. this is the rectangle in question, the main character of the rect situation πX1β a pointer to the starting X-coordinate of the line πY1β a pointer to the starting Y-coordinate of the line πX2β a pointer to the ending X-coordinate of the line πY2β a pointer to the ending Y-coordinate of the line π
π RETURN VALUE π
returns true if there is an intersection, false otherwise. simple as that fr fr π
π§ THREAD SAFETY π§
it is safe to call this function from any thread. go off, multithreaded icon π
β AVAILABILITY β
this function is available since SDL 3.2.0 π
not me writing a whole manpage and it's literally just "clip line to rect" π anyway slay
okay that's the whole page bestie, thanks for reading, mwah πβ¨πΈπ¦ππ π«Ά
β with love from the Simple Directmedia Layer girlies, SDL 3.4.18 era, SDL_GetRectAndLineIntersectionFloat(3), signing off πππ
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms