criptic v1
Cosmic Ray Interstellar Propagation Tool using Itô Calculus
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
criptic::Vec3< T > Class Template Reference

Class that represents a mathematical vector. More...

#include <Vec3.H>

Public Member Functions

 Vec3 ()
 Construct a vector of all zeros.
 
template<class U , class V , class W >
 Vec3 (const U &v0, const V &v1, const W &v2)
 Construct a vector from 3 scalars.
 
template<class U >
 Vec3 (const U &v0)
 Construct a vector with every element equal to given value.
 
template<class U >
 Vec3 (const Vec3< U > &a)
 Conversion constructor.
 
T & operator[] (int i)
 Return an element of the vector.
 
const T & operator[] (int i) const
 Return a const ref to an element of the vector.
 
T & operator() (int i)
 Return an element of the vector.
 
const T & operator() (int i) const
 Return a const ref to an element of the vector.
 
T * data ()
 Return pointer to data.
 
const T * data () const
 Return const pointer to data.
 
Vec3< T > operator- ()
 Return the negative of a vector.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
Vec3< T > & operator+= (const U &a)
 Add a scalar to the Vec3 elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
Vec3< T > & operator-= (const U &a)
 Subtract a scalar from the Vec3 elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
Vec3< T > & operator*= (const U &a)
 Multiply a scalar by the Vec3 elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
Vec3< T > & operator/= (const U &a)
 Divide the Vec3 by a scalar elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
Vec3< T > & operator+= (const Vec3< U > &a)
 Add another Vec3 to the Vec3 elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
Vec3< T > & operator-= (const Vec3< U > &a)
 Subtract another Vec3 from the Vec3 elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
Vec3operator*= (const Vec3< U > &a)
 Multiply another Vec3 by the Vec3 elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
Vec3operator/= (const Vec3< U > &a)
 Divide this Vec3 by another Vec3 elementwise.
 
Vec3< T > & operator= (const T &a)
 Assign a scalar value to every element of a Vec3.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
auto operator+ (const U &a) const -> Vec3< decltype(this->v[0]+a)>
 Add a scalar and a Vec3 elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
auto operator- (const U &a) const -> Vec3< decltype(this->v[0]-a)>
 Subtract a scalar from a Vec3 elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
auto operator* (const U &a) const -> Vec3< decltype(this->v[0] *a)>
 Multiply a scalar by a Vec3 elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
auto operator/ (const U &a) const -> Vec3< decltype(this->v[0]/a)>
 Divide a Vec3 by a scalar elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value||std::is_enum< T >::value, bool > = true>
Vec3< bool > operator== (const U &a) const
 Evaluate equality of vector elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value||std::is_enum< T >::value, bool > = true>
Vec3< bool > operator!= (const U &a) const
 Evaluate inequality of vector elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
auto operator+ (const Vec3< U > &a) const -> Vec3< decltype(this->v[0]+a[0])>
 Add two Vec3s elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
auto operator- (const Vec3< U > &a) const -> Vec3< decltype(this->v[0]-a[0])>
 Subtract two Vec3s elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
auto operator* (const Vec3< U > &a) const -> Vec3< decltype(this->v[0] *a[0])>
 Multiply two Vec3s elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
auto operator/ (const Vec3< U > &a) const -> Vec3< decltype(this->v[0]/a[0])>
 Divide two Vec3s elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value||std::is_enum< T >::value, bool > = true>
Vec3< bool > operator== (const Vec3< U > &a) const
 Evaluate equality of two Vec3's elementwise.
 
template<class U , std::enable_if_t< std::is_arithmetic< U >::value||std::is_enum< T >::value, bool > = true>
Vec3< bool > operator!= (const Vec3< U > &a) const
 Evaluate inequality of two Vec3's elementwise.
 
constexpr T mag2 () const
 Computes the squared magnitude of the vector.
 
Real mag () const
 Computes the magnitude of the vector.
 
