cpp-sdl2
C++ header-only SDL2 wrapper
sdl::Vec2< T, Base > Class Template Reference

Generic templated 2D vector class. More...

#include <vec2.hpp>

+ Inheritance diagram for sdl::Vec2< T, Base >:

Public Member Functions

constexpr Vec2 ()
 ctor, that will initialize vector to null vector More...
 
constexpr Vec2 (T x, T y)
 ctor that will initialize it to the current value More...
 
constexpr Vec2 (SDL_Point const &p)
 Convert SDL_Point to sdl::Vec2. More...
 
constexpr Vec2 (Vec2 const &) noexcept=default
 
constexpr Vec2 (Vec2 &&) noexcept=default
 
Vec2operator= (Vec2 const &) noexcept=default
 
Vec2operator= (Vec2 &&) noexcept=default
 
constexpr Vec2 operator- () const
 Return the opposite vector. More...
 
Vec2operator+= (Vec2 const &other)
 Add vector to this one. More...
 
Vec2operator-= (Vec2 const &other)
 Substract vector to this one. More...
 
Vec2operator*= (T value)
 Multiply vector to this one (x1*x2, y1*y2) More...
 
Vec2operator/= (T value)
 Divide vector to this one (x1/x2, y1/y2) More...
 
constexpr Vec2 operator+ (Vec2 const &other) const
 Add vectors together. More...
 
constexpr Vec2 operator- (Vec2 const &other) const
 Substract vectors together. More...
 
constexpr Vec2 operator* (T value) const
 Multiply vectors together. More...
 
constexpr Vec2 operator/ (T value) const
 Divide vectors together. More...
 
constexpr bool operator== (Vec2 const &other) const
 Compare vectors, true if they are the same. More...
 
constexpr bool operator!= (Vec2 const &other) const
 Compare vectors, false if they are the same. More...
 
Vec2 clamped (SDL_Rect const &box) const
 Clamp vector inside a box rectangle were to clamp vector. More...
 
void clamp (SDL_Rect const &box)
 Clamp vector inside a box rectangle were to clamp vector. More...
 
length () const
 Get lenghts of this vector. More...
 
sqlength () const
 Get squared lenght of this vector. More...
 
bool is_null () const
 Return true if this vector is null. More...
 
Vec2 normalized () const
 Return normalized copy of this vector. More...
 
void normalize ()
 Normalize this vector. More...
 
template<typename U >
 operator Vec2< U > () const
 Convert this vectort to a vector of <U> type. More...
 

Static Public Member Functions

template<typename A >
static constexpr Vec2 from_polar (A alpha, T radius)
 Convert a vector in polar cordinates to cartesian in the 2D plan. More...
 

Private Member Functions

clamp (T x, T a, T b)
 Actual implementation of clamp function. More...
 

Friends

constexpr Vec2 operator* (T lhs, Vec2 const &rhs)
 Multiply operator that works on the other side. More...
 
std::ostream & operator<< (std::ostream &stream, Vec2 const &v)
 Print that vector to stream. More...
 

Detailed Description

template<typename T, class Base = details::Vec2Base<T>>
class sdl::Vec2< T, Base >

Generic templated 2D vector class.

Definition at line 24 of file vec2.hpp.

Constructor & Destructor Documentation

◆ Vec2() [1/5]

template<typename T , class Base = details::Vec2Base<T>>
constexpr sdl::Vec2< T, Base >::Vec2 ( )
inline

ctor, that will initialize vector to null vector

Definition at line 28 of file vec2.hpp.

◆ Vec2() [2/5]

template<typename T , class Base = details::Vec2Base<T>>
constexpr sdl::Vec2< T, Base >::Vec2 ( x,
y 
)
inline

ctor that will initialize it to the current value

Definition at line 30 of file vec2.hpp.

References sdl::details::Vec2Base< T >::x.

◆ Vec2() [3/5]

template<typename T , class Base = details::Vec2Base<T>>
constexpr sdl::Vec2< T, Base >::Vec2 ( SDL_Point const &  p)
inline

Convert SDL_Point to sdl::Vec2.

Definition at line 32 of file vec2.hpp.

◆ Vec2() [4/5]

template<typename T , class Base = details::Vec2Base<T>>
constexpr sdl::Vec2< T, Base >::Vec2 ( Vec2< T, Base > const &  )
defaultnoexcept

◆ Vec2() [5/5]

template<typename T , class Base = details::Vec2Base<T>>
constexpr sdl::Vec2< T, Base >::Vec2 ( Vec2< T, Base > &&  )
defaultnoexcept

Member Function Documentation

◆ clamp() [1/2]

template<typename T , class Base = details::Vec2Base<T>>
void sdl::Vec2< T, Base >::clamp ( SDL_Rect const &  box)
inline

Clamp vector inside a box rectangle were to clamp vector.

Definition at line 109 of file vec2.hpp.

Referenced by sdl::Vec2< T, Base >::clamped().

◆ clamp() [2/2]

template<typename T , class Base = details::Vec2Base<T>>
T sdl::Vec2< T, Base >::clamp ( x,
a,
b 
)
inlineprivate

Actual implementation of clamp function.

Definition at line 156 of file vec2.hpp.

◆ clamped()

template<typename T , class Base = details::Vec2Base<T>>
Vec2 sdl::Vec2< T, Base >::clamped ( SDL_Rect const &  box) const
inline

Clamp vector inside a box rectangle were to clamp vector.

Definition at line 101 of file vec2.hpp.

References sdl::Vec2< T, Base >::clamp().

◆ from_polar()

template<typename T , class Base = details::Vec2Base<T>>
template<typename A >
static constexpr Vec2 sdl::Vec2< T, Base >::from_polar ( alpha,
radius 
)
inlinestatic

