Point.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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)
  25. , y(Y)
  26. {
  27. }
  28. explicit DLL_LINKAGE Point(const int3 &a);
  29. template<typename T>
  30. Point operator+(const T &b) const
  31. {
  32. return Point(x+b.x,y+b.y);
  33. }
  34. template<typename T>
  35. Point operator/(const T &div) const
  36. {
  37. return Point(x/div, y/div);
  38. }
  39. template<typename T>
  40. Point operator*(const T &mul) const
  41. {
  42. return Point(x*mul, y*mul);
  43. }
  44. Point operator*(const Point &b) const
  45. {
  46. return Point(x*b.x,y*b.y);
  47. }
  48. template<typename T>
  49. Point& operator+=(const T &b)
  50. {
  51. x += b.x;
  52. y += b.y;
  53. return *this;
  54. }
  55. template<typename T>
  56. Point operator-(const T &b) const
  57. {
  58. return Point(x - b.x, y - b.y);
  59. }
  60. template<typename T>
  61. Point& operator-=(const T &b)
  62. {
  63. x -= b.x;
  64. y -= b.y;
  65. return *this;
  66. }
  67. template<typename T> Point& operator=(const T &t)
  68. {
  69. x = t.x;
  70. y = t.y;
  71. return *this;
  72. }
  73. template<typename T> bool operator==(const T &t) const
  74. {
  75. return x == t.x && y == t.y;
  76. }
  77. template<typename T> bool operator!=(const T &t) const
  78. {
  79. return !(*this == t);
  80. }
  81. template <typename Handler>
  82. void serialize(Handler &h, const int version)
  83. {
  84. h & x;
  85. h & y;
  86. }
  87. };
  88. VCMI_LIB_NAMESPACE_END