ACF $AcfVersion:0$
Public Types | Public Member Functions | Protected Attributes | List of all members
imath::TFastVector< MaxSize, Element > Class Template Reference

Optimized implementation of a variable-size vector with compile-time maximum capacity. More...

#include <TFastVector.h>

Public Types

enum  { MAX_ELEMENTS_COUNT = MaxSize }
 
typedef Element ElementType
 

Public Member Functions

 TFastVector ()
 Create an uninitialized point.
 
 TFastVector (int componentsCount, const Element &value=Element())
 Create vector and initialize number of components.
 
 TFastVector (const TFastVector< MaxSize, Element > &vector)
 Copy constructor.
 
 TFastVector (std::initializer_list< Element > values)
 Initializer list constructor.
 
template<int Size>
 TFastVector (const imath::TVector< Size, Element > &vector)
 
int GetElementsCount () const
 Get number of elements.
 
bool SetElementsCount (int count, const Element &value=Element())
 Set number of elements.
 
bool EnsureElementsCount (int count, const Element &value=Element())
 Ensure, that number of elements vector cannot be smaller that some value.
 
const Element & GetElement (int i) const
 Get element at specified i.
 
Element & GetElementRef (int i)
 Get reference to element at specified i.
 
void SetElement (int i, const Element &value)
 Set element at specified i.
 
void Clear ()
 Set all coordinates to zero.
 
void SetElementsFrom (const TFastVector &vector, const Element &expansionValue=Element())
 Set elemenents from other vector without resizing.
 
void Translate (const TFastVector< MaxSize, Element > &vector)
 Translate the point.
 
TFastVector< MaxSize, Element > GetTranslated (const TFastVector< MaxSize, Element > &vector)
 Get translated point.
 
void GetTranslated (const TFastVector< MaxSize, Element > &vector, TFastVector< MaxSize, Element > &result)
 /overloaded
 
void ScaledCumulate (const TFastVector< MaxSize, Element > &vector, Element scale)
 Add second vector scaled by specified factor.
 
bool IsNull (Element tolerance=I_BIG_EPSILON) const
 Check if this vector is null.
 
Element GetDotProduct (const TFastVector< MaxSize, Element > &vector) const
 Return dot product of two vectors.
 
Element GetLength2 () const
 Return euclidian length square.
 
Element GetLength () const
 Return euclidian length.
 
Element GetDistance2 (const TFastVector< MaxSize, Element > &vector) const
 Return distance square between two vectors.
 
Element GetDistance (const TFastVector< MaxSize, Element > &vector) const
 Return distance between two vectors.
 
Element GetElementsSum () const
 Get simple sum of all elements.
 
bool Normalize (Element length=1.0)
 Normalize vector to specified length.
 
bool GetNormalized (TFastVector< MaxSize, Element > &result, Element length=1.0) const
 Return normalized vector with the same direction and specified length.
 
void GetMinimal (const TFastVector< MaxSize, Element > &vector, TFastVector< MaxSize, Element > &result) const
 Get vector with minimal elements values.
 
void GetMaximal (const TFastVector< MaxSize, Element > &vector, TFastVector< MaxSize, Element > &result) const
 Get vector with maximal elements values.
 
bool Serialize (iser::IArchive &archive)
 Serialize this vector to specified archive.
 
bool operator== (const TFastVector< MaxSize, Element > &vector) const
 
bool operator!= (const TFastVector< MaxSize, Element > &vector) const
 
bool operator< (const TFastVector< MaxSize, Element > &vector) const
 
bool operator> (const TFastVector< MaxSize, Element > &vector) const
 
bool operator<= (const TFastVector< MaxSize, Element > &vector) const
 
bool operator>= (const TFastVector< MaxSize, Element > &vector) const
 
TFastVector< MaxSize, Element > operator- () const
 
TFastVector< MaxSize, Element > operator+ (const TFastVector< MaxSize, Element > &vector) const
 
TFastVector< MaxSize, Element > operator- (const TFastVector< MaxSize, Element > &vector) const
 
TFastVector< MaxSize, Element > operator* (Element scalar) const
 
TFastVector< MaxSize, Element > operator/ (Element scalar) const
 
TFastVector< MaxSize, Element > & operator= (const TFastVector< MaxSize, Element > &vector)
 
TFastVector< MaxSize, Element > & operator+= (const TFastVector< MaxSize, Element > &vector)
 
