Point.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include "Point.h"
  2. //METHODS
  3. //constructor
  4. Point::Point(double x, double y)
  5. {
  6. m_x = x;
  7. m_y = y;
  8. }
  9. //destructor
  10. Point::~Point()
  11. {
  12. //???
  13. }
  14. //Get_all
  15. void Point::Get_all(double& x, double& y)
  16. {
  17. x = m_x;
  18. y = m_y;
  19. }
  20. //Get_all const
  21. void Point::Get_all(double& x, double& y) const
  22. {
  23. x = m_x;
  24. y = m_y;
  25. }
  26. //Set_all
  27. void Point::Set_all(double& x, double& y)
  28. {
  29. m_x = x;
  30. m_y = y;
  31. }
  32. //operator=
  33. Point& Point::operator=(const Point& other)
  34. {
  35. m_x = other.m_x;
  36. m_y = other.m_y;
  37. return *this;
  38. }
  39. //operator=
  40. Point& Point::operator=(Point&& other)
  41. {
  42. m_x = other.m_x;
  43. m_y = other.m_y;
  44. return *this;
  45. }
  46. //operator+
  47. Point Point::operator+(const Point& other) const
  48. {
  49. return Point(m_x + other.m_x, m_y + other.m_y);
  50. }
  51. //operator+
  52. Point Point::operator+(const double num) const
  53. {
  54. return Point(m_x + num, m_y + num);
  55. }
  56. //operator+=
  57. Point& Point::operator+=(const Point& other)
  58. {
  59. m_x += other.m_x;
  60. m_y += other.m_y;
  61. return *this;
  62. }
  63. //operator+=
  64. Point& Point::operator+=(const double num)
  65. {
  66. m_x += num;
  67. m_y += num;
  68. return *this;
  69. }
  70. //Point& Point::operator+=(Point&& other)
  71. //{
  72. // m_x += other.m_x;
  73. // m_y += other.m_y;
  74. // return *this;
  75. //}
  76. //operator+ uno
  77. Point Point::operator+() const
  78. {
  79. return Point(+m_x,+m_y);
  80. }
  81. //operator- uno
  82. Point Point::operator-() const
  83. {
  84. return Point(-m_x, -m_y);
  85. }
  86. //GLOBAL FUNCTIONS
  87. //operator+
  88. Point operator+(const double num, const Point& other)
  89. {
  90. double Other_x, Other_y;
  91. other.Get_all(Other_x, Other_y);
  92. return Point(Other_x + num, Other_y + num);
  93. }
  94. //operator-
  95. Point operator-(const Point& thirst, const double num)
  96. {
  97. double thirst_x, thirst_y;
  98. thirst.Get_all(thirst_x, thirst_y);
  99. return Point(thirst_x - num, thirst_y - num);
  100. }
  101. //operator-
  102. Point operator-(const Point& thirst, const Point& second)
  103. {
  104. double thirst_x, thirst_y, second_x, second_y;
  105. thirst.Get_all(thirst_x, thirst_y);
  106. second.Get_all(second_x, second_y);
  107. return Point(thirst_x - second_x, thirst_y - second_y);
  108. }
  109. //operator-=
  110. Point& operator-=(Point& This, const Point& Other)
  111. {
  112. double This_x, This_y, Other_x, Other_y;
  113. This.Get_all(This_x, This_y);
  114. Other.Get_all(Other_x, Other_y);
  115. This.Set_all(This_x -= Other_x, This_y -= Other_y);
  116. return This;
  117. }