Added scalar addition and subtraction operators.

This commit is contained in:
Maciej Suminski 2013-07-26 18:12:22 +02:00
parent 2ee99f74c4
commit 862d5a4bf2
1 changed files with 44 additions and 0 deletions

View File

@ -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-()
{