Skip to content

Commit

Permalink
constexpr for Vector<2> constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSaw committed Nov 15, 2021
1 parent d46c09d commit a97cf02
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
25 changes: 9 additions & 16 deletions src/modm/math/geometry/vector2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,11 @@ namespace modm
typedef typename GeometricTraits<T>::FloatType FloatType;

public:
/**
* \brief Default-Constructor
*
* Creates a Vector with coordinates (0, 0).
*/
Vector();

Vector(const T& inX, const T& inY);

Vector(const Vector<T, 1> &inX, const Vector<T, 1> &inY);
Vector(const T &inX, const Vector<T, 1> &inY);
Vector(const Vector<T, 1> &inX, const T &inY);
constexpr Vector() = default;
constexpr Vector(const T& inX, const T& inY);
constexpr Vector(const Vector<T, 1> &inX, const Vector<T, 1> &inY);
constexpr Vector(const T &inX, const Vector<T, 1> &inY);
constexpr Vector(const Vector<T, 1> &inX, const T &inY);
explicit Vector(T inVal);
Vector(const Matrix<T, 2, 1> &rhs);

Expand Down Expand Up @@ -246,8 +239,8 @@ namespace modm
const T* ptr() const;

Vector operator - () const;
Vector operator - (const Vector &rhs) const;
Vector operator + (const Vector &rhs) const;
constexpr Vector operator - (const Vector &rhs) const;
constexpr Vector operator + (const Vector &rhs) const;
T operator * (const Vector &rhs) const;
T operator ^ (const Vector &rhs) const;
Vector operator * (float rhs) const;
Expand Down Expand Up @@ -295,8 +288,8 @@ namespace modm
#endif

public:
T x;
T y;
T x = 0;
T y = 0;

protected:
template<typename U>
Expand Down
20 changes: 6 additions & 14 deletions src/modm/math/geometry/vector2_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,15 @@

// ----------------------------------------------------------------------------
template<typename T>
modm::Vector<T, 2>::Vector() :
x(),
y()
{
}

// ----------------------------------------------------------------------------
template<typename T>
modm::Vector<T, 2>::Vector(const T& inX, const T& inY) :
constexpr modm::Vector<T, 2>::Vector(const T& inX, const T& inY) :
x(inX),
y(inY)
{
}

// ----------------------------------------------------------------------------
template<typename T>
modm::Vector<T, 2>::Vector(
constexpr modm::Vector<T, 2>::Vector(
const modm::Vector<T, 1> &inX,
const modm::Vector<T, 1> &inY) :
x(inX.x),
Expand All @@ -44,15 +36,15 @@ modm::Vector<T, 2>::Vector(

// ----------------------------------------------------------------------------
template<typename T>
modm::Vector<T, 2>::Vector(const T &inX, const modm::Vector<T, 1> &inY) :
constexpr modm::Vector<T, 2>::Vector(const T &inX, const modm::Vector<T, 1> &inY) :
x(inX),
y(inY.x)
{
}

// ----------------------------------------------------------------------------
template<typename T>
modm::Vector<T, 2>::Vector(const modm::Vector<T, 1> &inX, const T &inY) :
constexpr modm::Vector<T, 2>::Vector(const modm::Vector<T, 1> &inX, const T &inY) :
x(inX.x),
y(inY)
{
Expand Down Expand Up @@ -406,15 +398,15 @@ modm::Vector<T, 2>::operator - () const

// ----------------------------------------------------------------------------
template<typename T>
modm::Vector<T, 2>
constexpr modm::Vector<T, 2>
modm::Vector<T, 2>::operator - (const modm::Vector<T, 2> &rhs) const
{
return modm::Vector<T, 2>(x - rhs.x, y - rhs.y);
}

// ----------------------------------------------------------------------------
template<typename T>
modm::Vector<T, 2>
constexpr modm::Vector<T, 2>
modm::Vector<T, 2>::operator + (const modm::Vector<T, 2> &rhs) const
{
return modm::Vector<T, 2>(x + rhs.x, y + rhs.y);
Expand Down

0 comments on commit a97cf02

Please sign in to comment.