From c0460b31c612016b25049dbd451c1b3fa8065bff Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Sat, 22 Oct 2022 19:06:36 +0800 Subject: [PATCH] Move vector and matrix operators into the math::operators namespace for documentation purposes --- src/math/matrix.hpp | 108 ++++++++++++++++++++++------------------- src/math/operators.hpp | 8 ++- src/math/vector.hpp | 102 ++++++++++++++++++++------------------ 3 files changed, 118 insertions(+), 100 deletions(-) diff --git a/src/math/matrix.hpp b/src/math/matrix.hpp index 4d46974..a6a98a2 100644 --- a/src/math/matrix.hpp +++ b/src/math/matrix.hpp @@ -974,104 +974,104 @@ constexpr matrix transpose(const matrix& m) noexcept return transpose(m, std::make_index_sequence{}); } -} // namespace math +namespace operators { -/// @copydoc math::add(const math::matrix&, const math::matrix&) +/// @copydoc add(const matrix&, const matrix&) template -constexpr inline math::matrix operator+(const math::matrix& a, const math::matrix& b) noexcept +constexpr inline matrix operator+(const matrix& a, const matrix& b) noexcept { - return math::add(a, b); + return add(a, b); } -/// @copydoc math::add(const math::matrix&, T) +/// @copydoc add(const matrix&, T) /// @{ template -constexpr inline math::matrix operator+(const math::matrix& a, T b) noexcept +constexpr inline matrix operator+(const matrix& a, T b) noexcept { - return math::add(a, b); + return add(a, b); } template -constexpr inline math::matrix operator+(T a, const math::matrix& b) noexcept +constexpr inline matrix operator+(T a, const matrix& b) noexcept { - return math::add(b, a); + return add(b, a); } /// @} -/// @copydoc math::div(const math::matrix&, const math::matrix&) +/// @copydoc div(const matrix&, const matrix&) template -constexpr inline math::matrix operator/(const math::matrix& a, const math::matrix& b) noexcept +constexpr inline matrix operator/(const matrix& a, const matrix& b) noexcept { - return math::div(a, b); + return div(a, b); } -/// @copydoc math::div(const math::matrix&, T) +/// @copydoc div(const matrix&, T) template -constexpr inline math::matrix operator/(const math::matrix& a, T b) noexcept +constexpr inline matrix operator/(const matrix& a, T b) noexcept { - return math::div(a, b); + return div(a, b); } -/// @copydoc math::div(T, const math::matrix&) +/// @copydoc div(T, const matrix&) template -constexpr inline math::matrix operator/(T a, const math::matrix& b) noexcept +constexpr inline matrix operator/(T a, const matrix& b) noexcept { - return math::div(a, b); + return div(a, b); } -/// @copydoc math::mul(const math::matrix&, const math::matrix&) +/// @copydoc mul(const matrix&, const matrix&) template -constexpr inline math::matrix operator*(const math::matrix& a, const math::matrix& b) noexcept +constexpr inline matrix operator*(const matrix& a, const matrix& b) noexcept { - return math::mul(a, b); + return mul(a, b); } -/// @copydoc math::mul(const math::matrix&, T) +/// @copydoc mul(const matrix&, T) /// @{ template -constexpr inline math::matrix operator*(const math::matrix& a, T b) noexcept +constexpr inline matrix operator*(const matrix& a, T b) noexcept { - return math::mul(a, b); + return mul(a, b); } template -constexpr inline math::matrix operator*(T a, const math::matrix& b) noexcept +constexpr inline matrix operator*(T a, const matrix& b) noexcept { - return math::mul(b, a); + return mul(b, a); } /// @} -/// @copydoc math::mul(const math::matrix&, const typename math::matrix::row_vector_type&) +/// @copydoc mul(const matrix&, const typename matrix::row_vector_type&) template -constexpr inline typename math::matrix::column_vector_type operator*(const math::matrix& a, const typename math::matrix::row_vector_type& b) noexcept +constexpr inline typename matrix::column_vector_type operator*(const matrix& a, const typename matrix::row_vector_type& b) noexcept { - return math::mul(a, b); + return mul(a, b); } -/// @copydoc math::mul(const typename math::matrix::column_vector_type&, const math::matrix&) +/// @copydoc mul(const typename matrix::column_vector_type&, const matrix&) template -constexpr inline typename math::matrix::row_vector_type operator*(const typename math::matrix::column_vector_type& a, const math::matrix& b) noexcept +constexpr inline typename matrix::row_vector_type operator*(const typename matrix::column_vector_type& a, const matrix& b) noexcept { - return math::mul(a, b); + return mul(a, b); } -/// @copydoc math::sub(const math::matrix&, const math::matrix&) +/// @copydoc sub(const matrix&, const matrix&) template -constexpr inline math::matrix operator-(const math::matrix& a, const math::matrix& b) noexcept +constexpr inline matrix operator-(const matrix& a, const matrix& b) noexcept { - return math::sub(a, b); + return sub(a, b); } -/// @copydoc math::sub(const math::matrix&, T) +/// @copydoc sub(const matrix&, T) template -constexpr inline math::matrix operator-(const math::matrix& a, T b) noexcept +constexpr inline matrix operator-(const matrix& a, T b) noexcept { - return math::sub(a, b); + return sub(a, b); } -/// @copydoc math::sub(T, const math::matrix&) +/// @copydoc sub(T, const matrix&) template -constexpr inline math::matrix operator-(T a, const math::matrix& b) noexcept +constexpr inline matrix operator-(T a, const matrix& 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 -constexpr inline math::matrix& operator+=(math::matrix& a, const math::matrix& b) noexcept +constexpr inline matrix& operator+=(matrix& a, const matrix& b) noexcept { return (a = a + b); } template -constexpr inline math::matrix& operator+=(math::matrix& a, T b) noexcept +constexpr inline matrix& operator+=(matrix& a, T b) noexcept { return (a = a + b); } @@ -1103,12 +1103,12 @@ constexpr inline math::matrix& operator+=(math::matrix& a, T b */ /// @{ template -constexpr inline math::matrix& operator-=(math::matrix& a, const math::matrix& b) noexcept +constexpr inline matrix& operator-=(matrix& a, const matrix& b) noexcept { return (a = a - b); } template -constexpr inline math::matrix& operator-=(math::matrix& a, T b) noexcept +constexpr inline matrix& operator-=(matrix& a, T b) noexcept { return (a = a - b); } @@ -1123,12 +1123,12 @@ constexpr inline math::matrix& operator-=(math::matrix& a, T b */ /// @{ template -constexpr inline math::matrix& operator*=(math::matrix& a, math::matrix& b) noexcept +constexpr inline matrix& operator*=(matrix& a, matrix& b) noexcept { return (a = a * b); } template -constexpr inline math::matrix& operator*=(math::matrix& a, T b) noexcept +constexpr inline matrix& operator*=(matrix& a, T b) noexcept { return (a = a * b); } @@ -1143,12 +1143,12 @@ constexpr inline math::matrix& operator*=(math::matrix& a, T b */ /// @{ template -constexpr inline math::matrix& operator/=(math::matrix& a, const math::matrix& b) noexcept +constexpr inline matrix& operator/=(matrix& a, const matrix& b) noexcept { return (a = a / b); } template -constexpr inline math::matrix& operator/=(math::matrix& a, T b) noexcept +constexpr inline matrix& operator/=(matrix& 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 -std::ostream& operator<<(std::ostream& os, const math::matrix& m) +std::ostream& operator<<(std::ostream& os, const matrix& 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 -std::istream& operator>>(std::istream& is, math::matrix& m) +std::istream& operator>>(std::istream& is, matrix& 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 diff --git a/src/math/operators.hpp b/src/math/operators.hpp index 64ed239..0387520 100644 --- a/src/math/operators.hpp +++ b/src/math/operators.hpp @@ -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 diff --git a/src/math/vector.hpp b/src/math/vector.hpp index 62fd7a2..e5ad5cb 100644 --- a/src/math/vector.hpp +++ b/src/math/vector.hpp @@ -1324,97 +1324,97 @@ constexpr inline vector trunc(const vector& x) return trunc(x, std::make_index_sequence{}); } -} // namespace math +namespace operators { -/// @copydoc math::add(const math::vector&, const math::vector&) +/// @copydoc add(const vector&, const vector&) template -constexpr inline math::vector operator+(const math::vector& x, const math::vector& y) noexcept +constexpr inline vector operator+(const vector& x, const vector& y) noexcept { - return math::add(x, y); + return add(x, y); } -/// @copydoc math::add(const math::vector&, T) +/// @copydoc add(const vector&, T) /// @{ template -constexpr inline math::vector operator+(const math::vector& x, T y) noexcept +constexpr inline vector operator+(const vector& x, T y) noexcept { - return math::add(x, y); + return add(x, y); } template -constexpr inline math::vector operator+(T x, const math::vector& y) noexcept +constexpr inline vector operator+(T x, const vector& y) noexcept { - return math::add(y, x); + return add(y, x); } /// @} -/// @copydoc math::div(const math::vector&, const math::vector&) +/// @copydoc div(const vector&, const vector&) template -constexpr inline math::vector operator/(const math::vector& x, const math::vector& y) noexcept +constexpr inline vector operator/(const vector& x, const vector& y) noexcept { - return math::div(x, y); + return div(x, y); } -/// @copydoc math::div(const math::vector&, T) +/// @copydoc div(const vector&, T) template -constexpr inline math::vector operator/(const math::vector& x, T y) noexcept +constexpr inline vector operator/(const vector& x, T y) noexcept { - return math::div(x, y); + return div(x, y); } -/// @copydoc math::div(T, const math::vector&) +/// @copydoc div(T, const vector&) template -constexpr inline math::vector operator/(T x, const math::vector& y) noexcept +constexpr inline vector operator/(T x, const vector& y) noexcept { - return math::div(x, y); + return div(x, y); } -/// @copydoc math::mul(const math::vector&, const math::vector&) +/// @copydoc mul(const vector&, const vector&) template -constexpr inline math::vector operator*(const math::vector& x, const math::vector& y) noexcept +constexpr inline vector operator*(const vector& x, const vector& y) noexcept { - return math::mul(x, y); + return mul(x, y); } -/// @copydoc math::mul(const math::vector&, T) +/// @copydoc mul(const vector&, T) /// @{ template -constexpr inline math::vector operator*(const math::vector& x, T y) noexcept +constexpr inline vector operator*(const vector& x, T y) noexcept { - return math::mul(x, y); + return mul(x, y); } template -constexpr inline math::vector operator*(T x, const math::vector& y) noexcept +constexpr inline vector operator*(T x, const vector& y) noexcept { - return math::mul(y, x); + return mul(y, x); } /// @} -/// @copydoc math::negate(const math::vector&) +/// @copydoc negate(const vector&) template -constexpr inline math::vector operator-(const math::vector& x) noexcept +constexpr inline vector operator-(const vector& x) noexcept { - return math::negate(x); + return negate(x); } -/// @copydoc math::sub(const math::vector&, const math::vector&) +/// @copydoc sub(const vector&, const vector&) template -constexpr inline math::vector operator-(const math::vector& x, const math::vector& y) noexcept +constexpr inline vector operator-(const vector& x, const vector& y) noexcept { - return math::sub(x, y); + return sub(x, y); } -/// @copydoc math::sub(const math::vector&, T) +/// @copydoc sub(const vector&, T) template -constexpr inline math::vector operator-(const math::vector& x, T y) noexcept +constexpr inline vector operator-(const vector& x, T y) noexcept { - return math::sub(x, y); + return sub(x, y); } -/// @copydoc math::sub(T, const math::vector&) +/// @copydoc sub(T, const vector&) template -constexpr inline math::vector operator-(T x, const math::vector& y) noexcept +constexpr inline vector operator-(T x, const vector& 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 -constexpr inline math::vector& operator+=(math::vector& x, const math::vector& y) noexcept +constexpr inline vector& operator+=(vector& x, const vector& y) noexcept { return (x = x + y); } template -constexpr inline math::vector& operator+=(math::vector& x, T y) noexcept +constexpr inline vector& operator+=(vector& x, T y) noexcept { return (x = x + y); } @@ -1446,12 +1446,12 @@ constexpr inline math::vector& operator+=(math::vector& x, T y) noex */ /// @{ template -constexpr inline math::vector& operator-=(math::vector& x, const math::vector& y) noexcept +constexpr inline vector& operator-=(vector& x, const vector& y) noexcept { return (x = x - y); } template -constexpr inline math::vector& operator-=(math::vector& x, T y) noexcept +constexpr inline vector& operator-=(vector& x, T y) noexcept { return (x = x - y); } @@ -1466,12 +1466,12 @@ constexpr inline math::vector& operator-=(math::vector& x, T y) noex */ /// @{ template -constexpr inline math::vector& operator*=(math::vector& x, const math::vector& y) noexcept +constexpr inline vector& operator*=(vector& x, const vector& y) noexcept { return (x = x * y); } template -constexpr inline math::vector& operator*=(math::vector& x, T y) noexcept +constexpr inline vector& operator*=(vector& x, T y) noexcept { return (x = x * y); } @@ -1486,12 +1486,12 @@ constexpr inline math::vector& operator*=(math::vector& x, T y) noex */ /// @{ template -constexpr inline math::vector& operator/=(math::vector& x, const math::vector& y) noexcept +constexpr inline vector& operator/=(vector& x, const vector& y) noexcept { return (x = x / y); } template -constexpr inline math::vector& operator/=(math::vector& x, T y) noexcept +constexpr inline vector& operator/=(vector& 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 -std::ostream& operator<<(std::ostream& os, const math::vector& x) +std::ostream& operator<<(std::ostream& os, const vector& 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 -std::istream& operator>>(std::istream& is, math::vector& x) +std::istream& operator>>(std::istream& is, vector& 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