SDL 3.0
|
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_begin_code.h>
#include <SDL3/SDL_close_code.h>
Go to the source code of this file.
Data Structures | |
struct | SDL_Point |
struct | SDL_FPoint |
struct | SDL_Rect |
struct | SDL_FRect |
bool SDL_GetRectAndLineIntersection | ( | const SDL_Rect * | rect, |
int * | X1, | ||
int * | Y1, | ||
int * | X2, | ||
int * | Y2 | ||
) |
Calculate the intersection of a rectangle and line segment.
This function is used to clip a line segment to a rectangle. A line segment contained entirely within the rectangle or that does not intersect will remain unchanged. A line segment that crosses the rectangle at either or both ends will be clipped to the boundary of the rectangle and the new coordinates saved in X1
, Y1
, X2
, and/or Y2
as necessary.
rect | an SDL_Rect structure representing the rectangle to intersect. |
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. |
bool SDL_GetRectAndLineIntersectionFloat | ( | const SDL_FRect * | rect, |
float * | X1, | ||
float * | Y1, | ||
float * | X2, | ||
float * | Y2 | ||
) |
Calculate the intersection of a rectangle and line segment with float precision.
This function is used to clip a line segment to a rectangle. A line segment contained entirely within the rectangle or that does not intersect will remain unchanged. A line segment that crosses the rectangle at either or both ends will be clipped to the boundary of the rectangle and the new coordinates saved in X1
, Y1
, X2
, and/or Y2
as necessary.
rect | an SDL_FRect structure representing the rectangle to intersect. |
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. |
bool SDL_GetRectEnclosingPoints | ( | const SDL_Point * | points, |
int | count, | ||
const SDL_Rect * | clip, | ||
SDL_Rect * | result | ||
) |
Calculate a minimal rectangle enclosing a set of points.
If clip
is not NULL then only points inside of the clipping rectangle are considered.
points | an array of SDL_Point structures representing points to be enclosed. |
count | the number of structures in the points array. |
clip | an SDL_Rect used for clipping or NULL to enclose all points. |
result | an SDL_Rect structure filled in with the minimal enclosing rectangle. |
bool SDL_GetRectEnclosingPointsFloat | ( | const SDL_FPoint * | points, |
int | count, | ||
const SDL_FRect * | clip, | ||
SDL_FRect * | result | ||
) |
Calculate a minimal rectangle enclosing a set of points with float precision.
If clip
is not NULL then only points inside of the clipping rectangle are considered.
points | an array of SDL_FPoint structures representing points to be enclosed. |
count | the number of structures in the points array. |
clip | an SDL_FRect used for clipping or NULL to enclose all points. |
result | an SDL_FRect structure filled in with the minimal enclosing rectangle. |
Calculate the intersection of two rectangles.
If result
is NULL then this function will return false.
A | an SDL_Rect structure representing the first rectangle. |
B | an SDL_Rect structure representing the second rectangle. |
result | an SDL_Rect structure filled in with the intersection of rectangles A and B . |
Calculate the intersection of two rectangles with float precision.
If result
is NULL then this function will return false.
A | an SDL_FRect structure representing the first rectangle. |
B | an SDL_FRect structure representing the second rectangle. |
result | an SDL_FRect structure filled in with the intersection of rectangles A and B . |
Calculate the union of two rectangles.
A | an SDL_Rect structure representing the first rectangle. |
B | an SDL_Rect structure representing the second rectangle. |
result | an SDL_Rect structure filled in with the union of rectangles A and B . |
Calculate the union of two rectangles with float precision.
A | an SDL_FRect structure representing the first rectangle. |
B | an SDL_FRect structure representing the second rectangle. |
result | an SDL_FRect structure filled in with the union of rectangles A and B . |
Determine whether two rectangles intersect.
If either pointer is NULL the function will return false.
A | an SDL_Rect structure representing the first rectangle. |
B | an SDL_Rect structure representing the second rectangle. |
\threadsafety It is safe to call this function from any thread.
Determine whether two rectangles intersect with float precision.
If either pointer is NULL the function will return false.
A | an SDL_FRect structure representing the first rectangle. |
B | an SDL_FRect structure representing the second rectangle. |
SDL_FORCE_INLINE bool SDL_PointInRect | ( | const SDL_Point * | p, |
const SDL_Rect * | r | ||
) |
Determine whether a point resides inside a rectangle.
A point is considered part of a rectangle if both p
and r
are not NULL, and p
's x and y coordinates are >= to the rectangle's top left corner, and < the rectangle's x+w and y+h. So a 1x1 rectangle considers point (0,0) as "inside" and (0,1) as not.
Note that this is a forced-inline function in a header, and not a public API function available in the SDL library (which is to say, the code is embedded in the calling program and the linker and dynamic loader will not be able to find this function inside SDL itself).
p | the point to test. |
r | the rectangle to test. |
p
is contained by r
, false otherwise.\threadsafety It is safe to call this function from any thread.
Definition at line 155 of file SDL_rect.h.
References SDL_Rect::h, true, SDL_Rect::w, SDL_Point::x, SDL_Rect::x, SDL_Point::y, and SDL_Rect::y.
SDL_FORCE_INLINE bool SDL_PointInRectFloat | ( | const SDL_FPoint * | p, |
const SDL_FRect * | r | ||
) |
Determine whether a point resides inside a floating point rectangle.
A point is considered part of a rectangle if both p
and r
are not NULL, and p
's x and y coordinates are >= to the rectangle's top left corner, and <= the rectangle's x+w and y+h. So a 1x1 rectangle considers point (0,0) and (0,1) as "inside" and (0,2) as not.
Note that this is a forced-inline function in a header, and not a public API function available in the SDL library (which is to say, the code is embedded in the calling program and the linker and dynamic loader will not be able to find this function inside SDL itself).
p | the point to test. |
r | the rectangle to test. |
p
is contained by r
, false otherwise.\threadsafety It is safe to call this function from any thread.
Definition at line 320 of file SDL_rect.h.
References SDL_FRect::h, true, SDL_FRect::w, SDL_FPoint::x, SDL_FRect::x, SDL_FPoint::y, and SDL_FRect::y.
SDL_FORCE_INLINE bool SDL_RectEmpty | ( | const SDL_Rect * | r | ) |
Determine whether a rectangle has no area.
A rectangle is considered "empty" for this function if r
is NULL, or if r
's width and/or height are <= 0.
Note that this is a forced-inline function in a header, and not a public API function available in the SDL library (which is to say, the code is embedded in the calling program and the linker and dynamic loader will not be able to find this function inside SDL itself).
r | the rectangle to test. |
\threadsafety It is safe to call this function from any thread.
Definition at line 179 of file SDL_rect.h.
References SDL_Rect::h, true, and SDL_Rect::w.
SDL_FORCE_INLINE bool SDL_RectEmptyFloat | ( | const SDL_FRect * | r | ) |
Determine whether a floating point rectangle can contain any point.
A rectangle is considered "empty" for this function if r
is NULL, or if r
's width and/or height are < 0.0f.
Note that this is a forced-inline function in a header, and not a public API function available in the SDL library (which is to say, the code is embedded in the calling program and the linker and dynamic loader will not be able to find this function inside SDL itself).
r | the rectangle to test. |
\threadsafety It is safe to call this function from any thread.
Definition at line 344 of file SDL_rect.h.
References SDL_FRect::h, true, and SDL_FRect::w.
SDL_FORCE_INLINE bool SDL_RectsEqual | ( | const SDL_Rect * | a, |
const SDL_Rect * | b | ||
) |
Determine whether two rectangles are equal.
Rectangles are considered equal if both are not NULL and each of their x, y, width and height match.
Note that this is a forced-inline function in a header, and not a public API function available in the SDL library (which is to say, the code is embedded in the calling program and the linker and dynamic loader will not be able to find this function inside SDL itself).
a | the first rectangle to test. |
b | the second rectangle to test. |
\threadsafety It is safe to call this function from any thread.
Definition at line 203 of file SDL_rect.h.
References SDL_Rect::h, true, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.
SDL_FORCE_INLINE bool SDL_RectsEqualEpsilon | ( | const SDL_FRect * | a, |
const SDL_FRect * | b, | ||
const float | epsilon | ||
) |
Determine whether two floating point rectangles are equal, within some given epsilon.
Rectangles are considered equal if both are not NULL and each of their x, y, width and height are within epsilon
of each other. If you don't know what value to use for epsilon
, you should call the SDL_RectsEqualFloat function instead.
Note that this is a forced-inline function in a header, and not a public API function available in the SDL library (which is to say, the code is embedded in the calling program and the linker and dynamic loader will not be able to find this function inside SDL itself).
a | the first rectangle to test. |
b | the second rectangle to test. |
epsilon | the epsilon value for comparison. |
\threadsafety It is safe to call this function from any thread.
Definition at line 374 of file SDL_rect.h.
References SDL_FRect::h, SDL_fabsf(), true, SDL_FRect::w, SDL_FRect::x, and SDL_FRect::y.
Referenced by SDL_RectsEqualFloat().
SDL_FORCE_INLINE bool SDL_RectsEqualFloat | ( | const SDL_FRect * | a, |
const SDL_FRect * | b | ||
) |
Determine whether two floating point rectangles are equal, within a default epsilon.
Rectangles are considered equal if both are not NULL and each of their x, y, width and height are within SDL_FLT_EPSILON of each other. This is often a reasonable way to compare two floating point rectangles and deal with the slight precision variations in floating point calculations that tend to pop up.
Note that this is a forced-inline function in a header, and not a public API function available in the SDL library (which is to say, the code is embedded in the calling program and the linker and dynamic loader will not be able to find this function inside SDL itself).
a | the first rectangle to test. |
b | the second rectangle to test. |
\threadsafety It is safe to call this function from any thread.
Definition at line 409 of file SDL_rect.h.
References SDL_FLT_EPSILON, and SDL_RectsEqualEpsilon().
SDL_FORCE_INLINE void SDL_RectToFRect | ( | const SDL_Rect * | rect, |
SDL_FRect * | frect | ||
) |
Convert an SDL_Rect to SDL_FRect
rect | a pointer to an SDL_Rect. |
frect | a pointer filled in with the floating point representation of rect . |
\threadsafety It is safe to call this function from any thread.
Definition at line 126 of file SDL_rect.h.
References SDL_Rect::h, SDL_FRect::h, SDL_Rect::w, SDL_FRect::w, SDL_Rect::x, SDL_FRect::x, SDL_Rect::y, and SDL_FRect::y.