From 2f20661b5b3703b1b226cbee72f97096a8369b58 Mon Sep 17 00:00:00 2001 From: zvon Date: Sat, 13 Mar 2021 18:36:29 +0100 Subject: [PATCH] SDLPP: formatting, make compileable on Linux --- sdlpp/sdlpp_circlecolider.cpp | 2 +- sdlpp/sdlpp_circlecolider.hpp | 6 ++-- sdlpp/sdlpp_circlerenderer.cpp | 7 +++-- sdlpp/sdlpp_circlerenderer.hpp | 26 ++++++++++------- sdlpp/sdlpp_collision.cpp | 11 +++---- sdlpp/sdlpp_font.cpp | 4 +-- sdlpp/sdlpp_fontconfiguration.hpp | 1 + sdlpp/sdlpp_geometry_vector.hpp | 18 ++++++------ sdlpp/sdlpp_line.hpp | 48 +++++++++++++++---------------- sdlpp/sdlpp_linerenderer.cpp | 12 ++++---- sdlpp/sdlpp_linerenderer.hpp | 18 ++++++------ sdlpp/sdlpp_rectrenderer.cpp | 6 ++-- sdlpp/sdlpp_rectrenderer.hpp | 25 ++++++++++------ sdlpp/sdlpp_renderobject.cpp | 2 +- sdlpp/sdlpp_renderobject.hpp | 2 +- sdlpp/sdlpp_vector.hpp | 30 +++++++++---------- 16 files changed, 118 insertions(+), 100 deletions(-) diff --git a/sdlpp/sdlpp_circlecolider.cpp b/sdlpp/sdlpp_circlecolider.cpp index 9355163..6693f31 100644 --- a/sdlpp/sdlpp_circlecolider.cpp +++ b/sdlpp/sdlpp_circlecolider.cpp @@ -3,7 +3,7 @@ namespace SDLPP { CircleColider::CircleColider( double x, double y, double rad ) - : CircleColider( { x, y }, rad ){}; + : CircleColider( { x, y }, rad ) {} CircleColider::CircleColider( const Vec2D< double > ¢er, double rad ) : CollisionPolygon( center ), original_rad( rad ) {} diff --git a/sdlpp/sdlpp_circlecolider.hpp b/sdlpp/sdlpp_circlecolider.hpp index 3199197..ec9364d 100644 --- a/sdlpp/sdlpp_circlecolider.hpp +++ b/sdlpp/sdlpp_circlecolider.hpp @@ -10,7 +10,7 @@ namespace SDLPP { class SDLPPSCOPE CircleColider : public CollisionPolygon { public: CircleColider( double x, double y, double rad ); - CircleColider( const Vec2D ¢er, double rad ); + CircleColider( const Vec2D< double > ¢er, double rad ); virtual ~CircleColider() {} virtual bool colidesWith( const CollisionPolygon &other ) const override; @@ -25,8 +25,8 @@ public: const SDL_Color &outline_color ) override; virtual void render( Renderer &renderer, const SDL_Color &color ) override; virtual void render( Renderer &renderer ) override; - virtual std::shared_ptr copySelf() override; - virtual std::vector> getLines() const override; + virtual std::shared_ptr< CollisionPolygon > copySelf() override; + virtual std::vector< Line< int > > getLines() const override; private: int getRadius() const; diff --git a/sdlpp/sdlpp_circlerenderer.cpp b/sdlpp/sdlpp_circlerenderer.cpp index 99a5992..10f61a9 100644 --- a/sdlpp/sdlpp_circlerenderer.cpp +++ b/sdlpp/sdlpp_circlerenderer.cpp @@ -28,7 +28,7 @@ CircleRender::CircleRender( Vec2D< double > center, double rad, CircleRender::CircleRender( Vec2D< double > center, double rad, std::shared_ptr< Renderer > &r, - std::shared_ptr< Texture > &/*UNUSED*/ ) + std::shared_ptr< Texture > & /*UNUSED*/ ) : CircleRender( center, rad, r ) { throw "I don't support textures yet!!!"; } @@ -63,9 +63,10 @@ void CircleRender::setOutlineColor( const std::string &color ) { polygon->setOutlineColor( color ); } -std::pair< Vec2D, Vec2D > +std::pair< Vec2D< double >, Vec2D< double > > CircleRender::getDoubleRect() const { - return { { original.getX() - og_r, original.getY() - og_r }, { 2 * og_r, 2 * og_r } }; + return { { original.getX() - og_r, original.getY() - og_r }, + { 2 * og_r, 2 * og_r } }; } int CircleRender::leftmost() { diff --git a/sdlpp/sdlpp_circlerenderer.hpp b/sdlpp/sdlpp_circlerenderer.hpp index bc872dc..17d7985 100644 --- a/sdlpp/sdlpp_circlerenderer.hpp +++ b/sdlpp/sdlpp_circlerenderer.hpp @@ -11,22 +11,28 @@ class SDLPPSCOPE CircleRender : public RenderObject { public: CircleRender() = delete; virtual ~CircleRender(){}; - CircleRender( double x, double y, double rad, std::shared_ptr< Renderer > &r ); - CircleRender( double x, double y, double rad, std::shared_ptr< Renderer > &r, + CircleRender( double x, double y, double rad, + std::shared_ptr< Renderer > &r ); + CircleRender( double x, double y, double rad, + std::shared_ptr< Renderer > &r, std::shared_ptr< Texture > &t ); - CircleRender( double x, double y, double rad, std::shared_ptr< Renderer > &r, + CircleRender( double x, double y, double rad, + std::shared_ptr< Renderer > &r, const std::string &img_or_color, bool is_polygon = false ); - CircleRender( Vec2D center, double rad, std::shared_ptr< Renderer > &r ); - CircleRender( Vec2D center, double rad, std::shared_ptr< Renderer > &r, + CircleRender( Vec2D< double > center, double rad, + std::shared_ptr< Renderer > &r ); + CircleRender( Vec2D< double > center, double rad, + std::shared_ptr< Renderer > &r, std::shared_ptr< Texture > &t ); - CircleRender( Vec2D center, double rad, std::shared_ptr< Renderer > &r, + CircleRender( Vec2D< double > center, double rad, + std::shared_ptr< Renderer > &r, const std::string &img_or_color, bool is_polygon = false ); virtual void setColor( const std::string &color ) override; virtual void setOutlineColor( const std::string &color ) override; - virtual void specialAction( int /*UNUSED*/ ) override{} - virtual void custom_move( int /*UNUSED*/ ) override{} - virtual std::pair< Vec2D, Vec2D > + virtual void specialAction( int /*UNUSED*/ ) override {} + virtual void custom_move( int /*UNUSED*/ ) override {} + virtual std::pair< Vec2D< double >, Vec2D< double > > getDoubleRect() const override; virtual int leftmost() override; virtual int topmost() override; @@ -43,7 +49,7 @@ public: std::string getColor() const; private: - virtual void copyTo(std::shared_ptr other) override; + virtual void copyTo( std::shared_ptr< RenderObject > other ) override; void updateXY(); double og_r; double r_; diff --git a/sdlpp/sdlpp_collision.cpp b/sdlpp/sdlpp_collision.cpp index f8dc63f..187554a 100644 --- a/sdlpp/sdlpp_collision.cpp +++ b/sdlpp/sdlpp_collision.cpp @@ -3,7 +3,7 @@ namespace SDLPP { CollisionPolygon::CollisionPolygon( double x, double y ) - : CollisionPolygon( Vec2D( x, y ) ) {} + : CollisionPolygon( Vec2D< double >( x, y ) ) {} CollisionPolygon::CollisionPolygon( const Vec2D< double > &input ) { original = input; @@ -54,11 +54,12 @@ bool infinityIntersection( const SDLPP::CollisionPolygon &infinite, bool intersects( const SDLPP::CollisionPolygon &p1, const SDLPP::CollisionPolygon &p2 ) { - if(p1.rightmost() < p2.leftmost() || p2.rightmost() < p1.leftmost() || p1.bottommost() < p2.topmost() || p2.bottommost() < p1.topmost()) + if ( p1.rightmost() < p2.leftmost() || p2.rightmost() < p1.leftmost() || + p1.bottommost() < p2.topmost() || p2.bottommost() < p1.topmost() ) return false; - for(auto &line : p1.getLines()) { - for(auto &line2 : p2.getLines()) { - if(linesCross(line, line2)) + for ( auto &line : p1.getLines() ) { + for ( auto &line2 : p2.getLines() ) { + if ( linesCross( line, line2 ) ) return true; } } diff --git a/sdlpp/sdlpp_font.cpp b/sdlpp/sdlpp_font.cpp index f4d7f11..d974cb7 100644 --- a/sdlpp/sdlpp_font.cpp +++ b/sdlpp/sdlpp_font.cpp @@ -1,8 +1,8 @@ #include "sdlpp_font.hpp" namespace SDLPP { -Font::Font( const std::string &font ) : font_path(font) {} -Font::Font( const std::string &font, int size ) : Font(font) { +Font::Font( const std::string &font ) : font_path( font ) {} +Font::Font( const std::string &font, int size ) : Font( font ) { original_size = size; font_ptr = TTF_OpenFont( font_path.c_str(), size ); checkFont(); diff --git a/sdlpp/sdlpp_fontconfiguration.hpp b/sdlpp/sdlpp_fontconfiguration.hpp index 08863de..d3bb44e 100644 --- a/sdlpp/sdlpp_fontconfiguration.hpp +++ b/sdlpp/sdlpp_fontconfiguration.hpp @@ -3,6 +3,7 @@ #include "sdlpp_common.hpp" #include "sdlpp_font.hpp" +#include namespace SDLPP { class SDLPPSCOPE FontConfiguration { diff --git a/sdlpp/sdlpp_geometry_vector.hpp b/sdlpp/sdlpp_geometry_vector.hpp index e1405fe..b6c85b2 100644 --- a/sdlpp/sdlpp_geometry_vector.hpp +++ b/sdlpp/sdlpp_geometry_vector.hpp @@ -6,24 +6,22 @@ #include namespace SDLPP { -template -double vecDotProduct( const Vec2D &a, const Vec2D &b ) { +template < typename T > +double vecDotProduct( const Vec2D< T > &a, const Vec2D< T > &b ) { return a * b; } -template -double vecLengthSquared( const Vec2D &vec ) { +template < typename T > double vecLengthSquared( const Vec2D< T > &vec ) { return vecDotProduct( vec, vec ); } -template -double vecLength( const Vec2D &vec ) { +template < typename T > double vecLength( const Vec2D< T > &vec ) { return std::sqrt( vecLengthSquared( vec ) ); } -template -double vecDistanceSquared( const Vec2D &a, const Vec2D &b ) { +template < typename T > +double vecDistanceSquared( const Vec2D< T > &a, const Vec2D< T > &b ) { return vecLengthSquared( a - b ); } -template -double vecDistance( const Vec2D &a, const Vec2D &b ) { +template < typename T > +double vecDistance( const Vec2D< T > &a, const Vec2D< T > &b ) { return vecLength( a - b ); } } // namespace SDLPP diff --git a/sdlpp/sdlpp_line.hpp b/sdlpp/sdlpp_line.hpp index e988b09..be93db0 100644 --- a/sdlpp/sdlpp_line.hpp +++ b/sdlpp/sdlpp_line.hpp @@ -6,37 +6,37 @@ #include namespace SDLPP { -template -class SDLPPSCOPE Line { +template < typename T > class SDLPPSCOPE Line { public: Line() = delete; ~Line() = default; - Line( const Vec2D &start, const Vec2D &end ) + Line( const Vec2D< T > &start, const Vec2D< T > &end ) : _start( start ), _end( end ) { updateMost(); } - Line( T x_1, T y_1, T x_2, T y_2 ) - : Line( { x_1, y_1 }, { x_2, y_2 } ) {} - Line( const Vec2D &start, const Vec2D &end, bool infinite ) - : Line( start, end ), _infinite( infinite ) {} + Line( T x_1, T y_1, T x_2, T y_2 ) : Line( { x_1, y_1 }, { x_2, y_2 } ) {} + Line( const Vec2D< T > &start, const Vec2D< T > &end, bool infinite ) + : Line( start, end ) { + _infinite = infinite; + } Line( T x_1, T y_1, T x_2, T y_2, bool infinite ) : Line( { x_1, y_1 }, { x_2, y_2 }, infinite ) {} - Line(const Line &input) : Line(input.getStart(), input.getEnd()) {} - Line &operator=(const Line &input) { + Line( const Line &input ) : Line( input.getStart(), input.getEnd() ) {} + Line &operator=( const Line &input ) { _start = input.getStart(); _end = input.getEnd(); updateMost(); return *this; } void updateMost() { - if(_start.getY() < _end.getY()) { + if ( _start.getY() < _end.getY() ) { top = &_start; bottom = &_end; } else { top = &_end; bottom = &_start; } - if(_start.getX() < _end.getX()) { + if ( _start.getX() < _end.getX() ) { left = &_start; right = &_end; } else { @@ -44,10 +44,10 @@ public: right = &_start; } } - const Vec2D &getStart() const { + const Vec2D< T > &getStart() const { return _start; } - const Vec2D &getEnd() const { + const Vec2D< T > &getEnd() const { return _end; } double length() const { @@ -62,30 +62,30 @@ public: bool isInfinite() { return _infinite; } - void add(const Vec2D &vec) { + void add( const Vec2D< T > &vec ) { _start += vec; _end += vec; } - const Vec2D &topmost() const { + const Vec2D< T > &topmost() const { return *top; } - const Vec2D &bottomost() const { + const Vec2D< T > &bottomost() const { return *bottom; } - const Vec2D &leftmost() const { + const Vec2D< T > &leftmost() const { return *left; } - const Vec2D &rightmost() const { + const Vec2D< T > &rightmost() const { return *right; } private: - Vec2D _start; - Vec2D _end; - Vec2D *top = nullptr; - Vec2D *bottom = nullptr; - Vec2D *left = nullptr; - Vec2D *right = nullptr; + Vec2D< T > _start; + Vec2D< T > _end; + Vec2D< T > *top = nullptr; + Vec2D< T > *bottom = nullptr; + Vec2D< T > *left = nullptr; + Vec2D< T > *right = nullptr; bool _infinite = false; }; } // namespace SDLPP diff --git a/sdlpp/sdlpp_linerenderer.cpp b/sdlpp/sdlpp_linerenderer.cpp index 9943e05..dbb7eea 100644 --- a/sdlpp/sdlpp_linerenderer.cpp +++ b/sdlpp/sdlpp_linerenderer.cpp @@ -67,7 +67,7 @@ void LineRenderer::setPos( double x, double y ) { void LineRenderer::setPos( const std::pair< double, double > &pos ) { setPos( pos.first, pos.second ); } -void LineRenderer::setPos( const Vec2D &vec ) { +void LineRenderer::setPos( const Vec2D< double > &vec ) { setPos( vec.getX(), vec.getY() ); } Vec2D< double > LineRenderer::getPos() const { @@ -135,7 +135,7 @@ SDL_Rect LineRenderer::getRect() { return { leftmost(), topmost(), rightmost() - leftmost(), bottommost() - topmost() }; } -std::pair< Vec2D, Vec2D > +std::pair< Vec2D< double >, Vec2D< double > > LineRenderer::getDoubleRect() const { return { original.getStart(), original.getEnd() - original.getStart() }; } @@ -151,14 +151,16 @@ void LineRenderer::updateXY() { if ( width > height ) { auto multiplier = static_cast< double >( width ) / static_cast< double >( height ); - x1_ = original.getStart().getX() + static_cast< double >( multiplier - 1 ) / 2; - x2_ = original.getEnd().getX() + static_cast< double >( multiplier - 1 ) / 2; + x1_ = original.getStart().getX() + + static_cast< double >( multiplier - 1 ) / 2; + x2_ = original.getEnd().getX() + + static_cast< double >( multiplier - 1 ) / 2; } else { x1_ = original.getStart().getX(); x2_ = original.getEnd().getX(); } y1_ = original.getStart().getY(); y2_ = original.getEnd().getY(); - current = {{x1_, y1_}, {x2_, y2_}}; + current = { { x1_, y1_ }, { x2_, y2_ } }; } } // namespace SDLPP diff --git a/sdlpp/sdlpp_linerenderer.hpp b/sdlpp/sdlpp_linerenderer.hpp index c852296..1ccc82a 100644 --- a/sdlpp/sdlpp_linerenderer.hpp +++ b/sdlpp/sdlpp_linerenderer.hpp @@ -16,9 +16,9 @@ public: LineRenderer( double x1, double y1, double x2, double y2, const std::shared_ptr< Renderer > &r, const std::string &color ); - LineRenderer( const Line &line, + LineRenderer( const Line< double > &line, const std::shared_ptr< Renderer > &r ); - LineRenderer( const Line &line, + LineRenderer( const Line< double > &line, const std::shared_ptr< Renderer > &r, const std::string &color ); virtual void setColor( const std::string &color ) override; @@ -28,8 +28,8 @@ public: virtual void custom_move( int /*UNUSED*/ ) override {} virtual void setPos( double x, double y ) override; virtual void setPos( const std::pair< double, double > &pos ) override; - virtual void setPos( const Vec2D &vec ) override; - virtual Vec2D getPos() const override; + virtual void setPos( const Vec2D< double > &vec ) override; + virtual Vec2D< double > getPos() const override; virtual int leftmost() override; virtual int topmost() override; virtual int rightmost() override; @@ -43,16 +43,16 @@ public: virtual std::shared_ptr< RenderObject > copySelf() override; virtual SDL_Rect getRect() override; - virtual std::pair< Vec2D, Vec2D> + virtual std::pair< Vec2D< double >, Vec2D< double > > getDoubleRect() const override; void setOutlineColor( const std::string & /*UNUSED*/ ) override {} protected: - virtual void copyTo(std::shared_ptr other) override; + virtual void copyTo( std::shared_ptr< RenderObject > other ) override; void updateXY(); - Line original = {{0, 0}, {0, 0}}; - Line current = {{0, 0}, {0, 0}}; - Line pixel_line = {{0, 0}, {0, 0}}; + Line< double > original = { { 0, 0 }, { 0, 0 } }; + Line< double > current = { { 0, 0 }, { 0, 0 } }; + Line< int > pixel_line = { { 0, 0 }, { 0, 0 } }; bool centerx = false; std::tuple< int, int, int, int > _color; }; diff --git a/sdlpp/sdlpp_rectrenderer.cpp b/sdlpp/sdlpp_rectrenderer.cpp index 34a414d..f747279 100644 --- a/sdlpp/sdlpp_rectrenderer.cpp +++ b/sdlpp/sdlpp_rectrenderer.cpp @@ -139,9 +139,11 @@ void RectangleRender::updateSizeAndPosition() { rect.x = std::round( current.getX() * dimension ); rect.y = std::round( current.getY() * dimension ); rect.w = - std::round( ( current.getX() + original_size.getX() ) * dimension ) - rect.x; + std::round( ( current.getX() + original_size.getX() ) * dimension ) - + rect.x; rect.h = - std::round( ( current.getY() + original_size.getY() ) * dimension ) - rect.y; + std::round( ( current.getY() + original_size.getY() ) * dimension ) - + rect.y; if ( polygon ) polygon->updateCollision( collisionPushX(), collisionPushY(), collisionWidth(), collisionHeight() ); diff --git a/sdlpp/sdlpp_rectrenderer.hpp b/sdlpp/sdlpp_rectrenderer.hpp index aa73f3f..d4a59aa 100644 --- a/sdlpp/sdlpp_rectrenderer.hpp +++ b/sdlpp/sdlpp_rectrenderer.hpp @@ -32,31 +32,38 @@ public: const std::shared_ptr< Renderer > &r, const std::string &img, const SDL_Rect &source_rect ); - RectangleRender( const Vec2D &top_left, const Vec2D &size, + RectangleRender( const Vec2D< double > &top_left, + const Vec2D< double > &size, const std::shared_ptr< Renderer > &r ); - RectangleRender( const Vec2D &top_left, const Vec2D &size, + RectangleRender( const Vec2D< double > &top_left, + const Vec2D< double > &size, const std::shared_ptr< Renderer > &r, const std::shared_ptr< Texture > &t, int source_x, int source_y, int source_width, int source_height ); - RectangleRender( const Vec2D &top_left, const Vec2D &size, + RectangleRender( const Vec2D< double > &top_left, + const Vec2D< double > &size, const std::shared_ptr< Renderer > &r, const std::shared_ptr< Texture > &t, const SDL_Rect &source_rect = { -1, -1, -1, -1 } ); - RectangleRender( const Vec2D &top_left, const Vec2D &size, + RectangleRender( const Vec2D< double > &top_left, + const Vec2D< double > &size, const std::shared_ptr< Renderer > &r, const std::string &img_or_color, bool is_polygon = false ); - RectangleRender( const Vec2D &top_left, const Vec2D &size, + RectangleRender( const Vec2D< double > &top_left, + const Vec2D< double > &size, const std::shared_ptr< Renderer > &r, const std::string &img, int source_x, int source_y, int source_width, int source_height ); - RectangleRender( const Vec2D &top_left, const Vec2D &size, + RectangleRender( const Vec2D< double > &top_left, + const Vec2D< double > &size, const std::shared_ptr< Renderer > &r, const std::string &img, const SDL_Rect &source_rect ); virtual void setColor( const std::string &color ) override; virtual void setOutlineColor( const std::string &color ) override; virtual void specialAction( int /*UNUSED*/ ) override {} virtual void custom_move( int /*UNUSED*/ ) override {} - virtual std::pair< Vec2D, Vec2D > getDoubleRect() const override; + virtual std::pair< Vec2D< double >, Vec2D< double > > + getDoubleRect() const override; virtual int leftmost() override; virtual int topmost() override; virtual int rightmost() override; @@ -74,8 +81,8 @@ public: protected: virtual void copyTo( std::shared_ptr< RenderObject > other ) override; void updateXY(); - Vec2D original_size; - Vec2D size; + Vec2D< double > original_size; + Vec2D< double > size; std::string color = ""; }; } // end of namespace SDLPP diff --git a/sdlpp/sdlpp_renderobject.cpp b/sdlpp/sdlpp_renderobject.cpp index 2348073..acdfcf8 100644 --- a/sdlpp/sdlpp_renderobject.cpp +++ b/sdlpp/sdlpp_renderobject.cpp @@ -34,7 +34,7 @@ void RenderObject::setPos( double x, double y ) { void RenderObject::setPos( const std::pair< double, double > &pos ) { setPos( pos.first, pos.second ); } -void RenderObject::setPos( const Vec2D &vec ) { +void RenderObject::setPos( const Vec2D< double > &vec ) { setPos( vec.getX(), vec.getY() ); } Vec2D< double > RenderObject::getPos() const { diff --git a/sdlpp/sdlpp_renderobject.hpp b/sdlpp/sdlpp_renderobject.hpp index df09cb1..125f04a 100644 --- a/sdlpp/sdlpp_renderobject.hpp +++ b/sdlpp/sdlpp_renderobject.hpp @@ -31,7 +31,7 @@ public: getDoubleRect() const = 0; virtual void setPos( double x, double y ); virtual void setPos( const std::pair< double, double > &pos ); - virtual void setPos( const Vec2D &vec ); + virtual void setPos( const Vec2D< double > &vec ); virtual Vec2D< double > getPos() const; bool colidesWith( const RenderObject &other ) const; template < class T > void addCollision( const T &p ) { diff --git a/sdlpp/sdlpp_vector.hpp b/sdlpp/sdlpp_vector.hpp index 4644c9e..e567e8a 100644 --- a/sdlpp/sdlpp_vector.hpp +++ b/sdlpp/sdlpp_vector.hpp @@ -4,53 +4,53 @@ #include "sdlpp_common.hpp" namespace SDLPP { -template -class SDLPPSCOPE Vec2D { +template < typename T > class SDLPPSCOPE Vec2D { public: Vec2D() = default; ~Vec2D() = default; - Vec2D(T x, T y) : _x(x), _y(y) {} + Vec2D( T x, T y ) : _x( x ), _y( y ) {} T getX() const { return _x; } T getY() const { return _y; } - Vec2D operator-(const Vec2D &other) const { + Vec2D operator-( const Vec2D &other ) const { return Vec2D( getX() - other.getX(), getY() - other.getY() ); } - Vec2D operator+(const Vec2D &other) const { + Vec2D operator+( const Vec2D &other ) const { return Vec2D( getX() + other.getX(), getY() + other.getY() ); } - Vec2D operator*(double multiplier) const { + Vec2D operator*( double multiplier ) const { return Vec2D( getX() * multiplier, getY() * multiplier ); } - Vec2D operator/(double divisor) const { + Vec2D operator/( double divisor ) const { return *this * ( 1.0 / divisor ); } - T operator*(const Vec2D &other) const { + T operator*( const Vec2D &other ) const { return getX() * other.getX() + getY() * other.getY(); } - Vec2D &operator+=(const Vec2D &other) { + Vec2D &operator+=( const Vec2D &other ) { *this = *this + other; return *this; } - Vec2D &operator-=(const Vec2D &other) { + Vec2D &operator-=( const Vec2D &other ) { *this = *this - other; return *this; } + private: T _x = 0.0; T _y = 0.0; }; -template -Vec2D operator*(double multiplier, const Vec2D &vec) { +template < typename T > +Vec2D< T > operator*( double multiplier, const Vec2D< T > &vec ) { return vec * multiplier; } -template -Vec2D operator/(double divisor, const Vec2D &vec) { +template < typename T > +Vec2D< T > operator/( double divisor, const Vec2D< T > &vec ) { return vec / divisor; } -} +} // namespace SDLPP #endif