TFastVector< MaxSize, Element > & operator-= (const TFastVector< MaxSize, Element > &vector)
 
TFastVector< MaxSize, Element > & operator*= (Element scalar)
 
TFastVector< MaxSize, Element > & operator/= (Element scalar)
 
const Element & operator[] (int i) const
 
Element & operator[] (int i)
 

Protected Attributes

Element m_elements [MaxSize]
 
int m_elementsCount
 

Detailed Description

template<int MaxSize, class Element = double>
class imath::TFastVector< MaxSize, Element >

Optimized implementation of a variable-size vector with compile-time maximum capacity.

Purpose

TFastVector is a hybrid between fixed-size and dynamic vectors. It allocates space for MaxSize elements on the stack (or inline within the containing object), but allows the actual number of active elements to vary at runtime. This provides the performance benefits of stack allocation while maintaining some runtime flexibility.

TFastVector vs Other Vector Types

When to Use TFastVector

Usage Examples

// Example 1: Basic usage
imath::TFastVector<10, double> vec; // Can hold up to 10 doubles
// Start with 3 elements, initialized to 0.0
vec.SetElementsCount(3, 0.0);
// Set values
vec.SetElement(0, 1.5);
vec.SetElement(1, 2.5);
vec.SetElement(2, 3.5);
// Access values
double sum = 0.0;
for (int i = 0; i < vec.GetElementsCount(); ++i) {
sum += vec.GetElement(i);
}
// Example 2: Dynamic growth
numbers.SetElementsCount(0); // Start empty
for (int i = 0; i < 50; ++i) {
int currentSize = numbers.GetElementsCount();
if (numbers.SetElementsCount(currentSize + 1)) {
numbers.SetElement(currentSize, i * i);
}
}
// Example 3: Initializer list
imath::TFastVector<5, double> coords = {1.0, 2.0, 3.0};
// coords has 3 elements
// Example 4: Conversion from TVector
fixedVec.SetElement(0, 1.0);
fixedVec.SetElement(1, 2.0);
fixedVec.SetElement(2, 3.0);
imath::TFastVector<10, double> fastVec(fixedVec); // Convert to TFastVector
// Example 5: Ensure minimum size
buffer.SetElementsCount(5);
// Ensure at least 10 elements (grows if needed, stays same if >= 10)
// Now has 10 elements
// Example 6: Vector operations
imath::TFastVector<10, double> v1(3, 1.0); // [1, 1, 1]
imath::TFastVector<10, double> v2(3, 2.0); // [2, 2, 2]
v1.Translate(v2); // v1 is now [3, 3, 3]
double length = v1.GetLength(); // sqrt(3^2 + 3^2 + 3^2) = sqrt(27)
v1.Normalize(); // Make unit length
Optimized implementation of a variable-size vector with compile-time maximum capacity.
const Element & GetElement(int i) const
Get element at specified i.
bool SetElementsCount(int count, const Element &value=Element())
Set number of elements.
void SetElement(int i, const Element &value)
Set element at specified i.
int GetElementsCount() const
Get number of elements.
bool EnsureElementsCount(int count, const Element &value=Element())
Ensure, that number of elements vector cannot be smaller that some value.
Implementation of fixed-size mathematical vector with specified type of elements.
Definition TVector.h:95
void SetElement(int i, const Element &value)
Sets the element at the specified index.
Definition TVector.h:560

Performance Characteristics

Limitations

See also
imath::TVector, imath::CVarVector, imath::TMathVectorWrap

Definition at line 122 of file TFastVector.h.

Member Typedef Documentation

◆ ElementType

template<int MaxSize, class Element = double>
typedef Element imath::TFastVector< MaxSize, Element >::ElementType

Definition at line 125 of file TFastVector.h.

Member Enumeration Documentation

◆ anonymous enum

template<int MaxSize, class Element = double>
anonymous enum
Enumerator
MAX_ELEMENTS_COUNT 

Definition at line 127 of file TFastVector.h.

Constructor & Destructor Documentation

◆ TFastVector() [1/5]

template<int MaxSize, class Element >
imath::TFastVector< MaxSize, Element >::TFastVector ( )
inline

Create an uninitialized point.

Definition at line 325 of file TFastVector.h.

◆ TFastVector() [2/5]

template<int MaxSize, class Element >
imath::TFastVector< MaxSize, Element >::TFastVector ( int  componentsCount,
const Element &  value = Element() 
)
inlineexplicit

