Changeset 167 in flair-src for trunk/lib/FlairCore/src/Vector2D.cpp


Ignore:
Timestamp:
Apr 12, 2017, 1:59:38 PM (8 years ago)
Author:
Sanahuja Guillaume
Message:

modifs pour template vectors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/src/Vector2D.cpp

    r161 r167  
    2222namespace flair {
    2323namespace core {
     24 
     25template class Vector2D<double>;
     26template Vector2D<double> operator+(const Vector2D<double>&, const Vector2D<double>&);
     27template Vector2D<double> operator-(const Vector2D<double>&, const Vector2D<double>&);
     28template Vector2D<double> operator-(const Vector2D<double>&);
     29template Vector2D<double> operator/(const Vector2D<double>&, float);
     30template Vector2D<double> operator*(const Vector2D<double>&, float);
     31template Vector2D<double> operator*(float, const Vector2D<double>&);
    2432
    25 Vector2D::Vector2D(float inX, float inY) : x(inX), y(inY) {}
     33template class Vector2D<float>;
     34template Vector2D<float> operator+(const Vector2D<float>&, const Vector2D<float>&);
     35template Vector2D<float> operator-(const Vector2D<float>&, const Vector2D<float>&);
     36template Vector2D<float> operator-(const Vector2D<float>&);
     37template Vector2D<float> operator/(const Vector2D<float>&, float);
     38template Vector2D<float> operator*(const Vector2D<float>&, float);
     39template Vector2D<float> operator*(float, const Vector2D<float>&);
    2640
    27 Vector2D::~Vector2D() {}
     41template <typename T> Vector2D<T>::Vector2D(T inX, T inY) : x(inX), y(inY) {}
    2842
    29 Vector2D &Vector2D::operator=(const Vector2D &vector) {
    30   x = vector.x;
    31   y = vector.y;
    32   return (*this);
    33 }
     43template <typename T> Vector2D<T>::~Vector2D() {}
    3444
    35 Vector2D &Vector2D::operator+=(const Vector2D &vector) {
     45template <typename T> Vector2D<T> &Vector2D<T>::operator+=(const Vector2D<T> &vector) {
    3646  x += vector.x;
    3747  y += vector.y;
     
    3949}
    4050
    41 Vector2D &Vector2D::operator-=(const Vector2D &vector) {
     51template <typename T> Vector2D<T> &Vector2D<T>::operator-=(const Vector2D<T> &vector) {
    4252  x -= vector.x;
    4353  y -= vector.y;
     
    4555}
    4656
    47 Vector2D operator+(const Vector2D &vectorA, const Vector2D &vectorB) {
    48   return Vector2D(vectorA.x + vectorB.x, vectorA.y + vectorB.y);
     57template <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);
    4959}
    5060
    51 Vector2D operator-(const Vector2D &vectorA, const Vector2D &vectorB) {
    52   return Vector2D(vectorA.x - vectorB.x, vectorA.y - vectorB.y);
     61template <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);
    5363}
    5464
    55 Vector2D operator-(const Vector2D &vectorA) {
    56  return Vector2D(-vectorA.x, -vectorA.y);
     65template <typename T> Vector2D<T> operator-(const Vector2D<T> &vectorA) {
     66 return Vector2D<T>(-vectorA.x, -vectorA.y);
    5767}
    5868
    59 Vector2D operator/(const Vector2D &vector, float coeff) {
     69template <typename T> Vector2D<T> operator/(const Vector2D<T> &vector, float coeff) {
    6070  if (coeff != 0) {
    61     return Vector2D(vector.x / coeff, vector.y / coeff);
     71    return Vector2D<T>(vector.x / coeff, vector.y / coeff);
    6272  } else {
    63     return Vector2D(0, 0);
     73    return Vector2D<T>(0, 0);
    6474  }
    6575}
    6676
    67 Vector2D operator*(const Vector2D &vector, float coeff) {
    68   return Vector2D(vector.x * coeff, vector.y * coeff);
     77template <typename T> Vector2D<T> operator*(const Vector2D<T> &vector, float coeff) {
     78  return Vector2D<T>(vector.x * coeff, vector.y * coeff);
    6979}
    7080
    71 Vector2D operator*(float coeff, const Vector2D &vector) {
    72   return Vector2D(vector.x * coeff, vector.y * coeff);
     81template <typename T> Vector2D<T> operator*(float coeff, const Vector2D<T> &vector) {
     82  return Vector2D<T>(vector.x * coeff, vector.y * coeff);
    7383}
    7484
    75 void Vector2D::Rotate(float value) {
     85template <typename T> void Vector2D<T>::Rotate(float value) {
    7686  float xTmp;
    7787  xTmp = x * cosf(value) - y * sinf(value);
     
    8090}
    8191
    82 void Vector2D::RotateDeg(float value) { Rotate(Euler::ToRadian(value)); }
     92template <typename T> void Vector2D<T>::RotateDeg(float value) { Rotate(Euler::ToRadian(value)); }
    8393
    84 float Vector2D::GetNorm(void) const { return sqrt(x * x + y * y); }
     94template <typename T> float Vector2D<T>::GetNorm(void) const { return sqrt(x * x + y * y); }
    8595
    86 void Vector2D::Normalize(void) {
     96template <typename T> void Vector2D<T>::Normalize(void) {
    8797  float n = GetNorm();
    8898  if (n != 0) {
     
    92102}
    93103
    94 void Vector2D::Saturate(Vector2D min, Vector2D max) {
     104template <typename T> void Vector2D<T>::Saturate(Vector2D min, Vector2D max) {
    95105  if (x < min.x)
    96106    x = min.x;
     
    104114}
    105115
    106 void Vector2D::Saturate(float min, float max) {
     116template <typename T> void Vector2D<T>::Saturate(float min, float max) {
    107117  Saturate(Vector2D(min, min), Vector2D(max, max));
    108118}
    109119
    110 void Vector2D::Saturate(const Vector2D &value) {
     120template <typename T> void Vector2D<T>::Saturate(const Vector2D &value) {
    111121  float x = fabs(value.x);
    112122  float y = fabs(value.y);
     
    114124}
    115125
    116 void Vector2D::Saturate(float value) {
     126template <typename T> void Vector2D<T>::Saturate(float value) {
    117127  float sat = fabs(value);
    118128  Saturate(Vector2D(-sat, -sat), Vector2D(sat, sat));
Note: See TracChangeset for help on using the changeset viewer.