PIP 5.6.1
Platform-Independent Primitives
Public Member Functions | Static Public Member Functions | List of all members
PIMathVector< Type > Class Template Reference

Template class for dynamic-size mathematical vector Provides vector operations including arithmetic, normalization, angles, cross product, and dot product for dynamic-size vectors. More...

#include <pimathvector.h>

Public Member Functions

 PIMathVector (const uint size=0, const Type &new_value=Type())
 Constructs a vector of size elements initialized with new_value.
 
 PIMathVector (const PIVector< Type > &val)
 Constructs a vector from a raw PIVector.
 
 PIMathVector (PIVector< Type > &&val)
 Move-constructs a vector from a raw PIVector.
 
 PIMathVector (std::initializer_list< Type > init_list)
 Constructs a vector from an initializer list.
 
template<uint Size>
 PIMathVector (const PIMathVectorT< Size, Type > &val)
 Constructs a dynamic vector from a fixed-size one.
 
uint size () const
 Returns the current vector size.
 
_CVectorresize (uint size, const Type &new_value=Type())
 Resizes the vector and fills new coordinates with new_value.
 
_CVector resized (uint size, const Type &new_value=Type())
 Returns a resized copy of this vector.
 
_CVectorfill (const Type &v)
 Fills all coordinates with v.
 
_CVectormove (const Type &v)
 Adds v to every coordinate.
 
_CVectormove (const _CVector &v)
 Adds another vector component-wise.
 
_CVectorswapElements (uint f, uint s)
 Swaps two coordinates in place.
 
Type lengthSqr () const
 Returns the squared Euclidean length.
 
Type length () const
 Returns the Euclidean length.
 
Type manhattanLength () const
 Returns the Manhattan length.
 
Type angleCos (const _CVector &v) const
 Returns the cosine of the angle to v.
 
Type angleSin (const _CVector &v) const
 Returns the sine of the angle to v.
 
Type angleRad (const _CVector &v) const
 Returns the angle to v in radians.
 
Type angleDeg (const _CVector &v) const
 Returns the angle to v in degrees.
 
_CVector projection (const _CVector &v)
 Returns the projection of this vector onto v.
 
_CVectornormalize ()
 Normalizes this vector in place.
 
_CVector normalized ()
 Returns a normalized copy of this vector.
 
bool isNull () const
 Returns true when all coordinates are zero.
 
bool isValid () const
 Returns true when the vector contains allocated storage.
 
bool isOrtho (const _CVector &v) const
 Returns true when this vector is orthogonal to v.
 
Type & operator[] (uint index)
 Returns writable access to a coordinate.
 
const Type & operator[] (uint index) const
 Returns read-only access to a coordinate.
 
Type at (uint index) const
 Returns a coordinate by value.
 
_CVectoroperator= (const Type &v)
 Assigns the same value to all coordinates.
 
bool operator== (const _CVector &v) const
 Compares two vectors component-wise.
 
bool operator!= (const _CVector &v) const
 Returns true when vectors differ in at least one coordinate.
 
void operator+= (const _CVector &v)
 Adds v component-wise.
 
void operator-= (const _CVector &v)
 Subtracts v component-wise.
 
void operator*= (const Type &v)
 Multiplies all coordinates by v.
 
void operator/= (const Type &v)
 Divides all coordinates by v.
 
_CVector operator- () const
 Returns the vector with inverted sign.
 
_CVector operator+ (const _CVector &v) const
 Returns the component-wise sum with v.
 
_CVector operator- (const _CVector &v) const
 Returns the component-wise difference with v.
 
_CVector operator* (const Type &v) const
 Returns a copy scaled by v.
 
_CVector operator/ (const Type &v) const
 Returns a copy divided by v.
 
_CVector cross (const _CVector &v) const
 Returns the 3D cross product with v.
 
Type dot (const _CVector &v) const
 Returns the scalar product with v.
 
_CVector mul (const _CVector &v) const
 Returns the component-wise product with v.
 
_CVector mul (const Type &v) const
 Returns a copy scaled by v.
 
_CVector div (const _CVector &v) const
 Returns the component-wise division by v.
 
_CVector div (const Type &v) const
 Returns a copy divided by v.
 
Type distToLine (const _CVector &lp0, const _CVector &lp1)
 Returns the distance from this 2D point to the line through lp0 and lp1.
 
PIVector< Type > toVector () const
 Returns the underlying PIVector copy.
 
void forEach (std::function< void(const Type &)> f) const
 Applies f to every coordinate without modifying the vector.
 
_CVectorforEach (std::function< void(Type &)> f)
 Applies f to every coordinate and returns this vector.
 
Type * data ()
 Returns a writable pointer to contiguous vector data.
 
const Type * data () const
 Returns a read-only pointer to contiguous vector data.
 

Static Public Member Functions

static PIMathVector fromTwoPoints (const _CVector &st, const _CVector &fn)
 Builds the displacement vector from point st to point fn.
 
static PIMathVector zeros (const uint size)
 Returns a vector of size zeros.
 
static PIMathVector ones (const uint size)
 Returns a vector of size ones.
 
static PIMathVector arange (const Type start, const Type stop, const Type step=Type(1))
 Returns a vector filled by the arithmetic progression [start, stop) with step step.
 
static _CVector cross (const _CVector &v1, const _CVector &v2)
 Returns the cross product of v1 and v2.
 
static Type dot (const _CVector &v1, const _CVector &v2)
 Returns the scalar product of v1 and v2.
 
static _CVector mul (const _CVector &v1, const _CVector &v2)
 Returns the component-wise product of v1 and v2.
 
static _CVector mul (const Type &v1, const _CVector &v2)
 Returns v2 scaled by v1.
 
static _CVector mul (const _CVector &v1, const Type &v2)
 Returns v1 scaled by v2.
 
static _CVector div (const _CVector &v1, const _CVector &v2)
 Returns the component-wise division of v1 by v2.
 
static _CVector div (const _CVector &v1, const Type &v2)
 Returns v1 divided by scalar v2.
 

Detailed Description

template<typename Type>
class PIMathVector< Type >

Template class for dynamic-size mathematical vector Provides vector operations including arithmetic, normalization, angles, cross product, and dot product for dynamic-size vectors.