SDL_GETRECTANDLINEINTERSECTION(3)

✨ NAME ✨

SDL_GetRectAndLineIntersection β€” bestie, this one calculates the intersection of a rectangle and a line segment πŸ’– (it lives in the SDL3 FUNCTIONS manual, iykyk)


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_rect.h>

bool SDL_GetRectAndLineIntersection(const SDL_Rect *rect, int *X1, int *Y1, int *X2, int *Y2);

πŸŽ€ DESCRIPTION πŸŽ€

okay so picture this: you have a line segment and you have a rectangle, and you need to know where they overlap. That's literally what this function does β€” it's used to clip a line segment to a rectangle. Slay. ✨

Here's the vibe check on the possible outcomes:

  • A line segment that's contained entirely within the rectangle β†’ stays unchanged. No touchy.
  • A line segment that does not intersect β†’ also stays unchanged. She's unbothered.
  • A line segment that crosses the rectangle at either or both ends β†’ gets clipped to the boundary of the rectangle, and the new coordinates get saved into X1, Y1, X2, and/or Y2 as necessary. πŸ‘‘

Like the way that the endpoints just get rewritten in place? iconic behavior tbh.


πŸ¦‹ FUNCTION PARAMETERS πŸ¦‹

  • rect β€” an SDL_Rect structure representing the rectangle to intersect. This is the box, bestie. πŸ“¦
  • 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, no cap. 🫢


🌈 THREAD SAFETY 🌈

It is safe to call this function from any thread. Every thread gets to eat. periodt. πŸ’œ


⭐ AVAILABILITY ⭐

This function is available since SDL 3.2.0. If you're on something older, that's a no from her. πŸ™ˆ


Simple Directmedia Layer β€” SDL 3.4.18 β€” SDL_GetRectAn...eIntersection(3)

k bye bestie, go clip some lines πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…

πŸ“¦ where this page comes from