My Project
Loading...
Searching...
No Matches
SDL_rect.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
28#ifndef SDL_rect_h_
29#define SDL_rect_h_
30
31#include "SDL_stdinc.h"
32#include "SDL_error.h"
33#include "SDL_pixels.h"
34#include "SDL_rwops.h"
35
36#include "begin_code.h"
37/* Set up for C function definitions, even when using C++ */
38#ifdef __cplusplus
39extern "C" {
40#endif
41
48typedef struct SDL_Point
49{
50 int x;
51 int y;
53
60typedef struct SDL_FPoint
61{
62 float x;
63 float y;
65
66
78typedef struct SDL_Rect
79{
80 int x, y;
81 int w, h;
83
84
98typedef struct SDL_FRect
99{
100 float x;
101 float y;
102 float w;
103 float h;
105
106
110SDL_FORCE_INLINE SDL_bool SDL_PointInRect(const SDL_Point *p, const SDL_Rect *r)
111{
112 return ( (p->x >= r->x) && (p->x < (r->x + r->w)) &&
113 (p->y >= r->y) && (p->y < (r->y + r->h)) ) ? SDL_TRUE : SDL_FALSE;
114}
115
119SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
120{
121 return ((!r) || (r->w <= 0) || (r->h <= 0)) ? SDL_TRUE : SDL_FALSE;
122}
123
127SDL_FORCE_INLINE SDL_bool SDL_RectEquals(const SDL_Rect *a, const SDL_Rect *b)
128{
129 return (a && b && (a->x == b->x) && (a->y == b->y) &&
130 (a->w == b->w) && (a->h == b->h)) ? SDL_TRUE : SDL_FALSE;
131}
132
146extern DECLSPEC SDL_bool SDLCALL SDL_HasIntersection(const SDL_Rect * A,
147 const SDL_Rect * B);
148
164extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRect(const SDL_Rect * A,
165 const SDL_Rect * B,
166 SDL_Rect * result);
167
178extern DECLSPEC void SDLCALL SDL_UnionRect(const SDL_Rect * A,
179 const SDL_Rect * B,
180 SDL_Rect * result);
181
199extern DECLSPEC SDL_bool SDLCALL SDL_EnclosePoints(const SDL_Point * points,
200 int count,
201 const SDL_Rect * clip,
202 SDL_Rect * result);
203
222extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRectAndLine(const SDL_Rect *
223 rect, int *X1,
224 int *Y1, int *X2,
225 int *Y2);
226
227
228/* SDL_FRect versions... */
229
233SDL_FORCE_INLINE SDL_bool SDL_PointInFRect(const SDL_FPoint *p, const SDL_FRect *r)
234{
235 return ( (p->x >= r->x) && (p->x < (r->x + r->w)) &&
236 (p->y >= r->y) && (p->y < (r->y + r->h)) ) ? SDL_TRUE : SDL_FALSE;
237}
238
242SDL_FORCE_INLINE SDL_bool SDL_FRectEmpty(const SDL_FRect *r)
243{
244 return ((!r) || (r->w <= 0.0f) || (r->h <= 0.0f)) ? SDL_TRUE : SDL_FALSE;
245}
246
252SDL_FORCE_INLINE SDL_bool SDL_FRectEqualsEpsilon(const SDL_FRect *a, const SDL_FRect *b, const float epsilon)
253{
254 return (a && b && ((a == b) ||
255 ((SDL_fabsf(a->x - b->x) <= epsilon) &&
256 (SDL_fabsf(a->y - b->y) <= epsilon) &&
257 (SDL_fabsf(a->w - b->w) <= epsilon) &&
258 (SDL_fabsf(a->h - b->h) <= epsilon))))
259 ? SDL_TRUE : SDL_FALSE;
260}
261
267SDL_FORCE_INLINE SDL_bool SDL_FRectEquals(const SDL_FRect *a, const SDL_FRect *b)
268{
269 return SDL_FRectEqualsEpsilon(a, b, SDL_FLT_EPSILON);
270}
271
285extern DECLSPEC SDL_bool SDLCALL SDL_HasIntersectionF(const SDL_FRect * A,
286 const SDL_FRect * B);
287
303extern DECLSPEC SDL_bool SDLCALL SDL_IntersectFRect(const SDL_FRect * A,
304 const SDL_FRect * B,
305 SDL_FRect * result);
306
317extern DECLSPEC void SDLCALL SDL_UnionFRect(const SDL_FRect * A,
318 const SDL_FRect * B,
319 SDL_FRect * result);
320
339extern DECLSPEC SDL_bool SDLCALL SDL_EncloseFPoints(const SDL_FPoint * points,
340 int count,
341 const SDL_FRect * clip,
342 SDL_FRect * result);
343
363extern DECLSPEC SDL_bool SDLCALL SDL_IntersectFRectAndLine(const SDL_FRect *
364 rect, float *X1,
365 float *Y1, float *X2,
366 float *Y2);
367
368/* Ends C function definitions when using C++ */
369#ifdef __cplusplus
370}
371#endif
372#include "close_code.h"
373
374#endif /* SDL_rect_h_ */
375
376/* vi: set ts=4 sw=4 expandtab: */
SDL_FORCE_INLINE SDL_bool SDL_RectEquals(const SDL_Rect *a, const SDL_Rect *b)
Definition: SDL_rect.h:127
DECLSPEC SDL_bool SDLCALL SDL_HasIntersection(const SDL_Rect *A, const SDL_Rect *B)
DECLSPEC void SDLCALL SDL_UnionFRect(const SDL_FRect *A, const SDL_FRect *B, SDL_FRect *result)
DECLSPEC SDL_bool SDLCALL SDL_EncloseFPoints(const SDL_FPoint *points, int count, const SDL_FRect *clip, SDL_FRect *result)
SDL_FORCE_INLINE SDL_bool SDL_PointInRect(const SDL_Point *p, const SDL_Rect *r)
Definition: SDL_rect.h:110
SDL_FORCE_INLINE SDL_bool SDL_FRectEqualsEpsilon(const SDL_FRect *a, const SDL_FRect *b, const float epsilon)
Definition: SDL_rect.h:252
DECLSPEC void SDLCALL SDL_UnionRect(const SDL_Rect *A, const SDL_Rect *B, SDL_Rect *result)
SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
Definition: SDL_rect.h:119
SDL_FORCE_INLINE SDL_bool SDL_FRectEquals(const SDL_FRect *a, const SDL_FRect *b)
Definition: SDL_rect.h:267
DECLSPEC SDL_bool SDLCALL 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)
Definition: SDL_rect.h:233
DECLSPEC SDL_bool SDLCALL SDL_HasIntersectionF(const SDL_FRect *A, const SDL_FRect *B)
DECLSPEC SDL_bool SDLCALL SDL_IntersectFRectAndLine(const SDL_FRect *rect, float *X1, float *Y1, float *X2, float *Y2)
SDL_FORCE_INLINE SDL_bool SDL_FRectEmpty(const SDL_FRect *r)
Definition: SDL_rect.h:242
DECLSPEC SDL_bool SDLCALL SDL_IntersectFRect(const SDL_FRect *A, const SDL_FRect *B, SDL_FRect *result)
DECLSPEC SDL_bool SDLCALL SDL_EnclosePoints(const SDL_Point *points, int count, const SDL_Rect *clip, SDL_Rect *result)
DECLSPEC SDL_bool SDLCALL SDL_IntersectRect(const SDL_Rect *A, const SDL_Rect *B, SDL_Rect *result)
Definition: SDL_rect.h:61
Definition: SDL_rect.h:99
Definition: SDL_rect.h:49
Definition: SDL_rect.h:79