point.cpp 878 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "point.h"
  2. Point::Point( int px, int py )
  3. : x( px ),
  4. y( py )
  5. {
  6. }
  7. Point::Point( const Point& other )
  8. : x( other.x ),
  9. y( other.y )
  10. {
  11. }
  12. void Point::Offset( int xOffset, int yOffset )
  13. {
  14. x += xOffset;
  15. y += yOffset;
  16. }
  17. void Point::Offset( const Point& point )
  18. {
  19. x += point.x;
  20. y += point.y;
  21. }
  22. Point& Point::operator += ( const Point& other )
  23. {
  24. x += other.x;
  25. y += other.y;
  26. return *this;
  27. }
  28. Point& Point::operator -= ( const Point& other )
  29. {
  30. x -= other.x;
  31. y -= other.y;
  32. return *this;
  33. }
  34. Point operator + ( const Point& p1, const Point& p2 )
  35. {
  36. return Point( p1.x + p2.x, p1.y + p2.y );
  37. }
  38. Point operator - ( const Point& p1, const Point& p2 )
  39. {
  40. return Point( p1.x - p2.x, p1.y - p2.y );
  41. }
  42. bool operator == ( const Point& p1, const Point& p2 )
  43. {
  44. return ( ( p1.x == p2.x ) && ( p1.y == p2.y ) );
  45. }