💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.1 KiB

  1. /*
  2. * Copyright (C) 2020 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_MATH_MATRIX_OPERATORS_HPP
  20. #define ANTKEEPER_MATH_MATRIX_OPERATORS_HPP
  21. #include "math/matrix-type.hpp"
  22. #include "math/matrix-functions.hpp"
  23. namespace math {
  24. namespace matrix_operators {
  25. /// @addtogroup matrix
  26. /// @{
  27. /// @copydoc add(const matrix<T, 2, 2>&, const matrix<T, 2, 2>&)
  28. template <class T, std::size_t N, std::size_t M>
  29. matrix<T, N, M> operator+(const matrix<T, N, M>& x, const matrix<T, N, M>& y);
  30. /// @copydoc mul(const matrix<T, 2, 2>&, const matrix<T, 2, 2>&)
  31. template <class T, std::size_t N, std::size_t M>
  32. matrix<T, N, M> operator*(const matrix<T, N, M>& x, const matrix<T, N, M>& y);
  33. /// @copydoc mul(const matrix<T, N, M>&, T)
  34. template <class T, std::size_t N, std::size_t M>
  35. matrix<T, N, M> operator*(const matrix<T, N, M>& m, T s);
  36. /// @copydoc mul(const matrix<T, N, M>&, T)
  37. template <class T, std::size_t N, std::size_t M>
  38. matrix<T, N, M> operator*(T s, const matrix<T, N, M>& m);
  39. /// @copydoc mul(const matrix<T, 2, 2>&, const vector<T, 2>&)
  40. template <class T, std::size_t N>
  41. vector<T, N> operator*(const matrix<T, N, N>& m, const vector<T, N>& v);
  42. /// @copydoc sub(const matrix<T, 2, 2>&, const matrix<T, 2, 2>&)
  43. template <class T, std::size_t N, std::size_t M>
  44. matrix<T, N, M> operator-(const matrix<T, N, M>& x, const matrix<T, N, M>& y);
  45. template <class T, std::size_t N, std::size_t M>
  46. inline matrix<T, N, M> operator+(const matrix<T, N, M>& x, const matrix<T, N, M>& y)
  47. {
  48. return add(x, y);
  49. }
  50. template <class T, std::size_t N, std::size_t M>
  51. inline matrix<T, N, M> operator*(const matrix<T, N, M>& x, const matrix<T, N, M>& y)
  52. {
  53. return mul(x, y);
  54. }
  55. template <class T, std::size_t N, std::size_t M>
  56. inline matrix<T, N, M> operator*(const matrix<T, N, M>& m, T s)
  57. {
  58. return mul(m, s);
  59. }
  60. template <class T, std::size_t N, std::size_t M>
  61. inline matrix<T, N, M> operator*(T s, const matrix<T, N, M>& m)
  62. {
  63. return mul(m, s);
  64. }
  65. template <class T, std::size_t N>
  66. inline vector<T, N> operator*(const matrix<T, N, N>& m, const vector<T, N>& v)
  67. {
  68. return mul(m, v);
  69. }
  70. template <class T, std::size_t N, std::size_t M>
  71. inline matrix<T, N, M> operator-(const matrix<T, N, M>& x, const matrix<T, N, M>& y)
  72. {
  73. return sub(x, y);
  74. }
  75. /// @}
  76. } // namespace matrix_operators
  77. } // namespace math
  78. // Bring matrix operators into global namespace
  79. using namespace math::matrix_operators;
  80. #endif // ANTKEEPER_MATH_MATRIX_OPERATORS_HPP