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

#include <Vec4.h>

Public Member Functions

 Vec4t ()
 Default-construct to (0,0,0,0).
 Vec4t (T x, T y, T z, T w)
 Construct from four component values.
 Vec4t (const Vec4t &other)
 Copy-construct from the same type.
 Vec4t (const Vec3t< T > &other, T w)
 Construct from a 3D vector and a w value.
 Vec4t (const Vec2t< T > &other, T z, T w)
 Construct from a 2D vector and z, w values.
template<typename U>
 Vec4t (const Vec4t< U > &other)
 Explicitly convert from another Vec4t with different component type.
template<typename U>
 Vec4t (const Vec3t< U > &other, T w)
 Explicitly convert from a 3D vector of a different type and a w value.
template<typename U>
 Vec4t (const Vec2t< U > &other, T z, T w)
 Explicitly convert from a 2D vector of a different type and z, w values.
const std::string toString () const
 String representation "[x, y, z, w]".
Vec4t operator+ (const Vec4t &val) const
 Component-wise addition.
Vec4t operator- (const Vec4t &val) const
 Component-wise subtraction.
Vec4t operator* (const Vec4t &val) const
 Component-wise multiplication.
Vec4t operator/ (const Vec4t &val) const
 Component-wise division.
Vec4t operator* (const T &val) const
 Scalar multiplication.
Vec4t operator/ (const T &val) const
 Scalar division.
Vec4t operator+ (const T &val) const
 Add scalar to all components.
Vec4t operator- (const T &val) const
 Subtract scalar from all components.
bool operator== (const Vec4t &other) const
 Equality comparison (component-wise equality).
bool operator!= (const Vec4t &other) const
 Inequality comparison (component-wise inequality).
T length () const
 Euclidean length (magnitude).
T sqlength () const
 Squared length (avoids sqrt).
Vec3t< T > vec3 () const
 Drop the last component and return a 3D vector (x,y,z).
 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 T dot (const Vec4t &a, const Vec4t &b)
 Dot product of two 4D vectors.
static Vec4t normalize (const Vec4t &a)
 Return the normalized (unit-length) version of a vector.
static Vec4t< float > random ()
 Create a vector with components sampled from [0,1).
static Vec4t< float > clamp (const Vec4t &val, float minVal, float maxVal)
 Clamp each component to [minVal, maxVal].

Public Attributes

std::array< T, 4 > e
 Component storage and named aliases.
struct { 
   T   x 
   T   y 
   T   z 
   T   w 
}; 
 Cartesian aliases for components.
struct { 
   T   r 
   T   g 
   T   b 
   T   a 
}; 
 Color aliases for components.
Vec2t< T > xy
 2D view of the first two components.
Vec3t< T > xyz
 3D view of the first three components.

Constructor & Destructor Documentation

◆ Vec4t() [1/8]

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

Default-construct to (0,0,0,0).

◆ Vec4t() [2/8]

template<typename T>
Vec4t< T >::Vec4t ( T x,
T y,
T z,
T w )
inline

Construct from four component values.

Parameters
xFirst component.
ySecond component.
zThird component.
wFourth component.

◆ Vec4t() [3/8]

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

Copy-construct from the same type.

Parameters
otherSource vector to copy.

◆ Vec4t() [4/8]

template<typename T>
Vec4t< T >::Vec4t ( const Vec3t< T > & other,
T w )
inline

Construct from a 3D vector and a w value.

Parameters
otherSource 3D vector for x, y, z.
wFourth component.

◆ Vec4t() [5/8]

template<typename T>
Vec4t< T >::Vec4t ( const Vec2t< T > & other,
T z,
T w )
inline

Construct from a 2D vector and z, w values.

Parameters
otherSource 2D vector for x and y.
zThird component.
wFourth component.

◆ Vec4t() [6/8]

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

Explicitly convert from another Vec4t with different component type.

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

◆ Vec4t() [7/8]

