Vec2< T, STRIDE > Struct Template Reference

#include <vector.h>

详细描述

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

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

Public Types

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

公共成员函数

constexpr  Vec2 ()
constexpr  Vec2 ( ValueTypeParam in)
constexpr  Vec2 ( ValueTypeParam ix, ValueTypeParam iy)
template<typename T2 , Int S2>
constexpr  Vec2 (const Vec2 < T2, S2 > &v)
template<Int S2>
constexpr  Vec2 (const Vec2 < T, S2 > &v)
template<typename T2 , Int S2>
constexpr  Vec2 (const Vec3 < T2, S2 > &v)
constexpr  Vec2 ( ENUM_DONT_INITIALIZE v)
constexpr MAXON_IMPLICIT   Vec2 (const typename std::conditional< STRIDE ==1, DummyParamType, Vec2 >::type & src )
constexpr Vec2 operator= (const typename std::conditional< STRIDE ==1, DummyParamType, Vec2 >::type & src )
T &  operator[] ( Int l)
ValueTypeParam   operator[] ( Int l) const
template<typename T2 , Int S2>
constexpr Vec2 operator+= (const Vec2 < T2, S2 > &v)
constexpr Vec2 operator+= (const Vec2 &v)
template<typename T2 , Int S2>
constexpr Vec2 operator-= (const Vec2 < T2, S2 > &v)
constexpr Vec2 operator-= (const Vec2 &v)
template<typename T2 , Int S2>
constexpr Vec2 operator*= (const Vec2 < T2, S2 > &v)
constexpr Vec2 operator*= (const Vec2 &v)
constexpr Vec2 operator*= ( ValueTypeParam s)
constexpr Vec2 operator/= ( ValueTypeParam s)
constexpr Unstrided   operator* ( ValueTypeParam s) const
template<typename S >
constexpr Vec2 < 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 Vec2 &v) const
constexpr Unstrided   operator+ (const Vec2 &v) const
constexpr Unstrided   operator- (const Vec2 &v) const
constexpr Unstrided   operator- () const
template<typename T2 , Int S2>
constexpr BoolType   operator== (const Vec2 < T2, S2 > &v) const
constexpr BoolType   operator== (const Vec2 &v) const
template<typename T2 , Int S2>
constexpr BoolType   operator!= (const Vec2 < T2, S2 > &v) const
constexpr BoolType   operator!= (const Vec2 &v) const
constexpr BoolType   LessThanOrEqual (const Vec2 &v) const
constexpr BoolType   LessThan (const Vec2 &v) const
constexpr HashInt   GetHashCode () const
constexpr BoolType   IsEqual (const Vec2 &other, ValueTypeParam epsilon) const
constexpr BoolType   IsZero () const
constexpr void  SetZero ()
constexpr T  GetAverage () const
constexpr T  GetSum () const
constexpr void  ClampMin (const Vec2 &other= Vec2 ())
constexpr void  ClampMax (const Vec2 &other)
constexpr Unstrided   Clamp01 () const
constexpr T  GetLength () const
constexpr T  GetSquaredLength () const
constexpr Unstrided   GetNormalized () const
constexpr Unstrided   operator! () const
constexpr void  Normalize ()
String   ToString (const FormatStatement *formatStatement=nullptr) const
constexpr T  GetMin () const
constexpr T  GetMax () const
constexpr Unstrided   GetRightRotated ( Int rots) const
template<typename T2 >
constexpr Vec2 operator*= (const Mat2 < T2 > &m)

静态公共成员函数

static constexpr const Vec2 NullValue ()

Public Attributes

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

Friends

constexpr friend Unstrided   operator* ( ValueTypeParam s, const Vec2 &v)
constexpr friend T  Dot (const Vec2 &v1, const Vec2 &v2)
constexpr friend Unstrided   Abs (const Vec2 &v1)
template<typename T2 , Int S2>
constexpr friend MultiplicativePromotion < T, T2 >::type  Dot (const Vec2 &v1, const Vec2 < T2, S2 > &v2)
constexpr friend Unstrided   最小 (const Vec2 &a, const Vec2 &other)
constexpr friend Unstrided   最大 (const Vec2 &a, const Vec2 &other)
constexpr friend void  SetMin ( Vec2 &a, const Vec2 &other)
constexpr friend void  SetMax ( Vec2 &a, const Vec2 &other)
constexpr friend T  GetAngle (const Vec2 &v1, const Vec2 &v2)
constexpr friend Unstrided   Cross (const Vec2 &v1)

Member Typedef Documentation

◆  Rebind

using Rebind = Vec2 <U, STRIDE >

◆  VectorStrideType

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

◆  ValueType

using ValueType = T

◆  ValueTypeParam

using ValueTypeParam = typename ByValueParam <T>::type

◆  Unstrided

using Unstrided = Vec2 <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.

构造函数 & 析构函数文档编制

◆  Vec2() [1/8]

constexpr Vec2 ( )
constexpr

Initializes all vector components with 0.0.

◆  Vec2() [2/8]

constexpr Vec2 ( ValueTypeParam   in )
explicit constexpr

Initializes all vector components with a scalar.

◆  Vec2() [3/8]

constexpr Vec2 ( ValueTypeParam   ix ,
ValueTypeParam   iy  
)
explicit constexpr

Initializes all vector components individually.

◆  Vec2() [4/8]

constexpr Vec2 ( const Vec2 < T2, S2 > &  v )
explicit constexpr

Initializes components from another 2d vector.

◆  Vec2() [5/8]

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

Initializes components from another 2d vector.

◆  Vec2() [6/8]

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