Vec3< Realunit () const
 Returns a unit vector parallel to the vector.
 
void normalize ()
 Normalizes this vector to have unit length.
 
max () const
 Return the value of the largest element.
 
int argmax () const
 Return the index of the largest element.
 
min () const
 Return the value of the smallest element.
 
int argmin () const
 Return the index of the smallest element.
 
sum () const
 Return the sum of the elements.
 
template<class U >
auto dot (const Vec3< U > &a) const
 Returns the dot product of this vector with another vector.
 
template<class U >
auto cross (const Vec3< U > &a) const -> Vec3< decltype(this->v[0]+a[0])>
 Returns the cross product of this vector with another vector.
 
template<class U >
Vec3< T > & operator= (const std::vector< U > &a)
 Assign a Vec3 from a std::vector.
 

Public Attributes

v [3]
 

Detailed Description

template<class T>
class criptic::Vec3< T >

Class that represents a mathematical vector.

Template Parameters
Thetype of the three vector

This class represents a mathematical vector in 3 dimensional space. When the the type of the vector is an arithmetic type, it provides standard algebraic operations.

Constructor & Destructor Documentation

◆ Vec3() [1/4]

template<class T >
criptic::Vec3< T >::Vec3 ( )
inline

Construct a vector of all zeros.

◆ Vec3() [2/4]

template<class T >
template<class U , class V , class W >
criptic::Vec3< T >::Vec3 ( const U &  v0,
const V &  v1,
const W &  v2 
)
inline

Construct a vector from 3 scalars.

Parameters
v0First element
v1First element
v2First element

◆ Vec3() [3/4]

template<class T >
template<class U >
criptic::Vec3< T >::Vec3 ( const U &  v0)
inline

Construct a vector with every element equal to given value.

Parameters
v0Value to store in every element

◆ Vec3() [4/4]

template<class T >
template<class U >
criptic::Vec3< T >::Vec3 ( const Vec3< U > &  a)
inline

Conversion constructor.

Parameters
aThe vector to convert

Member Function Documentation

◆ argmax()

template<class T >
int criptic::Vec3< T >::argmax ( ) const
inline

Return the index of the largest element.

Returns
Index of the largest element of the vector

◆ argmin()

template<class T >
int criptic::Vec3< T >::argmin ( ) const
inline

Return the index of the smallest element.

Returns
Index of the smallest element of the vector

◆ cross()

template<class T >
template<class U >
auto criptic::Vec3< T >::cross ( const Vec3< U > &  a) const -> Vec3<decltype(this->v[0]+a[0])>
inline

Returns the cross product of this vector with another vector.

Parameters
aVector to cross with this vector
Returns
Value of this vector x a

◆ data() [1/2]

template<class T >
T * criptic::Vec3< T >::data ( )
inline

Return pointer to data.

Returns
Pointer to data

◆ data() [2/2]

template<class T >
const T * criptic::Vec3< T >::data ( ) const
inline

Return const pointer to data.

Returns
Const pointer to data

◆ dot()

template<class T >
template<class U >
auto criptic::Vec3< T >::dot ( const Vec3< U > &  a) const
inline

Returns the dot product of this vector with another vector.

Parameters
aVector to dot with this vector
Returns
Value of this vector . a

◆ mag()

template<class T >
Real criptic::Vec3< T >::mag ( ) const
inline

Computes the magnitude of the vector.

Returns
Magnitude of the vector

◆ mag2()

template<class T >
constexpr T criptic::Vec3< T >::mag2 ( ) const
inlineconstexpr

Computes the squared magnitude of the vector.

Returns
Squared magnitude of the vector

◆ max()

template<class T >
T criptic::Vec3< T >::max ( ) const
inline

Return the value of the largest element.

Returns
Value of the largest element of the vector

◆ min()

template<class T >
T criptic::Vec3< T >::min ( ) const
inline

Return the value of the smallest element.

Returns
Value of the smallest element of the vector

◆ normalize()

