Browse Source

Move vector and matrix operators into the math::operators namespace for documentation purposes

master
C. J. Howard 2 years ago
parent
commit
c0460b31c6
3 changed files with 118 additions and 100 deletions
  1. +57
    -51
      src/math/matrix.hpp
  2. +7
    -1
      src/math/operators.hpp
  3. +54
    -48
      src/math/vector.hpp

+ 57
- 51
src/math/matrix.hpp View File

@ -974,104 +974,104 @@ constexpr matrix transpose(const matrix& m) noexcept
return transpose(m, std::make_index_sequence<M>{});
}
} // namespace math
namespace operators {
/// @copydoc math::add(const math::matrix<T, N, M>&, const math::matrix<T, N, M>&)
/// @copydoc add(const matrix<T, N, M>&, const matrix<T, N, M>&)
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M> operator+(const math::matrix<T, N, M>& a, const math::matrix<T, N, M>& b) noexcept
constexpr inline matrix<T, N, M> operator+(const matrix<T, N, M>& a, const matrix<T, N, M>& b) noexcept
{
return math::add(a, b);
return add(a, b);
}
/// @copydoc math::add(const math::matrix<T, N, M>&, T)
/// @copydoc add(const matrix<T, N, M>&, T)
/// @{
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M> operator+(const math::matrix<T, N, M>& a, T b) noexcept
constexpr inline matrix<T, N, M> operator+(const matrix<T, N, M>& a, T b) noexcept
{
return math::add(a, b);
return add(a, b);
}
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M> operator+(T a, const math::matrix<T, N, M>& b) noexcept
constexpr inline matrix<T, N, M> operator+(T a, const matrix<T, N, M>& b) noexcept
{
return math::add(b, a);
return add(b, a);
}
/// @}
/// @copydoc math::div(const math::matrix<T, N, M>&, const math::matrix<T, N, M>&)
/// @copydoc div(const matrix<T, N, M>&, const matrix<T, N, M>&)
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M> operator/(const math::matrix<T, N, M>& a, const math::matrix<T, N, M>& b) noexcept
constexpr inline matrix<T, N, M> operator/(const matrix<T, N, M>& a, const matrix<T, N, M>& b) noexcept
{
return math::div(a, b);
return div(a, b);
}
/// @copydoc math::div(const math::matrix<T, N, M>&, T)
/// @copydoc div(const matrix<T, N, M>&, T)
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M> operator/(const math::matrix<T, N, M>& a, T b) noexcept
constexpr inline matrix<T, N, M> operator/(const matrix<T, N, M>& a, T b) noexcept
{
return math::div(a, b);
return div(a, b);
}
/// @copydoc math::div(T, const math::matrix<T, N, M>&)
/// @copydoc div(T, const matrix<T, N, M>&)
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M> operator/(T a, const math::matrix<T, N, M>& b) noexcept
constexpr inline matrix<T, N, M> operator/(T a, const matrix<T, N, M>& b) noexcept
{
return math::div(a, b);
return div(a, b);
}
/// @copydoc math::mul(const math::matrix<T, N, M>&, const math::matrix<T, P, N>&)
/// @copydoc mul(const matrix<T, N, M>&, const matrix<T, P, N>&)
template <typename T, std::size_t N, std::size_t M, std::size_t P>
constexpr inline math::matrix<T, P, M> operator*(const math::matrix<T, N, M>& a, const math::matrix<T, P, N>& b) noexcept
constexpr inline matrix<T, P, M> operator*(const matrix<T, N, M>& a, const matrix<T, P, N>& b) noexcept
{
return math::mul(a, b);
return mul(a, b);
}
/// @copydoc math::mul(const math::matrix<T, N, M>&, T)
/// @copydoc mul(const matrix<T, N, M>&, T)
/// @{
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M> operator*(const math::matrix<T, N, M>& a, T b) noexcept
constexpr inline matrix<T, N, M> operator*(const matrix<T, N, M>& a, T b) noexcept
{
return math::mul(a, b);
return mul(a, b);
}
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M> operator*(T a, const math::matrix<T, N, M>& b) noexcept
constexpr inline matrix<T, N, M> operator*(T a, const matrix<T, N, M>& b) noexcept
{
return math::mul(b, a);
return mul(b, a);
}
/// @}
/// @copydoc math::mul(const math::matrix<T, N, M>&, const typename math::matrix<T, N, M>::row_vector_type&)
/// @copydoc mul(const matrix<T, N, M>&, const typename matrix<T, N, M>::row_vector_type&)
template <typename T, std::size_t N, std::size_t M>
constexpr inline typename math::matrix<T, N, M>::column_vector_type operator*(const math::matrix<T, N, M>& a, const typename math::matrix<T, N, M>::row_vector_type& b) noexcept
constexpr inline typename matrix<T, N, M>::column_vector_type operator*(const matrix<T, N, M>& a, const typename matrix<T, N, M>::row_vector_type& b) noexcept
{
return math::mul(a, b);
return mul(a, b);
}
/// @copydoc math::mul(const typename math::matrix<T, N, M>::column_vector_type&, const math::matrix<T, N, M>&)
/// @copydoc mul(const typename matrix<T, N, M>::column_vector_type&, const matrix<T, N, M>&)
template <typename T, std::size_t N, std::size_t M>
constexpr inline typename math::matrix<T, N, M>::row_vector_type operator*(const typename math::matrix<T, N, M>::column_vector_type& a, const math::matrix<T, N, M>& b) noexcept
constexpr inline typename matrix<T, N, M>::row_vector_type operator*(const typename matrix<T, N, M>::column_vector_type& a, const matrix<T, N, M>& b) noexcept
{
return math::mul(a, b);
return mul(a, b);
}
/// @copydoc math::sub(const math::matrix<T, N, M>&, const math::matrix<T, N, M>&)
/// @copydoc sub(const matrix<T, N, M>&, const matrix<T, N, M>&)
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M> operator-(const math::matrix<T, N, M>& a, const math::matrix<T, N, M>& b) noexcept
constexpr inline matrix<T, N, M> operator-(const matrix<T, N, M>& a, const matrix<T, N, M>& b) noexcept
{
return math::sub(a, b);
return sub(a, b);
}
/// @copydoc math::sub(const math::matrix<T, N, M>&, T)
/// @copydoc sub(const matrix<T, N, M>&, T)
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M> operator-(const math::matrix<T, N, M>& a, T b) noexcept
constexpr inline matrix<T, N, M> operator-(const matrix<T, N, M>& a, T b) noexcept
{
return math::sub(a, b);
return sub(a, b);
}
/// @copydoc math::sub(T, const math::matrix<T, N, M>&)
/// @copydoc sub(T, const matrix<T, N, M>&)
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M> operator-(T a, const math::matrix<T, N, M>& b) noexcept
constexpr inline matrix<T, N, M> operator-(T a, const matrix<T, N, M>& b) noexcept
{
return math::sub(a, b);
return sub(a, b);
}
/**
@ -1083,12 +1083,12 @@ constexpr inline math::matrix operator-(T a, const math::matrix
*/
/// @{
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M>& operator+=(math::matrix<T, N, M>& a, const math::matrix<T, N, M>& b) noexcept
constexpr inline matrix<T, N, M>& operator+=(matrix<T, N, M>& a, const matrix<T, N, M>& b) noexcept
{
return (a = a + b);
}
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M>& operator+=(math::matrix<T, N, M>& a, T b) noexcept
constexpr inline matrix<T, N, M>& operator+=(matrix<T, N, M>& a, T b) noexcept
{
return (a = a + b);
}
@ -1103,12 +1103,12 @@ constexpr inline math::matrix& operator+=(math::matrix& a, T b
*/
/// @{
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M>& operator-=(math::matrix<T, N, M>& a, const math::matrix<T, N, M>& b) noexcept
constexpr inline matrix<T, N, M>& operator-=(matrix<T, N, M>& a, const matrix<T, N, M>& b) noexcept
{
return (a = a - b);
}
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M>& operator-=(math::matrix<T, N, M>& a, T b) noexcept
constexpr inline matrix<T, N, M>& operator-=(matrix<T, N, M>& a, T b) noexcept
{
return (a = a - b);
}
@ -1123,12 +1123,12 @@ constexpr inline math::matrix& operator-=(math::matrix& a, T b
*/
/// @{
template <class T, std::size_t N>
constexpr inline math::matrix<T, N, N>& operator*=(math::matrix<T, N, N>& a, math::matrix<T, N, N>& b) noexcept
constexpr inline matrix<T, N, N>& operator*=(matrix<T, N, N>& a, matrix<T, N, N>& b) noexcept
{
return (a = a * b);
}
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M>& operator*=(math::matrix<T, N, M>& a, T b) noexcept
constexpr inline matrix<T, N, M>& operator*=(matrix<T, N, M>& a, T b) noexcept
{
return (a = a * b);
}
@ -1143,12 +1143,12 @@ constexpr inline math::matrix& operator*=(math::matrix& a, T b
*/
/// @{
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M>& operator/=(math::matrix<T, N, M>& a, const math::matrix<T, N, M>& b) noexcept
constexpr inline matrix<T, N, M>& operator/=(matrix<T, N, M>& a, const matrix<T, N, M>& b) noexcept
{
return (a = a / b);
}
template <class T, std::size_t N, std::size_t M>
constexpr inline math::matrix<T, N, M>& operator/=(math::matrix<T, N, M>& a, T b) noexcept
constexpr inline matrix<T, N, M>& operator/=(matrix<T, N, M>& a, T b) noexcept
{
return (a = a / b);
}
@ -1162,7 +1162,7 @@ constexpr inline math::matrix& operator/=(math::matrix& a, T b
* @return Output stream.
*/
template <class T, std::size_t N, std::size_t M>
std::ostream& operator<<(std::ostream& os, const math::matrix<T, N, M>& m)
std::ostream& operator<<(std::ostream& os, const matrix<T, N, M>& m)
{
for (std::size_t i = 0; i < m.size(); ++i)
{
@ -1182,7 +1182,7 @@ std::ostream& operator<<(std::ostream& os, const math::matrix& m)
* @return Input stream.
*/
template <class T, std::size_t N, std::size_t M>
std::istream& operator>>(std::istream& is, math::matrix<T, N, M>& m)
std::istream& operator>>(std::istream& is, matrix<T, N, M>& m)
{
for (std::size_t i = 0; i < m.size(); ++i)
is >> m.element(i);
@ -1190,4 +1190,10 @@ std::istream& operator>>(std::istream& is, math::matrix& m)
return is;
}
} // namespace operators
} // namespace math
using namespace math::operators;
#endif // ANTKEEPER_MATH_MATRIX_HPP

+ 7
- 1
src/math/operators.hpp View File

@ -20,9 +20,15 @@
#ifndef ANTKEEPER_MATH_OPERATORS_HPP
#define ANTKEEPER_MATH_OPERATORS_HPP
#include "math/matrix-operators.hpp"
#include "math/quaternion-operators.hpp"
#include "math/transform-operators.hpp"
#include "math/stream-operators.hpp"
namespace math {
/// Mathematical operators.
namespace operators {}
} // namespace math
#endif // ANTKEEPER_MATH_OPERATORS_HPP

+ 54
- 48
src/math/vector.hpp View File

@ -1324,97 +1324,97 @@ constexpr inline vector trunc(const vector& x)
return trunc(x, std::make_index_sequence<N>{});
}
} // namespace math
namespace operators {
/// @copydoc math::add(const math::vector<T, N>&, const math::vector<T, N>&)
/// @copydoc add(const vector<T, N>&, const vector<T, N>&)
template <class T, std::size_t N>
constexpr inline math::vector<T, N> operator+(const math::vector<T, N>& x, const math::vector<T, N>& y) noexcept
constexpr inline vector<T, N> operator+(const vector<T, N>& x, const vector<T, N>& y) noexcept
{
return math::add(x, y);
return add(x, y);
}
/// @copydoc math::add(const math::vector<T, N>&, T)
/// @copydoc add(const vector<T, N>&, T)
/// @{
template <class T, std::size_t N>
constexpr inline math::vector<T, N> operator+(const math::vector<T, N>& x, T y) noexcept
constexpr inline vector<T, N> operator+(const vector<T, N>& x, T y) noexcept
{
return math::add(x, y);
return add(x, y);
}
template <class T, std::size_t N>
constexpr inline math::vector<T, N> operator+(T x, const math::vector<T, N>& y) noexcept
constexpr inline vector<T, N> operator+(T x, const vector<T, N>& y) noexcept
{
return math::add(y, x);
return add(y, x);
}
/// @}
/// @copydoc math::div(const math::vector<T, N>&, const math::vector<T, N>&)
/// @copydoc div(const vector<T, N>&, const vector<T, N>&)
template <class T, std::size_t N>
constexpr inline math::vector<T, N> operator/(const math::vector<T, N>& x, const math::vector<T, N>& y) noexcept
constexpr inline vector<T, N> operator/(const vector<T, N>& x, const vector<T, N>& y) noexcept
{
return math::div(x, y);
return div(x, y);
}
/// @copydoc math::div(const math::vector<T, N>&, T)
/// @copydoc div(const vector<T, N>&, T)
template <class T, std::size_t N>
constexpr inline math::vector<T, N> operator/(const math::vector<T, N>& x, T y) noexcept
constexpr inline vector<T, N> operator/(const vector<T, N>& x, T y) noexcept
{
return math::div(x, y);
return div(x, y);
}
/// @copydoc math::div(T, const math::vector<T, N>&)
/// @copydoc div(T, const vector<T, N>&)
template <class T, std::size_t N>
constexpr inline math::vector<T, N> operator/(T x, const math::vector<T, N>& y) noexcept
constexpr inline vector<T, N> operator/(T x, const vector<T, N>& y) noexcept
{
return math::div(x, y);
return div(x, y);
}
/// @copydoc math::mul(const math::vector<T, N>&, const math::vector<T, N>&)
/// @copydoc mul(const vector<T, N>&, const vector<T, N>&)
template <class T, std::size_t N>
constexpr inline math::vector<T, N> operator*(const math::vector<T, N>& x, const math::vector<T, N>& y) noexcept
constexpr inline vector<T, N> operator*(const vector<T, N>& x, const vector<T, N>& y) noexcept
{
return math::mul(x, y);
return mul(x, y);
}
/// @copydoc math::mul(const math::vector<T, N>&, T)
/// @copydoc mul(const vector<T, N>&, T)
/// @{
template <class T, std::size_t N>
constexpr inline math::vector<T, N> operator*(const math::vector<T, N>& x, T y) noexcept
constexpr inline vector<T, N> operator*(const vector<T, N>& x, T y) noexcept
{
return math::mul(x, y);
return mul(x, y);
}
template <class T, std::size_t N>
constexpr inline math::vector<T, N> operator*(T x, const math::vector<T, N>& y) noexcept
constexpr inline vector<T, N> operator*(T x, const vector<T, N>& y) noexcept
{
return math::mul(y, x);
return mul(y, x);
}
/// @}
/// @copydoc math::negate(const math::vector<T, N>&)
/// @copydoc negate(const vector<T, N>&)
template <class T, std::size_t N>
constexpr inline math::vector<T, N> operator-(const math::vector<T, N>& x) noexcept
constexpr inline vector<T, N> operator-(const vector<T, N>& x) noexcept
{
return math::negate(x);
return negate(x);
}
/// @copydoc math::sub(const math::vector<T, N>&, const math::vector<T, N>&)
/// @copydoc sub(const vector<T, N>&, const vector<T, N>&)
template <class T, std::size_t N>
constexpr inline math::vector<T, N> operator-(const math::vector<T, N>& x, const math::vector<T, N>& y) noexcept
constexpr inline vector<T, N> operator-(const vector<T, N>& x, const vector<T, N>& y) noexcept
{
return math::sub(x, y);
return sub(x, y);
}
/// @copydoc math::sub(const math::vector<T, N>&, T)
/// @copydoc sub(const vector<T, N>&, T)
template <class T, std::size_t N>
constexpr inline math::vector<T, N> operator-(const math::vector<T, N>& x, T y) noexcept
constexpr inline vector<T, N> operator-(const vector<T, N>& x, T y) noexcept
{
return math::sub(x, y);
return sub(x, y);
}
/// @copydoc math::sub(T, const math::vector<T, N>&)
/// @copydoc sub(T, const vector<T, N>&)
template <class T, std::size_t N>
constexpr inline math::vector<T, N> operator-(T x, const math::vector<T, N>& y) noexcept
constexpr inline vector<T, N> operator-(T x, const vector<T, N>& y) noexcept
{
return math::sub(x, y);
return sub(x, y);
}
/**
@ -1426,12 +1426,12 @@ constexpr inline math::vector operator-(T x, const math::vector& y)
*/
/// @{
template <class T, std::size_t N>
constexpr inline math::vector<T, N>& operator+=(math::vector<T, N>& x, const math::vector<T, N>& y) noexcept
constexpr inline vector<T, N>& operator+=(vector<T, N>& x, const vector<T, N>& y) noexcept
{
return (x = x + y);
}
template <class T, std::size_t N>
constexpr inline math::vector<T, N>& operator+=(math::vector<T, N>& x, T y) noexcept
constexpr inline vector<T, N>& operator+=(vector<T, N>& x, T y) noexcept
{
return (x = x + y);
}
@ -1446,12 +1446,12 @@ constexpr inline math::vector& operator+=(math::vector& x, T y) noex
*/
/// @{
template <class T, std::size_t N>
constexpr inline math::vector<T, N>& operator-=(math::vector<T, N>& x, const math::vector<T, N>& y) noexcept
constexpr inline vector<T, N>& operator-=(vector<T, N>& x, const vector<T, N>& y) noexcept
{
return (x = x - y);
}
template <class T, std::size_t N>
constexpr inline math::vector<T, N>& operator-=(math::vector<T, N>& x, T y) noexcept
constexpr inline vector<T, N>& operator-=(vector<T, N>& x, T y) noexcept
{
return (x = x - y);
}
@ -1466,12 +1466,12 @@ constexpr inline math::vector& operator-=(math::vector& x, T y) noex
*/
/// @{
template <class T, std::size_t N>
constexpr inline math::vector<T, N>& operator*=(math::vector<T, N>& x, const math::vector<T, N>& y) noexcept
constexpr inline vector<T, N>& operator*=(vector<T, N>& x, const vector<T, N>& y) noexcept
{
return (x = x * y);
}
template <class T, std::size_t N>
constexpr inline math::vector<T, N>& operator*=(math::vector<T, N>& x, T y) noexcept
constexpr inline vector<T, N>& operator*=(vector<T, N>& x, T y) noexcept
{
return (x = x * y);
}
@ -1486,12 +1486,12 @@ constexpr inline math::vector& operator*=(math::vector& x, T y) noex
*/
/// @{
template <class T, std::size_t N>
constexpr inline math::vector<T, N>& operator/=(math::vector<T, N>& x, const math::vector<T, N>& y) noexcept
constexpr inline vector<T, N>& operator/=(vector<T, N>& x, const vector<T, N>& y) noexcept
{
return (x = x / y);
}
template <class T, std::size_t N>
constexpr inline math::vector<T, N>& operator/=(math::vector<T, N>& x, T y) noexcept
constexpr inline vector<T, N>& operator/=(vector<T, N>& x, T y) noexcept
{
return (x = x / y);
}
@ -1506,7 +1506,7 @@ constexpr inline math::vector& operator/=(math::vector& x, T y) noex
* @return Output stream.
*/
template <class T, std::size_t N>
std::ostream& operator<<(std::ostream& os, const math::vector<T, N>& x)
std::ostream& operator<<(std::ostream& os, const vector<T, N>& x)
{
for (std::size_t i = 0; i < N; ++i)
{
@ -1527,7 +1527,7 @@ std::ostream& operator<<(std::ostream& os, const math::vector& x)
* @return Input stream.
*/
template <class T, std::size_t N>
std::istream& operator>>(std::istream& is, math::vector<T, N>& x)
std::istream& operator>>(std::istream& is, vector<T, N>& x)
{
for (std::size_t i = 0; i < N; ++i)
is >> x[i];
@ -1535,4 +1535,10 @@ std::istream& operator>>(std::istream& is, math::vector& x)
return is;
}
} // namespace operators
} // namespace math
using namespace math::operators;
#endif // ANTKEEPER_MATH_VECTOR_HPP

Loading…
Cancel
Save