🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
4.7 KiB

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_rect.h
  20. *
  21. * Header file for SDL_rect definition and management functions.
  22. */
  23. #ifndef SDL_rect_h_
  24. #define SDL_rect_h_
  25. #include "SDL_stdinc.h"
  26. #include "SDL_error.h"
  27. #include "SDL_pixels.h"
  28. #include "SDL_rwops.h"
  29. #include "begin_code.h"
  30. /* Set up for C function definitions, even when using C++ */
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /**
  35. * \brief The structure that defines a point (integer)
  36. *
  37. * \sa SDL_EnclosePoints
  38. * \sa SDL_PointInRect
  39. */
  40. typedef struct SDL_Point
  41. {
  42. int x;
  43. int y;
  44. } SDL_Point;
  45. /**
  46. * \brief The structure that defines a point (floating point)
  47. *
  48. * \sa SDL_EnclosePoints
  49. * \sa SDL_PointInRect
  50. */
  51. typedef struct SDL_FPoint
  52. {
  53. float x;
  54. float y;
  55. } SDL_FPoint;
  56. /**
  57. * \brief A rectangle, with the origin at the upper left (integer).
  58. *
  59. * \sa SDL_RectEmpty
  60. * \sa SDL_RectEquals
  61. * \sa SDL_HasIntersection
  62. * \sa SDL_IntersectRect
  63. * \sa SDL_UnionRect
  64. * \sa SDL_EnclosePoints
  65. */
  66. typedef struct SDL_Rect
  67. {
  68. int x, y;
  69. int w, h;
  70. } SDL_Rect;
  71. /**
  72. * \brief A rectangle, with the origin at the upper left (floating point).
  73. */
  74. typedef struct SDL_FRect
  75. {
  76. float x;
  77. float y;
  78. float w;
  79. float h;
  80. } SDL_FRect;
  81. /**
  82. * \brief Returns true if point resides inside a rectangle.
  83. */
  84. SDL_FORCE_INLINE SDL_bool SDL_PointInRect(const SDL_Point *p, const SDL_Rect *r)
  85. {
  86. return ( (p->x >= r->x) && (p->x < (r->x + r->w)) &&
  87. (p->y >= r->y) && (p->y < (r->y + r->h)) ) ? SDL_TRUE : SDL_FALSE;
  88. }
  89. /**
  90. * \brief Returns true if the rectangle has no area.
  91. */
  92. SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
  93. {
  94. return ((!r) || (r->w <= 0) || (r->h <= 0)) ? SDL_TRUE : SDL_FALSE;
  95. }
  96. /**
  97. * \brief Returns true if the two rectangles are equal.
  98. */
  99. SDL_FORCE_INLINE SDL_bool SDL_RectEquals(const SDL_Rect *a, const SDL_Rect *b)
  100. {
  101. return (a && b && (a->x == b->x) && (a->y == b->y) &&
  102. (a->w == b->w) && (a->h == b->h)) ? SDL_TRUE : SDL_FALSE;
  103. }
  104. /**
  105. * \brief Determine whether two rectangles intersect.
  106. *
  107. * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
  108. */
  109. extern DECLSPEC SDL_bool SDLCALL SDL_HasIntersection(const SDL_Rect * A,
  110. const SDL_Rect * B);
  111. /**
  112. * \brief Calculate the intersection of two rectangles.
  113. *
  114. * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
  115. */
  116. extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRect(const SDL_Rect * A,
  117. const SDL_Rect * B,
  118. SDL_Rect * result);
  119. /**
  120. * \brief Calculate the union of two rectangles.
  121. */
  122. extern DECLSPEC void SDLCALL SDL_UnionRect(const SDL_Rect * A,
  123. const SDL_Rect * B,
  124. SDL_Rect * result);
  125. /**
  126. * \brief Calculate a minimal rectangle enclosing a set of points
  127. *
  128. * \return SDL_TRUE if any points were within the clipping rect
  129. */
  130. extern DECLSPEC SDL_bool SDLCALL SDL_EnclosePoints(const SDL_Point * points,
  131. int count,
  132. const SDL_Rect * clip,
  133. SDL_Rect * result);
  134. /**
  135. * \brief Calculate the intersection of a rectangle and line segment.
  136. *
  137. * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
  138. */
  139. extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRectAndLine(const SDL_Rect *
  140. rect, int *X1,
  141. int *Y1, int *X2,
  142. int *Y2);
  143. /* Ends C function definitions when using C++ */
  144. #ifdef __cplusplus
  145. }
  146. #endif
  147. #include "close_code.h"
  148. #endif /* SDL_rect_h_ */
  149. /* vi: set ts=4 sw=4 expandtab: */