template<class T >
void criptic::Vec3< T >::normalize ( )
inline

Normalizes this vector to have unit length.

Equivalent to (*this) = (*this) / mag()

◆ operator!=() [1/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value||std::is_enum< T >::value, bool > = true>
criptic::Vec3< T >::operator!= ( const U &  a) const
inline

Evaluate inequality of vector elementwise.

Parameters
aThe scalar
Returns
A vector of bool giving elementwise inequality

◆ operator!=() [2/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value||std::is_enum< T >::value, bool > = true>
criptic::Vec3< T >::operator!= ( const Vec3< U > &  a) const
inline

Evaluate inequality of two Vec3's elementwise.

Template Parameters
UThe data type held by a
Parameters
aThe Vec3 to compare
Returns
A vector of bool giving elementwise inequality

◆ operator()() [1/2]

template<class T >
criptic::Vec3< T >::operator() ( int  i)
inline

Return an element of the vector.

Parameters
iThe element to return
Returns
Vector element i

◆ operator()() [2/2]

template<class T >
criptic::Vec3< T >::operator() ( int  i) const
inline

Return a const ref to an element of the vector.

Parameters
iThe element to return
Returns
Vector element i

◆ operator*() [1/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
criptic::Vec3< T >::operator* ( const U &  a) const -> Vec3<decltype(this->v[0]*a)>
inline

Multiply a scalar by a Vec3 elementwise.

Parameters
aThe scalar
Returns
A Vec3 containing the elementwise product

◆ operator*() [2/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
criptic::Vec3< T >::operator* ( const Vec3< U > &  a) const -> Vec3<decltype(this->v[0]*a[0])>
inline

Multiply two Vec3s elementwise.

Parameters
aThe Vec3 to multiply
Returns
A Vec3 containing the elementwise product

◆ operator*=() [1/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
criptic::Vec3< T >::operator*= ( const U &  a)
inline

Multiply a scalar by the Vec3 elementwise.

Parameters
aThe scalar
Returns
A reference to the modified Vec3

◆ operator*=() [2/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
criptic::Vec3< T >::operator*= ( const Vec3< U > &  a)
inline

Multiply another Vec3 by the Vec3 elementwise.

Parameters
aThe Vec3 to multiply
Returns
A reference to the modified Vec3

◆ operator+() [1/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
criptic::Vec3< T >::operator+ ( const U &  a) const -> Vec3<decltype(this->v[0]+a)>
inline

Add a scalar and a Vec3 elementwise.

Parameters
aThe scalar
Returns
A Vec3 containing the elementwise sum

◆ operator+() [2/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
criptic::Vec3< T >::operator+ ( const Vec3< U > &  a) const -> Vec3<decltype(this->v[0]+a[0])>
inline

Add two Vec3s elementwise.

Parameters
aThe Vec3 to add
Returns
A Vec3 containing the elementwise sum

◆ operator+=() [1/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
criptic::Vec3< T >::operator+= ( const U &  a)
inline

Add a scalar to the Vec3 elementwise.

Parameters
aThe scalar
Returns
A reference to the modified Vec3

◆ operator+=() [2/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
criptic::Vec3< T >::operator+= ( const Vec3< U > &  a)
inline

Add another Vec3 to the Vec3 elementwise.

Parameters
aThe Vec3 to add
Returns
A reference to the modified Vec3

◆ operator-() [1/3]

template<class T >
criptic::Vec3< T >::operator- ( )
inline

Return the negative of a vector.

Returns
A copy of the Vec3 with every element multiplied by -1

◆ operator-() [2/3]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
criptic::Vec3< T >::operator- ( const U &  a) const -> Vec3<decltype(this->v[0]-a)>
inline

Subtract a scalar from a Vec3 elementwise.

Parameters
aThe scalar
Returns
A Vec3 containing the elementwise difference

◆ operator-() [3/3]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
criptic::Vec3< T >::operator- ( const Vec3< U > &  a) const -> Vec3<decltype(this->v[0]-a[0])>
inline

Subtract two Vec3s elementwise.

Parameters
aThe Vec3 to subtract
Returns
A Vec3 containing the elementwise difference

◆ operator-=() [1/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
criptic::Vec3< T >::operator-= ( const U &  a)
inline

Subtract a scalar from the Vec3 elementwise.

Parameters
aThe scalar
Returns
A reference to the modified Vec3

◆ operator-=() [2/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
criptic::Vec3< T >::operator-= ( const Vec3< U > &  a)
inline

Subtract another Vec3 from the Vec3 elementwise.

Parameters
aThe Vec3 to subtract
Returns
A reference to the modified Vec3

◆ operator/() [1/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
criptic::Vec3< T >::operator/ ( const U &  a) const -> Vec3<decltype(this->v[0]/a)>
inline

Divide a Vec3 by a scalar elementwise.

Parameters
aThe scalar
Returns
A Vec3 containing the elementwise dividend

◆ operator/() [2/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
criptic::Vec3< T >::operator/ ( const Vec3< U > &  a) const -> Vec3<decltype(this->v[0]/a[0])>
inline

Divide two Vec3s elementwise.

Parameters
aThe Vec3 to divide by
Returns
A Vec3 containing the elementwise dividend

◆ operator/=() [1/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
criptic::Vec3< T >::operator/= ( const U &  a)
inline

Divide the Vec3 by a scalar elementwise.

Parameters
aThe scalar
Returns
A reference to the modified Vec3

◆ operator/=() [2/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value, bool > = true>
criptic::Vec3< T >::operator/= ( const Vec3< U > &  a)
inline

Divide this Vec3 by another Vec3 elementwise.

Parameters
aThe Vec3 to divide by
Returns
A reference to the modified Vec3

◆ operator=() [1/2]

template<class T >
template<class U >
criptic::Vec3< T >::operator= ( const std::vector< U > &  a)
inline

Assign a Vec3 from a std::vector.

Template Parameters
UThe data type held by a
Parameters
aThe vector from which to assign
Returns
This Vec3

◆ operator=() [2/2]

template<class T >
criptic::Vec3< T >::operator= ( const T &  a)
inline

Assign a scalar value to every element of a Vec3.

Parameters
aThe scalar
Returns
The Vec3 with every element set equal to a

◆ operator==() [1/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value||std::is_enum< T >::value, bool > = true>
criptic::Vec3< T >::operator== ( const U &  a) const
inline

Evaluate equality of vector elementwise.

Parameters
aThe scalar
Returns
A vector of bool giving elementwise equality

◆ operator==() [2/2]

template<class T >
template<class U , std::enable_if_t< std::is_arithmetic< U >::value||std::is_enum< T >::value, bool > = true>
criptic::Vec3< T >::operator== ( const Vec3< U > &  a) const
inline

Evaluate equality of two Vec3's elementwise.

Template Parameters
UThe data type held by a
Parameters
aThe Vec3 to compare
Returns
A vector of bool giving elementwise equality

◆ operator[]() [1/2]

template<class T >
criptic::Vec3< T >::operator[] ( int  i)
inline

Return an element of the vector.

Parameters
iThe element to return
Returns
Vector element i

◆ operator[]() [2/2]

template<class T >
criptic::Vec3< T >::operator[] ( int  i) const
inline

Return a const ref to an element of the vector.

Parameters
iThe element to return
Returns
Vector element i

◆ sum()

template<class T >
T criptic::Vec3< T >::sum ( ) const
inline

Return the sum of the elements.

Returns
Sum of elements of the vector

◆ unit()

template<class T >
Vec3< Real > criptic::Vec3< T >::unit ( ) const
inline

Returns a unit vector parallel to the vector.

Returns
Unit vector parallel to the vector

Member Data Documentation

◆ v

template<class T >
T criptic::Vec3< T >::v[3]

Data in Vec3


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