Changeset 167 in flair-src for trunk/lib/FlairCore/src/Vector2D.cpp
- Timestamp:
- Apr 12, 2017, 1:59:38 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/src/Vector2D.cpp
r161 r167 22 22 namespace flair { 23 23 namespace core { 24 25 template class Vector2D<double>; 26 template Vector2D<double> operator+(const Vector2D<double>&, const Vector2D<double>&); 27 template Vector2D<double> operator-(const Vector2D<double>&, const Vector2D<double>&); 28 template Vector2D<double> operator-(const Vector2D<double>&); 29 template Vector2D<double> operator/(const Vector2D<double>&, float); 30 template Vector2D<double> operator*(const Vector2D<double>&, float); 31 template Vector2D<double> operator*(float, const Vector2D<double>&); 24 32 25 Vector2D::Vector2D(float inX, float inY) : x(inX), y(inY) {} 33 template class Vector2D<float>; 34 template Vector2D<float> operator+(const Vector2D<float>&, const Vector2D<float>&); 35 template Vector2D<float> operator-(const Vector2D<float>&, const Vector2D<float>&); 36 template Vector2D<float> operator-(const Vector2D<float>&); 37 template Vector2D<float> operator/(const Vector2D<float>&, float); 38 template Vector2D<float> operator*(const Vector2D<float>&, float); 39 template Vector2D<float> operator*(float, const Vector2D<float>&); 26 40 27 Vector2D::~Vector2D() {}41 template <typename T> Vector2D<T>::Vector2D(T inX, T inY) : x(inX), y(inY) {} 28 42 29 Vector2D &Vector2D::operator=(const Vector2D &vector) { 30 x = vector.x; 31 y = vector.y; 32 return (*this); 33 } 43 template <typename T> Vector2D<T>::~Vector2D() {} 34 44 35 Vector2D &Vector2D::operator+=(const Vector2D&vector) {45 template <typename T> Vector2D<T> &Vector2D<T>::operator+=(const Vector2D<T> &vector) { 36 46 x += vector.x; 37 47 y += vector.y; … … 39 49 } 40 50 41 Vector2D &Vector2D::operator-=(const Vector2D&vector) {51 template <typename T> Vector2D<T> &Vector2D<T>::operator-=(const Vector2D<T> &vector) { 42 52 x -= vector.x; 43 53 y -= vector.y; … … 45 55 } 46 56 47 Vector2D operator+(const Vector2D &vectorA, const Vector2D&vectorB) {48 return Vector2D (vectorA.x + vectorB.x, vectorA.y + vectorB.y);57 template <typename T> Vector2D<T> operator+(const Vector2D<T> &vectorA, const Vector2D<T> &vectorB) { 58 return Vector2D<T>(vectorA.x + vectorB.x, vectorA.y + vectorB.y); 49 59 } 50 60 51 Vector2D operator-(const Vector2D &vectorA, const Vector2D&vectorB) {52 return Vector2D (vectorA.x - vectorB.x, vectorA.y - vectorB.y);61 template <typename T> Vector2D<T> operator-(const Vector2D<T> &vectorA, const Vector2D<T> &vectorB) { 62 return Vector2D<T>(vectorA.x - vectorB.x, vectorA.y - vectorB.y); 53 63 } 54 64 55 Vector2D operator-(const Vector2D&vectorA) {56 return Vector2D (-vectorA.x, -vectorA.y);65 template <typename T> Vector2D<T> operator-(const Vector2D<T> &vectorA) { 66 return Vector2D<T>(-vectorA.x, -vectorA.y); 57 67 } 58 68 59 Vector2D operator/(const Vector2D&vector, float coeff) {69 template <typename T> Vector2D<T> operator/(const Vector2D<T> &vector, float coeff) { 60 70 if (coeff != 0) { 61 return Vector2D (vector.x / coeff, vector.y / coeff);71 return Vector2D<T>(vector.x / coeff, vector.y / coeff); 62 72 } else { 63 return Vector2D (0, 0);73 return Vector2D<T>(0, 0); 64 74 } 65 75 } 66 76 67 Vector2D operator*(const Vector2D&vector, float coeff) {68 return Vector2D (vector.x * coeff, vector.y * coeff);77 template <typename T> Vector2D<T> operator*(const Vector2D<T> &vector, float coeff) { 78 return Vector2D<T>(vector.x * coeff, vector.y * coeff); 69 79 } 70 80 71 Vector2D operator*(float coeff, const Vector2D&vector) {72 return Vector2D (vector.x * coeff, vector.y * coeff);81 template <typename T> Vector2D<T> operator*(float coeff, const Vector2D<T> &vector) { 82 return Vector2D<T>(vector.x * coeff, vector.y * coeff); 73 83 } 74 84 75 void Vector2D::Rotate(float value) {85 template <typename T> void Vector2D<T>::Rotate(float value) { 76 86 float xTmp; 77 87 xTmp = x * cosf(value) - y * sinf(value); … … 80 90 } 81 91 82 void Vector2D::RotateDeg(float value) { Rotate(Euler::ToRadian(value)); }92 template <typename T> void Vector2D<T>::RotateDeg(float value) { Rotate(Euler::ToRadian(value)); } 83 93 84 float Vector2D::GetNorm(void) const { return sqrt(x * x + y * y); }94 template <typename T> float Vector2D<T>::GetNorm(void) const { return sqrt(x * x + y * y); } 85 95 86 void Vector2D::Normalize(void) {96 template <typename T> void Vector2D<T>::Normalize(void) { 87 97 float n = GetNorm(); 88 98 if (n != 0) { … … 92 102 } 93 103 94 void Vector2D::Saturate(Vector2D min, Vector2D max) {104 template <typename T> void Vector2D<T>::Saturate(Vector2D min, Vector2D max) { 95 105 if (x < min.x) 96 106 x = min.x; … … 104 114 } 105 115 106 void Vector2D::Saturate(float min, float max) {116 template <typename T> void Vector2D<T>::Saturate(float min, float max) { 107 117 Saturate(Vector2D(min, min), Vector2D(max, max)); 108 118 } 109 119 110 void Vector2D::Saturate(const Vector2D &value) {120 template <typename T> void Vector2D<T>::Saturate(const Vector2D &value) { 111 121 float x = fabs(value.x); 112 122 float y = fabs(value.y); … … 114 124 } 115 125 116 void Vector2D::Saturate(float value) {126 template <typename T> void Vector2D<T>::Saturate(float value) { 117 127 float sat = fabs(value); 118 128 Saturate(Vector2D(-sat, -sat), Vector2D(sat, sat));
Note:
See TracChangeset
for help on using the changeset viewer.