Create vector and initialize number of components.

Definition at line 332 of file TFastVector.h.

References imath::TFastVector< MaxSize, Element >::m_elements, and imath::TFastVector< MaxSize, Element >::m_elementsCount.

◆ TFastVector() [3/5]

template<int MaxSize, class Element >
imath::TFastVector< MaxSize, Element >::TFastVector ( const TFastVector< MaxSize, Element > &  vector)
inline

◆ TFastVector() [4/5]

template<int MaxSize, class Element >
imath::TFastVector< MaxSize, Element >::TFastVector ( std::initializer_list< Element >  values)
inline

◆ TFastVector() [5/5]

template<int MaxSize, class Element = double>
template<int Size>
imath::TFastVector< MaxSize, Element >::TFastVector ( const imath::TVector< Size, Element > &  vector)
inline

Definition at line 152 of file TFastVector.h.

References imath::TFastVector< MaxSize, Element >::m_elements.

Member Function Documentation

◆ Clear()

template<int MaxSize, class Element >
void imath::TFastVector< MaxSize, Element >::Clear ( )
inline

Set all coordinates to zero.

Definition at line 439 of file TFastVector.h.

◆ EnsureElementsCount()

template<int MaxSize, class Element >
bool imath::TFastVector< MaxSize, Element >::EnsureElementsCount ( int  count,
const Element &  value = Element() 
)
inline

Ensure, that number of elements vector cannot be smaller that some value.

If number of elements was bigger or equal to specified value, it does nothing. In other case, number of elements will be set.

Parameters
countnumber of elements.
Returns
true, if the number of set is not greater than template parameter MaxSize.

Definition at line 389 of file TFastVector.h.

◆ GetDistance()

template<int MaxSize, class Element >
Element imath::TFastVector< MaxSize, Element >::GetDistance ( const TFastVector< MaxSize, Element > &  vector) const
inline

Return distance between two vectors.

Definition at line 554 of file TFastVector.h.

◆ GetDistance2()

template<int MaxSize, class Element >
Element imath::TFastVector< MaxSize, Element >::GetDistance2 ( const TFastVector< MaxSize, Element > &  vector) const
inline

Return distance square between two vectors.

Definition at line 547 of file TFastVector.h.

◆ GetDotProduct()

template<int MaxSize, class Element >
Element imath::TFastVector< MaxSize, Element >::GetDotProduct ( const TFastVector< MaxSize, Element > &  vector) const
inline

Return dot product of two vectors.

Definition at line 519 of file TFastVector.h.

References imath::TFastVector< MaxSize, Element >::m_elements, and imath::TFastVector< MaxSize, Element >::m_elementsCount.

◆ GetElement()

template<int MaxSize, class Element >
const Element & imath::TFastVector< MaxSize, Element >::GetElement ( int  i) const
inline

Get element at specified i.

Definition at line 409 of file TFastVector.h.

Referenced by imath::TFastVector< MaxSize, Element >::GetMaximal(), and imath::TFastVector< MaxSize, Element >::GetMinimal().

◆ GetElementRef()

template<int MaxSize, class Element >
Element & imath::TFastVector< MaxSize, Element >::GetElementRef ( int  i)
inline

Get reference to element at specified i.

Definition at line 419 of file TFastVector.h.

◆ GetElementsCount()

template<int MaxSize, class Element >
int imath::TFastVector< MaxSize, Element >::GetElementsCount ( ) const
inline

◆ GetElementsSum()

template<int MaxSize, class Element >
Element imath::TFastVector< MaxSize, Element >::GetElementsSum ( ) const

Get simple sum of all elements.

Definition at line 820 of file TFastVector.h.

◆ GetLength()

template<int MaxSize, class Element >
Element imath::TFastVector< MaxSize, Element >::GetLength ( ) const
inline

Return euclidian length.

Definition at line 540 of file TFastVector.h.

◆ GetLength2()

template<int MaxSize, class Element >
Element imath::TFastVector< MaxSize, Element >::GetLength2 ( ) const
inline

Return euclidian length square.

Definition at line 533 of file TFastVector.h.

◆ GetMaximal()

template<int MaxSize, class Element >
void imath::TFastVector< MaxSize, Element >::GetMaximal ( const TFastVector< MaxSize, Element > &  vector,
TFastVector< MaxSize, Element > &  result 
) const

