int3.h 1.4 KB

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