wasabi_std_rect.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "wasabi_std_rect.h"
  2. #include <bfc/platform/minmax.h>
  3. #include <bfc/std_mem.h>
  4. bool Wasabi::Std::rectIntersect(const RECT &i1, const RECT &i2, RECT *intersection)
  5. {
  6. RECT out;
  7. out.left = MAX(i1.left, i2.left);
  8. out.right = MIN(i1.right, i2.right);
  9. out.top = MAX(i1.top, i2.top);
  10. out.bottom = MIN(i1.bottom, i2.bottom);
  11. if (intersection != NULL) *intersection = out;
  12. return (out.left < out.right && out.top < out.bottom);
  13. }
  14. bool Wasabi::Std::pointInRect(const RECT &r, const POINT &p)
  15. {
  16. if (p.x < r.left ||
  17. p.x >= r.right ||
  18. p.y < r.top ||
  19. p.y >= r.bottom) return 0;
  20. return true;
  21. }
  22. void Wasabi::Std::setRect(RECT *r, int left, int top, int right, int bottom)
  23. {
  24. r->left = left;
  25. r->top = top;
  26. r->right = right;
  27. r->bottom = bottom;
  28. }
  29. RECT Wasabi::Std::makeRect(int left, int top, int right, int bottom)
  30. {
  31. RECT r;
  32. r.left = left;
  33. r.top = top;
  34. r.right = right;
  35. r.bottom = bottom;
  36. return r;
  37. }
  38. POINT Wasabi::Std::makePoint(int x, int y)
  39. {
  40. POINT p = { x, y };
  41. return p;
  42. }
  43. void Wasabi::Std::offsetRect(RECT *r, int x, int y)
  44. {
  45. r->left += x;
  46. r->right += x;
  47. r->top += y;
  48. r->bottom += y;
  49. }
  50. bool Wasabi::Std::rectEqual(const RECT &a, const RECT &b)
  51. {
  52. return !MEMCMP(&a, &b, sizeof(RECT));
  53. }
  54. bool Wasabi::Std::rectEqual(const RECT *a, const RECT *b)
  55. {
  56. return !MEMCMP(a, b, sizeof(RECT));
  57. }
  58. void Wasabi::Std::scaleRect(RECT *r, double scale)
  59. {
  60. r->left =(long)(r->left * scale + 0.5);
  61. r->right = (long)(r->right * scale + 0.5);
  62. r->bottom = (long)(r->bottom * scale + 0.5);
  63. r->top = (long)(r->top * scale + 0.5);
  64. }