Vec3< T, STRIDE > Struct Template Reference

#include <vector.h>

Detailed Description

template<typename T, Int STRIDE = 1>
struct maxon::Vec3< T, STRIDE >

A vector consisting of three components X, Y and Z.

Public Types

template<typename U >
using Rebind = Vec3< U, STRIDE >
 
using VectorStrideType = std::integral_constant< Int, STRIDE >
 
using ValueType = T
 
using ValueTypeParam = typename ByValueParam< T >::type
 
using Unstrided = Vec3< T, 1 >
 
using BoolType = decltype(T()==T())
 

Public Member Functions

 Vec3 ()
 
 Vec3 (ValueTypeParam in)
 
 Vec3 (ValueTypeParam ix, ValueTypeParam iy, ValueTypeParam iz)
 
template<typename T2 , Int S2>
 Vec3 (const Vec3< T2, S2 > &v)
 
template<typename T2 , Int S2>
 Vec3 (const Col3< T2, S2 > &v)
 
template<Int S2>
 Vec3 (const Vec3< T, S2 > &v)
 
template<typename T2 , Int S2>
 Vec3 (const Vec2< T2, S2 > &v, T vz=T())
 
template<typename T2 , Int S2>
 Vec3 (const Vec4< T2, S2 > &v)
 
template<typename T2 , Int S2>
 Vec3 (const Col4< T2, S2 > &v)
 
 Vec3 (ENUM_DONT_INITIALIZE v)
 
MAXON_IMPLICIT Vec3 (const typename std::conditional< STRIDE==1, DummyParamType, Vec3 >::type &src)
 
Vec3operator= (const typename std::conditional< STRIDE==1, DummyParamType, Vec3 >::type &src)
 
T & operator[] (Int l)
 
ValueTypeParam operator[] (Int l) const
 
template<typename T2 , Int S2>
Vec3operator+= (const Vec3< T2, S2 > &v)
 
Vec3operator+= (const Vec3 &v)
 
template<typename T2 , Int S2>
Vec3operator-= (const Vec3< T2, S2 > &v)
 
Vec3operator-= (const Vec3 &v)
 
template<typename T2 , Int S2>
Vec3operator*= (const Vec3< T2, S2 > &v)
 
Vec3operator*= (const Vec3 &v)
 
Vec3operator*= (ValueTypeParam s)
 
Vec3operator/= (ValueTypeParam s)
 
Unstrided operator* (ValueTypeParam s) const
 
template<typename S >
Vec3< typename MultiplicativePromotion< T, S, std::is_scalar< S >::value >::type, 1 > operator* (S s) const
 
Unstrided operator/ (ValueTypeParam s) const
 
Unstrided operator* (const Vec3 &v) const
 
Unstrided operator+ (const Vec3 &v) const
 
Unstrided operator- (const Vec3 &v) const
 
Unstrided operator- () const
 
template<typename T2 , Int S2>
BoolType operator== (const Vec3< T2, S2 > &v) const
 
BoolType operator== (const Vec3 &v) const
 
template<typename T2 , Int S2>
BoolType operator!= (const Vec3< T2, S2 > &v) const
 
BoolType operator!= (const Vec3 &v) const
 
BoolType LessThanOrEqual (const Vec3 &v) const
 
UInt GetHashCode () const
 
BoolType IsEqual (const Vec3 &other, ValueTypeParam epsilon) const
 
BoolType IsZero () const
 
void SetZero ()
 
GetAverage () const
 
GetSum () const
 
void ClampMin (const Vec3 &other=Vec3())
 
void ClampMax (const Vec3 &other)
 
Unstrided Clamp01 () const
 
GetLength () const
 
GetSquaredLength () const
 
Unstrided GetNormalized () const
 
Unstrided operator! () const
 
void Normalize ()
 
String ToString (const FormatStatement *formatStatement) const
 
const Col3< T, STRIDE > & GetColor () const
 
Col3< T, STRIDE > & GetColor ()
 
GetMin () const
 
GetMax () const
 
Unstrided GetRightRotated (Int rots) const
 
template<typename T2 >
Vec3operator*= (const Mat3< T2 > &m)
 

Static Public Member Functions

static const Vec3NullValue ()
 

Public Attributes

union {
   T   x
 
   T   _xpadding [STRIDE]
 
}; 
 
union {
   T   y
 
   T   _ypadding [STRIDE]
 
}; 
 
union {
   T   z
 
   T   _zpadding [STRIDE]
 
}; 
 

Friends

Unstrided operator* (ValueTypeParam s, const Vec3 &v)
 