template<typename T>
template<typename U>
Vec4t< T >::Vec4t ( const Vec3t< U > & other,
T w )
inlineexplicit

Explicitly convert from a 3D vector of a different type and a w value.

Template Parameters
USource component type.
Parameters
otherSource 3D vector for x, y, z.
wFourth component.

◆ Vec4t() [8/8]

template<typename T>
template<typename U>
Vec4t< T >::Vec4t ( const Vec2t< U > & other,
T z,
T w )
inlineexplicit

Explicitly convert from a 2D vector of a different type and z, w values.

Template Parameters
USource component type.
Parameters
otherSource 2D vector for x and y.
zThird component.
wFourth component.

Member Function Documentation

◆ clamp()

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

Clamp each component to [minVal, maxVal].

Parameters
valInput vector.
minValLower bound.
maxValUpper bound.
Returns
New vector with components clamped to the given range.

◆ dot()

template<typename T>
T Vec4t< T >::dot ( const Vec4t< T > & a,
const Vec4t< T > & b )
inlinestatic

Dot product of two 4D vectors.

Parameters
aFirst vector.
bSecond vector.
Returns
a·b.

◆ length()

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

Euclidean length (magnitude).

Returns
sqrt(x*x + y*y + z*z + w*w).

◆ normalize()

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

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

Parameters
aInput vector.
Returns
a / |a|.
Note
If |a| == 0 the behavior follows the underlying division semantics.

◆ operator const T *()

template<typename T>
Vec4t< 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>
Vec4t< 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 Vec4t< T >::operator!= ( const Vec4t< 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>
Vec4t Vec4t< T >::operator* ( const T & val) const
inline

Scalar multiplication.

Parameters
valScalar factor.
Returns
Result of this * val.

◆ operator*() [2/2]

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

Component-wise multiplication.

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

◆ operator+() [1/2]

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

Add scalar to all components.

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

◆ operator+() [2/2]

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

Component-wise addition.

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

◆ operator-() [1/2]

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

Subtract scalar from all components.

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

◆ operator-() [2/2]

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

Component-wise subtraction.

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

◆ operator/() [1/2]

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

Scalar division.

Parameters
valScalar divisor.
Returns
Result of this / val.

◆ operator/() [2/2]

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

Component-wise division.

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

◆ operator==()

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

Equality comparison (component-wise equality).

Parameters
otherVector to compare against.
Returns
True iff all components are equal.

◆ random()

template<typename T>
Vec4t< float > Vec4t< T >::random ( )
inlinestatic

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

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

◆ sqlength()

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

Squared length (avoids sqrt).

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

◆ toString()

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

String representation "[x, y, z, w]".

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

◆ vec3()

template<typename T>
Vec3t< T > Vec4t< T >::vec3 ( ) const
inline

Drop the last component and return a 3D vector (x,y,z).

Returns
{x, y, z}.

Member Data Documentation

◆ [struct]

struct { ... } Vec4t< T >

Cartesian aliases for components.

◆ [struct]

struct { ... } Vec4t< T >

Color aliases for components.

◆ a

template<typename T>
T Vec4t< T >::a

◆ b

template<typename T>
T Vec4t< T >::b

◆ e

template<typename T>
std::array<T, 4> Vec4t< T >::e

Component storage and named aliases.

Indexed access: e[0], e[1], e[2], e[3].

◆ g

template<typename T>
T Vec4t< T >::g

◆ r

template<typename T>
T Vec4t< T >::r

◆ w

template<typename T>
T Vec4t< T >::w

◆ x

template<typename T>
T Vec4t< T >::x

◆ xy

template<typename T>
Vec2t<T> Vec4t< T >::xy

2D view of the first two components.

◆ xyz

template<typename T>
Vec3t<T> Vec4t< T >::xyz

3D view of the first three components.

◆ y

template<typename T>
T Vec4t< T >::y

◆ z

template<typename T>
T Vec4t< T >::z

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