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/or Y2 as necessary ✨

like it's giving "we trimmed your line, you're welcome" πŸ’…


πŸ‘‘ FUNCTION PARAMETERS πŸ‘‘

  • rect β€” an SDL_FRect structure 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