Commit 862d5a4b authored by Maciej Suminski's avatar Maciej Suminski

Added scalar addition and subtraction operators.

parent 2ee99f74
......@@ -215,15 +215,27 @@ public:
/// Vector addition operator
VECTOR2<T> operator+( const VECTOR2<T>& aVector ) const;
/// Scalar addition operator
VECTOR2<T> operator+( const T& aScalar ) const;
/// Compound assignment operator
VECTOR2<T>& operator+=( const VECTOR2<T>& aVector );
/// Compound assignment operator
VECTOR2<T>& operator+=( const T& aScalar );
/// Vector subtraction operator
VECTOR2<T> operator-( const VECTOR2<T>& aVector ) const;
/// Scalar subtraction operator
VECTOR2<T> operator-( const T& aScalar ) const;
/// Compound assignment operator
VECTOR2<T>& operator-=( const VECTOR2<T>& aVector );
/// Compound assignment operator
VECTOR2<T>& operator-=( const T& aScalar );
/// Negate Vector operator
VECTOR2<T> operator-();
......@@ -330,6 +342,15 @@ VECTOR2<T>& VECTOR2<T>::operator+=( const VECTOR2<T>& aVector )
}
template <class T>
VECTOR2<T>& VECTOR2<T>::operator+=( const T& aScalar )
{
x += aScalar;
y += aScalar;
return *this;
}
template <class T>
VECTOR2<T>& VECTOR2<T>::operator-=( const VECTOR2<T>& aVector )
{
......@@ -339,6 +360,15 @@ VECTOR2<T>& VECTOR2<T>::operator-=( const VECTOR2<T>& aVector )
}
template <class T>
VECTOR2<T>& VECTOR2<T>::operator-=( const T& aScalar )
{
x -= aScalar;
y -= aScalar;
return *this;
}
template <class T>
int VECTOR2<T>::LineSide( const VECTOR2<T>& aStart, const VECTOR2<T>& aEnd ) const
{
......@@ -463,6 +493,13 @@ VECTOR2<T> VECTOR2<T>::operator+( const VECTOR2<T>& aVector ) const
}
template <class T>
VECTOR2<T> VECTOR2<T>::operator+( const T& aScalar ) const
{
return VECTOR2<T> ( x + aScalar, y + aScalar );
}
template <class T>
VECTOR2<T> VECTOR2<T>::operator-( const VECTOR2<T>& aVector ) const
{
......@@ -470,6 +507,13 @@ VECTOR2<T> VECTOR2<T>::operator-( const VECTOR2<T>& aVector ) const
}
template <class T>
VECTOR2<T> VECTOR2<T>::operator-( const T& aScalar ) const
{
return VECTOR2<T> ( x - aScalar, y - aScalar );
}
template <class T>
VECTOR2<T> VECTOR2<T>::operator-()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment