|
Ginger 1.1.9
|
#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 & |
A template class representing a 2D vector with x and y components.
| T1 | The type of the x component |
| T2 | The type of the y component (defaults to T1) |
|
inlineconstexpr |
Construct a new Vector2 object.
The function constructs a new Vector2 object with given x and y values.
| [in] | x | The 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] | y | The parameter "y" is the y-coordinate of the Vector2 object. It represents the vertical position of the vector in a 2D coordinate system. |
|
inlineexplicitconstexpr |
Construct a new Vector2 object.
The function constructs a new Vector2 object with given x and y values.
| [in] | x | The 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] | y | The 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.
| [in] | other | The parameter "other" is a reference to another Vector2 object. |
|
inlineconstexpr |
The cross product of two 2D vectors (scalar, z-component):
\[ u \times v = u_x v_y - u_y v_x \]
| U1 | |
| U2 |
| [in] | other | The parameter "other" is a reference to an object of type Vector2<U1, U2>. |
cross returns the result of the cross product between the current vector and the other vector. The result is of type double.
|
inlineconstexpr |
The dot function calculates the dot product of two 2D vectors:
\[ u \cdot v = u_x v_x + u_y v_y \]
| U1 | |
| U2 |
| [in] | other | The parameter "other" is a reference to an object of type Vector2<U1, U2>. |
dot function is returning the dot product of two vectors, which is a scalar value of type double.
|
inline |
|
inline |
The function operator+= adds the components of another Vector2 object to the current Vector2 object and returns a reference to the updated object.
| U1 | |
| U2 |
| [in] | other | The parameter "other" is a reference to an object of type Vector2<U1, U2>. |
|
inlineconstexpr |
|
inline |
The function divides the x and y components of a Vector2 object by a given value.
| R |
| [in] | alpha | The 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. |
The function returns a reference to a constant value of type T1.
The function y() returns a reference to a constant value of type T2.
|
friend |
The above function is a friend function that adds two Vector2 objects and returns the result.
| U1 | |
| U2 |
| [in] | x | A Vector2 object with template types T1 and T2. |
| [in] | y | The parameter y is a constant reference to a Vector2 object with template parameters U1 and U2. |
|
friend |
The function is a friend function that subtracts two Vector2 objects and returns the result.
| U1 | |
| U2 |
| [in] | x | A Vector2 object with template types T1 and T2. |
| [in] | y | The parameter y is a constant reference to a Vector2 object with template parameters U1 and U2. |
The above function overloads the << operator to output a Vector2 object in the format "{x, y}".
| Stream |
| [out] | out | The parameter "out" is a reference to a Stream object. It is used to output the contents of the Vector2 object to the stream. |
| [in] | vec | The parameter vec is a constant reference to an object of type Vector2<T1, T2>. |
operator<< function is Stream&.