Dot (const Vec3 &v1, const Vec3 &v2)
 
Unstrided Abs (const Vec3 &v1)
 
template<typename T2 , Int S2>
MultiplicativePromotion< T, T2 >::type Dot (const Vec3 &v1, const Vec3< T2, S2 > &v2)
 
Unstrided Min (const Vec3 &a, const Vec3 &other)
 
Unstrided Max (const Vec3 &a, const Vec3 &other)
 
void SetMin (Vec3 &a, const Vec3 &other)
 
void SetMax (Vec3 &a, const Vec3 &other)
 
GetAngle (const Vec3 &v1, const Vec3 &v2)
 
Unstrided Cross (const Vec3 &v1, const Vec3 &v2)
 
template<typename T2 , Int S2>
Vec3< typename MultiplicativePromotion< T, T2 >::type, 1 > Cross (const Vec3 &v1, const Vec3< T2, S2 > &v2)
 

Member Typedef Documentation

◆ Rebind

using Rebind = Vec3<U, STRIDE>

◆ VectorStrideType

using VectorStrideType = std::integral_constant<Int, STRIDE>

◆ ValueType

using ValueType = T

◆ ValueTypeParam

using ValueTypeParam = typename ByValueParam<T>::type

◆ Unstrided

using Unstrided = Vec3<T, 1>

◆ BoolType

using BoolType = decltype(T() == T())

The type returned by comparisons. If the template argument for T is a SIMD type, this will be a SIMD type, too, which contains the per-element results.

Constructor & Destructor Documentation

◆ Vec3() [1/11]

Vec3 ( )

Initializes all vector components with 0.0.

◆ Vec3() [2/11]

Vec3 ( ValueTypeParam  in)
explicit

Initializes all vector components with a scalar.

◆ Vec3() [3/11]

Vec3 ( ValueTypeParam  ix,
ValueTypeParam  iy,
ValueTypeParam  iz 
)
explicit

Initializes all vector components individually.

◆ Vec3() [4/11]

Vec3 ( const Vec3< T2, S2 > &  v)
explicit

Initializes components from another 3d vector.

◆ Vec3() [5/11]

Vec3 ( const Col3< T2, S2 > &  v)
explicit

Initializes components from another 3d vector.

◆ Vec3() [6/11]

Vec3 ( const Vec3< T, S2 > &  v)

Initializes components from another 3d vector.

◆ Vec3() [7/11]

Vec3 ( const Vec2< T2, S2 > &  v,
vz = T() 
)
explicit

Initializes components from a 2d vector. The z-component is set to 0.0 unless an extra parameter is passed.

◆ Vec3() [8/11]

Vec3 ( const Vec4< T2, S2 > &  v)
explicit

Initializes components from a 4d vector. The w-component is omitted.

◆ Vec3() [9/11]

Vec3 ( const Col4< T2, S2 > &  v)
explicit

Initializes components from a 4d vector. The w-component is omitted.

◆ Vec3() [10/11]

Vec3 ( ENUM_DONT_INITIALIZE  v)
explicit

Skips initialization of vector (for better speed)

◆ Vec3() [11/11]

MAXON_IMPLICIT Vec3 ( const typename std::conditional< STRIDE==1, DummyParamType, Vec3< T, STRIDE > >::type &  src)

