Recti 1.2.4
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
recti::Vector2< T1, T2 > Class Template Reference

2D vector template class. More...

#include <vector2.hpp>

Public Member Functions

constexpr Vector2 (T1 vec_x, T2 vec_y) noexcept
 Construct a new Vector2 object.
 
template<typename U1 , typename U2 >
constexpr Vector2 (const Vector2< U1, U2 > &other_vector)
 Construct a new Vector2 object.
 
constexpr auto x () const noexcept -> const T1 &
 Returns a const reference to the x-coordinate of the vector.
 
constexpr auto y () const noexcept -> const T2 &
 Returns a const reference to the y-coordinate of the vector.
 
template<typename U1 , typename U2 >
constexpr auto cross (const Vector2< U1, U2 > &other_vector) const
 Calculates the cross product of two Vector2 objects.
 
Comparison operators

definie ==, !=, <, >, <=, >=.

template<typename U1 , typename U2 >
constexpr auto operator== (const Vector2< U1, U2 > &other_vector) const -> bool
 Compares two Vector2 objects for equality.
 
template<typename U1 , typename U2 >
constexpr auto operator!= (const Vector2< U1, U2 > &other_vector) const -> bool
 Compares two Vector2 objects for inequality.
 

Friends

template<class Stream >
auto operator<< (Stream &output_stream, const Vector2 &vector) -> Stream &
 Overload the stream insertion operator to print a Vector2 object.
 

Arithmetic operators

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

constexpr auto operator- () const -> Vector2
 Negate the vector, returning a new vector with the negated components.
 
template<typename U1 , typename U2 >
CONSTEXPR14 auto operator+= (const Vector2< U1, U2 > &other_vector) -> Vector2 &
 Add the components of the given vector to this vector.
 
template<typename U1 , typename U2 >
CONSTEXPR14 auto operator-= (const Vector2< U1, U2 > &other_vector) -> Vector2 &
 Subtract the components of the given vector from this vector.
 
template<typename R >
CONSTEXPR14 auto operator*= (const R &scalar) -> Vector2 &
 Multiply the components of this vector by the given scalar.
 
template<typename R >
CONSTEXPR14 auto operator/= (const R &scalar) -> Vector2 &
 Divide the components of this vector by the given scalar.
 
template<typename U1 , typename U2 >
constexpr auto operator+ (Vector2 right_vector, const Vector2< U1, U2 > &left_vector) -> Vector2
 Add the components of the given vector to this vector.
 
template<typename U1 , typename U2 >
constexpr auto operator- (Vector2 right_vector, const Vector2< U1, U2 > &left_vector) -> Vector2
 Subtract the components of the given vector from this vector.
 
template<typename R >
constexpr auto operator* (Vector2 right_vector, const R &scalar) -> Vector2
 Multiply the components of this vector by the given scalar.
 
template<typename R >
constexpr auto operator* (const R &scalar, Vector2 left_vector) -> Vector2
 Multiply the components of the given vector by the scalar.
 
template<typename R >
constexpr auto operator/ (Vector2 right_vector, const R &scalar) -> Vector2
 Divide the components of this vector by the given scalar.
 

Detailed Description

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

2D vector template class.

Represents a 2-dimensional vector with x and y components. Supports arithmetic operations (addition, subtraction, scaling, cross product) and comparison operators.

Template Parameters
T1Type of the x-component.
T2Type of the y-component (defaults to T1).

Constructor & Destructor Documentation

◆ Vector2() [1/2]

template<typename T1 , typename T2 = T1>
constexpr recti::Vector2< T1, T2 >::Vector2 ( T1  vec_x,
T2  vec_y 
)
inlineconstexprnoexcept

Construct a new Vector2 object.

This is a constructor for the Vector2 class. It takes two parameters vec_x and vec_y, both of which are rvalue references (T1&& and T2&&). The constructor is marked as constexpr, meaning it can be evaluated at compile-time. The constructor is also marked as noexcept, indicating that it does not throw any exceptions.

Parameters
[in]vec_xThe x-coordinate of the vector.
[in]vec_yThe y-coordinate of the vector.

◆ Vector2() [2/2]

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

Construct a new Vector2 object.

This is a constructor for the Vector2 class. It takes a Vector2 object of a different type (U1 and U2) and initializes the current Vector2 object with the x and y coordinates of the other Vector2 object. This constructor is marked as constexpr, meaning it can be evaluated at compile-time.

Template Parameters
U1The type of the x-coordinate of the other Vector2 object.
U2The type of the y-coordinate of the other Vector2 object.
Parameters
[in]other_vectorThe other Vector2 object to copy from.

Member Function Documentation

◆ cross()

template<typename T1 , typename T2 = T1>
template<typename U1 , typename U2 >
constexpr auto recti::Vector2< T1, T2 >::cross ( const Vector2< U1, U2 > &  other_vector) const
inlineconstexpr

Calculates the cross product of two Vector2 objects.

This function computes the cross product of the current Vector2 object and the provided Vector2 object other_vector. The cross product of two 2D vectors is a scalar value that represents the signed area of the parallelogram formed by the two vectors.

