SDL_rect.h File Reference
`#include "SDL_stdinc.h"`
`#include "SDL_error.h"`
`#include "SDL_pixels.h"`
`#include "SDL_rwops.h"`
`#include "begin_code.h"`
`#include "close_code.h"`
Include dependency graph for SDL_rect.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures

struct | SDL_Point
struct | SDL_FPoint
struct | SDL_Rect
struct | SDL_FRect

## Functions

SDL_FORCE_INLINE SDL_bool | SDL_PointInRect (const SDL_Point *p, const SDL_Rect *r)
SDL_FORCE_INLINE SDL_bool | SDL_RectEmpty (const SDL_Rect *r)
SDL_FORCE_INLINE SDL_bool | SDL_RectEquals (const SDL_Rect *a, const SDL_Rect *b)
SDL_bool | SDL_HasIntersection (const SDL_Rect *A, const SDL_Rect *B)
SDL_bool | SDL_IntersectRect (const SDL_Rect *A, const SDL_Rect *B, SDL_Rect *result)
void | SDL_UnionRect (const SDL_Rect *A, const SDL_Rect *B, SDL_Rect *result)
SDL_bool | SDL_EnclosePoints (const SDL_Point *points, int count, const SDL_Rect *clip, SDL_Rect *result)
SDL_bool | SDL_IntersectRectAndLine (const SDL_Rect *rect, int *X1, int *Y1, int *X2, int *Y2)
SDL_FORCE_INLINE SDL_bool | SDL_PointInFRect (const SDL_FPoint *p, const SDL_FRect *r)
SDL_FORCE_INLINE SDL_bool | SDL_FRectEmpty (const SDL_FRect *r)
SDL_FORCE_INLINE SDL_bool | SDL_FRectEqualsEpsilon (const SDL_FRect *a, const SDL_FRect *b, const float epsilon)
SDL_FORCE_INLINE SDL_bool | SDL_FRectEquals (const SDL_FRect *a, const SDL_FRect *b)
SDL_bool | SDL_HasIntersectionF (const SDL_FRect *A, const SDL_FRect *B)
SDL_bool | SDL_IntersectFRect (const SDL_FRect *A, const SDL_FRect *B, SDL_FRect *result)
void | SDL_UnionFRect (const SDL_FRect *A, const SDL_FRect *B, SDL_FRect *result)
SDL_bool | SDL_EncloseFPoints (const SDL_FPoint *points, int count, const SDL_FRect *clip, SDL_FRect *result)
SDL_bool | SDL_IntersectFRectAndLine (const SDL_FRect *rect, float *X1, float *Y1, float *X2, float *Y2)

## Function Documentation

## SDL_EncloseFPoints()

SDL_bool SDL_EncloseFPoints | ( | const SDL_FPoint * | points,
|  | int | count,
|  | const SDL_FRect * | clip,
|  | SDL_FRect * | result )

extern

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.

Parameters

  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.

Returns
  SDL_TRUE if any points were enclosed or SDL_FALSE if all the points were outside of the clipping rectangle.

Since
  This function is available since SDL 2.0.22.

## SDL_EnclosePoints()

SDL_bool SDL_EnclosePoints | ( | const SDL_Point * | points,
|  | int | count,
|  | const SDL_Rect * | clip,
|  | SDL_Rect * | result )

extern

Calculate a minimal rectangle enclosing a set of points.

If clip is not NULL then only points inside of the clipping rectangle are considered.

Parameters

  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.

Returns
  SDL_TRUE if any points were enclosed or SDL_FALSE if all the points were outside of the clipping rectangle.

Since
  This function is available since SDL 2.0.0.

## SDL_FRectEmpty()

SDL_FORCE_INLINE SDL_bool SDL_FRectEmpty | ( | const SDL_FRect * | r | ) |

Returns true if the rectangle has no area.

Definition at line 242 of file SDL_rect.h.

{
return ((!r) || (r->w <= 0.0f) || (r->h <= 0.0f)) ? SDL_TRUE : SDL_FALSE;
}
SDL_TRUE
@ SDL_TRUE
Definition SDL_stdinc.h:189
SDL_FALSE
@ SDL_FALSE
Definition SDL_stdinc.h:188
SDL_FRect::h
float h
Definition SDL_rect.h:103
SDL_FRect::w
float w
Definition SDL_rect.h:102

References SDL_FRect::h, SDL_FALSE, SDL_FORCE_INLINE, SDL_TRUE, and SDL_FRect::w.

