Face.cpp 1.2 KB

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