Source code of Windows XP (NT5)
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.

84 lines
2.3 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: misc.c
  3. *
  4. * Miscellaneous common routines.
  5. *
  6. * Copyright (c) 1992-1995 Microsoft Corporation
  7. *
  8. \**************************************************************************/
  9. #include "precomp.h"
  10. /******************************Public*Routine******************************\
  11. * BOOL bIntersect
  12. *
  13. * If 'prcl1' and 'prcl2' intersect, has a return value of TRUE and returns
  14. * the intersection in 'prclResult'. If they don't intersect, has a return
  15. * value of FALSE, and 'prclResult' is undefined.
  16. *
  17. \**************************************************************************/
  18. BOOL bIntersect(
  19. RECTL* prcl1,
  20. RECTL* prcl2,
  21. RECTL* prclResult)
  22. {
  23. prclResult->left = max(prcl1->left, prcl2->left);
  24. prclResult->right = min(prcl1->right, prcl2->right);
  25. if (prclResult->left < prclResult->right)
  26. {
  27. prclResult->top = max(prcl1->top, prcl2->top);
  28. prclResult->bottom = min(prcl1->bottom, prcl2->bottom);
  29. if (prclResult->top < prclResult->bottom)
  30. {
  31. return(TRUE);
  32. }
  33. }
  34. return(FALSE);
  35. }
  36. /******************************Public*Routine******************************\
  37. * LONG cIntersect
  38. *
  39. * This routine takes a list of rectangles from 'prclIn' and clips them
  40. * in-place to the rectangle 'prclClip'. The input rectangles don't
  41. * have to intersect 'prclClip'; the return value will reflect the
  42. * number of input rectangles that did intersect, and the intersecting
  43. * rectangles will be densely packed.
  44. *
  45. \**************************************************************************/
  46. LONG cIntersect(
  47. RECTL* prclClip,
  48. RECTL* prclIn, // List of rectangles
  49. LONG c) // Can be zero
  50. {
  51. LONG cIntersections;
  52. RECTL* prclOut;
  53. cIntersections = 0;
  54. prclOut = prclIn;
  55. for (; c != 0; prclIn++, c--)
  56. {
  57. prclOut->left = max(prclIn->left, prclClip->left);
  58. prclOut->right = min(prclIn->right, prclClip->right);
  59. if (prclOut->left < prclOut->right)
  60. {
  61. prclOut->top = max(prclIn->top, prclClip->top);
  62. prclOut->bottom = min(prclIn->bottom, prclClip->bottom);
  63. if (prclOut->top < prclOut->bottom)
  64. {
  65. prclOut++;
  66. cIntersections++;
  67. }
  68. }
  69. }
  70. return(cIntersections);
  71. }