## SDL_FRectEquals()

SDL_FORCE_INLINE SDL_bool SDL_FRectEquals | ( | const SDL_FRect * | a,
|  | const SDL_FRect * | b )

Returns true if the two rectangles are equal, using a default epsilon.

Since
  This function is available since SDL 2.0.22.

Definition at line 267 of file SDL_rect.h.

{
return SDL_FRectEqualsEpsilon(a, b, SDL_FLT_EPSILON);
}
SDL_FRectEqualsEpsilon
SDL_FORCE_INLINE SDL_bool SDL_FRectEqualsEpsilon(const SDL_FRect *a, const SDL_FRect *b, const float epsilon)
Definition SDL_rect.h:252
SDL_FLT_EPSILON
#define SDL_FLT_EPSILON
Definition SDL_stdinc.h:260

References SDL_FLT_EPSILON, SDL_FORCE_INLINE, and SDL_FRectEqualsEpsilon().

## SDL_FRectEqualsEpsilon()

SDL_FORCE_INLINE SDL_bool SDL_FRectEqualsEpsilon | ( | const SDL_FRect * | a,
|  | const SDL_FRect * | b,
|  | const float | epsilon )

Returns true if the two rectangles are equal, within some given epsilon.

Since
  This function is available since SDL 2.0.22.

Definition at line 252 of file SDL_rect.h.

{
return (a && b && ((a == b) ||
((SDL_fabsf(a->x - b->x) <= epsilon) &&
(SDL_fabsf(a->y - b->y) <= epsilon) &&
(SDL_fabsf(a->w - b->w) <= epsilon) &&
(SDL_fabsf(a->h - b->h) <= epsilon))))
? SDL_TRUE : SDL_FALSE;
}
SDL_fabsf
float SDL_fabsf(float x)
SDL_FRect::x
float x
Definition SDL_rect.h:100
SDL_FRect::y
float y
Definition SDL_rect.h:101

References SDL_FRect::h, SDL_fabsf(), SDL_FALSE, SDL_FORCE_INLINE, SDL_TRUE, SDL_FRect::w, SDL_FRect::x, and SDL_FRect::y.

Referenced by SDL_FRectEquals().

## SDL_HasIntersection()

SDL_bool SDL_HasIntersection | ( | const SDL_Rect * | A,
|  | const SDL_Rect * | B )

extern

Determine whether two rectangles intersect.

If either pointer is NULL the function will return SDL_FALSE.

Parameters

  A | an SDL_Rect structure representing the first rectangle.
  B | an SDL_Rect structure representing the second rectangle.

Returns
  SDL_TRUE if there is an intersection, SDL_FALSE otherwise.

Since
  This function is available since SDL 2.0.0.

See also
  SDL_IntersectRect

## SDL_HasIntersectionF()

SDL_bool SDL_HasIntersectionF | ( | const SDL_FRect * | A,
|  | const SDL_FRect * | B )

extern

Determine whether two rectangles intersect with float precision.

If either pointer is NULL the function will return SDL_FALSE.

Parameters

  A | an SDL_FRect structure representing the first rectangle.
  B | an SDL_FRect structure representing the second rectangle.

Returns
  SDL_TRUE if there is an intersection, SDL_FALSE otherwise.

Since
  This function is available since SDL 2.0.22.

See also
  SDL_IntersectRect

## SDL_IntersectFRect()

SDL_bool SDL_IntersectFRect | ( | const SDL_FRect * | A,
|  | const SDL_FRect * | B,
|  | SDL_FRect * | result )

extern

Calculate the intersection of two rectangles with float precision.

If result is NULL then this function will return SDL_FALSE.

Parameters

  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.

Returns
  SDL_TRUE if there is an intersection, SDL_FALSE otherwise.

Since
  This function is available since SDL 2.0.22.

See also
  SDL_HasIntersectionF

## SDL_IntersectFRectAndLine()

SDL_bool SDL_IntersectFRectAndLine | ( | const SDL_FRect * | rect,
|  | float * | X1,
|  | float * | Y1,
|  | float * | X2,
|  | float * | Y2 )

extern

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.

Parameters

  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.

Returns
  SDL_TRUE if there is an intersection, SDL_FALSE otherwise.

Since
  This function is available since SDL 2.0.22.

## SDL_IntersectRect()

SDL_bool SDL_IntersectRect | ( | const SDL_Rect * | A,
|  | const SDL_Rect * | B,
|  | SDL_Rect * | result )

