Gromacs  2025.0-dev-20241009-5c23d5f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions
gmx::BasicVector< ValueType > Class Template Reference

#include <gromacs/math/vectypes.h>

Description

template<typename ValueType>
class gmx::BasicVector< ValueType >

C++ class for 3D vectors.

Template Parameters
ValueTypeType

This class provides a C++ version of rvec/dvec/ivec that can be put into STL containers etc. It is more or less a drop-in replacement for rvec and friends: it can be used in most contexts that accept the equivalent C type. However, there is one case where explicit conversion is necessary:

For the array conversion to work, the compiler should not add any extra alignment/padding in the layout of this class; that this actually works as intended is tested in the unit tests.

Public Types

using RawArray = ValueType[3]
 Underlying raw C array type (rvec/dvec/ivec).
 

Public Member Functions

 BasicVector ()
 Constructs default (uninitialized) vector.
 
constexpr BasicVector (ValueType x, ValueType y, ValueType z)
 Constructs a vector from given values.
 
constexpr BasicVector (const RawArray x)
 Constructs a vector from given values. More...
 
constexpr BasicVector (const BasicVector &src)=default
 Default copy constructor.
 
constexpr BasicVectoroperator= (const BasicVector &v)=default
 Default copy assignment operator.
 
constexpr BasicVector (BasicVector &&src) noexcept=default
 Default move constructor.
 
constexpr BasicVectoroperator= (BasicVector &&v) noexcept=default
 Default move assignment operator.
 
constexpr ValueType & operator[] (int i)
 Indexing operator to make the class work as the raw array.
 
constexpr ValueType operator[] (int i) const
 Indexing operator to make the class work as the raw array.
 
constexpr bool operator== (const BasicVector< ValueType > &right) const
 Return whether all elements compare equal.
 
constexpr bool operator!= (const BasicVector< ValueType > &right) const
 Return whether any elements compare unequal.
 
constexpr BasicVector
< ValueType > & 
operator+= (const BasicVector< ValueType > &right)
 Allow inplace addition for BasicVector.
 
constexpr BasicVector
< ValueType > & 
operator-= (const BasicVector< ValueType > &right)
 Allow inplace subtraction for BasicVector.
 
constexpr BasicVector< ValueType > operator+ (const BasicVector< ValueType > &right) const
 Allow vector addition.
 
constexpr BasicVector< ValueType > operator- (const BasicVector< ValueType > &right) const
 Allow vector subtraction.
 
constexpr BasicVector< ValueType > operator/ (const ValueType &right) const
 Allow vector scalar division.
 
constexpr BasicVector
< ValueType > & 
operator*= (const ValueType &right)
 Scale vector by a scalar.
 
constexpr BasicVector
< ValueType > & 
operator/= (const ValueType &right)
 Divide vector by a scalar.
 
constexpr BasicVector< ValueType > operator- () const
 Unary minus.
 
constexpr ValueType dot (const BasicVector< ValueType > &right) const
 Return dot product.
 
constexpr BasicVector< ValueType > cross (const BasicVector< ValueType > &right) const
 Allow vector vector multiplication (cross product)
 
constexpr BasicVector< ValueType > unitVector () const
 Return normalized to unit vector.
 
constexpr ValueType norm2 () const
 Length^2 of vector.
 
constexpr ValueType norm () const
 Norm or length of vector.
 
constexpr BasicVector< realtoRVec () const
 cast to RVec
 
constexpr BasicVector< int > toIVec () const
 cast to IVec
 
constexpr BasicVector< double > toDVec () const
 cast to DVec
 
constexpr RawArrayas_vec ()
 Converts to a raw C array where implicit conversion does not work.
 
constexpr const RawArrayas_vec () const
 Converts to a raw C array where implicit conversion does not work.
 
constexpr operator RawArray & ()
 Makes BasicVector usable in contexts where a raw C array is expected.
 
constexpr operator const RawArray & () const
 Makes BasicVector usable in contexts where a raw C array is expected.
 

Constructor & Destructor Documentation

template<typename ValueType>
constexpr gmx::BasicVector< ValueType >::BasicVector ( const RawArray  x)
inline

Constructs a vector from given values.

This constructor is not explicit to support implicit conversions that allow, e.g., calling std::vector<RVec>::push_back() directly with an rvec parameter.


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