When STRIDE is not 1, we have to provide copy constructor and operator because the default ones would also copy the padding. When STRIDE is 1, we want to avoid to declare them (because then the type wouldn't be trivially copyable any longer), so we use DummyParamType for the parameter in that case.

Member Function Documentation

◆ operator=()

Vec3& operator= ( const typename std::conditional< STRIDE==1, DummyParamType, Vec3< T, STRIDE > >::type &  src)

Copies the source vector.

Parameters
[in]srcSource vector.
Returns
*this.

◆ operator[]() [1/2]

T& operator[] ( Int  l)

Accesses vector component: index 0 is 'x', index 1 is 'y', index 2 is 'z'. All other values must not be used and will crash.

◆ operator[]() [2/2]

ValueTypeParam operator[] ( Int  l) const

Accesses vector component: index 0 is 'x', index 1 is 'y', index 2 is 'z'. All other values must not be used and will crash.

◆ operator+=() [1/2]

Vec3& operator+= ( const Vec3< T2, S2 > &  v)

Adds two vectors.

◆ operator+=() [2/2]

Vec3& operator+= ( const Vec3< T, STRIDE > &  v)

Adds a vector. We repeat the function template as non-template function, this allows the usage in contexts where the parameter is not a vector itself, but something with a conversion operator to a vector.

Parameters
[in]vVector to be added.
Returns
*this.

◆ operator-=() [1/2]

Vec3& operator-= ( const Vec3< T2, S2 > &  v)

Subtracts two vectors.

◆ operator-=() [2/2]

Vec3& operator-= ( const Vec3< T, STRIDE > &  v)

Subtracts a vector. We repeat the function template as non-template function, this allows the usage in contexts where the parameter is not a vector itself, but something with a conversion operator to a vector.

Parameters
[in]vVector to be substracted from this.
Returns
*this.

◆ operator*=() [1/4]

Vec3& operator*= ( const Vec3< T2, S2 > &  v)

Multiplies two vectors component-wise.

◆ operator*=() [2/4]

Vec3& operator*= ( const Vec3< T, STRIDE > &  v)

Multiplies with vector component-wise. We repeat the function template as non-template function, this allows the usage in contexts where the parameter is not a vector itself, but something with a conversion operator to a vector.

Parameters
[in]vVector to be multiplied with.
Returns
*this.

◆ operator*=() [3/4]

Vec3& operator*= ( ValueTypeParam  s)

Multiplies each vector component by a scalar.

◆ operator/=()

Vec3& operator/= ( ValueTypeParam  s)

Divides each vector component by a scalar. The passed argument is checked for 0.0.

◆ operator*() [1/3]

Unstrided operator* ( ValueTypeParam  s) const

Multiplies each vector component by a scalar.

◆ operator*() [2/3]

Vec3<typename MultiplicativePromotion<T, S, std::is_scalar<S>::value>::type, 1> operator* ( s) const

Multiplies each vector component by a scalar.

◆ operator/()

Unstrided operator/ ( ValueTypeParam  s) const

Divides each vector component by a scalar. The scalar value is tested for 0.0.

◆ operator*() [3/3]

Unstrided operator* ( const Vec3< T, STRIDE > &  v) const

Multiplies two vectors component-wise.

◆ operator+()

Unstrided operator+ ( const Vec3< T, STRIDE > &  v) const

Adds two vectors.

◆ operator-() [1/2]

Unstrided operator- ( const Vec3< T, STRIDE > &  v) const

Subtracts vector v2 from v1.

◆ operator-() [2/2]

Unstrided operator- ( ) const

Negates vector v.

◆ operator==() [1/2]

BoolType operator== ( const Vec3< T2, S2 > &  v) const

Equality operator.

Parameters
[in]vComparison vector.
Returns
True if this and v are equal, otherwise false.

◆ operator==() [2/2]

BoolType operator== ( const Vec3< T, STRIDE > &  v) const

Equality operator. We repeat the function template as non-template function, this allows the usage in contexts where the parameter is not a vector itself, but something with a conversion operator to a vector

Parameters
[in]vComparison vector.
Returns
True if this and v are equal, otherwise false.

◆ operator!=() [1/2]

BoolType operator!= ( const Vec3< T2, S2 > &  v) const

Inequality operator.

Parameters
[in]vComparison vector.
Returns
False if this and v are equal, otherwise true.

◆ operator!=() [2/2]

BoolType operator!= ( const Vec3< T, STRIDE > &  v) const

Inequality operator. We repeat the function template as non-template function, this allows the usage in contexts where the parameter is not a vector itself, but something with a conversion operator to a vector

Parameters
[in]vComparison vector.
Returns
False if this and v are equal, otherwise true.

◆ LessThanOrEqual()

BoolType LessThanOrEqual ( const Vec3< T, STRIDE > &  v) const

◆ GetHashCode()

UInt GetHashCode ( ) const

Returns the hash code of the vector (used for hash maps and comparisons).

Returns
The vector's hash code.

◆ IsEqual()

BoolType IsEqual ( const Vec3< T, STRIDE > &  other,
ValueTypeParam  epsilon 
) const

Tests component-wise if the difference is no bigger than 'epsilon'.

◆ IsZero()

BoolType IsZero ( ) const

Checks if each component is zero.

◆ SetZero()

void SetZero ( )

Sets all components to zero.

◆ GetAverage()

T GetAverage ( ) const

Calculates the average value of 'x', 'y' and 'z'.

◆ GetSum()

T GetSum ( ) const

Calculates the sum of 'x', 'y' and 'z'.

◆ ClampMin()

void ClampMin ( const Vec3< T, STRIDE > &  other = Vec3< T, STRIDE >())

Set the minimum of each component.

◆ ClampMax()

void ClampMax ( const Vec3< T, STRIDE > &  other)

Set the maximum of each component.

◆ Clamp01()

Unstrided Clamp01 ( ) const

Returns a vector that is clamped to the range [0.0 .. 1.0].

◆ GetLength()

T GetLength ( void  ) const

Returns the length of the vector.

◆ GetSquaredLength()

T GetSquaredLength ( ) const

Returns the squared length of the vector.

◆ GetNormalized()

Unstrided GetNormalized ( ) const

Returns a normalized vector, so that GetLength(vector)==1.0.

◆ operator!()

Unstrided operator! ( ) const

Returns a normalized vector, so that GetLength(vector)==1.0.

◆ Normalize()

void Normalize ( )

Normalizes this vector, so that GetLength()==1.0.

◆ ToString()

String ToString ( const FormatStatement formatStatement) const

Returns a readable string of the content.

Parameters
[in]formatStatementNullptr or additional formatting instruction. See also format_float.
Returns
The converted result.

◆ GetColor() [1/2]

const Col3<T, STRIDE>& GetColor ( void  ) const

Reinterprets the vector as color.

◆ GetColor() [2/2]

Col3<T, STRIDE>& GetColor ( void  )

◆ GetMin()

T GetMin ( void  ) const

Returns the minimum of 'x', 'y' and 'z'.

◆ GetMax()

T GetMax ( void  ) const

Returns the maximum of 'x', 'y' and 'z'.

◆ GetRightRotated()

Unstrided GetRightRotated ( Int  rots) const

Returns a vector where the components have been rotated to the right (in the usual (x, y, z)-representation). E.g., with a value of 1 for rots, the result will be (z, x, y).

Parameters
[in]rotsNumber of rotations, may be negative. The result depends only on the number modulo 3.
Returns
Vector with rotated components.

◆ operator*=() [4/4]

Vec3& operator*= ( const Mat3< T2 > &  m)

Transforms point by a matrix.

◆ NullValue()

static const Vec3& NullValue ( )
static

Returns a null value of the vector (see nullvalue.h for more details).

Returns
A null value of the vector.

Friends And Related Function Documentation

◆ operator*

Unstrided operator* ( ValueTypeParam  s,
const Vec3< T, STRIDE > &  v 
)
friend

Multiplies each vector component by a scalar.

◆ Dot [1/2]

T Dot ( const Vec3< T, STRIDE > &  v1,
const Vec3< T, STRIDE > &  v2 
)
friend

Calculates dot product of v1 and v2.

◆ Abs

Unstrided Abs ( const Vec3< T, STRIDE > &  v1)
friend

returns the vector with absolute value for each entry

Parameters
[in]v1input vector to work on
Returns
component wise absolute value vector of input vector

◆ Dot [2/2]

MultiplicativePromotion<T, T2>::type Dot ( const Vec3< T, STRIDE > &  v1,
const Vec3< T2, S2 > &  v2 
)
friend

Calculates dot product of v1 and v2.

◆ Min

Unstrided Min ( const Vec3< T, STRIDE > &  a,
const Vec3< T, STRIDE > &  other 
)
friend

Calculates the minimum of each component.

◆ Max

Unstrided Max ( const Vec3< T, STRIDE > &  a,
const Vec3< T, STRIDE > &  other 
)
friend

Calculates the maximum of each component.

◆ SetMin

void SetMin ( Vec3< T, STRIDE > &  a,
const Vec3< T, STRIDE > &  other 
)
friend

Set the minimum of each component.

◆ SetMax

void SetMax ( Vec3< T, STRIDE > &  a,
const Vec3< T, STRIDE > &  other 
)
friend

Set the maximum of each component.

◆ GetAngle

T GetAngle ( const Vec3< T, STRIDE > &  v1,
const Vec3< T, STRIDE > &  v2 
)
friend

Calculates angle (in radians) between v1 and v2.

◆ Cross [1/2]

Unstrided Cross ( const Vec3< T, STRIDE > &  v1,
const Vec3< T, STRIDE > &  v2 
)
friend

Calculates cross product of v1 and v2.

◆ Cross [2/2]

Vec3<typename MultiplicativePromotion<T, T2>::type, 1> Cross ( const Vec3< T, STRIDE > &  v1,
const Vec3< T2, S2 > &  v2 
)
friend

Calculates cross product of v1 and v2.

Member Data Documentation

◆ x

T x

◆ _xpadding

T _xpadding[STRIDE]

◆ @1088

union { ... }

◆ y

T y

◆ _ypadding

T _ypadding[STRIDE]

◆ @1090

union { ... }

◆ z

T z

◆ _zpadding

T _zpadding[STRIDE]

◆ @1092

union { ... }