Point.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include <AK/AKString.h>
  3. class Rect;
  4. struct WSAPI_Point;
  5. class Point {
  6. public:
  7. Point() { }
  8. Point(int x, int y) : m_x(x) , m_y(y) { }
  9. Point(const WSAPI_Point&);
  10. int x() const { return m_x; }
  11. int y() const { return m_y; }
  12. void set_x(int x) { m_x = x; }
  13. void set_y(int y) { m_y = y; }
  14. void move_by(int dx, int dy)
  15. {
  16. m_x += dx;
  17. m_y += dy;
  18. }
  19. void move_by(const Point& delta)
  20. {
  21. move_by(delta.x(), delta.y());
  22. }
  23. Point translated(int dx, int dy) const
  24. {
  25. Point point = *this;
  26. point.move_by(dx, dy);
  27. return point;
  28. }
  29. void constrain(const Rect&);
  30. bool operator==(const Point& other) const
  31. {
  32. return m_x == other.m_x
  33. && m_y == other.m_y;
  34. }
  35. bool operator!=(const Point& other) const
  36. {
  37. return !(*this == other);
  38. }
  39. operator WSAPI_Point() const;
  40. String to_string() const { return String::format("[%d,%d]", x(), y()); }
  41. private:
  42. int m_x { 0 };
  43. int m_y { 0 };
  44. };