◆ GetMinimal()

template<int MaxSize, class Element >
void imath::TFastVector< MaxSize, Element >::GetMinimal ( const TFastVector< MaxSize, Element > &  vector,
TFastVector< MaxSize, Element > &  result 
) const

◆ GetNormalized()

template<int MaxSize, class Element >
bool imath::TFastVector< MaxSize, Element >::GetNormalized ( TFastVector< MaxSize, Element > &  result,
Element  length = 1.0 
) const

Return normalized vector with the same direction and specified length.

Parameters
lengthnew vector length.
Returns
true, if normalization succeeded.

Definition at line 853 of file TFastVector.h.

References imath::TFastVector< MaxSize, Element >::Normalize().

◆ GetTranslated() [1/2]

template<int MaxSize, class Element >
TFastVector< MaxSize, Element > imath::TFastVector< MaxSize, Element >::GetTranslated ( const TFastVector< MaxSize, Element > &  vector)
inline

Get translated point.

Definition at line 496 of file TFastVector.h.

◆ GetTranslated() [2/2]

template<int MaxSize, class Element >
void imath::TFastVector< MaxSize, Element >::GetTranslated ( const TFastVector< MaxSize, Element > &  vector,
TFastVector< MaxSize, Element > &  result 
)

/overloaded

Definition at line 503 of file TFastVector.h.

References imath::TFastVector< MaxSize, Element >::Translate().

◆ IsNull()

template<int MaxSize, class Element >
bool imath::TFastVector< MaxSize, Element >::IsNull ( Element  tolerance = I_BIG_EPSILON) const
inline

Check if this vector is null.

Definition at line 512 of file TFastVector.h.

◆ Normalize()

template<int MaxSize, class Element >
bool imath::TFastVector< MaxSize, Element >::Normalize ( Element  length = 1.0)

Normalize vector to specified length.

Parameters
lengthnew vector length.
Returns
true, if normalization succeeded.

Definition at line 833 of file TFastVector.h.

References I_BIG_EPSILON.

Referenced by imath::TFastVector< MaxSize, Element >::GetNormalized().

◆ operator!=()

template<int MaxSize, class Element >
bool imath::TFastVector< MaxSize, Element >::operator!= ( const TFastVector< MaxSize, Element > &  vector) const
inline

Definition at line 580 of file TFastVector.h.

◆ operator*()

template<int MaxSize, class Element >
TFastVector< MaxSize, Element > imath::TFastVector< MaxSize, Element >::operator* ( Element  scalar) const
inline

Definition at line 776 of file TFastVector.h.

◆ operator*=()

template<int MaxSize, class Element >
TFastVector< MaxSize, Element > & imath::TFastVector< MaxSize, Element >::operator*= ( Element  scalar)
inline

Definition at line 719 of file TFastVector.h.

◆ operator+()

template<int MaxSize, class Element >
TFastVector< MaxSize, Element > imath::TFastVector< MaxSize, Element >::operator+ ( const TFastVector< MaxSize, Element > &  vector) const
inline

Definition at line 754 of file TFastVector.h.

◆ operator+=()

template<int MaxSize, class Element >
TFastVector< MaxSize, Element > & imath::TFastVector< MaxSize, Element >::operator+= ( const TFastVector< MaxSize, Element > &  vector)
inline

◆ operator-() [1/2]

template<int MaxSize, class Element >
TFastVector< MaxSize, Element > imath::TFastVector< MaxSize, Element >::operator- ( ) const
inline

Definition at line 741 of file TFastVector.h.

References imath::TFastVector< MaxSize, Element >::m_elements.

◆ operator-() [2/2]

template<int MaxSize, class Element >
TFastVector< MaxSize, Element > imath::TFastVector< MaxSize, Element >::operator- ( const TFastVector< MaxSize, Element > &  vector) const
inline

Definition at line 765 of file TFastVector.h.

◆ operator-=()

template<int MaxSize, class Element >
TFastVector< MaxSize, Element > & imath::TFastVector< MaxSize, Element >::operator-= ( const TFastVector< MaxSize, Element > &  vector)
inline

◆ operator/()

template<int MaxSize, class Element >
TFastVector< MaxSize, Element > imath::TFastVector< MaxSize, Element >::operator/ ( Element  scalar) const
inline

Definition at line 787 of file TFastVector.h.

◆ operator/=()

