int3.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef INT3_H
  2. #define INT3_H
  3. class int3
  4. {
  5. public:
  6. int x,y,z;
  7. inline int3():x(0),y(0),z(0){}; //c-tor, x/y/z initialized to 0
  8. inline int3(const int & X, const int & Y, const int & Z):x(X),y(Y),z(Z){}; //c-tor
  9. inline ~int3(){} // d-tor - does nothing
  10. inline int3 operator+(const int3 & i) const
  11. {return int3(x+i.x,y+i.y,z+i.z);}
  12. inline int3 operator+(const int i) const //increases all components by int
  13. {return int3(x+i,y+i,z+i);}
  14. inline int3 operator-(const int3 & i) const
  15. {return int3(x-i.x,y-i.y,z-i.z);}
  16. inline int3 operator-(const int i) const
  17. {return int3(x-i,y-i,z-i);}
  18. inline int3 operator-() const //increases all components by int
  19. {return int3(-x,-y,-z);}
  20. inline void operator+=(const int3 & i)
  21. {
  22. x+=i.x;
  23. y+=i.y;
  24. z+=i.z;
  25. }
  26. inline void operator+=(const int & i)
  27. {
  28. x+=i;
  29. y+=i;
  30. z+=i;
  31. }
  32. inline void operator-=(const int3 & i)
  33. {
  34. x-=i.x;
  35. y-=i.y;
  36. z-=i.z;
  37. }
  38. inline void operator-=(const int & i)
  39. {
  40. x+=i;
  41. y+=i;
  42. z+=i;
  43. }
  44. inline bool operator==(const int3 & i) const
  45. {return (x==i.x) && (y==i.y) && (z==i.z);}
  46. inline bool operator!=(const int3 & i) const
  47. {return !(*this==i);}
  48. inline bool operator<(const int3 & i) const
  49. {
  50. if (z<i.z)
  51. return true;
  52. if (z>i.z)
  53. return false;
  54. if (y<i.y)
  55. return true;
  56. if (y>i.y)
  57. return false;
  58. if (x<i.x)
  59. return true;
  60. if (x>i.x)
  61. return false;
  62. return false;
  63. }
  64. };
  65. #endif //INT3_H