CGVIS Utils
Loading...
Searching...
No Matches
Vec2t< T > Union Template Reference

#include <Vec2.h>

Public Member Functions

 Vec2t ()
 Default-construct to (0, 0).
 Vec2t (T x, T y)
 Construct from two component values.
 Vec2t (const Vec2t &other)
 Copy-construct from another vector of the same type.
template<typename U>
 Vec2t (const Vec2t< U > &other)
 Explicitly convert from another Vec2t with different component type.
const std::string toString () const
 String representation "[x, y]".
Vec2t operator+ (const Vec2t &val) const
 Component-wise addition.
Vec2t operator- (const Vec2t &val) const
 Component-wise subtraction.
Vec2t operator* (const Vec2t &val) const
 Component-wise multiplication.
Vec2t operator/ (const Vec2t &val) const
 Component-wise division.
Vec2t operator* (const T &val) const
 Scalar multiplication.
Vec2t operator/ (const T &val) const
 Scalar division.
Vec2t operator+ (const T &val) const
 Add scalar to both components.
Vec2t operator- (const T &val) const
 Subtract scalar from both components.
bool operator== (const Vec2t &other) const
 Equality comparison (component-wise equality).
bool operator!= (const Vec2t &other) const
 Inequality comparison (component-wise inequality).
T length () const
 Euclidean length (magnitude).
T sqlength () const
 Squared length (avoids sqrt).
 operator T* (void)
 Implicit pointer conversion to raw component storage.
 operator const T * (void) const
 Implicit pointer conversion to raw component storage (const).

Static Public Member Functions

static Vec2t random ()
 Create a vector with components sampled from [0,1).
static Vec2t normalize (const Vec2t &a)
 Return the normalized (unit-length) version of a vector.
static Vec2t< float > clamp (const Vec2t &val, float minVal, float maxVal)
 Clamp both components to [minVal, maxVal].

Public Attributes

std::array< T, 2 > e
 Component storage and named aliases.
struct { 
   T   x 
   T   y 
}; 
 Cartesian alias for components.
struct { 
   T   r 
   T   g 
}; 
 Color alias for components.

Constructor & Destructor Documentation

◆ Vec2t() [1/4]

template<typename T>
Vec2t< T >::Vec2t ( )
inline

Default-construct to (0, 0).

◆ Vec2t() [2/4]

template<typename T>
Vec2t< T >::Vec2t ( T x,
T y )
inline

Construct from two component values.

Parameters
xFirst component.
ySecond component.

◆ Vec2t() [3/4]

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

Copy-construct from another vector of the same type.

Parameters
otherSource vector to copy from.

◆ Vec2t() [4/4]

template<typename T>
template<typename U>
Vec2t< T >::Vec2t ( const Vec2t< U > & other)
inlineexplicit

Explicitly convert from another Vec2t with different component type.

Template Parameters
USource component type.
Parameters
otherSource vector to convert from.

Member Function Documentation

◆ clamp()

template<typename T>
Vec2t< float > Vec2t< T >::clamp ( const Vec2t< T > & val,
float minVal,
float maxVal )
inlinestatic

Clamp both components to [minVal, maxVal].

Parameters
valInput vector.
minValLower bound.
maxValUpper bound.
Returns
New vector with each component clamped to the given range.
Note
The return type is specialized as Vec2t<float>.

◆ length()

template<typename T>
T Vec2t< T >::length ( ) const
inline

Euclidean length (magnitude).

Returns
sqrt(x*x + y*y).
Here is the caller graph for this function:

◆ normalize()

template<typename T>
Vec2t Vec2t< T >::normalize ( const Vec2t< T > & a)
inlinestatic

Return the normalized (unit-length) version of a vector.

Parameters
aInput vector.
Returns
a / |a| if |a| != 0, otherwise (0,0).

◆ operator const T *()

template<typename T>
Vec2t< T >::operator const T * ( void ) const
inline

