MatrixStack.h 837 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef MATRIXSTACK_H
  2. #define MATRIXSTACK_H
  3. #include "math/Matrix.h"
  4. #include "utils/ArrayList.h"
  5. template<int N>
  6. class MatrixStack final {
  7. ArrayList<Matrix, N> stack;
  8. public:
  9. MatrixStack() {
  10. stack.add(Matrix());
  11. }
  12. bool pop() {
  13. stack.remove(stack.getLength() - 1);
  14. if(stack.getLength() == 0) {
  15. stack.add(Matrix());
  16. return true;
  17. }
  18. return false;
  19. }
  20. bool push() {
  21. return stack.add(peek());
  22. }
  23. Matrix& peek() {
  24. return stack[stack.getLength() - 1];
  25. }
  26. const Matrix& peek() const {
  27. return stack[stack.getLength() - 1];
  28. }
  29. void clear() {
  30. stack.clear();
  31. stack.add(Matrix());
  32. }
  33. template<int L>
  34. void toString(StringBuffer<L>& s) const {
  35. s.append(stack);
  36. }
  37. };
  38. #endif