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

Added scalar addition and subtraction operators.

parent 2ee99f74
Loading
Loading
Loading
Loading
+44 −0
Original line number Original line Diff line number Diff line
@@ -215,15 +215,27 @@ public:
    /// Vector addition operator
    /// Vector addition operator
    VECTOR2<T> operator+( const VECTOR2<T>& aVector ) const;
    VECTOR2<T> operator+( const VECTOR2<T>& aVector ) const;


    /// Scalar addition operator
    VECTOR2<T> operator+( const T& aScalar ) const;

    /// Compound assignment operator
    /// Compound assignment operator
    VECTOR2<T>& operator+=( const VECTOR2<T>& aVector );
    VECTOR2<T>& operator+=( const VECTOR2<T>& aVector );


    /// Compound assignment operator
    VECTOR2<T>& operator+=( const T& aScalar );

    /// Vector subtraction operator
    /// Vector subtraction operator
    VECTOR2<T> operator-( const VECTOR2<T>& aVector ) const;
    VECTOR2<T> operator-( const VECTOR2<T>& aVector ) const;


    /// Scalar subtraction operator
    VECTOR2<T> operator-( const T& aScalar ) const;

    /// Compound assignment operator
    /// Compound assignment operator
    VECTOR2<T>& operator-=( const VECTOR2<T>& aVector );
    VECTOR2<T>& operator-=( const VECTOR2<T>& aVector );


    /// Compound assignment operator
    VECTOR2<T>& operator-=( const T& aScalar );

    /// Negate Vector operator
    /// Negate Vector operator
    VECTOR2<T> 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>
template <class T>
VECTOR2<T>& VECTOR2<T>::operator-=( const VECTOR2<T>& aVector )
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>
template <class T>
int VECTOR2<T>::LineSide( const VECTOR2<T>& aStart, const VECTOR2<T>& aEnd ) const
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>
template <class T>
VECTOR2<T> VECTOR2<T>::operator-( const VECTOR2<T>& aVector ) const
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>
template <class T>
VECTOR2<T> VECTOR2<T>::operator-()
VECTOR2<T> VECTOR2<T>::operator-()
{
{