27 #ifndef CDPL_MATH_QUATERNION_HPP
28 #define CDPL_MATH_QUATERNION_HPP
32 #include <type_traits>
62 typedef typename std::conditional<std::is_const<Q>::value,
63 typename Q::ConstReference,
176 data.operator=(
r.data);
186 template <
typename E>
199 template <
typename T>
213 template <
typename E>
226 template <
typename T>
240 template <
typename E>
253 template <
typename T>
267 template <
typename E>
280 template <
typename T>
294 template <
typename E>
307 template <
typename T>
321 template <
typename E>
334 template <
typename E>
347 template <
typename E>
383 data.set(c1, c2, c3, c4);
394 template <
typename T>
447 std::copy(q.data, q.data + 4, data);
455 template <
typename E>
458 quaternionAssignQuaternion<ScalarAssignment>(*
this, e);
575 std::copy(q.data, q.data + 4, data);
586 template <
typename C>
598 template <
typename E>
612 template <
typename T1>
613 typename std::enable_if<IsScalar<T1>::value,
Quaternion>::type&
630 template <
typename T1>
631 typename std::enable_if<IsScalar<T1>::value,
Quaternion>::type&
644 template <
typename C>
656 template <
typename E>
670 template <
typename T1>
671 typename std::enable_if<IsScalar<T1>::value,
Quaternion>::type&
684 template <
typename C>
696 template <
typename E>
710 template <
typename T1>
711 typename std::enable_if<IsScalar<T1>::value,
Quaternion>::type&
714 quaternionAssignScalar<ScalarMultiplicationAssignment>(*
this, t);
724 template <
typename E>
738 template <
typename T1>
739 typename std::enable_if<IsScalar<T1>::value,
Quaternion>::type&
742 quaternionAssignScalar<ScalarDivisionAssignment>(*
this, t);
752 template <
typename E>
766 template <
typename E>
769 quaternionAssignQuaternion<ScalarAssignment>(*
this, e);
779 template <
typename E>
782 quaternionAssignQuaternion<ScalarAdditionAssignment>(*
this, e);
792 template <
typename E>
795 quaternionAssignQuaternion<ScalarSubtractionAssignment>(*
this, e);
806 std::swap_ranges(data, data + 4, q.data);
827 template <
typename T>
865 template <
typename T1>
932 template <
typename T1>
945 template <
typename T1>
946 typename std::enable_if<IsScalar<T1>::value,
RealQuaternion>::type&
959 template <
typename T1>
972 template <
typename T1>
973 typename std::enable_if<IsScalar<T1>::value,
RealQuaternion>::type&
986 template <
typename T1>
999 template <
typename T1>
1000 typename std::enable_if<IsScalar<T1>::value,
RealQuaternion>::type&
1013 template <
typename T1>
1026 template <
typename T1>
1027 typename std::enable_if<IsScalar<T1>::value,
RealQuaternion>::type&
1040 template <
typename T1>
1053 template <
typename T1>
1054 typename std::enable_if<IsScalar<T1>::value,
RealQuaternion>::type&
1067 template <
typename T1>
1080 template <
typename T1>
1093 template <
typename T1>
1107 std::swap(value, q.value);
1125 template <
typename T>
1132 template <
typename Q>
1140 template <
typename Q>
1150 template <
typename T>
1165 template <
typename T1,
typename T2>
1166 Quaternion<typename CommonType<T1, T2>::Type>
1171 return QuaternionType(t1, t2);
1184 template <
typename T1,
typename T2,
typename T3>
1185 Quaternion<typename CommonType<typename CommonType<T1, T2>::Type, T3>::Type>
1186 quat(
const T1& t1,
const T2& t2,
const T3& t3)
1190 return QuaternionType(t1, t2, t3);
1205 template <
typename T1,
typename T2,
typename T3,
typename T4>
1206 Quaternion<typename CommonType<typename CommonType<typename CommonType<T1, T2>::Type, T3>::Type, T4>::Type>
1207 quat(
const T1& t1,
const T2& t2,
const T3& t3,
const T4& t4)
1211 return QuaternionType(t1, t2, t3, t4);
Definition of various functors.
Implementation of quaternion assignment routines.
Definition of various quaternion expression types and operations.
Definition of type traits.
Refinement of Math::QuaternionExpression marking the derived type as a concrete (writable) quaternion...
Definition: Expression.hpp:285
CRTP base class for all quaternion expression types.
Definition: Expression.hpp:142
Lightweight quaternion expression that proxies a reference to an underlying quaternion container.
Definition: Quaternion.hpp:52
QuaternionReference & operator+=(const QuaternionExpression< E > &e)
Adds the quaternion expression e component-wise to the wrapped quaternion.
Definition: Quaternion.hpp:214
Reference getC3()
Returns a mutable reference to the imaginary component C3.
Definition: Quaternion.hpp:101
void set(const ValueType &c1=ValueType(), const ValueType &c2=ValueType(), const ValueType &c3=ValueType(), const ValueType &c4=ValueType())
Sets the components of the wrapped quaternion to the supplied values (omitted components default to t...
Definition: Quaternion.hpp:380
QuaternionReference(QuaternionType &q)
Constructs the reference proxy referring to q.
Definition: Quaternion.hpp:76
ConstReference getC4() const
Returns a const reference to the imaginary component C4.
Definition: Quaternion.hpp:146
ConstReference getC2() const
Returns a const reference to the imaginary component C2.
Definition: Quaternion.hpp:128
QuaternionReference & operator=(const QuaternionExpression< E > &e)
Assigns the quaternion expression e to the wrapped quaternion.
Definition: Quaternion.hpp:187
std::enable_if< IsScalar< T >::value, QuaternionReference >::type & operator-=(const T &t)
Subtracts the scalar t from the real component of the wrapped quaternion.
Definition: Quaternion.hpp:255
std::enable_if< IsScalar< T >::value, QuaternionReference >::type & operator/=(const T &t)
Divides every component of the wrapped quaternion by the scalar t.
Definition: Quaternion.hpp:309
ConstReference getC1() const
Returns a const reference to the real component C1.
Definition: Quaternion.hpp:119
SelfType ClosureType
Closure type used when this proxy appears inside another expression.
Definition: Quaternion.hpp:68
QuaternionReference & operator-=(const QuaternionExpression< E > &e)
Subtracts the quaternion expression e component-wise from the wrapped quaternion.
Definition: Quaternion.hpp:241
const SelfType ConstClosureType
Constant closure type used when this proxy appears inside another expression.
Definition: Quaternion.hpp:70
Reference getC1()
Returns a mutable reference to the real component C1.
Definition: Quaternion.hpp:83
void swap(QuaternionReference &r)
Swaps the contents of the two wrapped quaternions.
Definition: Quaternion.hpp:358
Q::ValueType ValueType
The scalar component value type of the wrapped quaternion.
Definition: Quaternion.hpp:60
QuaternionType & getData()
Returns a reference to the wrapped quaternion.
Definition: Quaternion.hpp:164
Reference getC4()
Returns a mutable reference to the imaginary component C4.
Definition: Quaternion.hpp:110
Q::ConstReference ConstReference
Constant reference type to a component.
Definition: Quaternion.hpp:66
std::enable_if< IsScalar< T >::value, QuaternionReference >::type & operator+=(const T &t)
Adds the scalar t to the real component of the wrapped quaternion.
Definition: Quaternion.hpp:228
const QuaternionType & getData() const
Returns a const reference to the wrapped quaternion.
Definition: Quaternion.hpp:155
QuaternionReference & minusAssign(const QuaternionExpression< E > &e)
Subtracts the quaternion expression e from the wrapped quaternion without intermediate temporary.
Definition: Quaternion.hpp:348
std::enable_if< IsScalar< T >::value, QuaternionReference >::type & operator=(const T &t)
Assigns the scalar t to the real component of the wrapped quaternion (other components are zeroed).
Definition: Quaternion.hpp:201
QuaternionReference & operator/=(const QuaternionExpression< E > &e)
Right-divides the wrapped quaternion by the quaternion expression e (Hamilton-product inverse).
Definition: Quaternion.hpp:295
QuaternionReference & operator=(const QuaternionReference &r)
Copy-assigns the wrapped quaternion from the quaternion referenced by r.
Definition: Quaternion.hpp:174
QuaternionReference & operator*=(const QuaternionExpression< E > &e)
Right-multiplies the wrapped quaternion by the quaternion expression e (Hamilton product).
Definition: Quaternion.hpp:268
std::conditional< std::is_const< Q >::value, typename Q::ConstReference, typename Q::Reference >::type Reference
Mutable reference type (degrades to ConstReference when the wrapped quaternion is const).
Definition: Quaternion.hpp:64
Reference getC2()
Returns a mutable reference to the imaginary component C2.
Definition: Quaternion.hpp:92
QuaternionReference & assign(const QuaternionExpression< E > &e)
Assigns the quaternion expression e to the wrapped quaternion without intermediate temporary.
Definition: Quaternion.hpp:322
Q QuaternionType
The wrapped quaternion type.
Definition: Quaternion.hpp:58
QuaternionReference & plusAssign(const QuaternionExpression< E > &e)
Adds the quaternion expression e to the wrapped quaternion without intermediate temporary.
Definition: Quaternion.hpp:335
ConstReference getC3() const
Returns a const reference to the imaginary component C3.
Definition: Quaternion.hpp:137
friend void swap(QuaternionReference &r1, QuaternionReference &r2)
ADL-enabled free-function form of swap().
Definition: Quaternion.hpp:368
std::enable_if< IsScalar< T >::value, QuaternionReference >::type & operator*=(const T &t)
Multiplies every component of the wrapped quaternion by the scalar t.
Definition: Quaternion.hpp:282
General 4-component quaternion .
Definition: Quaternion.hpp:396
Reference getC3()
Returns a mutable reference to the imaginary component C3.
Definition: Quaternion.hpp:501
std::enable_if< IsScalar< T1 >::value, Quaternion >::type & operator+=(const T1 &t)
Adds the scalar t to the real component.
Definition: Quaternion.hpp:632
Quaternion & plusAssign(const QuaternionExpression< E > &e)
Adds the quaternion expression e to this quaternion without intermediate temporary.
Definition: Quaternion.hpp:780
ValueType ArrayType[4]
The plain C-array type used for in-memory storage of the four components.
Definition: Quaternion.hpp:408
std::enable_if< IsScalar< T1 >::value, Quaternion >::type & operator=(const T1 &t)
Assigns the scalar t to the real component (zeroing the three imaginary components).
Definition: Quaternion.hpp:614
Reference getC1()
Returns a mutable reference to the real component C1.
Definition: Quaternion.hpp:483
Quaternion & operator=(const QuaternionExpression< E > &e)
Assigns the quaternion expression e to this quaternion (via a temporary to handle aliasing).
Definition: Quaternion.hpp:599
T * Pointer
Pointer type for raw access to the component array.
Definition: Quaternion.hpp:410
Quaternion & operator=(const QuaternionContainer< C > &c)
Assigns the components of the quaternion container c to this quaternion (no alias check needed).
Definition: Quaternion.hpp:587
const T & ConstReference
Constant reference type to a component.
Definition: Quaternion.hpp:406
Quaternion(const QuaternionExpression< E > &e)
Constructs the quaternion from the quaternion expression e.
Definition: Quaternion.hpp:456
Quaternion & operator-=(const QuaternionContainer< C > &c)
Subtracts the components of the quaternion container c from this quaternion (no alias check needed).
Definition: Quaternion.hpp:685
Pointer getData()
Returns a pointer to the contiguous 4-element component array.
Definition: Quaternion.hpp:465
ConstReference getC1() const
Returns a const reference to the real component C1.
Definition: Quaternion.hpp:519
Quaternion & minusAssign(const QuaternionExpression< E > &e)
Subtracts the quaternion expression e from this quaternion without intermediate temporary.
Definition: Quaternion.hpp:793
Quaternion & operator+=(const QuaternionContainer< C > &c)
Adds the components of the quaternion container c to this quaternion (no alias check needed).
Definition: Quaternion.hpp:645
Quaternion & operator=(const Quaternion &q)
Copy-assigns the components of q to this quaternion.
Definition: Quaternion.hpp:572
ConstReference getC4() const
Returns a const reference to the imaginary component C4.
Definition: Quaternion.hpp:546
Quaternion & operator*=(const QuaternionExpression< E > &e)
Right-multiplies this quaternion by the quaternion expression e (Hamilton product,...
Definition: Quaternion.hpp:725
SelfType QuaternionTemporaryType
Concrete temporary quaternion type used by expression-template machinery.
Definition: Quaternion.hpp:418
std::enable_if< IsScalar< T1 >::value, Quaternion >::type & operator-=(const T1 &t)
Subtracts the scalar t from the real component.
Definition: Quaternion.hpp:672
ConstReference getC3() const
Returns a const reference to the imaginary component C3.
Definition: Quaternion.hpp:537
friend void swap(Quaternion &q1, Quaternion &q2)
ADL-enabled free-function form of swap().
Definition: Quaternion.hpp:814
void swap(Quaternion &q)
Swaps the four components of this quaternion with those of q.
Definition: Quaternion.hpp:803
Quaternion(const ValueType &c1, const ValueType &c2=ValueType(), const ValueType &c3=ValueType(), const ValueType &c4=ValueType())
Constructs the quaternion with the supplied component values (omitted components default to the value...
Definition: Quaternion.hpp:432
const T * ConstPointer
Constant pointer type for raw access to the component array.
Definition: Quaternion.hpp:412
QuaternionReference< SelfType > ClosureType
Closure type used when this quaternion appears inside another expression.
Definition: Quaternion.hpp:414
Quaternion(const Quaternion &q)
Constructs a copy of the quaternion q.
Definition: Quaternion.hpp:445
Quaternion & operator-=(const QuaternionExpression< E > &e)
Subtracts the quaternion expression e from this quaternion (via a temporary to handle aliasing).
Definition: Quaternion.hpp:697
Quaternion()
Constructs an uninitialized quaternion.
Definition: Quaternion.hpp:423
Quaternion & operator+=(const QuaternionExpression< E > &e)
Adds the quaternion expression e to this quaternion (via a temporary to handle aliasing).
Definition: Quaternion.hpp:657
T ValueType
The scalar component value type.
Definition: Quaternion.hpp:402
std::enable_if< IsScalar< T1 >::value, Quaternion >::type & operator/=(const T1 &t)
Divides every component by the scalar t.
Definition: Quaternion.hpp:740
Reference getC4()
Returns a mutable reference to the imaginary component C4.
Definition: Quaternion.hpp:510
Reference getC2()
Returns a mutable reference to the imaginary component C2.
Definition: Quaternion.hpp:492
std::enable_if< IsScalar< T1 >::value, Quaternion >::type & operator*=(const T1 &t)
Multiplies every component by the scalar t.
Definition: Quaternion.hpp:712
Quaternion & assign(const QuaternionExpression< E > &e)
Assigns the quaternion expression e to this quaternion without intermediate temporary.
Definition: Quaternion.hpp:767
T & Reference
Mutable reference type to a component.
Definition: Quaternion.hpp:404
Quaternion & operator/=(const QuaternionExpression< E > &e)
Right-divides this quaternion by the quaternion expression e (Hamilton-product inverse,...
Definition: Quaternion.hpp:753
void set(const ValueType &c1=ValueType(), const ValueType &c2=ValueType(), const ValueType &c3=ValueType(), const ValueType &c4=ValueType())
Sets the four quaternion components to the supplied values (omitted arguments default to the value-in...
Definition: Quaternion.hpp:558
ConstPointer getData() const
Returns a const pointer to the contiguous 4-element component array.
Definition: Quaternion.hpp:474
const QuaternionReference< const SelfType > ConstClosureType
Constant closure type used when this quaternion appears inside another expression.
Definition: Quaternion.hpp:416
ConstReference getC2() const
Returns a const reference to the imaginary component C2.
Definition: Quaternion.hpp:528
Pure-real quaternion that stores only the real component.
Definition: Quaternion.hpp:829
RealQuaternion & plusAssign(const RealQuaternion< T1 > &q)
Adds the real component of q to this quaternion's real component without intermediate temporary.
Definition: Quaternion.hpp:1081
ConstReference getC4() const
Returns a const reference to the imaginary component C4 (always zero for a real quaternion).
Definition: Quaternion.hpp:901
RealQuaternion(const ValueType &r)
Constructs the real quaternion with the supplied real component.
Definition: Quaternion.hpp:857
std::enable_if< IsScalar< T1 >::value, RealQuaternion >::type & operator/=(const T1 &t)
Divides the real component by the scalar t.
Definition: Quaternion.hpp:1055
RealQuaternion()
Constructs a zero-valued real quaternion (C1 = 0).
Definition: Quaternion.hpp:850
T ValueType
The scalar component value type.
Definition: Quaternion.hpp:835
std::enable_if< IsScalar< T1 >::value, RealQuaternion >::type & operator-=(const T1 &t)
Subtracts the scalar t from the real component.
Definition: Quaternion.hpp:1001
RealQuaternion & operator-=(const RealQuaternion< T1 > &q)
Subtracts the real component of q from this quaternion's real component.
Definition: Quaternion.hpp:987
std::enable_if< IsScalar< T1 >::value, RealQuaternion >::type & operator*=(const T1 &t)
Multiplies the real component by the scalar t.
Definition: Quaternion.hpp:1028
RealQuaternion & operator=(const RealQuaternion &q)
Copy-assigns the real component from q.
Definition: Quaternion.hpp:920
ConstReference getC1() const
Returns a const reference to the real component C1.
Definition: Quaternion.hpp:874
RealQuaternion & operator/=(const RealQuaternion< T1 > &q)
Divides the real component by the real component of q.
Definition: Quaternion.hpp:1041
RealQuaternion & operator=(const RealQuaternion< T1 > &q)
Assigns the real component from q (possibly converting the component type).
Definition: Quaternion.hpp:933
RealQuaternion & assign(const RealQuaternion< T1 > &q)
Assigns the real component from q without intermediate temporary.
Definition: Quaternion.hpp:1068
std::enable_if< IsScalar< T1 >::value, RealQuaternion >::type & operator+=(const T1 &t)
Adds the scalar t to the real component.
Definition: Quaternion.hpp:974
const T & ConstReference
Constant reference type to the real component.
Definition: Quaternion.hpp:839
RealQuaternion(const RealQuaternion< T1 > &q)
Constructs a copy of the real quaternion q (possibly converting the component type).
Definition: Quaternion.hpp:866
const T & Reference
Reference type (always a const reference — only the real component is mutable, via assignment).
Definition: Quaternion.hpp:837
QuaternionReference< SelfType > ClosureType
Closure type used when this quaternion appears inside another expression.
Definition: Quaternion.hpp:841
ConstReference getC3() const
Returns a const reference to the imaginary component C3 (always zero for a real quaternion).
Definition: Quaternion.hpp:892
Quaternion< T > QuaternionTemporaryType
Concrete temporary quaternion type used by expression-template machinery (a general Math::Quaternion<...
Definition: Quaternion.hpp:845
ConstReference getC2() const
Returns a const reference to the imaginary component C2 (always zero for a real quaternion).
Definition: Quaternion.hpp:883
RealQuaternion & operator*=(const RealQuaternion< T1 > &q)
Multiplies the real component by the real component of q.
Definition: Quaternion.hpp:1014
RealQuaternion & minusAssign(const RealQuaternion< T1 > &q)
Subtracts the real component of q from this quaternion's real component without intermediate temporar...
Definition: Quaternion.hpp:1094
friend void swap(RealQuaternion &q1, RealQuaternion &q2)
ADL-enabled free-function form of swap().
Definition: Quaternion.hpp:1115
void swap(RealQuaternion &q)
Swaps the real component value with q.
Definition: Quaternion.hpp:1104
RealQuaternion & operator+=(const RealQuaternion< T1 > &q)
Adds the real component of q to this quaternion's real component.
Definition: Quaternion.hpp:960
const QuaternionReference< const SelfType > ConstClosureType
Constant closure type used when this quaternion appears inside another expression.
Definition: Quaternion.hpp:843
std::enable_if< IsScalar< T1 >::value, RealQuaternion >::type & operator=(const T1 &t)
Assigns the scalar t to the real component.
Definition: Quaternion.hpp:947
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
constexpr unsigned int Q
Generic type that covers any element except hydrogen and carbon.
Definition: AtomType.hpp:647
constexpr unsigned int r
Specifies that the stereocenter has r configuration.
Definition: CIPDescriptor.hpp:76
RealQuaternion< float > FRealQuaternion
A memory-efficient pure-real quaternion with component values of type float.
Definition: Quaternion.hpp:1237
Quaternion< unsigned long > ULQuaternion
General 4-component quaternion with component values of type unsigned long.
Definition: Quaternion.hpp:1232
Quaternion< double > DQuaternion
General 4-component quaternion with component values of type double.
Definition: Quaternion.hpp:1222
RealQuaternion< double > DRealQuaternion
A memory-efficient pure-real quaternion with component values of type double.
Definition: Quaternion.hpp:1242
Quaternion< float > FQuaternion
General 4-component quaternion with component values of type float.
Definition: Quaternion.hpp:1217
RealQuaternion< unsigned long > ULRealQuaternion
A memory-efficient pure-real quaternion with component values of type unsigned long.
Definition: Quaternion.hpp:1252
std::enable_if< IsScalar< T >::value, RealQuaternion< T > >::type quat(const T &t)
Constructs a Math::RealQuaternion from the scalar t (its real component).
Definition: Quaternion.hpp:1152
RealQuaternion< long > LRealQuaternion
A memory-efficient pure-real quaternion with component values of type long.
Definition: Quaternion.hpp:1247
Quaternion< long > LQuaternion
General 4-component quaternion with component values of type long.
Definition: Quaternion.hpp:1227
The namespace of the Chemical Data Processing Library.
Selects a concrete temporary quaternion type compatible with the quaternion expression Q.
Definition: TypeTraits.hpp:325