Template Parameters
U1The type of the x-coordinate of the other Vector2 object.
U2The type of the y-coordinate of the other Vector2 object.
Parameters
[in]other_vectorThe other Vector2 object to compute the cross product with.
Returns
constexpr auto The cross product of the two Vector2 objects.

◆ operator!=()

template<typename T1 , typename T2 = T1>
template<typename U1 , typename U2 >
constexpr auto recti::Vector2< T1, T2 >::operator!= ( const Vector2< U1, U2 > &  other_vector) const -> bool
inlineconstexpr

Compares two Vector2 objects for inequality.

This operator compares the x and y coordinates of the current Vector2 object with the x and y coordinates of the provided Vector2 object other_vector. The comparison is done using std::tie to compare the individual coordinates.

Template Parameters
U1The type of the x-coordinate of the other Vector2 object.
U2The type of the y-coordinate of the other Vector2 object.
Parameters
[in]other_vectorThe other Vector2 object to compare against.
Returns
true If the two Vector2 objects have different x or y coordinates.

◆ operator*=()

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

Multiply the components of this vector by the given scalar.

Template Parameters
RThe type of the scalar to multiply by.
Parameters
[in]scalarThe scalar to multiply the vector components by.
Returns
A reference to this vector, after the multiplication.

◆ operator+=()

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

Add the components of the given vector to this vector.

Template Parameters
U1The type of the x component of the other vector.
U2The type of the y component of the other vector.
Parameters
[in]other_vectorThe vector to add to this vector.
Returns
A reference to this vector, after the addition.

◆ operator-()

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

Negate the vector, returning a new vector with the negated components.

Returns
A new vector with the negated x and y components.

◆ operator-=()

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

Subtract the components of the given vector from this vector.

Template Parameters
U1The type of the x component of the other vector.
U2The type of the y component of the other vector.
Parameters
[in]other_vectorThe vector to subtract from this vector.
Returns
A reference to this vector, after the subtraction.

◆ operator/=()

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

Divide the components of this vector by the given scalar.

Template Parameters
RThe type of the scalar to divide by.
Parameters
[in]scalarThe scalar to divide the vector components by.
Returns
A reference to this vector, after the division.

◆ operator==()

template<typename T1 , typename T2 = T1>
template<typename U1 , typename U2 >
constexpr auto recti::Vector2< T1, T2 >::operator== ( const Vector2< U1, U2 > &  other_vector) const -> bool
inlineconstexpr

Compares two Vector2 objects for equality.

This operator compares the x and y coordinates of the current Vector2 object with the x and y coordinates of the provided Vector2 object other_vector. The comparison is done using std::tie to compare the individual coordinates.

Template Parameters
U1The type of the x-coordinate of the other Vector2 object.
U2The type of the y-coordinate of the other Vector2 object.
Parameters
[in]other_vectorThe other Vector2 object to compare against.
Returns
true If the two Vector2 objects have the same x and y coordinates.

◆ x()

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

Returns a const reference to the x-coordinate of the vector.

This function provides read-only access to the x-coordinate of the Vector2 object.

Returns
constexpr const T1& A const reference to the x-coordinate of the vector.

◆ y()

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

Returns a const reference to the y-coordinate of the vector.

This function provides read-only access to the y-coordinate of the Vector2 object.

Returns
constexpr const T2& A const reference to the y-coordinate of the vector.

Friends And Related Symbol Documentation

◆ operator* [1/2]

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

Multiply the components of the given vector by the scalar.

Template Parameters
RThe type of the scalar to multiply by.
Parameters
[in]scalarThe scalar to multiply the vector components by.
[in]left_vectorThe vector to multiply.
Returns
A new vector that is the result of multiplying the input vector by the scalar.

◆ operator* [2/2]

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

Multiply the components of this vector by the given scalar.

Template Parameters
RThe type of the scalar to multiply by.
Parameters
[in]right_vectorThe vector to multiply.
[in]scalarThe scalar to multiply the vector components by.
Returns
A new vector that is the result of multiplying the input vector by the scalar.

◆ operator+

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

Add the components of the given vector to this vector.

Template Parameters
U1The type of the x component of the other vector.
U2The type of the y component of the other vector.
Parameters
[in]right_vectorThe vector to add.
[in]left_vectorThe vector to add to the right-hand side vector.
Returns
A new vector that is the sum of the two input vectors.

◆ operator-

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

Subtract the components of the given vector from this vector.

Template Parameters
U1The type of the x component of the other vector.
U2The type of the y component of the other vector.
Parameters
[in]right_vectorThe vector to subtract from.
[in]left_vectorThe vector to subtract.
Returns
A new vector that is the difference of the two input vectors.

◆ operator/

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

Divide the components of this vector by the given scalar.

Template Parameters
RThe type of the scalar to divide by.
Parameters
[in]right_vectorThe vector to divide.
[in]scalarThe scalar to divide the vector components by.
Returns
A new vector that is the result of dividing the input vector by the scalar.

◆ operator<<

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

Overload the stream insertion operator to print a Vector2 object.

Template Parameters
StreamThe stream type to insert the Vector2 into.
Parameters
[out]output_streamThe output stream to insert the Vector2 into.
[in]vectorThe Vector2 object to insert into the stream.
Returns
Stream& The modified output stream.

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