Ginger 1.1.5; VERSION ${PROJECT_VERSION}
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Friends | List of all members
ginger::Vector2< T1, T2 > Class Template Reference

Vector2. More...

#include <vector2.hpp>

Public Member Functions

constexpr Vector2 ()
 Construct a new Vector2 object.
 
constexpr Vector2 (T1 x, T2 y) noexcept
 Construct a new Vector2 object.
 
template<typename U1 , typename U2 >
constexpr Vector2 (const Vector2< U1, U2 > &other)
 Construct a new Vector2 object.
 
constexpr auto x () const noexcept -> const T1 &
 
constexpr auto y () const noexcept -> const T2 &
 
template<typename U1 , typename U2 >
constexpr auto dot (const Vector2< U1, U2 > &other) const -> double
 
template<typename U1 , typename U2 >
constexpr auto cross (const Vector2< U1, U2 > &other) const -> double
 

Public Attributes

T1 _x
 
T2 _y
 

Friends

template<class Stream >
auto operator<< (Stream &out, const Vector2< T1, T2 > &vec) -> Stream &
 

Arithmetic operators

definie +, -, *, /, +=, -=, *=, /=, etc.

constexpr auto operator- () const -> Vector2< T1, T2 >
 
template<typename U1 , typename U2 >
auto operator+= (const Vector2< U1, U2 > &other) -> Vector2< T1, T2 > &
 
template<typename U1 , typename U2 >
auto operator-= (const Vector2< U1, U2 > &other) -> Vector2< T1, T2 > &
 
template<typename R >
auto operator*= (const R &alpha) -> Vector2< T1, T2 > &
 
template<typename R >
auto operator/= (const R &alpha) -> Vector2< T1, T2 > &
 
template<typename U1 , typename U2 >
constexpr auto operator+ (Vector2< T1, T2 > x, const Vector2< U1, U2 > &y) -> Vector2< T1, T2 >
 
template<typename U1 , typename U2 >
constexpr auto operator- (Vector2< T1, T2 > x, const Vector2< U1, U2 > &y) -> Vector2< T1, T2 >
 
template<typename R >
constexpr auto operator* (Vector2< T1, T2 > x, const R &alpha) -> Vector2< T1, T2 >
 
template<typename R >
constexpr auto operator* (const R &alpha, Vector2< T1, T2 > x) -> Vector2< T1, T2 >
 
template<typename R >
constexpr auto operator/ (Vector2< T1, T2 > x, const R &alpha) -> Vector2< T1, T2 >
 

Detailed Description

template<typename T1, typename T2 = T1>
class ginger::Vector2< T1, T2 >

Vector2.

A template class representing a 2D vector with x and y components.

Template Parameters
T1The type of the x component
T2The type of the y component (defaults to T1)

Constructor & Destructor Documentation

◆ Vector2() [1/3]

template<typename T1 , typename T2 = T1>
constexpr ginger::Vector2< T1, T2 >::Vector2 ( )
inlineconstexpr

Construct a new Vector2 object.

The function is a constructor for a Vector2 object that initializes its x and y values to 0.

◆ Vector2() [2/3]

template<typename T1 , typename T2 = T1>
constexpr ginger::Vector2< T1, T2 >::Vector2 ( T1  x,
T2  y 
)
inlineconstexprnoexcept

Construct a new Vector2 object.

The function constructs a new Vector2 object with given x and y values.

Parameters
[in]xThe parameter x is of type T1&&, which means it is a forwarding reference. It can accept any type, and it is passed as an rvalue reference. This allows the constructor to efficiently move or forward the value of x into the _x member variable.
[in]yThe parameter "y" is the y-coordinate of the Vector2 object. It represents the vertical position of the vector in a 2D coordinate system.

◆ Vector2() [3/3]

template<typename T1 , typename T2 = T1>
template<typename U1 , typename U2 >
constexpr ginger::Vector2< T1, T2 >::Vector2 ( const Vector2< U1, U2 > &  other)
inlineexplicitconstexpr

Construct a new Vector2 object.

