2021-03-12 21:33:46 +00:00
|
|
|
#ifndef SDLPP_HPP_VECTOR
|
|
|
|
#define SDLPP_HPP_VECTOR
|
|
|
|
|
|
|
|
#include "sdlpp_common.hpp"
|
|
|
|
|
|
|
|
namespace SDLPP {
|
2021-03-13 17:36:29 +00:00
|
|
|
template < typename T > class SDLPPSCOPE Vec2D {
|
2021-03-12 21:33:46 +00:00
|
|
|
public:
|
|
|
|
Vec2D() = default;
|
|
|
|
~Vec2D() = default;
|
2021-03-13 17:36:29 +00:00
|
|
|
Vec2D( T x, T y ) : _x( x ), _y( y ) {}
|
2021-03-12 21:33:46 +00:00
|
|
|
T getX() const {
|
|
|
|
return _x;
|
|
|
|
}
|
|
|
|
T getY() const {
|
|
|
|
return _y;
|
|
|
|
}
|
2021-03-13 17:36:29 +00:00
|
|
|
Vec2D operator-( const Vec2D &other ) const {
|
2021-03-12 21:33:46 +00:00
|
|
|
return Vec2D( getX() - other.getX(), getY() - other.getY() );
|
|
|
|
}
|
2021-03-13 17:36:29 +00:00
|
|
|
Vec2D operator+( const Vec2D &other ) const {
|
2021-03-12 21:33:46 +00:00
|
|
|
return Vec2D( getX() + other.getX(), getY() + other.getY() );
|
|
|
|
}
|
2021-03-13 17:36:29 +00:00
|
|
|
Vec2D operator*( double multiplier ) const {
|
2021-03-12 21:33:46 +00:00
|
|
|
return Vec2D( getX() * multiplier, getY() * multiplier );
|
|
|
|
}
|
2021-03-13 17:36:29 +00:00
|
|
|
Vec2D operator/( double divisor ) const {
|
2021-03-12 21:33:46 +00:00
|
|
|
return *this * ( 1.0 / divisor );
|
|
|
|
}
|
2021-03-13 17:36:29 +00:00
|
|
|
T operator*( const Vec2D &other ) const {
|
2021-03-12 21:33:46 +00:00
|
|
|
return getX() * other.getX() + getY() * other.getY();
|
|
|
|
}
|
2021-03-13 17:36:29 +00:00
|
|
|
Vec2D &operator+=( const Vec2D &other ) {
|
2021-03-12 21:33:46 +00:00
|
|
|
*this = *this + other;
|
|
|
|
return *this;
|
|
|
|
}
|
2021-03-13 17:36:29 +00:00
|
|
|
Vec2D &operator-=( const Vec2D &other ) {
|
2021-03-12 21:33:46 +00:00
|
|
|
*this = *this - other;
|
|
|
|
return *this;
|
|
|
|
}
|
2021-04-27 13:54:30 +00:00
|
|
|
bool operator==( const Vec2D &other ) {
|
|
|
|
return other._x == _x && other._y == _y;
|
|
|
|
}
|
2021-03-13 17:36:29 +00:00
|
|
|
|
2021-03-12 21:33:46 +00:00
|
|
|
private:
|
|
|
|
T _x = 0.0;
|
|
|
|
T _y = 0.0;
|
|
|
|
};
|
2021-03-13 17:36:29 +00:00
|
|
|
template < typename T >
|
|
|
|
Vec2D< T > operator*( double multiplier, const Vec2D< T > &vec ) {
|
2021-03-12 21:33:46 +00:00
|
|
|
return vec * multiplier;
|
|
|
|
}
|
2021-03-13 17:36:29 +00:00
|
|
|
template < typename T >
|
|
|
|
Vec2D< T > operator/( double divisor, const Vec2D< T > &vec ) {
|
2021-03-12 21:33:46 +00:00
|
|
|
return vec / divisor;
|
|
|
|
}
|
2021-03-13 17:36:29 +00:00
|
|
|
} // namespace SDLPP
|
2021-03-12 21:33:46 +00:00
|
|
|
|
|
|
|
#endif
|