Col4< T, STRIDE > Struct Template Reference

#include <col4.h>

Detailed Description

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

A color consisting of three components R, G, B and an alpha.

Public Types

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

Public Member Functions

constexpr Col4 ()
 
constexpr Col4 (ValueTypeParam in)
 
constexpr Col4 (ValueTypeParam ix, ValueTypeParam iy, ValueTypeParam iz, ValueTypeParam iw)
 
template<typename T2 , Int S2>
constexpr Col4 (const Col4< T2, S2 > &v)
 
template<typename T2 , Int S2>
constexpr Col4 (const Vec4< T2, S2 > &v)
 
template<Int S2>
constexpr Col4 (const Col4< T, S2 > &v)
 
template<typename T2 , Int S2>
constexpr Col4 (const Col3< T2, S2 > &v, T iw=T(1))
 
constexpr Col4 (ENUM_DONT_INITIALIZE v)
 
constexpr const Vec4< T, STRIDE > & GetVector () const
 
constexpr Vec4< T, STRIDE > & GetVector ()
 
constexpr const Col3< T, STRIDE > & GetColor3 () const
 
constexpr MAXON_IMPLICIT Col4 (const typename std::conditional< STRIDE==1, DummyParamType, Col4 >::type &src)
 
constexpr Col4operator= (const typename std::conditional< STRIDE==1, DummyParamType, Col4 >::type &src)
 
T & operator[] (Int l)
 
ValueTypeParam operator[] (Int l) const
 
template<typename T2 , Int S2>
constexpr Col4operator+= (const Col4< T2, S2 > &v)
 
constexpr Col4operator+= (const Col4 &v)
 
template<typename T2 , Int S2>
constexpr Col4operator-= (const Col4< T2, S2 > &v)
 
constexpr Col4operator-= (const Col4 &v)
 
template<typename T2 , Int S2>
constexpr Col4operator*= (const Col4< T2, S2 > &v)
 
constexpr Col4operator*= (const Col4 &v)
 
constexpr Col4operator*= (ValueTypeParam s)
 
constexpr Col4operator/= (ValueTypeParam s)
 
constexpr Unstrided operator* (ValueTypeParam s) const
 
template<typename S >
constexpr Col4< typename MultiplicativePromotion< T, S, STD_IS_REPLACEMENT(scalar, S)>::type, 1 > operator* (S s) const
 
constexpr Unstrided operator/ (ValueTypeParam s) const
 
constexpr Unstrided operator* (const Col4 &v) const
 
constexpr Unstrided operator+ (const Col4 &v) const
 
constexpr Unstrided operator- (const Col4 &v) const
 
constexpr Unstrided operator- () const
 
template<typename T2 , Int S2>
constexpr BoolType operator== (const Col4< T2, S2 > &v) const
 
constexpr BoolType operator== (const Col4 &v) const
 
template<typename T2 , Int S2>
constexpr BoolType operator!= (const Col4< T2, S2 > &v) const
 
constexpr BoolType operator!= (const Col4 &v) const
 
constexpr BoolType operator<= (const Col4 &v) const
 
constexpr BoolType operator>= (const Col4 &v) const
 
constexpr BoolType operator< (const Col4 &v) const
 
constexpr BoolType operator> (const Col4 &v) const
 
constexpr HashInt GetHashCode () const
 
UniqueHash GetUniqueHashCode () const
 
constexpr BoolType IsEqual (const Col4 &other, ValueTypeParam epsilon) const
 
constexpr BoolType IsZero () const
 
constexpr void SetZero ()
 
constexpr T GetAverage () const
 
constexpr T GetSum () const
 
constexpr void ClampMin (const Col4 &other=Col4())
 
constexpr void ClampMax (const Col4 &other)
 
constexpr Unstrided Clamp01 () const
 
String ToString (const FormatStatement *formatStatement=nullptr) const
 
constexpr T GetMin () const
 
constexpr T GetMax () const
 
constexpr Col4 GetRightRotated (Int rots) const
 
template<typename V >
constexpr Col4operator*= (const SqrMat4< V > &m)
 

Static Public Member Functions

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE const Col4NullValue ()
 

Public Attributes

union {
   T   r
 
   T   _xpadding [STRIDE]
 
}; 
 
union {
   T   g
 
   T   _ypadding [STRIDE]
 
}; 
 
union {
   T   b
 
   T   _zpadding [STRIDE]
 
}; 
 
union {
   T   a
 
   T   _wpadding [STRIDE]
 
}; 
 

Friends

constexpr friend Unstrided operator* (ValueTypeParam s, const Col4 &v)
 
constexpr friend T Dot (const Col4 &v1, const Col4 &v2)
 
constexpr friend Unstrided Abs (const Col4 &v1)
 
