From 862d5a4bf2e17f3d5ef9a81f4be9b8271253b6ed Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 26 Jul 2013 18:12:22 +0200 Subject: [PATCH] Added scalar addition and subtraction operators. --- include/math/vector2d.h | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/include/math/vector2d.h b/include/math/vector2d.h index 675e74d15f..a5eaa604e0 100644 --- a/include/math/vector2d.h +++ b/include/math/vector2d.h @@ -215,15 +215,27 @@ public: /// Vector addition operator VECTOR2 operator+( const VECTOR2& aVector ) const; + /// Scalar addition operator + VECTOR2 operator+( const T& aScalar ) const; + /// Compound assignment operator VECTOR2& operator+=( const VECTOR2& aVector ); + /// Compound assignment operator + VECTOR2& operator+=( const T& aScalar ); + /// Vector subtraction operator VECTOR2 operator-( const VECTOR2& aVector ) const; + /// Scalar subtraction operator + VECTOR2 operator-( const T& aScalar ) const; + /// Compound assignment operator VECTOR2& operator-=( const VECTOR2& aVector ); + /// Compound assignment operator + VECTOR2& operator-=( const T& aScalar ); + /// Negate Vector operator VECTOR2 operator-(); @@ -330,6 +342,15 @@ VECTOR2& VECTOR2::operator+=( const VECTOR2& aVector ) } +template +VECTOR2& VECTOR2::operator+=( const T& aScalar ) +{ + x += aScalar; + y += aScalar; + return *this; +} + + template VECTOR2& VECTOR2::operator-=( const VECTOR2& aVector ) { @@ -339,6 +360,15 @@ VECTOR2& VECTOR2::operator-=( const VECTOR2& aVector ) } +template +VECTOR2& VECTOR2::operator-=( const T& aScalar ) +{ + x -= aScalar; + y -= aScalar; + return *this; +} + + template int VECTOR2::LineSide( const VECTOR2& aStart, const VECTOR2& aEnd ) const { @@ -463,6 +493,13 @@ VECTOR2 VECTOR2::operator+( const VECTOR2& aVector ) const } +template +VECTOR2 VECTOR2::operator+( const T& aScalar ) const +{ + return VECTOR2 ( x + aScalar, y + aScalar ); +} + + template VECTOR2 VECTOR2::operator-( const VECTOR2& aVector ) const { @@ -470,6 +507,13 @@ VECTOR2 VECTOR2::operator-( const VECTOR2& aVector ) const } +template +VECTOR2 VECTOR2::operator-( const T& aScalar ) const +{ + return VECTOR2 ( x - aScalar, y - aScalar ); +} + + template VECTOR2 VECTOR2::operator-() {