Rect.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /** @file Rect.cpp
  2. @author Jukka Jylänki
  3. This work is released to Public Domain, do whatever you want with it.
  4. */
  5. #include "Rect.h"
  6. /*
  7. #include "clb/Algorithm/Sort.h"
  8. int CompareRectShortSide(const Rect &a, const Rect &b)
  9. {
  10. using namespace std;
  11. int smallerSideA = min(a.width, a.height);
  12. int smallerSideB = min(b.width, b.height);
  13. if (smallerSideA != smallerSideB)
  14. return clb::sort::TriCmp(smallerSideA, smallerSideB);
  15. // Tie-break on the larger side.
  16. int largerSideA = max(a.width, a.height);
  17. int largerSideB = max(b.width, b.height);
  18. return clb::sort::TriCmp(largerSideA, largerSideB);
  19. }
  20. */
  21. /*
  22. int NodeSortCmp(const Rect &a, const Rect &b)
  23. {
  24. if (a.x != b.x)
  25. return clb::sort::TriCmp(a.x, b.x);
  26. if (a.y != b.y)
  27. return clb::sort::TriCmp(a.y, b.y);
  28. if (a.width != b.width)
  29. return clb::sort::TriCmp(a.width, b.width);
  30. return clb::sort::TriCmp(a.height, b.height);
  31. }
  32. */
  33. bool IsContainedIn(const Rect &a, const Rect &b)
  34. {
  35. return a.x >= b.x && a.y >= b.y
  36. && a.x+a.width <= b.x+b.width
  37. && a.y+a.height <= b.y+b.height;
  38. }