extern

Calculate the intersection of two rectangles.

If result is NULL then this function will return SDL_FALSE.

Parameters

  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.

Returns
  SDL_TRUE if there is an intersection, SDL_FALSE otherwise.

Since
  This function is available since SDL 2.0.0.

See also
  SDL_HasIntersection

## SDL_IntersectRectAndLine()

SDL_bool SDL_IntersectRectAndLine | ( | const SDL_Rect * | rect,
|  | int * | X1,
|  | int * | Y1,
|  | int * | X2,
|  | int * | Y2 )

extern

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.

Parameters

  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.

Returns
  SDL_TRUE if there is an intersection, SDL_FALSE otherwise.

Since
  This function is available since SDL 2.0.0.

## SDL_PointInFRect()

SDL_FORCE_INLINE SDL_bool SDL_PointInFRect | ( | const SDL_FPoint * | p,
|  | const SDL_FRect * | r )

Returns true if point resides inside a rectangle.

Definition at line 233 of file SDL_rect.h.

{
return ( (p->x >= r->x) && (p->x < (r->x + r->w)) &&
(p->y >= r->y) && (p->y < (r->y + r->h)) ) ? SDL_TRUE : SDL_FALSE;
}
SDL_FPoint::x
float x
Definition SDL_rect.h:62
SDL_FPoint::y
float y
Definition SDL_rect.h:63

References SDL_FRect::h, SDL_FALSE, SDL_FORCE_INLINE, SDL_TRUE, SDL_FRect::w, SDL_FPoint::x, SDL_FRect::x, SDL_FPoint::y, and SDL_FRect::y.

## SDL_PointInRect()

SDL_FORCE_INLINE SDL_bool SDL_PointInRect | ( | const SDL_Point * | p,
|  | const SDL_Rect * | r )

Returns true if point resides inside a rectangle.

Definition at line 110 of file SDL_rect.h.

{
return ( (p->x >= r->x) && (p->x < (r->x + r->w)) &&
(p->y >= r->y) && (p->y < (r->y + r->h)) ) ? SDL_TRUE : SDL_FALSE;
}
SDL_Point::x
int x
Definition SDL_rect.h:50
SDL_Point::y
int y
Definition SDL_rect.h:51
SDL_Rect::h
int h
Definition SDL_rect.h:81
SDL_Rect::w
int w
Definition SDL_rect.h:81
SDL_Rect::y
int y
Definition SDL_rect.h:80
SDL_Rect::x
int x
Definition SDL_rect.h:80

References SDL_Rect::h, SDL_FALSE, SDL_FORCE_INLINE, SDL_TRUE, SDL_Rect::w, SDL_Point::x, SDL_Rect::x, SDL_Point::y, and SDL_Rect::y.

## SDL_RectEmpty()

SDL_FORCE_INLINE SDL_bool SDL_RectEmpty | ( | const SDL_Rect * | r | ) |

Returns true if the rectangle has no area.

Definition at line 119 of file SDL_rect.h.

{
return ((!r) || (r->w <= 0) || (r->h <= 0)) ? SDL_TRUE : SDL_FALSE;
}

References SDL_Rect::h, SDL_FALSE, SDL_FORCE_INLINE, SDL_TRUE, and SDL_Rect::w.

## SDL_RectEquals()

SDL_FORCE_INLINE SDL_bool SDL_RectEquals | ( | const SDL_Rect * | a,
|  | const SDL_Rect * | b )

Returns true if the two rectangles are equal.

Definition at line 127 of file SDL_rect.h.

{
return (a && b && (a->x == b->x) && (a->y == b->y) &&
(a->w == b->w) && (a->h == b->h)) ? SDL_TRUE : SDL_FALSE;
}

References SDL_Rect::h, SDL_FALSE, SDL_FORCE_INLINE, SDL_TRUE, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

## SDL_UnionFRect()

void SDL_UnionFRect | ( | const SDL_FRect * | A,
|  | const SDL_FRect * | B,
|  | SDL_FRect * | result )

extern

Calculate the union of two rectangles with float precision.

Parameters

  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.

Since
  This function is available since SDL 2.0.22.

## SDL_UnionRect()

void SDL_UnionRect | ( | const SDL_Rect * | A,
|  | const SDL_Rect * | B,
|  | SDL_Rect * | result )

extern

Calculate the union of two rectangles.

Parameters

  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.

Since
  This function is available since SDL 2.0.0.