The function constructs a new Vector2 object with given x and y values.

Parameters
[in]xThe parameter x is of type T1&&, which means it is a forwarding reference. It can accept any type, and it is passed as an rvalue reference. This allows the constructor to efficiently move or forward the value of x into the _x member variable.
[in]yThe parameter "y" is the y-coordinate of the Vector2 object. It represents the vertical position of the vector in a 2D coordinate system.

Construct a new Vector2 object This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
[in]otherThe parameter "other" is a reference to another Vector2 object.

Member Function Documentation

◆ cross()

template<typename T1 , typename T2 = T1>
template<typename U1 , typename U2 >
constexpr auto ginger::Vector2< T1, T2 >::cross ( const Vector2< U1, U2 > &  other) const -> double
inlineconstexpr

The cross product of two 2D vectors (scalar, z-component):

\[ u \times v = u_x v_y - u_y v_x \]

Template Parameters
U1
U2
Parameters
[in]otherThe parameter "other" is a reference to an object of type Vector2<U1, U2>.
Returns
The function cross returns the result of the cross product between the current vector and the other vector. The result is of type double.

◆ dot()

template<typename T1 , typename T2 = T1>
template<typename U1 , typename U2 >
constexpr auto ginger::Vector2< T1, T2 >::dot ( const Vector2< U1, U2 > &  other) const -> double
inlineconstexpr

The dot function calculates the dot product of two 2D vectors:

\[ u \cdot v = u_x v_x + u_y v_y \]

Template Parameters
U1
U2
Parameters
[in]otherThe parameter "other" is a reference to an object of type Vector2<U1, U2>.
Returns
The dot function is returning the dot product of two vectors, which is a scalar value of type double.

◆ operator*=()

template<typename T1 , typename T2 = T1>
template<typename R >
auto ginger::Vector2< T1, T2 >::operator*= ( const R &  alpha) -> Vector2<T1, T2>&
inline

The function multiplies the x and y components of a Vector2 object by a given value.

Template Parameters
R
Parameters
[in]alphaalpha is a constant reference to a variable of type R.
Returns
The operator*= function returns a reference to the modified Vector2 object.

◆ operator+=()

template<typename T1 , typename T2 = T1>
template<typename U1 , typename U2 >
auto ginger::Vector2< T1, T2 >::operator+= ( const Vector2< U1, U2 > &  other) -> Vector2<T1, T2>&
inline

The function operator+= adds the components of another Vector2 object to the current Vector2 object and returns a reference to the updated object.

Template Parameters
U1
U2
Parameters
[in]otherThe parameter "other" is a reference to an object of type Vector2<U1, U2>.
Returns
a reference to a Vector2 object.

◆ operator-()

template<typename T1 , typename T2 = T1>
constexpr auto ginger::Vector2< T1, T2 >::operator- ( ) const -> Vector2<T1, T2>
inlineconstexpr

The above function negates a Vector2 object.

Returns
The operator- function returns a Vector2 object with the negated values of _x and _y.

◆ operator-=()

template<typename T1 , typename T2 = T1>
template<typename U1 , typename U2 >
auto ginger::Vector2< T1, T2 >::operator-= ( const Vector2< U1, U2 > &  other) -> Vector2<T1, T2>&
inline

The function subtracts the x and y components of another Vector2 object from the current Vector2 object.

Template Parameters
U1
U2
Parameters
[in]otherThe parameter "other" is a reference to an object of type Vector2<U1, U2>.
Returns
a reference to a Vector2 object.

◆ operator/=()

template<typename T1 , typename T2 = T1>
template<typename R >
auto ginger::Vector2< T1, T2 >::operator/= ( const R &  alpha) -> Vector2<T1, T2>&
inline

The function divides the x and y components of a Vector2 object by a given value.

Template Parameters
R
Parameters
[in]alphaThe parameter "alpha" is of type R, which is a template parameter. It represents the value by which the x and y components of the Vector2 object are divided.
Returns
a reference to the current instance of the Vector2 class.

