Point.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Point.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. VCMI_LIB_NAMESPACE_BEGIN
  12. class int3;
  13. // A point with x/y coordinate, used mostly for graphic rendering
  14. class Point
  15. {
  16. public:
  17. int x, y;
  18. //constructors
  19. Point()
  20. {
  21. x = y = 0;
  22. };
  23. Point(int X, int Y)
  24. :x(X),y(Y)
  25. {};
  26. Point(const int3 &a);
  27. template<typename T>
  28. Point operator+(const T &b) const
  29. {
  30. return Point(x+b.x,y+b.y);
  31. }
  32. template<typename T>
  33. Point operator/(const T &div) const
  34. {
  35. return Point(x/div, y/div);
  36. }
  37. template<typename T>
  38. Point operator*(const T &mul) const
  39. {
  40. return Point(x*mul, y*mul);
  41. }
  42. template<typename T>
  43. Point& operator+=(const T &b)
  44. {
  45. x += b.x;
  46. y += b.y;
  47. return *this;
  48. }
  49. template<typename T>
  50. Point operator-(const T &b) const
  51. {
  52. return Point(x - b.x, y - b.y);
  53. }
  54. template<typename T>
  55. Point& operator-=(const T &b)
  56. {
  57. x -= b.x;
  58. y -= b.y;
  59. return *this;
  60. }
  61. template<typename T> Point& operator=(const T &t)
  62. {
  63. x = t.x;
  64. y = t.y;
  65. return *this;
  66. }
  67. template<typename T> bool operator==(const T &t) const
  68. {
  69. return x == t.x && y == t.y;
  70. }
  71. template<typename T> bool operator!=(const T &t) const
  72. {
  73. return !(*this == t);
  74. }
  75. template <typename Handler>
  76. void serialize(Handler &h, const int version)
  77. {
  78. h & x;
  79. h & y;
  80. }
  81. };
  82. VCMI_LIB_NAMESPACE_END