Leaked source code of windows server 2003
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.

220 lines
5.8 KiB

  1. #if !defined(BASE__Rect_inl_INCLUDED)
  2. #define BASE__Rect_inl_INCLUDED
  3. #pragma once
  4. /***************************************************************************\
  5. *
  6. * InlinePtInRect
  7. *
  8. * InlinePtInRect() provides a inline version of PtInRect(). This uses the
  9. * exact same comparisons as PtInRect (>= and <), so don't change this unless
  10. * PtInRect() changes.
  11. *
  12. \***************************************************************************/
  13. __forceinline bool
  14. InlinePtInRect(const RECT * prcCheck, POINT pt)
  15. {
  16. return (pt.x >= prcCheck->left) && (pt.x < prcCheck->right) &&
  17. (pt.y >= prcCheck->top) && (pt.y < prcCheck->bottom);
  18. }
  19. /***************************************************************************\
  20. *
  21. * InlineIsRectEmpty
  22. *
  23. * InlineIsRectEmpty() returns if a rect has a non-negative height and/or
  24. * width. This is different than InlineIsRectNull() which checks if the rect
  25. * is all 0's.
  26. *
  27. \***************************************************************************/
  28. __forceinline bool
  29. InlineIsRectEmpty(const RECT * prcCheck)
  30. {
  31. return ((prcCheck->left >= prcCheck->right) || (prcCheck->top >= prcCheck->bottom));
  32. }
  33. /***************************************************************************\
  34. *
  35. * InlineIsRectNull
  36. *
  37. * InlineIsRectNull() returns if a rect is all 0's.
  38. *
  39. \***************************************************************************/
  40. __forceinline bool
  41. InlineIsRectNull(const RECT * prcCheck)
  42. {
  43. return (prcCheck->left == 0) && (prcCheck->top == 0) &&
  44. (prcCheck->right == 0) && (prcCheck->bottom == 0);
  45. }
  46. /***************************************************************************\
  47. *
  48. * InlineIsRectNormalized
  49. *
  50. * InlineIsRectNormalized() returns if a rect is properly normalized so that
  51. * the upper-left corner is able the lower-right corner. This is different
  52. * than !IsRectEmpty() because the rectangle may still be empty.
  53. *
  54. \***************************************************************************/
  55. __forceinline bool
  56. InlineIsRectNormalized(const RECT * prcCheck)
  57. {
  58. return (prcCheck->left <= prcCheck->right) && (prcCheck->top <= prcCheck->bottom);
  59. }
  60. /***************************************************************************\
  61. *
  62. * InlineZeroRect
  63. *
  64. * InlineZeroRect() moves a rect to (0, 0)
  65. *
  66. \***************************************************************************/
  67. __forceinline void
  68. InlineZeroRect(RECT * prc)
  69. {
  70. prc->right -= prc->left;
  71. prc->bottom -= prc->top;
  72. prc->left = 0;
  73. prc->top = 0;
  74. }
  75. /***************************************************************************\
  76. *
  77. * InlineOffsetRect
  78. *
  79. * InlineOffsetRect() offsets a rect by a given amount.
  80. *
  81. \***************************************************************************/
  82. __forceinline void
  83. InlineOffsetRect(RECT * prc, int xOffset, int yOffset)
  84. {
  85. prc->left += xOffset;
  86. prc->top += yOffset;
  87. prc->right += xOffset;
  88. prc->bottom += yOffset;
  89. }
  90. /***************************************************************************\
  91. *
  92. * InlineInflateRect
  93. *
  94. * InlineInflateRect() moves the corners of the rectangle out from the center
  95. * by a given amount.
  96. *
  97. \***************************************************************************/
  98. __forceinline void
  99. InlineInflateRect(RECT * prc, int xIncrease, int yIncrease)
  100. {
  101. prc->left -= xIncrease;
  102. prc->top -= yIncrease;
  103. prc->right += xIncrease;
  104. prc->bottom += yIncrease;
  105. }
  106. /***************************************************************************\
  107. *
  108. * InlineCopyRect
  109. *
  110. * InlineCopyRect() copies a rectangle.
  111. *
  112. \***************************************************************************/
  113. __forceinline void
  114. InlineCopyRect(RECT * prcDest, const RECT * prcSrc)
  115. {
  116. prcDest->left = prcSrc->left;
  117. prcDest->top = prcSrc->top;
  118. prcDest->right = prcSrc->right;
  119. prcDest->bottom = prcSrc->bottom;
  120. }
  121. /***************************************************************************\
  122. *
  123. * InlineCopyZeroRect
  124. *
  125. * InlineCopyZeroRect() copies a rectangle and moves it to (0, 0)
  126. *
  127. \***************************************************************************/
  128. __forceinline void
  129. InlineCopyZeroRect(RECT * prcDest, const RECT * prcSrc)
  130. {
  131. prcDest->left = 0;
  132. prcDest->top = 0;
  133. prcDest->right = prcSrc->right - prcSrc->left;
  134. prcDest->bottom = prcSrc->bottom - prcSrc->top;
  135. }
  136. //------------------------------------------------------------------------------
  137. __forceinline void
  138. InlineSetRectEmpty(
  139. OUT RECT * prcDest)
  140. {
  141. prcDest->left = prcDest->top = prcDest->right = prcDest->bottom = 0;
  142. }
  143. //------------------------------------------------------------------------------
  144. __forceinline bool
  145. InlineIntersectRect(
  146. OUT RECT * prcDst,
  147. IN const RECT * prcSrc1,
  148. IN const RECT * prcSrc2)
  149. {
  150. prcDst->left = max(prcSrc1->left, prcSrc2->left);
  151. prcDst->right = min(prcSrc1->right, prcSrc2->right);
  152. /*
  153. * check for empty rect
  154. */
  155. if (prcDst->left < prcDst->right) {
  156. prcDst->top = max(prcSrc1->top, prcSrc2->top);
  157. prcDst->bottom = min(prcSrc1->bottom, prcSrc2->bottom);
  158. /*
  159. * check for empty rect
  160. */
  161. if (prcDst->top < prcDst->bottom) {
  162. return true; // not empty
  163. }
  164. }
  165. /*
  166. * empty rect
  167. */
  168. InlineSetRectEmpty(prcDst);
  169. return false;
  170. }
  171. //------------------------------------------------------------------------------
  172. __forceinline bool
  173. InlineEqualRect(
  174. IN const RECT * prc1,
  175. IN const RECT * prc2)
  176. {
  177. return (prc1->left == prc2->left) && (prc1->top == prc2->top) &&
  178. (prc1->right == prc2->right) && (prc1->bottom == prc2->bottom);
  179. }
  180. #endif // BASE__Rect_inl_INCLUDED