template<typename T2 , Int S2>
constexpr friend MultiplicativePromotion< T, T2 >::type Dot (const Col4 &v1, const Col4< T2, S2 > &v2)
 
constexpr friend Unstrided Min (const Col4 &th, const Col4 &other)
 
constexpr friend Unstrided Max (const Col4 &th, const Col4 &other)
 
constexpr friend void SetMin (Col4 &th, const Col4 &other)
 
constexpr friend void SetMax (Col4 &th, const Col4 &other)
 

Member Typedef Documentation

◆ Rebind

using Rebind = Col4<U, STRIDE>

◆ VectorStrideType

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

◆ ValueType

using ValueType = T

◆ ValueTypeParam

using ValueTypeParam = typename ByValueParam<T>::type

◆ Unstrided

using Unstrided = Col4<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

◆ Col4() [1/9]

constexpr Col4 ( )
constexpr

Initializes all color components with 0.0 and the alpha with 1.0.

◆ Col4() [2/9]

constexpr Col4 ( ValueTypeParam  in)
explicitconstexpr

Initializes all color components with a scalar and the alpha with 1.0.

◆ Col4() [3/9]

constexpr Col4 ( ValueTypeParam  ix,
ValueTypeParam  iy,
ValueTypeParam  iz,
ValueTypeParam  iw 
)
explicitconstexpr

Initializes all vector components individually.

◆ Col4() [4/9]

constexpr Col4 ( const Col4< T2, S2 > &  v)
explicitconstexpr

Initializes components from another 4d vector.

◆ Col4() [5/9]

constexpr Col4 ( const Vec4< T2, S2 > &  v)
explicitconstexpr

◆ Col4() [6/9]

constexpr Col4 ( const Col4< T, S2 > &  v)
constexpr

◆ Col4() [7/9]

constexpr Col4 ( const Col3< T2, S2 > &  v,
iw = T(1) 
)
explicitconstexpr

Initializes components from a 3d vector and add an additional value for the a-component. The default value for the alpha is 1.0.

◆ Col4() [8/9]

constexpr Col4 ( ENUM_DONT_INITIALIZE  v)
explicitconstexpr

Skips initialization of vector (for better speed)

◆ Col4() [9/9]

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

Member Function Documentation

◆ GetVector() [1/2]

constexpr const Vec4<T, STRIDE>& GetVector ( ) const
constexpr

Reinterprets the color as vector.

◆ GetVector() [2/2]

constexpr Vec4<T, STRIDE>& GetVector ( )
constexpr

◆ GetColor3()

constexpr const Col3<T, STRIDE>& GetColor3 ( ) const
constexpr

Gets the r/g/b components as a color without alpha.

◆ operator=()

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

◆ operator[]() [1/2]

T& operator[] ( Int  l)

Accesses vector component: index 0 is 'r', index 1 is 'g', index 2 is 'b'. All other values must not be used and will crash.

◆ operator[]() [2/2]

ValueTypeParam operator[] ( Int  l) const

Accesses vector component: index 0 is 'r', index 1 is 'g', index 2 is 'b'. All other values must not be used and will crash.

◆ operator+=() [1/2]

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

Adds two vectors.

◆ operator+=() [2/2]

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

◆ operator-=() [1/2]

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

Subtracts two vectors.

◆ operator-=() [2/2]

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

◆ operator*=() [1/4]

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

Multiplies two vectors component-wise.

◆ operator*=() [2/4]

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

◆ operator*=() [3/4]

constexpr Col4& operator*= ( ValueTypeParam  s)
constexpr

Multiplies each vector component by a scalar.

◆ operator/=()

constexpr Col4& operator/= ( ValueTypeParam  s)
constexpr

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

◆ operator*() [1/3]

constexpr Unstrided operator* ( ValueTypeParam  s) const
constexpr

Multiplies each vector component by a scalar.

◆ operator*() [2/3]

constexpr Col4<typename MultiplicativePromotion<T, S, STD_IS_REPLACEMENT(scalar, S)>::type, 1> operator* ( s) const
constexpr

Multiplies each vector component by a scalar.

◆ operator/()

constexpr Unstrided operator/ ( ValueTypeParam  s) const
constexpr

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

◆ operator*() [3/3]

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

Multiplies two vectors component-wise.

◆ operator+()

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

Adds two vectors.

◆ operator-() [1/2]

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

Subtracts vector v2 from v1.

◆ operator-() [2/2]

constexpr Unstrided operator- ( ) const
constexpr

Negates vector v.

◆ operator==() [1/2]

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

◆ operator==() [2/2]

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

◆ operator!=() [1/2]

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

◆ operator!=() [2/2]

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

◆ operator<=()

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

