SDL_Rect: Added floating point versions of all the rectangle APIs.
Fixes #5110.
This commit is contained in:
parent
4d9bef604a
commit
d81fee7623
6 changed files with 608 additions and 470 deletions
|
@ -54,8 +54,13 @@ typedef struct SDL_Point
|
|||
/**
|
||||
* The structure that defines a point (floating point)
|
||||
*
|
||||
* \sa SDL_EnclosePoints
|
||||
* \sa SDL_PointInRect
|
||||
* \sa SDL_FRectEmpty
|
||||
* \sa SDL_FRectEquals
|
||||
* \sa SDL_HasIntersectionF
|
||||
* \sa SDL_IntersectFRect
|
||||
* \sa SDL_UnionFRect
|
||||
* \sa SDL_EncloseFPoints
|
||||
* \sa SDL_PointInFRect
|
||||
*/
|
||||
typedef struct SDL_FPoint
|
||||
{
|
||||
|
@ -213,6 +218,119 @@ extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRectAndLine(const SDL_Rect *
|
|||
int *Y1, int *X2,
|
||||
int *Y2);
|
||||
|
||||
|
||||
/* SDL_FRect versions... */
|
||||
|
||||
/**
|
||||
* Returns true if point resides inside a rectangle.
|
||||
*/
|
||||
SDL_FORCE_INLINE SDL_bool SDL_PointInFRect(const SDL_FPoint *p, const SDL_FRect *r)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the rectangle has no area.
|
||||
*/
|
||||
SDL_FORCE_INLINE SDL_bool SDL_FRectEmpty(const SDL_FRect *r)
|
||||
{
|
||||
return ((!r) || (r->w <= 0.0f) || (r->h <= 0.0f)) ? SDL_TRUE : SDL_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the two rectangles are equal.
|
||||
*/
|
||||
SDL_FORCE_INLINE SDL_bool SDL_FRectEquals(const SDL_FRect *a, const SDL_FRect *b)
|
||||
{
|
||||
return (a && b && (a->x == b->x) && (a->y == b->y) &&
|
||||
(a->w == b->w) && (a->h == b->h)) ? SDL_TRUE : SDL_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether two rectangles intersect with float precision.
|
||||
*
|
||||
* If either pointer is NULL the function will return SDL_FALSE.
|
||||
*
|
||||
* \param A an SDL_FRect structure representing the first rectangle
|
||||
* \param B an SDL_FRect structure representing the second rectangle
|
||||
* \returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
|
||||
*
|
||||
* \sa SDL_IntersectRect
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_HasIntersectionF(const SDL_FRect * A,
|
||||
const SDL_FRect * B);
|
||||
|
||||
/**
|
||||
* Calculate the intersection of two rectangles with float precision.
|
||||
*
|
||||
* If `result` is NULL then this function will return SDL_FALSE.
|
||||
*
|
||||
* \param A an SDL_FRect structure representing the first rectangle
|
||||
* \param B an SDL_FRect structure representing the second rectangle
|
||||
* \param 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.
|
||||
*
|
||||
* \sa SDL_HasIntersectionF
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_IntersectFRect(const SDL_FRect * A,
|
||||
const SDL_FRect * B,
|
||||
SDL_FRect * result);
|
||||
|
||||
/**
|
||||
* Calculate the union of two rectangles with float precision.
|
||||
*
|
||||
* \param A an SDL_FRect structure representing the first rectangle
|
||||
* \param B an SDL_FRect structure representing the second rectangle
|
||||
* \param result an SDL_FRect structure filled in with the union of rectangles
|
||||
* `A` and `B`
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_UnionFRect(const SDL_FRect * A,
|
||||
const SDL_FRect * B,
|
||||
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.
|
||||
*
|
||||
* \param points an array of SDL_FPoint structures representing points to be
|
||||
* enclosed
|
||||
* \param count the number of structures in the `points` array
|
||||
* \param clip an SDL_FRect used for clipping or NULL to enclose all points
|
||||
* \param 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.
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_EncloseFPoints(const SDL_FPoint * points,
|
||||
int count,
|
||||
const SDL_FRect * clip,
|
||||
SDL_FRect * result);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* \param rect an SDL_FRect structure representing the rectangle to intersect
|
||||
* \param X1 a pointer to the starting X-coordinate of the line
|
||||
* \param Y1 a pointer to the starting Y-coordinate of the line
|
||||
* \param X2 a pointer to the ending X-coordinate of the line
|
||||
* \param Y2 a pointer to the ending Y-coordinate of the line
|
||||
* \returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
|
||||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_IntersectFRectAndLine(const SDL_FRect *
|
||||
rect, float *X1,
|
||||
float *Y1, float *X2,
|
||||
float *Y2);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue