Face.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "common/utils/Face.h"
  2. Face Face::FACES[6] =
  3. {
  4. {0, 0, 1, 0, "Up"},
  5. {1, 1, 0, 0, "North"},
  6. {2, 0, 0, 1, "East"},
  7. {3, 0, -1, 0, "Down"},
  8. {4, -1, 0, 0, "South"},
  9. {5, 0, 0, -1, "West"}
  10. };
  11. const Face& Face::UP = FACES[0];
  12. const Face& Face::DOWN = FACES[3];
  13. const Face& Face::NORTH = FACES[1];
  14. const Face& Face::SOUTH = FACES[4];
  15. const Face& Face::EAST = FACES[2];
  16. const Face& Face::WEST = FACES[5];
  17. Face::Face(int index, int offsetX, int offsetY, int offsetZ, const char* name) :
  18. index(index), offsetX(offsetX), offsetY(offsetY), offsetZ(offsetZ), name(name)
  19. {
  20. }
  21. int Face::getX() const
  22. {
  23. return offsetX;
  24. }
  25. int Face::getY() const
  26. {
  27. return offsetY;
  28. }
  29. int Face::getZ() const
  30. {
  31. return offsetZ;
  32. }
  33. Face& Face::getOpposite() const
  34. {
  35. return FACES[(index + 3) % 6];
  36. }
  37. const char* Face::getName() const
  38. {
  39. return name;
  40. }
  41. void Face::forEach(const std::function<void(Face&)>& f)
  42. {
  43. for(int i = 0; i < 6; i++)
  44. {
  45. f(FACES[i]);
  46. }
  47. }
  48. bool operator==(const Face& l, const Face& r)
  49. {
  50. return &l == &r;
  51. }
  52. bool operator!=(const Face& l, const Face& r)
  53. {
  54. return &l != &r;
  55. }
  56. std::ostream& operator<<(std::ostream& os, const Face& f)
  57. {
  58. os << f.getName();
  59. return os;
  60. }