[2] | 1 | // %flair:license{
|
---|
[13] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[2] | 4 | // %flair:license}
|
---|
| 5 | /*!
|
---|
| 6 | * \file Vector2D.h
|
---|
| 7 | * \brief Class defining a 2D vector
|
---|
| 8 | * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 9 | * \date 2013/05/02
|
---|
| 10 | * \version 4.0
|
---|
| 11 | */
|
---|
| 12 |
|
---|
| 13 | #ifndef VECTOR2D_H
|
---|
| 14 | #define VECTOR2D_H
|
---|
| 15 |
|
---|
[13] | 16 | namespace flair {
|
---|
| 17 | namespace core {
|
---|
[2] | 18 |
|
---|
[13] | 19 | /*! \class Vector2D
|
---|
| 20 | *
|
---|
| 21 | * \brief Class defining a 2D vector
|
---|
| 22 | */
|
---|
[50] | 23 | template <typename T>
|
---|
[13] | 24 | class Vector2D {
|
---|
| 25 | public:
|
---|
| 26 | /*!
|
---|
| 27 | * \brief Constructor
|
---|
| 28 | *
|
---|
| 29 | * Construct a Vector2D using specified values.
|
---|
| 30 | *
|
---|
| 31 | * \param x
|
---|
| 32 | * \param y
|
---|
| 33 | */
|
---|
[50] | 34 | Vector2D(T x = 0, T y = 0);
|
---|
[2] | 35 |
|
---|
[13] | 36 | /*!
|
---|
| 37 | * \brief Destructor
|
---|
| 38 | *
|
---|
| 39 | */
|
---|
| 40 | ~Vector2D();
|
---|
[2] | 41 |
|
---|
[13] | 42 | /*!
|
---|
| 43 | * \brief Rotation
|
---|
| 44 | *
|
---|
| 45 | * \param value rotation value in radians
|
---|
| 46 | */
|
---|
| 47 | void Rotate(float value);
|
---|
[2] | 48 |
|
---|
[13] | 49 | /*!
|
---|
| 50 | * \brief Rotation
|
---|
| 51 | *
|
---|
| 52 | * \param value rotation value in degrees
|
---|
| 53 | */
|
---|
| 54 | void RotateDeg(float value);
|
---|
[2] | 55 |
|
---|
[13] | 56 | /*!
|
---|
| 57 | * \brief Norm
|
---|
| 58 | *
|
---|
| 59 | * \return value
|
---|
| 60 | */
|
---|
| 61 | float GetNorm(void) const;
|
---|
[2] | 62 |
|
---|
[13] | 63 | /*!
|
---|
| 64 | * \brief Normalize
|
---|
| 65 | */
|
---|
| 66 | void Normalize(void);
|
---|
[2] | 67 |
|
---|
[13] | 68 | /*!
|
---|
| 69 | * \brief Saturate
|
---|
| 70 | *
|
---|
| 71 | * Saturate between min and max
|
---|
| 72 | *
|
---|
| 73 | * \param min minimum Vector2D value
|
---|
| 74 | * \param max maximum Vector2D value
|
---|
| 75 | */
|
---|
[50] | 76 | void Saturate(Vector2D<T> min, Vector2D<T> max);
|
---|
[2] | 77 |
|
---|
[13] | 78 | /*!
|
---|
| 79 | * \brief Saturate
|
---|
| 80 | *
|
---|
| 81 | * Saturate between min and max
|
---|
| 82 | *
|
---|
| 83 | * \param min minimum Vector2D(min,min) value
|
---|
| 84 | * \param max maximum Vector2D(max,max) value
|
---|
| 85 | */
|
---|
| 86 | void Saturate(float min, float max);
|
---|
[2] | 87 |
|
---|
[13] | 88 | /*!
|
---|
| 89 | * \brief Saturate
|
---|
| 90 | *
|
---|
| 91 | * Saturate between -abs(value) and abs(value)
|
---|
| 92 | *
|
---|
| 93 | * \param value saturation Vector2D value
|
---|
| 94 | */
|
---|
[50] | 95 | void Saturate(const Vector2D<T> &value);
|
---|
[2] | 96 |
|
---|
[13] | 97 | /*!
|
---|
| 98 | * \brief Saturate
|
---|
| 99 | *
|
---|
| 100 | * Saturate between -abs(Vector2D(value,value)) and abs(Vector2D(value,value))
|
---|
| 101 | *
|
---|
| 102 | * \param value saturation Vector2D(value,value)
|
---|
| 103 | */
|
---|
| 104 | void Saturate(float value);
|
---|
[2] | 105 |
|
---|
[13] | 106 | /*!
|
---|
| 107 | * \brief x
|
---|
| 108 | */
|
---|
[50] | 109 | T x;
|
---|
[2] | 110 |
|
---|
[13] | 111 | /*!
|
---|
| 112 | * \brief y
|
---|
| 113 | */
|
---|
[50] | 114 | T y;
|
---|
[2] | 115 |
|
---|
[50] | 116 | template<typename S> Vector2D<T> &operator=(const Vector2D<S> &vector) {
|
---|
| 117 | x = vector.x;
|
---|
| 118 | y = vector.y;
|
---|
| 119 | return (*this);
|
---|
| 120 | }
|
---|
| 121 | Vector2D<T> &operator+=(const Vector2D<T> &vector);
|
---|
| 122 | Vector2D<T> &operator-=(const Vector2D<T> &vector);
|
---|
[13] | 123 | };
|
---|
[2] | 124 |
|
---|
[50] | 125 | typedef Vector2D<float> Vector2Df;
|
---|
| 126 |
|
---|
[13] | 127 | /*! Add
|
---|
| 128 | *
|
---|
| 129 | * \brief Add
|
---|
| 130 | *
|
---|
| 131 | * \param vectorA vector
|
---|
| 132 | * \param vectorB vector
|
---|
| 133 | */
|
---|
[50] | 134 | template<typename T> Vector2D<T> operator+(const Vector2D<T> &vectorA, const Vector2D<T> &vectorB);
|
---|
[2] | 135 |
|
---|
[13] | 136 | /*! Substract
|
---|
| 137 | *
|
---|
| 138 | * \brief Substract
|
---|
| 139 | *
|
---|
| 140 | * \param vectorA vector
|
---|
| 141 | * \param vectorB vector
|
---|
| 142 | */
|
---|
[50] | 143 | template<typename T> Vector2D<T> operator-(const Vector2D<T> &vectorA, const Vector2D<T> &vectorB);
|
---|
[2] | 144 |
|
---|
[50] | 145 | /*! Opposite
|
---|
| 146 | *
|
---|
| 147 | * \brief Opposite
|
---|
| 148 | *
|
---|
| 149 | * \param vectorA vector
|
---|
| 150 | *
|
---|
| 151 | * \return -vectorA
|
---|
| 152 | */
|
---|
| 153 | template<typename T> Vector2D<T> operator-(const Vector2D<T> &vectorA);
|
---|
| 154 |
|
---|
[13] | 155 | /*! Divid
|
---|
| 156 | *
|
---|
| 157 | * \brief Divid
|
---|
| 158 | *
|
---|
| 159 | * \param vector vector
|
---|
| 160 | * \param coeff coefficent
|
---|
| 161 | * \return vector/coefficient
|
---|
| 162 | */
|
---|
[50] | 163 | template<typename T> Vector2D<T> operator/(const Vector2D<T> &vector, float coeff);
|
---|
[2] | 164 |
|
---|
[13] | 165 | /*! Multiply
|
---|
| 166 | *
|
---|
| 167 | * \brief Multiplyf
|
---|
| 168 | *
|
---|
| 169 | * \param vector vector
|
---|
| 170 | * \param coeff coefficent
|
---|
| 171 | * \return coefficient*vector
|
---|
| 172 | */
|
---|
[50] | 173 | template<typename T> Vector2D<T> operator*(const Vector2D<T> &vector, float coeff);
|
---|
[2] | 174 |
|
---|
[13] | 175 | /*! Multiply
|
---|
| 176 | *
|
---|
| 177 | * \brief Multiply
|
---|
| 178 | *
|
---|
| 179 | * \param coeff coefficent
|
---|
| 180 | * \param vector vector
|
---|
| 181 | * \return coefficient*vector
|
---|
| 182 | */
|
---|
[50] | 183 | template<typename T> Vector2D<T> operator*(float coeff, const Vector2D<T> &vector);
|
---|
[2] | 184 |
|
---|
| 185 | } // end namespace core
|
---|
| 186 | } // end namespace flair
|
---|
| 187 |
|
---|
| 188 | #endif // VECTOR2D_H
|
---|