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


Ignore:
Timestamp:
Apr 8, 2016, 3:40:57 PM (9 years ago)
Author:
Bayard Gildas
Message:

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

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

    r2 r15  
    2020#include <math.h>
    2121
    22 namespace flair { namespace core {
     22namespace flair {
     23namespace core {
    2324
    24 Vector2D::Vector2D(float inX,float inY): x(inX),y(inY) {
     25Vector2D::Vector2D(float inX, float inY) : x(inX), y(inY) {}
     26
     27Vector2D::~Vector2D() {}
     28
     29Vector2D &Vector2D::operator=(const Vector2D &vector) {
     30  x = vector.x;
     31  y = vector.y;
     32  return (*this);
    2533}
    2634
    27 Vector2D::~Vector2D() {
    28 
     35Vector2D operator+(const Vector2D &vectorA, const Vector2D &vectorB) {
     36  return Vector2D(vectorA.x + vectorB.x, vectorA.y + vectorB.y);
    2937}
    3038
    31 Vector2D &Vector2D::operator=(const Vector2D &vector) {
    32     x=vector.x;
    33     y=vector.y;
    34     return (*this);
     39Vector2D operator-(const Vector2D &vectorA, const Vector2D &vectorB) {
     40  return Vector2D(vectorA.x - vectorB.x, vectorA.y - vectorB.y);
    3541}
    3642
    37 Vector2D operator+ (const Vector2D &vectorA,const Vector2D &vectorB) {
    38     return Vector2D(vectorA.x + vectorB.x,vectorA.y + vectorB.y);
     43Vector2D operator/(const Vector2D &vector, float coeff) {
     44  if (coeff != 0) {
     45    return Vector2D(vector.x / coeff, vector.y / coeff);
     46  } else {
     47    return Vector2D(0, 0);
     48  }
    3949}
    4050
    41 Vector2D operator- (const Vector2D &vectorA,const Vector2D  &vectorB) {
    42     return Vector2D(vectorA.x - vectorB.x,vectorA.y - vectorB.y);
     51Vector2D operator*(const Vector2D &vector, float coeff) {
     52  return Vector2D(vector.x * coeff, vector.y * coeff);
    4353}
    4454
    45 Vector2D operator/ (const Vector2D &vector, float coeff) {
    46     if(coeff!=0) {
    47         return Vector2D(vector.x/ coeff,vector.y/ coeff);
    48     } else {
    49         return Vector2D(0,0);
    50     }
    51 }
    52 
    53 Vector2D operator * (const Vector2D &vector, float coeff) {
    54     return Vector2D(vector.x * coeff,vector.y * coeff);
    55 }
    56 
    57 Vector2D operator * (float coeff,const Vector2D &vector) {
    58     return Vector2D(vector.x * coeff,vector.y * coeff);
     55Vector2D operator*(float coeff, const Vector2D &vector) {
     56  return Vector2D(vector.x * coeff, vector.y * coeff);
    5957}
    6058
    6159void Vector2D::Rotate(float value) {
    62     float xTmp;
    63     xTmp=x*cosf(value)-y*sinf(value);
    64     y=x*sinf(value)+y*cosf(value);
    65     x=xTmp;
     60  float xTmp;
     61  xTmp = x * cosf(value) - y * sinf(value);
     62  y = x * sinf(value) + y * cosf(value);
     63  x = xTmp;
    6664}
    6765
    68 void Vector2D::RotateDeg(float value) {
    69     Rotate(Euler::ToRadian(value));
     66void Vector2D::RotateDeg(float value) { Rotate(Euler::ToRadian(value)); }
     67
     68float Vector2D::GetNorm(void) const { return sqrt(x * x + y * y); }
     69
     70void Vector2D::Normalize(void) {
     71  float n = GetNorm();
     72  if (n != 0) {
     73    x = x / n;
     74    y = y / n;
     75  }
    7076}
    7177
    72 float Vector2D::GetNorm(void) const {
    73     return sqrt(x*x+y*y);
     78void Vector2D::Saturate(Vector2D min, Vector2D max) {
     79  if (x < min.x)
     80    x = min.x;
     81  if (x > max.x)
     82    x = max.x;
     83
     84  if (y < min.y)
     85    y = min.y;
     86  if (y > max.y)
     87    y = max.y;
    7488}
    7589
    76 void Vector2D::Normalize(void) {
    77     float n=GetNorm();
    78     if(n!=0) {
    79         x=x/n;
    80         y=y/n;
    81     }
    82 }
    83 
    84 void Vector2D::Saturate(Vector2D min,Vector2D max) {
    85     if(x<min.x) x=min.x;
    86     if(x>max.x) x=max.x;
    87 
    88     if(y<min.y) y=min.y;
    89     if(y>max.y) y=max.y;
    90 }
    91 
    92 void Vector2D::Saturate(float min,float max) {
    93     Saturate(Vector2D(min,min),Vector2D(max,max));
     90void Vector2D::Saturate(float min, float max) {
     91  Saturate(Vector2D(min, min), Vector2D(max, max));
    9492}
    9593
    9694void Vector2D::Saturate(const Vector2D &value) {
    97     float x=fabs(value.x);
    98     float y=fabs(value.y);
    99     Saturate(Vector2D(-x,-y),Vector2D(x,y));
     95  float x = fabs(value.x);
     96  float y = fabs(value.y);
     97  Saturate(Vector2D(-x, -y), Vector2D(x, y));
    10098}
    10199
    102100void Vector2D::Saturate(float value) {
    103     float sat=fabs(value);
    104     Saturate(Vector2D(-sat,-sat),Vector2D(sat,sat));
     101  float sat = fabs(value);
     102  Saturate(Vector2D(-sat, -sat), Vector2D(sat, sat));
    105103}
    106104
Note: See TracChangeset for help on using the changeset viewer.