NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
nc::Vec2 Class Reference

Holds a 2D vector. More...

#include <Vec2.hpp>

Public Member Functions

constexpr Vec2 ()=default
 
 Vec2 (const NdArray< double > &ndArray)
 
 Vec2 (const std::initializer_list< double > &inList)
 
constexpr Vec2 (double inX, double inY) noexcept
 
double angle (const Vec2 &otherVec) const noexcept
 
Vec2 clampMagnitude (double maxLength) const noexcept
 
double distance (const Vec2 &otherVec) const noexcept
 
double dot (const Vec2 &otherVec) const noexcept
 
Vec2 lerp (const Vec2 &otherVec, double t) const noexcept
 
double norm () const noexcept
 
Vec2 normalize () const noexcept
 
bool operator!= (const Vec2 &rhs) const noexcept
 
Vec2operator*= (double scalar) noexcept
 
Vec2operator+= (const Vec2 &rhs) noexcept
 
Vec2operator+= (double scalar) noexcept
 
Vec2operator-= (const Vec2 &rhs) noexcept
 
Vec2operator-= (double scalar) noexcept
 
Vec2operator/= (double scalar) noexcept
 
bool operator== (const Vec2 &rhs) const noexcept
 
Vec2 project (const Vec2 &otherVec) const noexcept
 
NdArray< double > toNdArray () const
 
std::string toString () const
 

Static Public Member Functions

static constexpr Vec2 down () noexcept
 
static constexpr Vec2 left () noexcept
 
static constexpr Vec2 right () noexcept
 
static constexpr Vec2 up () noexcept
 

Data Fields

double x { 0. }
 
double y { 0. }
 

Detailed Description

Holds a 2D vector.

Constructor & Destructor Documentation

◆ Vec2() [1/4]

constexpr nc::Vec2::Vec2 ( )
constexprdefault

Default Constructor

◆ Vec2() [2/4]

constexpr nc::Vec2::Vec2 ( double  inX,
double  inY 
)
inlineconstexprnoexcept

Constructor

Parameters
inXthe x component
inYthe y component

◆ Vec2() [3/4]

nc::Vec2::Vec2 ( const std::initializer_list< double > &  inList)
inline

Constructor

Parameters
inList

◆ Vec2() [4/4]

nc::Vec2::Vec2 ( const NdArray< double > &  ndArray)
inline

Constructor

Parameters
ndArray

Member Function Documentation

◆ angle()

double nc::Vec2::angle ( const Vec2 otherVec) const
inlinenoexcept

Returns the angle between the two vectors

Parameters
otherVec
Returns
the angle in radians

◆ clampMagnitude()

Vec2 nc::Vec2::clampMagnitude ( double  maxLength) const
inlinenoexcept

Returns a copy of the vector with its magnitude clamped to maxLength

Parameters
maxLength
Returns
Vec2

◆ distance()

double nc::Vec2::distance ( const Vec2 otherVec) const
inlinenoexcept

Returns the distance between the two vectors

Parameters
otherVec
Returns
the distance (equivalent to (a - b).norm()

◆ dot()

double nc::Vec2::dot ( const Vec2 otherVec) const
inlinenoexcept

Returns the dot product of the two vectors

Parameters
otherVec
Returns
the dot product

◆ down()

static constexpr Vec2 nc::Vec2::down ( )
inlinestaticconstexprnoexcept

Returns the unit vector [0, -1]

Returns
Vec2

◆ left()

static constexpr Vec2 nc::Vec2::left ( )
inlinestaticconstexprnoexcept

Returns the unit vector [-1, 0]

Returns
Vec2

◆ lerp()

Vec2 nc::Vec2::lerp ( const Vec2 otherVec,
double  t 
) const
inlinenoexcept

Linearly interpolates between two vectors

Parameters
otherVec
tthe amount to interpolate by (clamped from [0, 1]);
Returns
Vec2

◆ norm()

double nc::Vec2::norm ( ) const
inlinenoexcept

Returns the magnitude of the vector

Returns
magnitude of the vector

◆ normalize()

Vec2 nc::Vec2::normalize ( ) const
inlinenoexcept

Returns a new normalized Vec2

Returns
Vec2

◆ operator!=()

bool nc::Vec2::operator!= ( const Vec2 rhs) const
inlinenoexcept

Not Equality operator

Parameters
rhs
Returns
bool

◆ operator*=()

Vec2 & nc::Vec2::operator*= ( double  scalar)
inlinenoexcept

Scalar mulitplication

Parameters
scalar
Returns
Vec2

◆ operator+=() [1/2]

Vec2 & nc::Vec2::operator+= ( const Vec2 rhs)
inlinenoexcept

Adds the two vectors

Parameters
rhs
Returns
Vec2

◆ operator+=() [2/2]

Vec2 & nc::Vec2::operator+= ( double  scalar)
inlinenoexcept

Adds the scalar to the vector

Parameters
scalar
Returns
Vec2

◆ operator-=() [1/2]

Vec2 & nc::Vec2::operator-= ( const Vec2 rhs)
inlinenoexcept

Subtracts the two vectors

Parameters
rhs
Returns
Vec2

◆ operator-=() [2/2]

Vec2 & nc::Vec2::operator-= ( double  scalar)
inlinenoexcept

Subtracts the scalar from the vector

Parameters
scalar
Returns
Vec2

◆ operator/=()

Vec2 & nc::Vec2::operator/= ( double  scalar)
inlinenoexcept

Scalar division

Parameters
scalar
Returns
Vec2

◆ operator==()

bool nc::Vec2::operator== ( const Vec2 rhs) const
inlinenoexcept

Equality operator

Parameters
rhs
Returns
bool

◆ project()

Vec2 nc::Vec2::project ( const Vec2 otherVec) const
inlinenoexcept

Projects the vector onto the input vector

Parameters
otherVec
Returns
Vec2

◆ right()

static constexpr Vec2 nc::Vec2::right ( )
inlinestaticconstexprnoexcept

Returns the unit vector [1, 0]

Returns
Vec2

◆ toNdArray()

NdArray< double > nc::Vec2::toNdArray ( ) const
inline

Returns the Vec2 as an NdArray

Returns
NdArray

◆ toString()

std::string nc::Vec2::toString ( ) const
inline

Returns the Vec2 as a string

Returns
std::string

◆ up()

static constexpr Vec2 nc::Vec2::up ( )
inlinestaticconstexprnoexcept

Returns the unit vector [0, 1]

Returns
Vec2

Field Documentation

◆ x

double nc::Vec2::x { 0. }

◆ y

double nc::Vec2::y { 0. }

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