|
| 1 | +/** |
| 2 | + * \file vector2.h |
| 3 | + * |
| 4 | + * \brief This header defines a two dimensional vector and functionalities. |
| 5 | + */ |
| 6 | + |
| 7 | +#pragma once |
| 8 | +#ifndef _ECM_VECTOR_EXT_H_ |
| 9 | +#define _ECM_VECTOR_EXT_H_ |
| 10 | + |
| 11 | +#include <ecm/ecm_api.h> |
| 12 | +#include <ecm/ecm_types.hpp> |
| 13 | +#include <ecm/math/vector2.hpp> |
| 14 | +#include <ecm/math/vector3.hpp> |
| 15 | +#include <ecm/math/vector4.hpp> |
| 16 | + |
| 17 | +#include <type_traits> |
| 18 | + |
| 19 | +namespace ecm::math |
| 20 | +{ |
| 21 | + // Lerp |
| 22 | + |
| 23 | + /** |
| 24 | + * Linearly interpolates between two 2D vectors, \p x and \p y, using a |
| 25 | + * scalar factor \p t. |
| 26 | + * |
| 27 | + * This function computes the interpolation component-wise according to: |
| 28 | + * \f[ |
| 29 | + * \text{Lerp}(x, y, t) = x + t \cdot (y - x) |
| 30 | + * \f] |
| 31 | + * where \p x and \p y are 2D vectors, and \p t is a scalar. |
| 32 | + * |
| 33 | + * \tparam T The type of the elements in vector \p x. |
| 34 | + * \tparam U The type of the elements in vector \p y. |
| 35 | + * \tparam W The type of the interpolation factor \p t (must be arithmetic). |
| 36 | + * |
| 37 | + * \param x The starting 2D vector. |
| 38 | + * \param y The ending 2D vector. |
| 39 | + * \param t The interpolation factor, typically in the range \[0, 1\]. |
| 40 | + * |
| 41 | + * \returns A 2D vector that is the result of the linear interpolation. |
| 42 | + * |
| 43 | + * \since v1.0.0 |
| 44 | + */ |
| 45 | + template<typename T, typename U, typename W, typename = std::enable_if_t<std::is_arithmetic<W>::value>> |
| 46 | + ECM_NODISCARD constexpr Vector2_Base<T> ECM_CALL Lerp(const Vector2_Base<T>& x, const Vector2_Base<U>& y, W t); |
| 47 | + |
| 48 | + /** |
| 49 | + * Linearly interpolates between two 3D vectors, \p x and \p y, using a |
| 50 | + * scalar factor \p t. |
| 51 | + * |
| 52 | + * This function computes the interpolation component-wise according to: |
| 53 | + * \f[ |
| 54 | + * \text{Lerp}(x, y, t) = x + t \cdot (y - x) |
| 55 | + * \f] |
| 56 | + * where \p x and \p y are 3D vectors, and \p t is a scalar. |
| 57 | + * |
| 58 | + * \tparam T The type of the elements in vector \p x. |
| 59 | + * \tparam U The type of the elements in vector \p y. |
| 60 | + * \tparam W The type of the interpolation factor \p t (must be arithmetic). |
| 61 | + * |
| 62 | + * \param x The starting 3D vector. |
| 63 | + * \param y The ending 3D vector. |
| 64 | + * \param t The interpolation factor, typically in the range \[0, 1\]. |
| 65 | + * |
| 66 | + * \returns A 3D vector that is the result of the linear interpolation. |
| 67 | + * |
| 68 | + * \since v1.0.0 |
| 69 | + */ |
| 70 | + template<typename T, typename U, typename W, typename = std::enable_if_t<std::is_arithmetic<W>::value>> |
| 71 | + ECM_NODISCARD constexpr Vector3_Base<T> ECM_CALL Lerp(const Vector3_Base<T>& x, const Vector3_Base<U>& y, W t); |
| 72 | + |
| 73 | + /** |
| 74 | + * Linearly interpolates between two 4D vectors, \p x and \p y, using a |
| 75 | + * scalar factor \p t. |
| 76 | + * |
| 77 | + * This function computes the interpolation component-wise according to: |
| 78 | + * \f[ |
| 79 | + * \text{Lerp}(x, y, t) = x + t \cdot (y - x) |
| 80 | + * \f] |
| 81 | + * where \p x and \p y are 4D vectors, and \p t is a scalar. |
| 82 | + * |
| 83 | + * \tparam T The type of the elements in vector \p x. |
| 84 | + * \tparam U The type of the elements in vector \p y. |
| 85 | + * \tparam W The type of the interpolation factor \p t (must be arithmetic). |
| 86 | + * |
| 87 | + * \param x The starting 4D vector. |
| 88 | + * \param y The ending 4D vector. |
| 89 | + * \param t The interpolation factor, typically in the range \[0, 1\]. |
| 90 | + * |
| 91 | + * \returns A 4D vector that is the result of the linear interpolation. |
| 92 | + * |
| 93 | + * \since v1.0.0 |
| 94 | + */ |
| 95 | + template<typename T, typename U, typename W, typename = std::enable_if_t<std::is_arithmetic<W>::value>> |
| 96 | + ECM_NODISCARD constexpr Vector4_Base<T> ECM_CALL Lerp(const Vector4_Base<T>& x, const Vector4_Base<U>& y, W t); |
| 97 | + |
| 98 | + /** |
| 99 | + * Linearly interpolates between two 2D vectors, \p x and \p y, using a 2D |
| 100 | + * vector factor \p t. |
| 101 | + * |
| 102 | + * This function computes the interpolation component-wise according to: |
| 103 | + * \f[ |
| 104 | + * \text{Lerp}(x, y, t) = x + t \cdot (y - x) |
| 105 | + * \f] |
| 106 | + * where \p x and \p y are 2D vectors, and \p t is another 2D vector, |
| 107 | + * allowing for separate interpolation factors per component. |
| 108 | + * |
| 109 | + * \tparam T The type of the elements in vector \p x. |
| 110 | + * \tparam U The type of the elements in vector \p y. |
| 111 | + * \tparam W The type of the elements in vector \p t. |
| 112 | + * |
| 113 | + * \param x The starting 2D vector. |
| 114 | + * \param y The ending 2D vector. |
| 115 | + * \param t The 2D interpolation factors, one for each component. |
| 116 | + * |
| 117 | + * \returns A 2D vector that is the result of the component-wise linear |
| 118 | + * interpolation. |
| 119 | + * |
| 120 | + * \since v1.0.0 |
| 121 | + */ |
| 122 | + template<typename T, typename U, typename W> |
| 123 | + ECM_NODISCARD constexpr Vector2_Base<T> ECM_CALL Lerp(const Vector2_Base<T>& x, const Vector2_Base<U>& y, const Vector2_Base<W>& t); |
| 124 | + |
| 125 | + /** |
| 126 | + * Linearly interpolates between two 3D vectors, \p x and \p y, using a 3D |
| 127 | + * vector factor \p t. |
| 128 | + * |
| 129 | + * This function computes the interpolation component-wise according to: |
| 130 | + * \f[ |
| 131 | + * \text{Lerp}(x, y, t) = x + t \cdot (y - x) |
| 132 | + * \f] |
| 133 | + * where \p x and \p y are 3D vectors, and \p t is another 3D vector, |
| 134 | + * allowing for separate interpolation factors per component. |
| 135 | + * |
| 136 | + * \tparam T The type of the elements in vector \p x. |
| 137 | + * \tparam U The type of the elements in vector \p y. |
| 138 | + * \tparam W The type of the elements in vector \p t. |
| 139 | + * |
| 140 | + * \param x The starting 3D vector. |
| 141 | + * \param y The ending 3D vector. |
| 142 | + * \param t The 3D interpolation factors, one for each component. |
| 143 | + * |
| 144 | + * \returns A 3D vector that is the result of the component-wise linear |
| 145 | + * interpolation. |
| 146 | + * |
| 147 | + * \since v1.0.0 |
| 148 | + */ |
| 149 | + template<typename T, typename U, typename W> |
| 150 | + ECM_NODISCARD constexpr Vector3_Base<T> ECM_CALL Lerp(const Vector3_Base<T>& x, const Vector3_Base<U>& y, const Vector3_Base<W>& t); |
| 151 | + |
| 152 | + /** |
| 153 | + * Linearly interpolates between two 4D vectors, \p x and \p y, using a 4D |
| 154 | + * vector factor \p t. |
| 155 | + * |
| 156 | + * This function computes the interpolation component-wise according to: |
| 157 | + * \f[ |
| 158 | + * \text{Lerp}(x, y, t) = x + t \cdot (y - x) |
| 159 | + * \f] |
| 160 | + * where \p x and \p y are 4D vectors, and \p t is another 4D vector, |
| 161 | + * allowing for separate interpolation factors per component. |
| 162 | + * |
| 163 | + * \tparam T The type of the elements in vector \p x. |
| 164 | + * \tparam U The type of the elements in vector \p y. |
| 165 | + * \tparam W The type of the elements in vector \p t. |
| 166 | + * |
| 167 | + * \param x The starting 4D vector. |
| 168 | + * \param y The ending 4D vector. |
| 169 | + * \param t The 4D interpolation factors, one for each component. |
| 170 | + * |
| 171 | + * \returns A 4D vector that is the result of the component-wise linear |
| 172 | + * interpolation. |
| 173 | + * |
| 174 | + * \since v1.0.0 |
| 175 | + */ |
| 176 | + template<typename T, typename U, typename W> |
| 177 | + ECM_NODISCARD constexpr Vector4_Base<T> ECM_CALL Lerp(const Vector4_Base<T>& x, const Vector4_Base<U>& y, const Vector4_Base<W>& t); |
| 178 | +} // namespace ecm::math |
| 179 | + |
| 180 | +#include "vector_ext.inl" |
| 181 | + |
| 182 | +#endif // !_ECM_VECTOR_EXT_H_ |
0 commit comments