Convert a vector in polar cordinates to cartesian in the 2D plan.

Definition at line 39 of file vec2.hpp.

◆ is_null()

template<typename T , class Base = details::Vec2Base<T>>
bool sdl::Vec2< T, Base >::is_null ( ) const
inline

Return true if this vector is null.

Definition at line 121 of file vec2.hpp.

◆ length()

template<typename T , class Base = details::Vec2Base<T>>
T sdl::Vec2< T, Base >::length ( ) const
inline

Get lenghts of this vector.

Definition at line 116 of file vec2.hpp.

◆ normalize()

template<typename T , class Base = details::Vec2Base<T>>
void sdl::Vec2< T, Base >::normalize ( )
inline

Normalize this vector.

Definition at line 132 of file vec2.hpp.

Referenced by sdl::Vec2< T, Base >::normalized().

◆ normalized()

template<typename T , class Base = details::Vec2Base<T>>
Vec2 sdl::Vec2< T, Base >::normalized ( ) const
inline

Return normalized copy of this vector.

Definition at line 124 of file vec2.hpp.

References sdl::Vec2< T, Base >::normalize().

◆ operator Vec2< U >()

template<typename T , class Base = details::Vec2Base<T>>
template<typename U >
sdl::Vec2< T, Base >::operator Vec2< U > ( ) const
inlineexplicit

Convert this vectort to a vector of <U> type.

Definition at line 143 of file vec2.hpp.

◆ operator!=()

template<typename T , class Base = details::Vec2Base<T>>
constexpr bool sdl::Vec2< T, Base >::operator!= ( Vec2< T, Base > const &  other) const
inline

Compare vectors, false if they are the same.

Definition at line 94 of file vec2.hpp.

◆ operator*()

template<typename T , class Base = details::Vec2Base<T>>
constexpr Vec2 sdl::Vec2< T, Base >::operator* ( value) const
inline

Multiply vectors together.

Definition at line 84 of file vec2.hpp.

◆ operator*=()

template<typename T , class Base = details::Vec2Base<T>>
Vec2& sdl::Vec2< T, Base >::operator*= ( value)
inline

Multiply vector to this one (x1*x2, y1*y2)

Definition at line 65 of file vec2.hpp.

◆ operator+()

template<typename T , class Base = details::Vec2Base<T>>
constexpr Vec2 sdl::Vec2< T, Base >::operator+ ( Vec2< T, Base > const &  other) const
inline

Add vectors together.

Definition at line 80 of file vec2.hpp.

◆ operator+=()

template<typename T , class Base = details::Vec2Base<T>>
Vec2& sdl::Vec2< T, Base >::operator+= ( Vec2< T, Base > const &  other)
inline

Add vector to this one.

Definition at line 51 of file vec2.hpp.

◆ operator-() [1/2]

template<typename T , class Base = details::Vec2Base<T>>
constexpr Vec2 sdl::Vec2< T, Base >::operator- ( ) const
inline

Return the opposite vector.

Definition at line 48 of file vec2.hpp.

◆ operator-() [2/2]

template<typename T , class Base = details::Vec2Base<T>>
constexpr Vec2 sdl::Vec2< T, Base >::operator- ( Vec2< T, Base > const &  other) const
inline

Substract vectors together.

Definition at line 82 of file vec2.hpp.

◆ operator-=()

template<typename T , class Base = details::Vec2Base<T>>
Vec2& sdl::Vec2< T, Base >::operator-= ( Vec2< T, Base > const &  other)
inline

Substract vector to this one.

Definition at line 58 of file vec2.hpp.

◆ operator/()

template<typename T , class Base = details::Vec2Base<T>>
constexpr Vec2 sdl::Vec2< T, Base >::operator/ ( value) const
inline

Divide vectors together.

Definition at line 86 of file vec2.hpp.

◆ operator/=()

template<typename T , class Base = details::Vec2Base<T>>
Vec2& sdl::Vec2< T, Base >::operator/= ( value)
inline

Divide vector to this one (x1/x2, y1/y2)

Definition at line 72 of file vec2.hpp.

◆ operator=() [1/2]

template<typename T , class Base = details::Vec2Base<T>>
Vec2& sdl::Vec2< T, Base >::operator= ( Vec2< T, Base > const &  )
defaultnoexcept

◆ operator=() [2/2]

template<typename T , class Base = details::Vec2Base<T>>
Vec2& sdl::Vec2< T, Base >::operator= ( Vec2< T, Base > &&  )
defaultnoexcept

◆ operator==()

template<typename T , class Base = details::Vec2Base<T>>
constexpr bool sdl::Vec2< T, Base >::operator== ( Vec2< T, Base > const &  other) const
inline

Compare vectors, true if they are the same.

Definition at line 89 of file vec2.hpp.

◆ sqlength()

template<typename T , class Base = details::Vec2Base<T>>
T sdl::Vec2< T, Base >::sqlength ( ) const
inline

Get squared lenght of this vector.

Definition at line 118 of file vec2.hpp.

Friends And Related Function Documentation

◆ operator*

template<typename T , class Base = details::Vec2Base<T>>
constexpr Vec2 operator* ( lhs,
Vec2< T, Base > const &  rhs 
)
friend

Multiply operator that works on the other side.

Definition at line 97 of file vec2.hpp.

◆ operator<<

template<typename T , class Base = details::Vec2Base<T>>
std::ostream& operator<< ( std::ostream &  stream,
Vec2< T, Base > const &  v 
)
friend

Print that vector to stream.

Definition at line 149 of file vec2.hpp.


The documentation for this class was generated from the following file: