Skip to content

Commit

Permalink
utils/Vector: add "constexpr"
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed May 29, 2018
1 parent 1105746 commit 5d3815f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
20 changes: 0 additions & 20 deletions xbmc/utils/Vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,6 @@

#include "Vector.h"

CVector::CVector(float xCoord, float yCoord)
: x(xCoord),
y(yCoord)
{ }

const CVector CVector::operator+(const CVector &other) const
{
return CVector(x + other.x, y + other.y);
}

const CVector CVector::operator-(const CVector &other) const
{
return CVector(x - other.x, y - other.y);
}

CVector& CVector::operator+=(const CVector &other)
{
x += other.x;
Expand All @@ -53,11 +38,6 @@ CVector& CVector::operator-=(const CVector &other)
return *this;
}

float CVector::scalar(const CVector &other) const
{
return x * other.x + y * other.y;
}

float CVector::length() const
{
return sqrt(pow(x, 2) + pow(y, 2));
Expand Down
20 changes: 16 additions & 4 deletions xbmc/utils/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,26 @@ class CVector
{
public:
CVector() = default;
CVector(float xCoord, float yCoord);
constexpr CVector(float xCoord, float yCoord):x(xCoord), y(yCoord) {}

const CVector operator+(const CVector &other) const;
const CVector operator-(const CVector &other) const;
constexpr CVector operator+(const CVector &other) const
{
return CVector(x + other.x, y + other.y);
}

constexpr CVector operator-(const CVector &other) const
{
return CVector(x - other.x, y - other.y);
}

CVector& operator+=(const CVector &other);
CVector& operator-=(const CVector &other);

float scalar(const CVector &other) const;
constexpr float scalar(const CVector &other) const
{
return x * other.x + y * other.y;
}

float length() const;

float x = 0;
Expand Down

0 comments on commit 5d3815f

Please sign in to comment.