◆ x()

template<typename T1 , typename T2 = T1>
constexpr auto ginger::Vector2< T1, T2 >::x ( ) const -> const T1&
inlineconstexprnoexcept

The function returns a reference to a constant value of type T1.

Returns
a reference to a constant object of type T1.

◆ y()

template<typename T1 , typename T2 = T1>
constexpr auto ginger::Vector2< T1, T2 >::y ( ) const -> const T2&
inlineconstexprnoexcept

The function y() returns a reference to a constant value of type T2.

Returns
a reference to a constant object of type T2.

Friends And Related Symbol Documentation

◆ operator* [1/2]

template<typename T1 , typename T2 = T1>
template<typename R >
constexpr auto operator* ( const R &  alpha,
Vector2< T1, T2 >  x 
) -> Vector2<T1, T2>
friend

The above function multiplies a Vector2 object by a scalar value.

Template Parameters
R
Parameters
[in]alphaThe parameter alpha is a scalar value that will be multiplied with the vector x.
[in]xA Vector2 object of type T1 and T2.
Returns
a Vector2 object.

◆ operator* [2/2]

template<typename T1 , typename T2 = T1>
template<typename R >
constexpr auto operator* ( Vector2< T1, T2 >  x,
const R &  alpha 
) -> Vector2<T1, T2>
friend

The function multiplies a Vector2 object by a scalar value.

Template Parameters
R
Parameters
[in]xA Vector2 object of type T1 and T2.
[in]alphaThe parameter alpha is a scalar value that will be used to multiply each component of the Vector2 object x.
Returns
a Vector2 object.

◆ operator+

template<typename T1 , typename T2 = T1>
template<typename U1 , typename U2 >
constexpr auto operator+ ( Vector2< T1, T2 >  x,
const Vector2< U1, U2 > &  y 
) -> Vector2<T1, T2>
friend

The above function is a friend function that adds two Vector2 objects and returns the result.

Template Parameters
U1
U2
Parameters
[in]xA Vector2 object with template types T1 and T2.
[in]yThe parameter y is a constant reference to a Vector2 object with template parameters U1 and U2.
Returns
a Vector2 object.

◆ operator-

template<typename T1 , typename T2 = T1>
template<typename U1 , typename U2 >
constexpr auto operator- ( Vector2< T1, T2 >  x,
const Vector2< U1, U2 > &  y 
) -> Vector2<T1, T2>
friend

The function is a friend function that subtracts two Vector2 objects and returns the result.

Template Parameters
U1
U2
Parameters
[in]xA Vector2 object with template types T1 and T2.
[in]yThe parameter y is a constant reference to a Vector2 object with template parameters U1 and U2.
Returns
a Vector2 object.

◆ operator/

template<typename T1 , typename T2 = T1>
template<typename R >
constexpr auto operator/ ( Vector2< T1, T2 >  x,
const R &  alpha 
) -> Vector2<T1, T2>
friend

The above function divides a Vector2 object by a scalar value.

Template Parameters
R
Parameters
[in]xA Vector2 object of type T1 and T2.
[in]alphaThe parameter alpha is a scalar value that is used to divide each component of the Vector2 object x.
Returns
a Vector2 object.

◆ operator<<

template<typename T1 , typename T2 = T1>
template<class Stream >
auto operator<< ( Stream &  out,
const Vector2< T1, T2 > &  vec 
) -> Stream&
friend

The above function overloads the << operator to output a Vector2 object in the format "{x, y}".

Template Parameters
Stream
Parameters
[out]outThe parameter "out" is a reference to a Stream object. It is used to output the contents of the Vector2 object to the stream.
[in]vecThe parameter vec is a constant reference to an object of type Vector2<T1, T2>.
Returns
The return type of the operator<< function is Stream&.

Member Data Documentation

◆ _x

template<typename T1 , typename T2 = T1>
T1 ginger::Vector2< T1, T2 >::_x

◆ _y

template<typename T1 , typename T2 = T1>
T2 ginger::Vector2< T1, T2 >::_y

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