Initializes components from a 3d vector. The z-component of v is ignored.

◆  Vec2() [7/8]

constexpr Vec2 ( ENUM_DONT_INITIALIZE   v )
explicit constexpr

Skips initialization of vector (for better speed)

◆  Vec2() [8/8]

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

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.

成员函数文档编制

◆  operator=()

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

Copies the source vector.

参数
[in] src Source vector.
返回
*this.

◆  operator[]() [1/2]

T& operator[] ( Int   l )

Accesses vector component: index 0 is 'x', index 1 is 'y'. 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'. All other values must not be used and will crash.

◆  operator+=() [1/2]

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

Adds two vectors.

◆  operator+=() [2/2]

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

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.

参数
[in] v Vector to be added.
返回
*this.

◆  operator-=() [1/2]

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

Subtracts two vectors.

◆  operator-=() [2/2]

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

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.

参数
[in] v Vector to be substracted from this.
返回
*this.

◆  operator*=() [1/4]

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

Multiplies two vectors component-wise.

◆  operator*=() [2/4]

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

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.

参数
[in] v Vector to be multiplied with.
返回
*this.

◆  operator*=() [3/4]

constexpr Vec2 & operator*= ( ValueTypeParam   s )
constexpr

Multiplies each vector component by a scalar.

◆  operator/=()

constexpr Vec2 & 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 Vec2 <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 Vec2 < T, STRIDE > &  v ) const
constexpr

Multiplies two vectors component-wise.

◆  operator+()

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

Adds two vectors.

◆  operator-() [1/2]

constexpr Unstrided operator- ( const Vec2 < 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 Vec2 < T2, S2 > &  v ) const
constexpr

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

参数
[in] v Comparison vector.
返回
True if this and v are equal, otherwise false.

◆  operator==() [2/2]

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

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

参数
[in] v Comparison vector.
返回
True if this and v are equal, otherwise false.

◆  operator!=() [1/2]

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

Inequality operator.

参数
[in] v Comparison vector.
返回
False if this and v are equal, otherwise true.

◆  operator!=() [2/2]

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

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

参数
[in] v Comparison vector.
返回
False if this and v are equal, otherwise true.

◆  LessThanOrEqual()

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

◆  LessThan()

constexpr BoolType LessThan ( const Vec2 < T, STRIDE > &  v ) const
constexpr

◆  GetHashCode()

constexpr HashInt GetHashCode ( ) const
constexpr

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

返回
The vector's hash code.

◆  IsEqual()

constexpr BoolType IsEqual ( const Vec2 < 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 'x', 'y' and 'z'.

◆  GetSum()

constexpr T GetSum ( ) const
constexpr

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

◆  ClampMin()

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

Set the minimum of each component.

◆  ClampMax()

constexpr void ClampMax ( const Vec2 < 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].

◆  GetLength()

constexpr T GetLength ( ) const
constexpr

Returns the length of the vector.

◆  GetSquaredLength()

constexpr T GetSquaredLength ( ) const
constexpr

Returns the squared length of the vector.

◆  GetNormalized()

constexpr Unstrided GetNormalized ( ) const
constexpr

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

◆  operator!()

constexpr Unstrided operator! ( ) const
constexpr

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

◆  Normalize()

constexpr void Normalize ( )
constexpr

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

◆  ToString()

String ToString ( const FormatStatement formatStatement = nullptr ) const

Returns a readable string of the content.

参数
[in] formatStatement Nullptr or additional formatting instruction. See also Formatting Floating point values .
返回
The converted result.

◆  GetMin()

constexpr T GetMin ( ) const
constexpr

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

◆  GetMax()

constexpr T GetMax ( ) const
constexpr

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

◆  GetRightRotated()

constexpr Unstrided GetRightRotated ( Int   rots ) const
constexpr

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

参数
[in] rots Number of rotations, may be negative. The result depends only on the number modulo 2.
返回
Vector with rotated components.

◆  operator*=() [4/4]

constexpr Vec2 & operator*= ( const Mat2 < T2 > &  m )
constexpr

Transforms point by a matrix.

◆  NullValue()

static constexpr const Vec2 & NullValue ( )
static constexpr

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

返回
A null value of the vector.

Friends And Related Function Documentation

◆  operator*

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

Multiplies each vector component by a scalar.

◆  Dot [1/2]

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

Calculates dot product of v1 and v2.

◆  Abs

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

returns the vector with absolute value for each entry

参数
[in] v1 input vector to work on
返回
component wise absolute value vector of input vector

◆  Dot [2/2]

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

Calculates dot product of v1 and v2.

◆  最小

constexpr friend Unstrided 最小 ( const Vec2 < T, STRIDE > &  a ,
const Vec2 < T, STRIDE > &  other  
)
friend

Calculates the minimum of each component.

◆  最大

constexpr friend Unstrided 最大 ( const Vec2 < T, STRIDE > &  a ,
const Vec2 < T, STRIDE > &  other  
)
friend

Calculates the maximum of each component.

◆  SetMin

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

Set the minimum of each component.

◆  SetMax

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

Set the maximum of each component.

◆  GetAngle

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

Calculates angle (in radians) between v1 and v2.

◆  Cross

constexpr friend Unstrided Cross ( const Vec2 < T, STRIDE > &  v1 )
friend

Calculates the cross product of a 2d vector. This is the vector (Y, -X), i.e., the clockwise rotation by 90 degrees.

Member Data Documentation

◆  x

T x

◆  _xpadding

T _xpadding[ STRIDE ]

◆  @1069

union { ... }

◆  y

T y

◆  _ypadding

T _ypadding[ STRIDE ]

◆  @1071

union { ... }