Mundy: Multibody Nonlocal Dynamics Version of the Day
Loading...
Searching...
No Matches
mundy::AQuaternion< T, Accessor > Class Template Reference

AQuaternion class with floating point entries (an integer-valued quaternion doesn't make much sense). More...

#include <Quaternion.hpp>

Inheritance diagram for mundy::AQuaternion< T, Accessor >:
[legend]

Public Member Functions

Constructors and destructor
constexpr AQuaternion ()
 Default constructor. Assume elements are uninitialized.
constexpr AQuaternion (const Accessor &data)
 Constructor from a given accessor.
constexpr AQuaternion (const T &w, const T &x, const T &y, const T &z)
 Constructor to initialize all elements.
constexpr AQuaternion (const std::initializer_list< T > &list)
 Constructor to initialize all elements via initializer list.
constexpr ~AQuaternion ()=default
 Destructor.
constexpr AQuaternion (const AQuaternion< T, Accessor > &)=default
 Default copy constructor.
constexpr AQuaternion (AQuaternion< T, Accessor > &&)=default
 Default move constructor.
constexpr AQuaternion< T, Accessor > & operator= (const AQuaternion< T, Accessor > &)=default
 Default copy assignment operator.
constexpr AQuaternion< T, Accessor > & operator= (AQuaternion< T, Accessor > &&)=default
 Default move assignment operator.
template<ValidQuaternionType OtherQuaternionType>
constexpr AQuaternion (const OtherQuaternionType &other) &&(std
 Deep copy constructor with different accessor.
template<ValidQuaternionType OtherQuaternionType>
constexpr AQuaternion (OtherQuaternionType &&other) &&(std
 Deep move constructor with different accessor.
template<ValidQuaternionType OtherQuaternionType>
constexpr AQuaternion< T, Accessor > & operator= (const OtherQuaternionType &other)
 Deep copy assignment operator with different accessor.
template<ValidQuaternionType OtherQuaternionType>
constexpr AQuaternion< T, Accessor > & operator= (OtherQuaternionType &&other)
 Deep move assignment operator with different accessor.
Accessors
constexpr T & operator[] (size_t index)
 Element access operator via a single index.
constexpr const T & operator[] (size_t index) const
 Const element access operator via a single index.
constexpr T & operator() (size_t index)
 Element access operator via a single index.
constexpr const T & operator() (size_t index) const
 Const element access operator via a single index.
constexpr T & w ()
 Get a reference to the scalar component.
constexpr const T & w () const
 Get a reference to the scalar component.
constexpr T & x ()
 Get a reference to the x component.
constexpr const T & x () const
 Get a reference to the x component.
constexpr T & y ()
 Get a reference to the y component.
constexpr const T & y () const
 Get a reference to the y component.
constexpr T & z ()
 Get a reference to the z component.
constexpr const T & z () const
 Get a reference to the z component.
constexpr decltype(auto) data ()
 Get the internal data accessor.
constexpr decltype(auto) data () const
 Get the internal data accessor.
constexpr const auto vector () const
 Get a view of the quaternion vector component.
constexpr auto vector ()
 Get a view of the quaternion vector component.
constexpr deep_copy_t copy () const
 Get a deep copy of the quaternion.
template<typename U>
constexpr auto cast () const
 Cast (and copy) the quaternion to a different type.
Setters and modifiers
constexpr void set (const T &w, const T &x, const T &y, const T &z)
 Set all elements of the quaternion.
constexpr void set (const T &w, const Vector3< T > &vec)
 Set all elements of the quaternion.
template<ValidAccessor< T > OtherAccessor>
constexpr void set (const OtherAccessor &accessor)
 Set all elements of the vector using an accessor.
constexpr void set_vector (const Vector3< T > &vec)
 Set the quaternion vector component.
constexpr void normalize ()
 Normalize the quaternion in place.
constexpr void conjugate ()
 Conjugate the quaternion in place.
constexpr void invert ()
 Invert the quaternion in place.
Unary operators
constexpr AQuaternion< T > operator+ () const
 Unary plus operator.
constexpr AQuaternion< T > operator- () const
 Unary minus operator.
Addition and subtraction
template<typename U, ValidAccessor< U > OtherAccessor>
constexpr auto operator+ (const AQuaternion< U, OtherAccessor > &other) const
 AQuaternion-quaternion addition.
template<typename U, ValidAccessor< U > OtherAccessor>
constexpr AQuaternion< T, Accessor > & operator+= (const AQuaternion< U, OtherAccessor > &other)
 AQuaternion-quaternion addition.
template<typename U, ValidAccessor< U > OtherAccessor>
constexpr auto operator- (const AQuaternion< U, OtherAccessor > &other) const
 AQuaternion-quaternion subtraction.
template<typename U, ValidAccessor< U > OtherAccessor>
constexpr AQuaternion< T, Accessor > & operator-= (const AQuaternion< U, OtherAccessor > &other)
 AQuaternion-quaternion subtraction.
Multiplication and division
template<typename U, ValidAccessor< U > OtherAccessor>
constexpr auto operator* (const AQuaternion< U, OtherAccessor > &other) const
 AQuaternion-quaternion multiplication.
template<typename U, ValidAccessor< U > OtherAccessor>
constexpr AQuaternion< T, Accessor > & operator*= (const AQuaternion< U, OtherAccessor > &other)
 AQuaternion-quaternion multiplication.
template<typename U, ValidAccessor< U > OtherAccessor>
constexpr auto operator* (const AVector3< U, OtherAccessor > &vec) const
 AQuaternion-vector multiplication (same as R * v).
template<typename U, ValidAccessor< U > OtherAccessor>
constexpr auto operator* (const AMatrix3< U, OtherAccessor > &mat) const
 AQuaternion-matrix multiplication.
template<typename U>
constexpr auto operator* (const U &scalar) const
 AQuaternion-scalar multiplication.
template<typename U>
constexpr AQuaternion< T, Accessor > & operator*= (const U &scalar)
 Self-scalar multiplication.
template<typename U>
constexpr auto operator/ (const U &scalar) const
 AQuaternion-scalar division.
template<typename U>
constexpr AQuaternion< T, Accessor > & operator/= (const U &scalar)
 Self-scalar division.

Static Public Member Functions

Static methods
static constexpr AQuaternion< T > identity ()
 Get the identity quaternion.

Friends

Friends <3
template<typename U, ValidAccessor< U > OtherAccessor>
class AQuaternion
template<typename U, ValidAccessor< U > OtherAccessor>
std::ostream & operator<< (std::ostream &os, const AQuaternion< U, OtherAccessor > &quat)

Type aliases

using value_type = T
 The type of the entries.
using non_const_value_type = std::remove_const_t<T>
 The non-const type of the entries.
using deep_copy_t = AQuaternion<T>
 Deep copy type.

Internal data

static constexpr size_t x_storage_index = 0
static constexpr size_t y_storage_index = 1
static constexpr size_t z_storage_index = 2
static constexpr size_t w_storage_index = 3
storage< Accessor > accessor_
 Stored accessor via storage.

Detailed Description

template<typename T, ValidAccessor< T > Accessor>
class mundy::AQuaternion< T, Accessor >
Template Parameters
TThe type of the entries.
AccessorThe type of the accessor.

This class is designed to be used with Kokkos. It is a simple quaternion with arithmetic entries. It is templated on the type of the entries and Accessor type. See Accessor.hpp for more details on the Accessor type requirements.

The goal of AQuaternion is to be a lightweight class that can be used with Kokkos to perform mathematical operations on vectors in R3. It does not own the data, but rather it is templated on an Accessor type that provides access to the underlying data. This allows us to use AQuaternion with Kokkos Views, raw pointers, or any other type that meets the ValidAccessor requirements without copying the data. This is especially important for GPU-compatible code. The underlying data is stored in Eigen's coefficient order (x, y, z, w), even though the semantic quaternion constructor and setters accept values in (w, x, y, z) order.

Quaternions can be constructed by passing an accessor to the constructor. However, if the accessor has a 4-argument constructor, then the AQuaternion can also be constructed by passing the elements directly to the constructor. Similarly, if the accessor has an initializer list constructor, then the AQuaternion can be constructed by passing an initializer list to the constructor. This is a convenience feature which makes working with the default accessor (Array<T, 4>) easier. For example, the following are all valid ways to construct an AQuaternion:

// Constructs an AQuaternion with the default accessor (Array<double, 4>)
AQuaternion<double> quat1({1.0, 2.0, 3.0, 4.0});
AQuaternion<double> quat2(1.0, 2.0, 3.0, 4.0);
AQuaternion<double> quat3(Array<double, 4>({2.0, 3.0, 4.0, 1.0}));
quat4.set(1.0, 2.0, 3.0, 4.0);
// Construct an AQuaternion view from raw Eigen-style coefficient storage
double data[4] = {2.0, 3.0, 4.0, 1.0};
AQuaternion<double, double*> quat6{1.0, 2.0, 3.0, 4.0};
// Not allowed as double* doesn't have a 4-argument constructor
// AQuaternion<double, double*> quat7(1.0, 2.0, 3.0, 4.0);
AQuaternion class with floating point entries (an integer-valued quaternion doesn't make much sense).
Definition Quaternion.hpp:137
constexpr void set(const T &w, const T &x, const T &y, const T &z)
Set all elements of the quaternion.
Definition Quaternion.hpp:417
friend class AQuaternion
Definition Quaternion.hpp:634
constexpr decltype(auto) data()
Get the internal data accessor.
Definition Quaternion.hpp:370
A simplistic array type with a fixed size and type.
Definition Array.hpp:44
Note
Accessors may be owning or non-owning, that is irrelevant to the AQuaternion class; however, these accessors should be lightweight such that they can be copied around without much overhead. Furthermore, the lifetime of the data underlying the accessor should be as long as the AQuaternion that use it.

Member Typedef Documentation

◆ value_type

template<typename T, ValidAccessor< T > Accessor>
using mundy::AQuaternion< T, Accessor >::value_type = T

◆ non_const_value_type

template<typename T, ValidAccessor< T > Accessor>
using mundy::AQuaternion< T, Accessor >::non_const_value_type = std::remove_const_t<T>

◆ deep_copy_t

template<typename T, ValidAccessor< T > Accessor>
using mundy::AQuaternion< T, Accessor >::deep_copy_t = AQuaternion<T>

Constructor & Destructor Documentation

◆ AQuaternion() [1/8]

template<typename T, ValidAccessor< T > Accessor>
mundy::AQuaternion< T, Accessor >::AQuaternion ( )
inlineconstexpr
Note
This constructor is only enabled if the Accessor has a default constructor.

◆ AQuaternion() [2/8]

template<typename T, ValidAccessor< T > Accessor>
mundy::AQuaternion< T, Accessor >::AQuaternion ( const Accessor & data)
inlineexplicitconstexpr
Parameters
[in]dataThe accessor.

◆ AQuaternion() [3/8]

template<typename T, ValidAccessor< T > Accessor>
mundy::AQuaternion< T, Accessor >::AQuaternion ( const T & w,
const T & x,
const T & y,
const T & z )
inlineconstexpr
Parameters
[in]wThe scalar component.
[in]xThe x component.
[in]yThe y component.
[in]zThe z component.
Note
This constructor is only enabled if the Accessor has a 4-argument constructor.
The underlying storage order is (x, y, z, w).

◆ AQuaternion() [4/8]

template<typename T, ValidAccessor< T > Accessor>
mundy::AQuaternion< T, Accessor >::AQuaternion ( const std::initializer_list< T > & list)
inlineconstexpr
Parameters
[in]listThe initializer list.
Note
The initializer list is interpreted in (w, x, y, z) order.

◆ ~AQuaternion()

template<typename T, ValidAccessor< T > Accessor>
mundy::AQuaternion< T, Accessor >::~AQuaternion ( )
constexprdefault

◆ AQuaternion() [5/8]

template<typename T, ValidAccessor< T > Accessor>
mundy::AQuaternion< T, Accessor >::AQuaternion ( const AQuaternion< T, Accessor > & )
constexprdefault

◆ AQuaternion() [6/8]

template<typename T, ValidAccessor< T > Accessor>
mundy::AQuaternion< T, Accessor >::AQuaternion ( AQuaternion< T, Accessor > && )
constexprdefault

◆ AQuaternion() [7/8]

template<typename T, ValidAccessor< T > Accessor>
template<ValidQuaternionType OtherQuaternionType>
mundy::AQuaternion< T, Accessor >::AQuaternion ( const OtherQuaternionType & other) &&
inlineconstexpr

◆ AQuaternion() [8/8]

template<typename T, ValidAccessor< T > Accessor>
template<ValidQuaternionType OtherQuaternionType>
mundy::AQuaternion< T, Accessor >::AQuaternion ( OtherQuaternionType && other) &&
inlineconstexpr

Member Function Documentation

◆ operator=() [1/4]

template<typename T, ValidAccessor< T > Accessor>
AQuaternion< T, Accessor > & mundy::AQuaternion< T, Accessor >::operator= ( const AQuaternion< T, Accessor > & )
constexprdefault

◆ operator=() [2/4]

template<typename T, ValidAccessor< T > Accessor>
AQuaternion< T, Accessor > & mundy::AQuaternion< T, Accessor >::operator= ( AQuaternion< T, Accessor > && )
constexprdefault

◆ operator=() [3/4]

template<typename T, ValidAccessor< T > Accessor>
template<ValidQuaternionType OtherQuaternionType>
AQuaternion< T, Accessor > & mundy::AQuaternion< T, Accessor >::operator= ( const OtherQuaternionType & other)
inlineconstexpr

Copies the data from the other vector to our data. This is only enabled if T is not const.

◆ operator=() [4/4]

template<typename T, ValidAccessor< T > Accessor>
template<ValidQuaternionType OtherQuaternionType>
AQuaternion< T, Accessor > & mundy::AQuaternion< T, Accessor >::operator= ( OtherQuaternionType && other)
inlineconstexpr

Moves the data from the other vector to our data. This is only enabled if T is not const.

◆ operator[]() [1/2]

template<typename T, ValidAccessor< T > Accessor>
T & mundy::AQuaternion< T, Accessor >::operator[] ( size_t index)
inlineconstexpr
Parameters
[in]indexThe index of the element.
Note
Indices follow the raw storage order (x, y, z, w).

◆ operator[]() [2/2]

template<typename T, ValidAccessor< T > Accessor>
const T & mundy::AQuaternion< T, Accessor >::operator[] ( size_t index) const
inlineconstexpr
Parameters
[in]indexThe index of the element.
Note
Indices follow the raw storage order (x, y, z, w).

◆ operator()() [1/2]

template<typename T, ValidAccessor< T > Accessor>
T & mundy::AQuaternion< T, Accessor >::operator() ( size_t index)
inlineconstexpr
Parameters
[in]indexThe index of the element.
Note
Indices follow the raw storage order (x, y, z, w).

◆ operator()() [2/2]

template<typename T, ValidAccessor< T > Accessor>
const T & mundy::AQuaternion< T, Accessor >::operator() ( size_t index) const
inlineconstexpr
Parameters
[in]indexThe index of the element.
Note
Indices follow the raw storage order (x, y, z, w).

◆ w() [1/2]

template<typename T, ValidAccessor< T > Accessor>
T & mundy::AQuaternion< T, Accessor >::w ( )
inlineconstexpr

◆ w() [2/2]

template<typename T, ValidAccessor< T > Accessor>
const T & mundy::AQuaternion< T, Accessor >::w ( ) const
inlineconstexpr

◆ x() [1/2]

template<typename T, ValidAccessor< T > Accessor>
T & mundy::AQuaternion< T, Accessor >::x ( )
inlineconstexpr

◆ x() [2/2]

template<typename T, ValidAccessor< T > Accessor>
const T & mundy::AQuaternion< T, Accessor >::x ( ) const
inlineconstexpr

◆ y() [1/2]

template<typename T, ValidAccessor< T > Accessor>
T & mundy::AQuaternion< T, Accessor >::y ( )
inlineconstexpr

◆ y() [2/2]

template<typename T, ValidAccessor< T > Accessor>
const T & mundy::AQuaternion< T, Accessor >::y ( ) const
inlineconstexpr

◆ z() [1/2]

template<typename T, ValidAccessor< T > Accessor>
T & mundy::AQuaternion< T, Accessor >::z ( )
inlineconstexpr

◆ z() [2/2]

template<typename T, ValidAccessor< T > Accessor>
const T & mundy::AQuaternion< T, Accessor >::z ( ) const
inlineconstexpr

◆ data() [1/2]

template<typename T, ValidAccessor< T > Accessor>
decltype(auto) mundy::AQuaternion< T, Accessor >::data ( )
inlineconstexpr
Note
The returned accessor exposes the raw storage order (x, y, z, w).

◆ data() [2/2]

template<typename T, ValidAccessor< T > Accessor>
decltype(auto) mundy::AQuaternion< T, Accessor >::data ( ) const
inlineconstexpr
Note
The returned accessor exposes the raw storage order (x, y, z, w).

◆ vector() [1/2]

template<typename T, ValidAccessor< T > Accessor>
const auto mundy::AQuaternion< T, Accessor >::vector ( ) const
inlineconstexpr

◆ vector() [2/2]

template<typename T, ValidAccessor< T > Accessor>
auto mundy::AQuaternion< T, Accessor >::vector ( )
inlineconstexpr

◆ copy()

template<typename T, ValidAccessor< T > Accessor>
deep_copy_t mundy::AQuaternion< T, Accessor >::copy ( ) const
inlineconstexpr

◆ cast()

template<typename T, ValidAccessor< T > Accessor>
template<typename U>
auto mundy::AQuaternion< T, Accessor >::cast ( ) const
inlineconstexpr

◆ set() [1/3]

template<typename T, ValidAccessor< T > Accessor>
void mundy::AQuaternion< T, Accessor >::set ( const T & w,
const T & x,
const T & y,
const T & z )
inlineconstexpr
Parameters
[in]wThe scalar component.
[in]xThe x component.
[in]yThe y component.
[in]zThe z component.

◆ set() [2/3]

template<typename T, ValidAccessor< T > Accessor>
void mundy::AQuaternion< T, Accessor >::set ( const T & w,
const Vector3< T > & vec )
inlineconstexpr
Parameters
[in]wThe scalar component.
[in]vecThe vector component.

◆ set() [3/3]

template<typename T, ValidAccessor< T > Accessor>
template<ValidAccessor< T > OtherAccessor>
void mundy::AQuaternion< T, Accessor >::set ( const OtherAccessor & accessor)
inlineconstexpr
Parameters
[in]accessorA valid accessor.
Note
An AQuaternion is also a valid accessor.

◆ set_vector()

template<typename T, ValidAccessor< T > Accessor>
void mundy::AQuaternion< T, Accessor >::set_vector ( const Vector3< T > & vec)
inlineconstexpr
Parameters
[in]vecThe vector.

◆ normalize()

template<typename T, ValidAccessor< T > Accessor>
void mundy::AQuaternion< T, Accessor >::normalize ( )
inlineconstexpr

◆ conjugate()

template<typename T, ValidAccessor< T > Accessor>
void mundy::AQuaternion< T, Accessor >::conjugate ( )
inlineconstexpr

◆ invert()

template<typename T, ValidAccessor< T > Accessor>
void mundy::AQuaternion< T, Accessor >::invert ( )
inlineconstexpr

◆ operator+() [1/2]

template<typename T, ValidAccessor< T > Accessor>
AQuaternion< T > mundy::AQuaternion< T, Accessor >::operator+ ( ) const
inlineconstexpr

◆ operator-() [1/2]

template<typename T, ValidAccessor< T > Accessor>
AQuaternion< T > mundy::AQuaternion< T, Accessor >::operator- ( ) const
inlineconstexpr

◆ operator+() [2/2]

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
auto mundy::AQuaternion< T, Accessor >::operator+ ( const AQuaternion< U, OtherAccessor > & other) const
inlineconstexpr
Parameters
[in]otherThe other quaternion.

◆ operator+=()

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
AQuaternion< T, Accessor > & mundy::AQuaternion< T, Accessor >::operator+= ( const AQuaternion< U, OtherAccessor > & other)
inlineconstexpr
Parameters
[in]otherThe other quaternion.

◆ operator-() [2/2]

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
auto mundy::AQuaternion< T, Accessor >::operator- ( const AQuaternion< U, OtherAccessor > & other) const
inlineconstexpr
Parameters
[in]otherThe other quaternion.

◆ operator-=()

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
AQuaternion< T, Accessor > & mundy::AQuaternion< T, Accessor >::operator-= ( const AQuaternion< U, OtherAccessor > & other)
inlineconstexpr
Parameters
[in]otherThe other quaternion.

◆ operator*() [1/4]

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
auto mundy::AQuaternion< T, Accessor >::operator* ( const AQuaternion< U, OtherAccessor > & other) const
inlineconstexpr
Parameters
[in]otherThe other quaternion.

◆ operator*=() [1/2]

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
AQuaternion< T, Accessor > & mundy::AQuaternion< T, Accessor >::operator*= ( const AQuaternion< U, OtherAccessor > & other)
inlineconstexpr
Parameters
[in]otherThe other quaternion.

◆ operator*() [2/4]

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
auto mundy::AQuaternion< T, Accessor >::operator* ( const AVector3< U, OtherAccessor > & vec) const
inlineconstexpr
Parameters
[in]vecThe vector.

◆ operator*() [3/4]

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
auto mundy::AQuaternion< T, Accessor >::operator* ( const AMatrix3< U, OtherAccessor > & mat) const
inlineconstexpr
Parameters
[in]otherThe other matrix.

◆ operator*() [4/4]

template<typename T, ValidAccessor< T > Accessor>
template<typename U>
auto mundy::AQuaternion< T, Accessor >::operator* ( const U & scalar) const
inlineconstexpr
Parameters
[in]scalarThe scalar.

◆ operator*=() [2/2]

template<typename T, ValidAccessor< T > Accessor>
template<typename U>
AQuaternion< T, Accessor > & mundy::AQuaternion< T, Accessor >::operator*= ( const U & scalar)
inlineconstexpr
Parameters
[in]scalarThe scalar.

◆ operator/()

template<typename T, ValidAccessor< T > Accessor>
template<typename U>
auto mundy::AQuaternion< T, Accessor >::operator/ ( const U & scalar) const
inlineconstexpr
Parameters
[in]scalarThe scalar.

◆ operator/=()

template<typename T, ValidAccessor< T > Accessor>
template<typename U>
AQuaternion< T, Accessor > & mundy::AQuaternion< T, Accessor >::operator/= ( const U & scalar)
inlineconstexpr
Parameters
[in]scalarThe scalar.

◆ identity()

template<typename T, ValidAccessor< T > Accessor>
constexpr AQuaternion< T > mundy::AQuaternion< T, Accessor >::identity ( )
inlinestaticconstexpr

◆ AQuaternion

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
friend class AQuaternion
friend

◆ operator<<

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
std::ostream & operator<< ( std::ostream & os,
const AQuaternion< U, OtherAccessor > & quat )
friend

Member Data Documentation

◆ x_storage_index

template<typename T, ValidAccessor< T > Accessor>
size_t mundy::AQuaternion< T, Accessor >::x_storage_index = 0
staticconstexpr

◆ y_storage_index

template<typename T, ValidAccessor< T > Accessor>
size_t mundy::AQuaternion< T, Accessor >::y_storage_index = 1
staticconstexpr

◆ z_storage_index

template<typename T, ValidAccessor< T > Accessor>
size_t mundy::AQuaternion< T, Accessor >::z_storage_index = 2
staticconstexpr

◆ w_storage_index

template<typename T, ValidAccessor< T > Accessor>
size_t mundy::AQuaternion< T, Accessor >::w_storage_index = 3
staticconstexpr

◆ accessor_

template<typename T, ValidAccessor< T > Accessor>
storage<Accessor> mundy::AQuaternion< T, Accessor >::accessor_