Vector.cpp 628 B

12345678910111213141516171819202122232425262728293031
  1. #include "Vector.h"
  2. Vector::Vector(int x, int y) : x(x), y(y) {
  3. }
  4. void Vector::set(int x, int y) {
  5. this->x = x;
  6. this->y = y;
  7. }
  8. bool Vector::compare(int x, int y) const {
  9. return this->x == x && this->y == y;
  10. }
  11. Vector& Vector::operator+=(const Vector& other) {
  12. x += other.x;
  13. y += other.y;
  14. return *this;
  15. }
  16. Vector Vector::operator+(const Vector& other) const {
  17. return Vector(x + other.x, y + other.y);
  18. }
  19. Vector Vector::operator-(const Vector& other) const {
  20. return Vector(x - other.x, y - other.y);
  21. }
  22. bool Vector::operator==(const Vector& other) const {
  23. return compare(other.x, other.y);
  24. }