Basic.cpp 843 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "StdInc.h"
  2. #include "Basic.h"
  3. namespace Gfx
  4. {
  5. void Rect::addOffs_copySize(const Rect & r)
  6. {
  7. x += r.x;
  8. y += r.y;
  9. w = r.w;
  10. h = r.h;
  11. }
  12. Rect Rect::operator&(const Rect &p) const //rect intersection
  13. {
  14. bool intersect = true;
  15. if (
  16. leftX() > p.rightX() //rect p is on the left hand side of this
  17. || rightX() < p.leftX() //rect p is on the right hand side of this
  18. || topY() > p.bottomY() //rect p is above *this
  19. || bottomY() < p.topY() //rect p is below *this
  20. )
  21. {
  22. return Rect();
  23. }
  24. else
  25. {
  26. Rect ret;
  27. ret.x = std::max(this->x, p.x);
  28. ret.y = std::max(this->y, p.y);
  29. //bottomRight point of returned rect
  30. Point bR(
  31. std::min(rightX(), p.rightX()),
  32. std::min(bottomY(), p.bottomY())
  33. );
  34. ret.w = bR.x - ret.x;
  35. ret.h = bR.y - ret.y;
  36. return ret;
  37. }
  38. }
  39. }