💿🐜 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.

203 lines
5.9 KiB

  1. /*
  2. * Copyright (C) 2021 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_VECTOR_OPERATORS_HPP
  20. #define ANTKEEPER_MATH_VECTOR_OPERATORS_HPP
  21. #include "math/vector-type.hpp"
  22. #include "math/vector-functions.hpp"
  23. /// @copydoc math::add(const math::vector<T, N>&, const math::vector<T, N>&)
  24. template <class T, std::size_t N>
  25. math::vector<T, N> operator+(const math::vector<T, N>& x, const math::vector<T, N>& y);
  26. /// @copydoc math::div(const math::vector<T, N>&, const math::vector<T, N>&)
  27. template <class T, std::size_t N>
  28. math::vector<T, N> operator/(const math::vector<T, N>& x, const math::vector<T, N>& y);
  29. /// @copydoc math::div(const math::vector<T, N>&, T)
  30. template <class T, std::size_t N>
  31. math::vector<T, N> operator/(const math::vector<T, N>& v, T s);
  32. /// @copydoc math::mul(const math::vector<T, N>&, const math::vector<T, N>&)
  33. template <class T, std::size_t N>
  34. math::vector<T, N> operator*(const math::vector<T, N>& x, const math::vector<T, N>& y);
  35. /// @copydoc math::mul(const math::vector<T, N>&, T)
  36. template <class T, std::size_t N>
  37. math::vector<T, N> operator*(const math::vector<T, N>& v, T s);
  38. /// @copydoc math::mul(const math::vector<T, N>&, T)
  39. template <class T, std::size_t N>
  40. math::vector<T, N> operator*(T s, const math::vector<T, N>& v);
  41. /// @copydoc math::negate(const math::vector<T, N>&)
  42. template <class T, std::size_t N>
  43. math::vector<T, N> operator-(const math::vector<T, N>& x);
  44. /// @copydoc math::sub(const math::vector<T, N>&, const math::vector<T, N>&)
  45. template <class T, std::size_t N>
  46. math::vector<T, N> operator-(const math::vector<T, N>& x, const math::vector<T, N>& y);
  47. /**
  48. * Adds two vectors and stores the result in the first vector.
  49. *
  50. * @param x First vector.
  51. * @param y Second vector.
  52. * @return Reference to the first vector.
  53. */
  54. template <class T, std::size_t N>
  55. math::vector<T, N>& operator+=(math::vector<T, N>& x, const math::vector<T, N>& y);
  56. /**
  57. * Subtracts two vectors and stores the result in the first vector.
  58. *
  59. * @param x First vector.
  60. * @param y Second vector.
  61. * @return Reference to the first vector.
  62. */
  63. template <class T, std::size_t N>
  64. math::vector<T, N>& operator-=(math::vector<T, N>& x, const math::vector<T, N>& y);
  65. /**
  66. * Multiplies two vectors and stores the result in the first vector.
  67. *
  68. * @param x First vector.
  69. * @param y Second vector.
  70. * @return Reference to the first vector.
  71. */
  72. template <class T, std::size_t N>
  73. math::vector<T, N>& operator*=(math::vector<T, N>& x, const math::vector<T, N>& y);
  74. /**
  75. * Multiplies a vector and a scalar and stores the result in the vector.
  76. *
  77. * @param v Vector.
  78. * @param s Scalar.
  79. * @return Reference to the vector.
  80. */
  81. template <class T, std::size_t N>
  82. math::vector<T, N>& operator*=(math::vector<T, N>& v, T s);
  83. /**
  84. * Divides the first vector by the second vector the result in the first vector.
  85. *
  86. * @param x First vector.
  87. * @param y Second vector.
  88. * @return Reference to the first vector.
  89. */
  90. template <class T, std::size_t N>
  91. math::vector<T, N>& operator/=(math::vector<T, N>& x, const math::vector<T, N>& y);
  92. /**
  93. * Divides a vector by a scalar and stores the result in the vector.
  94. *
  95. * @param v Vector.
  96. * @param s Scalar.
  97. * @return Reference to the vector.
  98. */
  99. template <class T, std::size_t N>
  100. math::vector<T, N>& operator/=(math::vector<T, N>& v, T s);
  101. template <class T, std::size_t N>
  102. inline math::vector<T, N> operator+(const math::vector<T, N>& x, const math::vector<T, N>& y)
  103. {
  104. return add(x, y);
  105. }
  106. template <class T, std::size_t N>
  107. inline math::vector<T, N> operator-(const math::vector<T, N>& x)
  108. {
  109. return negate(x);
  110. }
  111. template <class T, std::size_t N>
  112. inline math::vector<T, N> operator-(const math::vector<T, N>& x, const math::vector<T, N>& y)
  113. {
  114. return sub(x, y);
  115. }
  116. template <class T, std::size_t N>
  117. inline math::vector<T, N> operator*(const math::vector<T, N>& x, const math::vector<T, N>& y)
  118. {
  119. return mul(x, y);
  120. }
  121. template <class T, std::size_t N>
  122. inline math::vector<T, N> operator*(const math::vector<T, N>& v, T s)
  123. {
  124. return mul(v, s);
  125. }
  126. template <class T, std::size_t N>
  127. inline math::vector<T, N> operator*(T s, const math::vector<T, N>& v)
  128. {
  129. return mul(v, s);
  130. }
  131. template <class T, std::size_t N>
  132. inline math::vector<T, N> operator/(const math::vector<T, N>& x, const math::vector<T, N>& y)
  133. {
  134. return div(x, y);
  135. }
  136. template <class T, std::size_t N>
  137. inline math::vector<T, N> operator/(const math::vector<T, N>& v, T s)
  138. {
  139. return div(v, s);
  140. }
  141. template <class T, std::size_t N>
  142. inline math::vector<T, N>& operator+=(math::vector<T, N>& x, const math::vector<T, N>& y)
  143. {
  144. return (x = x + y);
  145. }
  146. template <class T, std::size_t N>
  147. inline math::vector<T, N>& operator-=(math::vector<T, N>& x, const math::vector<T, N>& y)
  148. {
  149. return (x = x - y);
  150. }
  151. template <class T, std::size_t N>
  152. inline math::vector<T, N>& operator*=(math::vector<T, N>& x, const math::vector<T, N>& y)
  153. {
  154. return (x = x * y);
  155. }
  156. template <class T, std::size_t N>
  157. inline math::vector<T, N>& operator*=(math::vector<T, N>& v, T s)
  158. {
  159. return (v = v * s);
  160. }
  161. template <class T, std::size_t N>
  162. inline math::vector<T, N>& operator/=(math::vector<T, N>& x, const math::vector<T, N>& y)
  163. {
  164. return (x = x * y);
  165. }
  166. template <class T, std::size_t N>
  167. inline math::vector<T, N>& operator/=(math::vector<T, N>& v, T s)
  168. {
  169. return (v = v / s);
  170. }
  171. #endif // ANTKEEPER_MATH_VECTOR_OPERATORS_HPP