Compares this color with v. Note that this doesn't define a total order but just a partial order, so for a pair of colors it can happen that neither {v <= w} nor {v >= w}.

Parameters
[in]vComparison color.
Returns
True if this.c <= v.c for all components c of the colors, false otherwise.

◆ operator>=()

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

Compares this color with v. Note that this doesn't define a total order but just a partial order, so for a pair of colors it can happen that neither {v <= w} nor {v >= w}.

Parameters
[in]vComparison color.
Returns
True if this.c >= v.c for all components c of the colors, false otherwise.

◆ operator<()

constexpr BoolType operator< ( const Col4< T, STRIDE > &  v) const
constexpr

Compares this color with v. Note that this doesn't define a total order but just a partial order, so for a pair of colors it can happen that neither {v < w} nor {v > w} nor {v == w}. Also note that {v < w} is not the same as {v <= w && v != w}.

Parameters
[in]vComparison color.
Returns
True if this.c < v.c for all components c of the colors, false otherwise.

◆ operator>()

constexpr BoolType operator> ( const Col4< T, STRIDE > &  v) const
constexpr

Compares this color with v. Note that this doesn't define a total order but just a partial order, so for a pair of colors it can happen that neither {v < w} nor {v > w} nor {v == w}. Also note that {v > w} is not the same as {v >= w && v != w}.

Parameters
[in]vComparison color.
Returns
True if this.c > v.c for all components c of the colors, false otherwise.

◆ GetHashCode()

constexpr HashInt GetHashCode ( ) const
constexpr

◆ GetUniqueHashCode()

UniqueHash GetUniqueHashCode ( ) const

◆ IsEqual()

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

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

◆ IsZero()

constexpr BoolType IsZero ( ) const
constexpr

Checks if each component is zero.

◆ SetZero()

constexpr void SetZero ( )
constexpr

Sets all components to zero.

◆ GetAverage()

constexpr T GetAverage ( ) const
constexpr

Calculates the average value of 'r', 'g', 'b' and 'a'.

◆ GetSum()

constexpr T GetSum ( ) const
constexpr

Calculates the sum of 'r', 'g', 'b' and 'a'.

◆ ClampMin()

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

Set the minimum of each component.

◆ ClampMax()

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

Set the maximum of each component.

◆ Clamp01()

constexpr Unstrided Clamp01 ( ) const
constexpr

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

◆ ToString()

String ToString ( const FormatStatement formatStatement = nullptr) const

Returns a readable string of the content.

Parameters
[in]formatStatementNullptr or additional formatting instruction. See also Formatting Floating point values.
Returns
The converted result.

◆ GetMin()

constexpr T GetMin ( ) const
constexpr

Returns the minimum of 'r', 'g', 'b' and 'a'.

◆ GetMax()

constexpr T GetMax ( ) const
constexpr

Returns the maximum of 'r', 'g', 'b' and 'a'.

◆ GetRightRotated()

constexpr Col4 GetRightRotated ( Int  rots) const
constexpr

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

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

◆ operator*=() [4/4]

constexpr Col4& operator*= ( const SqrMat4< V > &  m)
constexpr

Multiplies vector by a matrix.

◆ NullValue()

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE const Col4& NullValue ( )
staticconstexpr

Friends And Related Function Documentation

◆ operator*

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

Multiplies each vector component by a scalar.

◆ Dot [1/2]

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

Calculates dot product of v1 and v2.

◆ Abs

constexpr friend Unstrided Abs ( const Col4< 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]

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

Calculates dot product of v1 and v2.

◆ Min

constexpr friend Unstrided Min ( const Col4< T, STRIDE > &  th,
const Col4< T, STRIDE > &  other 
)
friend

Calculates the minimum of each component.

◆ Max

constexpr friend Unstrided Max ( const Col4< T, STRIDE > &  th,
const Col4< T, STRIDE > &  other 
)
friend

Calculates the maximum of each component.

◆ SetMin

constexpr friend void SetMin ( Col4< T, STRIDE > &  th,
const Col4< T, STRIDE > &  other 
)
friend

Set the minimum of each component.

◆ SetMax

constexpr friend void SetMax ( Col4< T, STRIDE > &  th,
const Col4< T, STRIDE > &  other 
)
friend

Set the maximum of each component.

Member Data Documentation

◆ r

T r

◆ _xpadding

T _xpadding[STRIDE]

◆ 

union { ... }

◆ g

T g

◆ _ypadding

T _ypadding[STRIDE]

◆ 

union { ... }

◆ b

T b

◆ _zpadding

T _zpadding[STRIDE]

◆ 

union { ... }

◆ a

T a

◆ _wpadding

T _wpadding[STRIDE]

◆ 

union { ... }