template<int MaxSize, class Element >
TFastVector< MaxSize, Element > & imath::TFastVector< MaxSize, Element >::operator/= ( Element  scalar)
inline

Definition at line 730 of file TFastVector.h.

◆ operator<()

template<int MaxSize, class Element >
bool imath::TFastVector< MaxSize, Element >::operator< ( const TFastVector< MaxSize, Element > &  vector) const

◆ operator<=()

template<int MaxSize, class Element >
bool imath::TFastVector< MaxSize, Element >::operator<= ( const TFastVector< MaxSize, Element > &  vector) const

◆ operator=()

template<int MaxSize, class Element >
TFastVector< MaxSize, Element > & imath::TFastVector< MaxSize, Element >::operator= ( const TFastVector< MaxSize, Element > &  vector)
inline

◆ operator==()

template<int MaxSize, class Element >
bool imath::TFastVector< MaxSize, Element >::operator== ( const TFastVector< MaxSize, Element > &  vector) const
inline

◆ operator>()

template<int MaxSize, class Element >
bool imath::TFastVector< MaxSize, Element >::operator> ( const TFastVector< MaxSize, Element > &  vector) const

◆ operator>=()

template<int MaxSize, class Element >
bool imath::TFastVector< MaxSize, Element >::operator>= ( const TFastVector< MaxSize, Element > &  vector) const

◆ operator[]() [1/2]

template<int MaxSize, class Element >
Element & imath::TFastVector< MaxSize, Element >::operator[] ( int  i)

Definition at line 808 of file TFastVector.h.

◆ operator[]() [2/2]

template<int MaxSize, class Element >
const Element & imath::TFastVector< MaxSize, Element >::operator[] ( int  i) const

Definition at line 798 of file TFastVector.h.

◆ ScaledCumulate()

template<int MaxSize, class Element >
void imath::TFastVector< MaxSize, Element >::ScaledCumulate ( const TFastVector< MaxSize, Element > &  vector,
Element  scale 
)
inline

Add second vector scaled by specified factor.

It is equal of Translate(vector * scale) but can be faster implemented.

Definition at line 458 of file TFastVector.h.

References imath::TFastVector< MaxSize, Element >::m_elements, and imath::TFastVector< MaxSize, Element >::m_elementsCount.

◆ Serialize()

template<int MaxSize, class Element >
bool imath::TFastVector< MaxSize, Element >::Serialize ( iser::IArchive archive)

◆ SetElement()

template<int MaxSize, class Element >
void imath::TFastVector< MaxSize, Element >::SetElement ( int  i,
const Element &  value 
)
inline

Set element at specified i.

Definition at line 429 of file TFastVector.h.

Referenced by imath::TFastVector< MaxSize, Element >::GetMaximal(), and imath::TFastVector< MaxSize, Element >::GetMinimal().

◆ SetElementsCount()

template<int MaxSize, class Element >
bool imath::TFastVector< MaxSize, Element >::SetElementsCount ( int  count,
const Element &  value = Element() 
)
inline

Set number of elements.

Parameters
countnumber of elements.
Returns
true, if the number of set is not greater than template parameter MaxSize.

Definition at line 371 of file TFastVector.h.

Referenced by imath::TFastVector< MaxSize, Element >::GetMaximal(), and imath::TFastVector< MaxSize, Element >::GetMinimal().

◆ SetElementsFrom()

template<int MaxSize, class Element >
void imath::TFastVector< MaxSize, Element >::SetElementsFrom ( const TFastVector< MaxSize, Element > &  vector,
const Element &  expansionValue = Element() 
)

Set elemenents from other vector without resizing.

Parameters
vectorsource of element values will be copied.
expansionValueif actual vector has more elements than vector, rest will be replaced with this value.

Definition at line 481 of file TFastVector.h.

References imath::TFastVector< MaxSize, Element >::m_elementsCount.

◆ Translate()

template<int MaxSize, class Element >
void imath::TFastVector< MaxSize, Element >::Translate ( const TFastVector< MaxSize, Element > &  vector)
inline

Member Data Documentation

◆ m_elements

template<int MaxSize, class Element = double>
Element imath::TFastVector< MaxSize, Element >::m_elements[MaxSize]
protected

◆ m_elementsCount

template<int MaxSize, class Element = double>
int imath::TFastVector< MaxSize, Element >::m_elementsCount
protected

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