EllAlgo 1.6.13
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
Vector2< T > Class Template Reference

A simple 2D vector class for linear algebra operations. More...

#include <linear_algebra.hpp>

Public Types

using value_type = T
 

Public Member Functions

 Vector2 (size_t size)
 
 Vector2 (const std::vector< T > &v)
 
 ~Vector2 ()=default
 
 Vector2 (const Vector2 &)=default
 
Vector2operator= (const Vector2 &)=default
 
 Vector2 (Vector2 &&) noexcept=default
 
Vector2operator= (Vector2 &&) noexcept=default
 
T & operator[] (size_t i)
 
const T & operator[] (size_t i) const
 
size_t size () const
 
Vector2operator+= (const Vector2 &rhs)
 
Vector2operator-= (const Vector2 &rhs)
 
Vector2operator*= (T scalar)
 
dot (const Vector2 &other) const
 
norm () const
 

Detailed Description

template<typename T>
class Vector2< T >

A simple 2D vector class for linear algebra operations.

This class provides basic vector operations including addition, subtraction, scalar multiplication, dot product, and norm calculation. It is implemented using std::vector as the underlying storage.

Template Parameters
TThe element type (typically float or double)

Member Typedef Documentation

◆ value_type

template<typename T >
using Vector2< T >::value_type = T

Constructor & Destructor Documentation

◆ Vector2() [1/4]

template<typename T >
Vector2< T >::Vector2 ( size_t  size)
inline

Constructs a Vector2 with the given size, initializing all elements to the default value of T.

Parameters
sizeThe size of the Vector2.

◆ Vector2() [2/4]

template<typename T >
Vector2< T >::Vector2 ( const std::vector< T > &  v)
inline

Constructs a Vector2 from a std::vector.

Parameters
vThe std::vector to initialize the Vector2 with.

◆ ~Vector2()

template<typename T >
Vector2< T >::~Vector2 ( )
default

Destroys the Vector2 object.

◆ Vector2() [3/4]

template<typename T >
Vector2< T >::Vector2 ( const Vector2< T > &  )
default

Copy constructor.

◆ Vector2() [4/4]

template<typename T >
Vector2< T >::Vector2 ( Vector2< T > &&  )
defaultnoexcept

Move constructor.

Member Function Documentation

◆ dot()

template<typename T >
T Vector2< T >::dot ( const Vector2< T > &  other) const
inline

Computes the dot product of this Vector2 with the given Vector2.

\[ u \cdot v = \sum_{i=1}^{n} u_i v_i \]

Parameters
otherThe other Vector2 to compute the dot product with.
Returns
The dot product of this Vector2 and the given Vector2.

◆ norm()

template<typename T >
T Vector2< T >::norm ( ) const
inline

Computes the L2 norm (Euclidean length) of the Vector2.

\[ \|v\| = \sqrt{v_1^2 + v_2^2 + \cdots + v_n^2} \]

Returns
The L2 norm of the Vector2.

◆ operator*=()

template<typename T >
Vector2 & Vector2< T >::operator*= ( scalar)
inline

Multiplies each element of the Vector2 by the given scalar value.

Parameters
scalarThe scalar value to multiply the Vector2 elements by.
Returns
A reference to this Vector2 after the multiplication.

◆ operator+=()

template<typename T >
Vector2 & Vector2< T >::operator+= ( const Vector2< T > &  rhs)
inline

Adds the elements of the given Vector2 to the corresponding elements of this Vector2.

Parameters
rhsThe Vector2 to add to this Vector2.
Returns
A reference to this Vector2 after the addition.

◆ operator-=()

template<typename T >
Vector2 & Vector2< T >::operator-= ( const Vector2< T > &  rhs)
inline

Subtracts the elements of the given Vector2 from the corresponding elements of this Vector2.

Parameters
rhsThe Vector2 to subtract from this Vector2.
Returns
A reference to this Vector2 after the subtraction.

◆ operator=() [1/2]

template<typename T >
Vector2 & Vector2< T >::operator= ( const Vector2< T > &  )
default

Copy assignment operator.

◆ operator=() [2/2]

template<typename T >
Vector2 & Vector2< T >::operator= ( Vector2< T > &&  )
defaultnoexcept

Move assignment operator.

◆ operator[]() [1/2]

template<typename T >
T & Vector2< T >::operator[] ( size_t  i)
inline

Provides access to the elements of the Vector2 object.

Parameters
iThe index of the element to access.
Returns
A reference to the element at the specified index.

◆ operator[]() [2/2]

template<typename T >
const T & Vector2< T >::operator[] ( size_t  i) const
inline

Provides constant access to the elements of the Vector2 object.

Parameters
iThe index of the element to access.
Returns
A constant reference to the element at the specified index.

◆ size()

template<typename T >
size_t Vector2< T >::size ( ) const
inline

Returns the size of the Vector2 object.

Returns
The size of the Vector2 object.

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