fork download
  1. // (C) 2013-2015, Sergei Zaychenko, KNURE, Kharkiv, Ukraine
  2.  
  3. #include "rectangle.hpp"
  4.  
  5. #include <stdexcept>
  6.  
  7. /*****************************************************************************/
  8.  
  9. // ... TODO ...
  10.  
  11. /*****************************************************************************/
  12. Rectangle(Point _TopLeft, Point _BottomRight)
  13. {
  14. if ((_TopLeft.m_x > _BottomRight.m_x) || (_TopLeft.m_y > _BottomRight.m_y))
  15. throw std::logic_error("Invalid rectangle coordinates");
  16. }
  17. Rectangle(Point TopLeft, double Width, double Height)
  18. {
  19. if (Width <= 0 || Height <= 0)
  20. throw std::logic_error("Invalid rectangle coordinates");
  21. }
  22. double getPerimeter()
  23. {
  24. return (Width + Height) * 2;
  25. }
  26. double getArea()
  27. {
  28. return Width*Height;
  29. }
  30. bool operator == (Rectangle const& _p) const
  31. {
  32. return this->TopLeft == _p.TopLeft &&
  33. this->BottomLeft == _p.BottomLeft &&
  34. this->TopRight == _p.TopRight &&
  35. this->BottomRight == _p.BottomRight;
  36. }
  37. bool operator != (Rectangle const& _p) const
  38. {
  39. return !(*this == _p);
  40. }
  41. bool contains(Point _p)
  42. {
  43. return _p.m_x >= TopLeft.m_x&&_p.m_x <= BottomRight.m_x&&_p.m_y >= TopLeft.m_y&&_p.m_y <= BottomRight.m_y;
  44.  
  45. }
  46. bool contains(Point _p1, Point _p2)
  47. {
  48. return contains(_p1) && contains(_p2);
  49. }
  50. bool intersects(const Rectangle & _r)
  51. {
  52. if (_r.TopRight == this->TopRight
  53. || _r.TopLeft == this->TopLeft
  54. || _r.BottomLeft == this->BottomLeft
  55. || _r.BottomRight == this->BottomRight)
  56. return true;
  57. }
  58. bool covers(const Rectangle & _r)
  59. {
  60. if (_r.TopRight.m_x > this->TopRight.m_x
  61. &&_r.TopRight.m_y > this->TopRight.m_y
  62. && _r.TopLeft.m_x > this->TopLeft.m_x
  63. &&_r.TopLeft.m_y > this->TopLeft.m_y
  64. && _r.BottomLeft.m_x > this->BottomLeft.m_x
  65. &&_r.BottomLeft.m_y > this->BottomLeft.m_y
  66. && _r.BottomRight.m_x > this->BottomRight.m_x
  67. && _r.BottomRight.m_y > this->BottomRight.m_y
  68. )
  69. return true;
  70. }
  71. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:25: fatal error: rectangle.hpp: No such file or directory
compilation terminated.
stdout
Standard output is empty