Implicit pointer conversion to raw component storage (const).

Returns
Pointer to first component (const overload).

◆ operator T*()

template<typename T>
Vec2t< T >::operator T* ( void )
inline

Implicit pointer conversion to raw component storage.

Returns
Pointer to first component (non-const overload).
Warning
Raw pointer exposes internal layout; use with care.

◆ operator!=()

template<typename T>
bool Vec2t< T >::operator!= ( const Vec2t< T > & other) const
inline

Inequality comparison (component-wise inequality).

Parameters
otherVector to compare against.
Returns
True if any component differs.

◆ operator*() [1/2]

template<typename T>
Vec2t Vec2t< T >::operator* ( const T & val) const
inline

Scalar multiplication.

Parameters
valScalar factor.
Returns
Result of this * val.

◆ operator*() [2/2]

template<typename T>
Vec2t Vec2t< T >::operator* ( const Vec2t< T > & val) const
inline

Component-wise multiplication.

Parameters
valVector to multiply component-wise.
Returns
Result of this * val.

◆ operator+() [1/2]

template<typename T>
Vec2t Vec2t< T >::operator+ ( const T & val) const
inline

Add scalar to both components.

Parameters
valScalar to add.
Returns
Result of this + val.

◆ operator+() [2/2]

template<typename T>
Vec2t Vec2t< T >::operator+ ( const Vec2t< T > & val) const
inline

Component-wise addition.

Parameters
valVector to add.
Returns
Result of this + val.

◆ operator-() [1/2]

template<typename T>
Vec2t Vec2t< T >::operator- ( const T & val) const
inline

Subtract scalar from both components.

Parameters
valScalar to subtract.
Returns
Result of this - val.

◆ operator-() [2/2]

template<typename T>
Vec2t Vec2t< T >::operator- ( const Vec2t< T > & val) const
inline

Component-wise subtraction.

Parameters
valVector to subtract.
Returns
Result of this - val.

◆ operator/() [1/2]

template<typename T>
Vec2t Vec2t< T >::operator/ ( const T & val) const
inline

Scalar division.

Parameters
valScalar divisor.
Returns
Result of this / val.

◆ operator/() [2/2]

template<typename T>
Vec2t Vec2t< T >::operator/ ( const Vec2t< T > & val) const
inline

Component-wise division.

Parameters
valVector to divide by component-wise.
Returns
Result of this / val.

◆ operator==()

template<typename T>
bool Vec2t< T >::operator== ( const Vec2t< T > & other) const
inline

Equality comparison (component-wise equality).

Parameters
otherVector to compare against.
Returns
True if components are equal.

◆ random()

template<typename T>
Vec2t Vec2t< T >::random ( )
inlinestatic

Create a vector with components sampled from [0,1).

Returns
Random vector (x,y) in [0,1) each.
Note
Depends on a global/namespace-scope RNG named staticRand provided by Rand.h .

◆ sqlength()

template<typename T>
T Vec2t< T >::sqlength ( ) const
inline

Squared length (avoids sqrt).

Returns
x*x + y*y.
Here is the caller graph for this function:

◆ toString()

template<typename T>
const std::string Vec2t< T >::toString ( ) const
inline

String representation "[x, y]".

Returns
A new std::string describing the vector.
Here is the caller graph for this function:

Member Data Documentation

◆ [struct]

struct { ... } Vec2t< T >

Color alias for components.

◆ [struct]

struct { ... } Vec2t< T >

Cartesian alias for components.

◆ e

template<typename T>
std::array<T, 2> Vec2t< T >::e

Component storage and named aliases.

Indexed access: e[0] and e[1].

◆ g

template<typename T>
T Vec2t< T >::g

◆ r

template<typename T>
T Vec2t< T >::r

◆ x

template<typename T>
T Vec2t< T >::x

◆ y

template<typename T>
T Vec2t< T >::y

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