/* * Copyright (C) 2021 Christopher J. Howard * * This file is part of Antkeeper source code. * * Antkeeper source code is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Antkeeper source code is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Antkeeper source code. If not, see . */ #ifndef ANTKEEPER_MATH_VECTOR_OPERATORS_HPP #define ANTKEEPER_MATH_VECTOR_OPERATORS_HPP #include "math/vector-type.hpp" #include "math/vector-functions.hpp" /// @copydoc math::add(const math::vector&, const math::vector&) template math::vector operator+(const math::vector& x, const math::vector& y); /// @copydoc math::div(const math::vector&, const math::vector&) template math::vector operator/(const math::vector& x, const math::vector& y); /// @copydoc math::div(const math::vector&, T) template math::vector operator/(const math::vector& v, T s); /// @copydoc math::mul(const math::vector&, const math::vector&) template math::vector operator*(const math::vector& x, const math::vector& y); /// @copydoc math::mul(const math::vector&, T) template math::vector operator*(const math::vector& v, T s); /// @copydoc math::mul(const math::vector&, T) template math::vector operator*(T s, const math::vector& v); /// @copydoc math::negate(const math::vector&) template math::vector operator-(const math::vector& x); /// @copydoc math::sub(const math::vector&, const math::vector&) template math::vector operator-(const math::vector& x, const math::vector& y); /** * Adds two vectors and stores the result in the first vector. * * @param x First vector. * @param y Second vector. * @return Reference to the first vector. */ template math::vector& operator+=(math::vector& x, const math::vector& y); /** * Subtracts two vectors and stores the result in the first vector. * * @param x First vector. * @param y Second vector. * @return Reference to the first vector. */ template math::vector& operator-=(math::vector& x, const math::vector& y); /** * Multiplies two vectors and stores the result in the first vector. * * @param x First vector. * @param y Second vector. * @return Reference to the first vector. */ template math::vector& operator*=(math::vector& x, const math::vector& y); /** * Multiplies a vector and a scalar and stores the result in the vector. * * @param v Vector. * @param s Scalar. * @return Reference to the vector. */ template math::vector& operator*=(math::vector& v, T s); /** * Divides the first vector by the second vector the result in the first vector. * * @param x First vector. * @param y Second vector. * @return Reference to the first vector. */ template math::vector& operator/=(math::vector& x, const math::vector& y); /** * Divides a vector by a scalar and stores the result in the vector. * * @param v Vector. * @param s Scalar. * @return Reference to the vector. */ template math::vector& operator/=(math::vector& v, T s); template inline math::vector operator+(const math::vector& x, const math::vector& y) { return add(x, y); } template inline math::vector operator-(const math::vector& x) { return negate(x); } template inline math::vector operator-(const math::vector& x, const math::vector& y) { return sub(x, y); } template inline math::vector operator*(const math::vector& x, const math::vector& y) { return mul(x, y); } template inline math::vector operator*(const math::vector& v, T s) { return mul(v, s); } template inline math::vector operator*(T s, const math::vector& v) { return mul(v, s); } template inline math::vector operator/(const math::vector& x, const math::vector& y) { return div(x, y); } template inline math::vector operator/(const math::vector& v, T s) { return div(v, s); } template inline math::vector& operator+=(math::vector& x, const math::vector& y) { return (x = x + y); } template inline math::vector& operator-=(math::vector& x, const math::vector& y) { return (x = x - y); } template inline math::vector& operator*=(math::vector& x, const math::vector& y) { return (x = x * y); } template inline math::vector& operator*=(math::vector& v, T s) { return (v = v * s); } template inline math::vector& operator/=(math::vector& x, const math::vector& y) { return (x = x * y); } template inline math::vector& operator/=(math::vector& v, T s) { return (v = v / s); } #endif // ANTKEEPER_MATH_VECTOR_OPERATORS_HPP