27 #ifndef CDPL_MATH_QUATERNION_HPP
28 #define CDPL_MATH_QUATERNION_HPP
32 #include <type_traits>
70 typedef typename std::conditional<std::is_const<Q>::value,
71 typename Q::ConstReference,
193 data.operator=(
r.data);
203 template <
typename E>
216 template <
typename T>
230 template <
typename E>
243 template <
typename T>
257 template <
typename E>
270 template <
typename T>
284 template <
typename E>
297 template <
typename T>
311 template <
typename E>
324 template <
typename T>
338 template <
typename E>
351 template <
typename E>
364 template <
typename E>
400 data.set(c1, c2, c3, c4);
411 template <
typename T>
490 std::copy(q.data, q.data + 4, data);
498 template <
typename E>
501 quaternionAssignQuaternion<ScalarAssignment>(*
this, e);
618 std::copy(q.data, q.data + 4, data);
629 template <
typename C>
641 template <
typename E>
655 template <
typename T1>
656 typename std::enable_if<IsScalar<T1>::value,
Quaternion>::type&
673 template <
typename T1>
674 typename std::enable_if<IsScalar<T1>::value,
Quaternion>::type&
687 template <
typename C>
699 template <
typename E>
713 template <
typename T1>
714 typename std::enable_if<IsScalar<T1>::value,
Quaternion>::type&
727 template <
typename C>
739 template <
typename E>
753 template <
typename T1>
754 typename std::enable_if<IsScalar<T1>::value,
Quaternion>::type&
757 quaternionAssignScalar<ScalarMultiplicationAssignment>(*
this, t);
767 template <
typename E>
781 template <
typename T1>
782 typename std::enable_if<IsScalar<T1>::value,
Quaternion>::type&
785 quaternionAssignScalar<ScalarDivisionAssignment>(*
this, t);
795 template <
typename E>
809 template <
typename E>
812 quaternionAssignQuaternion<ScalarAssignment>(*
this, e);
822 template <
typename E>
825 quaternionAssignQuaternion<ScalarAdditionAssignment>(*
this, e);
835 template <
typename E>
838 quaternionAssignQuaternion<ScalarSubtractionAssignment>(*
this, e);
849 std::swap_ranges(data, data + 4, q.data);
870 template <
typename T>
925 template <
typename T1>
992 template <
typename T1>
1005 template <
typename T1>
1006 typename std::enable_if<IsScalar<T1>::value,
RealQuaternion>::type&
1019 template <
typename T1>
1032 template <
typename T1>
1033 typename std::enable_if<IsScalar<T1>::value,
RealQuaternion>::type&
1046 template <
typename T1>
1059 template <
typename T1>
1060 typename std::enable_if<IsScalar<T1>::value,
RealQuaternion>::type&
1073 template <
typename T1>
1086 template <
typename T1>
1087 typename std::enable_if<IsScalar<T1>::value,
RealQuaternion>::type&
1100 template <
typename T1>
1113 template <
typename T1>
1114 typename std::enable_if<IsScalar<T1>::value,
RealQuaternion>::type&
1127 template <
typename T1>
1140 template <
typename T1>
1153 template <
typename T1>
1167 std::swap(value, q.value);
1185 template <
typename T>
1192 template <
typename Q>
1200 template <
typename Q>
1210 template <
typename T>
1225 template <
typename T1,
typename T2>
1226 Quaternion<typename CommonType<T1, T2>::Type>
1231 return QuaternionType(t1, t2);
1244 template <
typename T1,
typename T2,
typename T3>
1245 Quaternion<typename CommonType<typename CommonType<T1, T2>::Type, T3>::Type>
1246 quat(
const T1& t1,
const T2& t2,
const T3& t3)
1250 return QuaternionType(t1, t2, t3);
1265 template <
typename T1,
typename T2,
typename T3,
typename T4>
1266 Quaternion<typename CommonType<typename CommonType<typename CommonType<T1, T2>::Type, T3>::Type, T4>::Type>
1267 quat(
const T1& t1,
const T2& t2,
const T3& t3,
const T4& t4)
1271 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:299
CRTP base class of all quaternion expression types.
Definition: Expression.hpp:148
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:231
Reference getC3()
Returns a mutable reference to the imaginary component C3.
Definition: Quaternion.hpp:118
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:397
QuaternionReference(QuaternionType &q)
Constructs the reference proxy referring to q.
Definition: Quaternion.hpp:93
ConstReference getC4() const
Returns a const reference to the imaginary component C4.
Definition: Quaternion.hpp:163
ConstReference getC2() const
Returns a const reference to the imaginary component C2.
Definition: Quaternion.hpp:145
QuaternionReference & operator=(const QuaternionExpression< E > &e)
Assigns the quaternion expression e to the wrapped quaternion.
Definition: Quaternion.hpp:204
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:272
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:326
ConstReference getC1() const
Returns a const reference to the real component C1.
Definition: Quaternion.hpp:136
SelfType ClosureType
Closure type used when this proxy appears inside another expression.
Definition: Quaternion.hpp:82
QuaternionReference & operator-=(const QuaternionExpression< E > &e)
Subtracts the quaternion expression e component-wise from the wrapped quaternion.
Definition: Quaternion.hpp:258
const SelfType ConstClosureType
Constant closure type used when this proxy appears inside another expression.
Definition: Quaternion.hpp:87
Reference getC1()
Returns a mutable reference to the real component C1.
Definition: Quaternion.hpp:100
void swap(QuaternionReference &r)
Swaps the contents of the two wrapped quaternions.
Definition: Quaternion.hpp:375
Q::ValueType ValueType
The scalar component value type of the wrapped quaternion.
Definition: Quaternion.hpp:65
QuaternionType & getData()
Returns a reference to the wrapped quaternion.
Definition: Quaternion.hpp:181
Reference getC4()
Returns a mutable reference to the imaginary component C4.
Definition: Quaternion.hpp:127
Q::ConstReference ConstReference
Constant component reference type.
Definition: Quaternion.hpp:77
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:245
const QuaternionType & getData() const
Returns a const reference to the wrapped quaternion.
Definition: Quaternion.hpp:172
QuaternionReference & minusAssign(const QuaternionExpression< E > &e)
Subtracts the quaternion expression e from the wrapped quaternion without intermediate temporary.
Definition: Quaternion.hpp:365
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:218
QuaternionReference & operator/=(const QuaternionExpression< E > &e)
Right-divides the wrapped quaternion by the quaternion expression e (Hamilton-product inverse).
Definition: Quaternion.hpp:312
QuaternionReference & operator=(const QuaternionReference &r)
Copy-assigns the wrapped quaternion from the quaternion referenced by r.
Definition: Quaternion.hpp:191
QuaternionReference & operator*=(const QuaternionExpression< E > &e)
Right-multiplies the wrapped quaternion by the quaternion expression e (Hamilton product).
Definition: Quaternion.hpp:285
std::conditional< std::is_const< Q >::value, typename Q::ConstReference, typename Q::Reference >::type Reference
Mutable component reference type (degrades to ConstReference when the wrapped quaternion is const).
Definition: Quaternion.hpp:72
Reference getC2()
Returns a mutable reference to the imaginary component C2.
Definition: Quaternion.hpp:109
QuaternionReference & assign(const QuaternionExpression< E > &e)
Assigns the quaternion expression e to the wrapped quaternion without intermediate temporary.
Definition: Quaternion.hpp:339
Q QuaternionType
The wrapped quaternion type.
Definition: Quaternion.hpp:60
QuaternionReference & plusAssign(const QuaternionExpression< E > &e)
Adds the quaternion expression e to the wrapped quaternion without intermediate temporary.
Definition: Quaternion.hpp:352
ConstReference getC3() const
Returns a const reference to the imaginary component C3.
Definition: Quaternion.hpp:154
friend void swap(QuaternionReference &r1, QuaternionReference &r2)
ADL-enabled free-function form of swap().
Definition: Quaternion.hpp:385
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:299
General 4-component quaternion .
Definition: Quaternion.hpp:413
Reference getC3()
Returns a mutable reference to the imaginary component C3.
Definition: Quaternion.hpp:544
std::enable_if< IsScalar< T1 >::value, Quaternion >::type & operator+=(const T1 &t)
Adds the scalar t to the real component.
Definition: Quaternion.hpp:675
Quaternion & plusAssign(const QuaternionExpression< E > &e)
Adds the quaternion expression e to this quaternion without intermediate temporary.
Definition: Quaternion.hpp:823
ValueType ArrayType[4]
The plain C-array type used for in-memory storage of the four components.
Definition: Quaternion.hpp:436
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:657
Reference getC1()
Returns a mutable reference to the real component C1.
Definition: Quaternion.hpp:526
Quaternion & operator=(const QuaternionExpression< E > &e)
Assigns the quaternion expression e to this quaternion (via a temporary to handle aliasing).
Definition: Quaternion.hpp:642
T * Pointer
Pointer type for raw access to the component array.
Definition: Quaternion.hpp:441
Quaternion & operator=(const QuaternionContainer< C > &c)
Assigns the components of the quaternion container c to this quaternion (no alias check needed).
Definition: Quaternion.hpp:630
const T & ConstReference
Constant component reference type.
Definition: Quaternion.hpp:431
Quaternion(const QuaternionExpression< E > &e)
Constructs the quaternion from the quaternion expression e.
Definition: Quaternion.hpp:499
Quaternion & operator-=(const QuaternionContainer< C > &c)
Subtracts the components of the quaternion container c from this quaternion (no alias check needed).
Definition: Quaternion.hpp:728
Pointer getData()
Returns a pointer to the contiguous 4-element component array.
Definition: Quaternion.hpp:508
ConstReference getC1() const
Returns a const reference to the real component C1.
Definition: Quaternion.hpp:562
Quaternion & minusAssign(const QuaternionExpression< E > &e)
Subtracts the quaternion expression e from this quaternion without intermediate temporary.
Definition: Quaternion.hpp:836
Quaternion & operator+=(const QuaternionContainer< C > &c)
Adds the components of the quaternion container c to this quaternion (no alias check needed).
Definition: Quaternion.hpp:688
Quaternion & operator=(const Quaternion &q)
Copy-assigns the components of q to this quaternion.
Definition: Quaternion.hpp:615
ConstReference getC4() const
Returns a const reference to the imaginary component C4.
Definition: Quaternion.hpp:589
Quaternion & operator*=(const QuaternionExpression< E > &e)
Right-multiplies this quaternion by the quaternion expression e (Hamilton product,...
Definition: Quaternion.hpp:768
SelfType QuaternionTemporaryType
Concrete temporary quaternion type used by expression template machinery.
Definition: Quaternion.hpp:461
std::enable_if< IsScalar< T1 >::value, Quaternion >::type & operator-=(const T1 &t)
Subtracts the scalar t from the real component.
Definition: Quaternion.hpp:715
ConstReference getC3() const
Returns a const reference to the imaginary component C3.
Definition: Quaternion.hpp:580
friend void swap(Quaternion &q1, Quaternion &q2)
ADL-enabled free-function form of swap().
Definition: Quaternion.hpp:857
void swap(Quaternion &q)
Swaps the four components of this quaternion with those of q.
Definition: Quaternion.hpp:846
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:475
const T * ConstPointer
Constant pointer type for raw access to the component array.
Definition: Quaternion.hpp:446
QuaternionReference< SelfType > ClosureType
Closure type used when this quaternion appears inside another expression.
Definition: Quaternion.hpp:451
Quaternion(const Quaternion &q)
Constructs a copy of the quaternion q.
Definition: Quaternion.hpp:488
Quaternion & operator-=(const QuaternionExpression< E > &e)
Subtracts the quaternion expression e from this quaternion (via a temporary to handle aliasing).
Definition: Quaternion.hpp:740
Quaternion()
Constructs an uninitialized quaternion.
Definition: Quaternion.hpp:466
Quaternion & operator+=(const QuaternionExpression< E > &e)
Adds the quaternion expression e to this quaternion (via a temporary to handle aliasing).
Definition: Quaternion.hpp:700
T ValueType
The scalar component value type.
Definition: Quaternion.hpp:421
std::enable_if< IsScalar< T1 >::value, Quaternion >::type & operator/=(const T1 &t)
Divides every component by the scalar t.
Definition: Quaternion.hpp:783
Reference getC4()
Returns a mutable reference to the imaginary component C4.
Definition: Quaternion.hpp:553
Reference getC2()
Returns a mutable reference to the imaginary component C2.
Definition: Quaternion.hpp:535
std::enable_if< IsScalar< T1 >::value, Quaternion >::type & operator*=(const T1 &t)
Multiplies every component by the scalar t.
Definition: Quaternion.hpp:755
Quaternion & assign(const QuaternionExpression< E > &e)
Assigns the quaternion expression e to this quaternion without intermediate temporary.
Definition: Quaternion.hpp:810
T & Reference
Mutable component reference type.
Definition: Quaternion.hpp:426
Quaternion & operator/=(const QuaternionExpression< E > &e)
Right-divides this quaternion by the quaternion expression e (Hamilton-product inverse,...
Definition: Quaternion.hpp:796
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:601
ConstPointer getData() const
Returns a const pointer to the contiguous 4-element component array.
Definition: Quaternion.hpp:517
const QuaternionReference< const SelfType > ConstClosureType
Constant closure type used when this quaternion appears inside another expression.
Definition: Quaternion.hpp:456
ConstReference getC2() const
Returns a const reference to the imaginary component C2.
Definition: Quaternion.hpp:571
Pure-real quaternion that stores only the real component.
Definition: Quaternion.hpp:872
RealQuaternion & plusAssign(const RealQuaternion< T1 > &q)
Adds the real component of q to this quaternion's real component without intermediate temporary.
Definition: Quaternion.hpp:1141
ConstReference getC4() const
Returns a const reference to the imaginary component C4 (always zero for a real quaternion).
Definition: Quaternion.hpp:961
RealQuaternion(const ValueType &r)
Constructs the real quaternion with the supplied real component.
Definition: Quaternion.hpp:917
std::enable_if< IsScalar< T1 >::value, RealQuaternion >::type & operator/=(const T1 &t)
Divides the real component by the scalar t.
Definition: Quaternion.hpp:1115
RealQuaternion()
Constructs a zero-valued real quaternion (C1 = 0).
Definition: Quaternion.hpp:910
T ValueType
The scalar component value type.
Definition: Quaternion.hpp:880
std::enable_if< IsScalar< T1 >::value, RealQuaternion >::type & operator-=(const T1 &t)
Subtracts the scalar t from the real component.
Definition: Quaternion.hpp:1061
RealQuaternion & operator-=(const RealQuaternion< T1 > &q)
Subtracts the real component of q from this quaternion's real component.
Definition: Quaternion.hpp:1047
std::enable_if< IsScalar< T1 >::value, RealQuaternion >::type & operator*=(const T1 &t)
Multiplies the real component by the scalar t.
Definition: Quaternion.hpp:1088
RealQuaternion & operator=(const RealQuaternion &q)
Copy-assigns the real component from q.
Definition: Quaternion.hpp:980
ConstReference getC1() const
Returns a const reference to the real component C1.
Definition: Quaternion.hpp:934
RealQuaternion & operator/=(const RealQuaternion< T1 > &q)
Divides the real component by the real component of q.
Definition: Quaternion.hpp:1101
RealQuaternion & operator=(const RealQuaternion< T1 > &q)
Assigns the real component from q (possibly converting the component type).
Definition: Quaternion.hpp:993
RealQuaternion & assign(const RealQuaternion< T1 > &q)
Assigns the real component from q without intermediate temporary.
Definition: Quaternion.hpp:1128
std::enable_if< IsScalar< T1 >::value, RealQuaternion >::type & operator+=(const T1 &t)
Adds the scalar t to the real component.
Definition: Quaternion.hpp:1034
const T & ConstReference
Constant reference type to the real component.
Definition: Quaternion.hpp:890
RealQuaternion(const RealQuaternion< T1 > &q)
Constructs a copy of the real quaternion q (possibly converting the component type).
Definition: Quaternion.hpp:926
const T & Reference
Reference type (always a const reference — only the real component is mutable, via assignment).
Definition: Quaternion.hpp:885
QuaternionReference< SelfType > ClosureType
Closure type used when this quaternion appears inside another expression.
Definition: Quaternion.hpp:895
ConstReference getC3() const
Returns a const reference to the imaginary component C3 (always zero for a real quaternion).
Definition: Quaternion.hpp:952
Quaternion< T > QuaternionTemporaryType
Concrete temporary quaternion type used by expression template machinery (a general Math::Quaternion<...
Definition: Quaternion.hpp:905
ConstReference getC2() const
Returns a const reference to the imaginary component C2 (always zero for a real quaternion).
Definition: Quaternion.hpp:943
RealQuaternion & operator*=(const RealQuaternion< T1 > &q)
Multiplies the real component by the real component of q.
Definition: Quaternion.hpp:1074
RealQuaternion & minusAssign(const RealQuaternion< T1 > &q)
Subtracts the real component of q from this quaternion's real component without intermediate temporar...
Definition: Quaternion.hpp:1154
friend void swap(RealQuaternion &q1, RealQuaternion &q2)
ADL-enabled free-function form of swap().
Definition: Quaternion.hpp:1175
void swap(RealQuaternion &q)
Swaps the real component value with q.
Definition: Quaternion.hpp:1164
RealQuaternion & operator+=(const RealQuaternion< T1 > &q)
Adds the real component of q to this quaternion's real component.
Definition: Quaternion.hpp:1020
const QuaternionReference< const SelfType > ConstClosureType
Constant closure type used when this quaternion appears inside another expression.
Definition: Quaternion.hpp:900
std::enable_if< IsScalar< T1 >::value, RealQuaternion >::type & operator=(const T1 &t)
Assigns the scalar t to the real component.
Definition: Quaternion.hpp:1007
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:1297
Quaternion< unsigned long > ULQuaternion
General 4-component quaternion with component values of type unsigned long.
Definition: Quaternion.hpp:1292
Quaternion< double > DQuaternion
General 4-component quaternion with component values of type double.
Definition: Quaternion.hpp:1282
RealQuaternion< double > DRealQuaternion
A memory-efficient pure-real quaternion with component values of type double.
Definition: Quaternion.hpp:1302
Quaternion< float > FQuaternion
General 4-component quaternion with component values of type float.
Definition: Quaternion.hpp:1277
RealQuaternion< unsigned long > ULRealQuaternion
A memory-efficient pure-real quaternion with component values of type unsigned long.
Definition: Quaternion.hpp:1312
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:1212
RealQuaternion< long > LRealQuaternion
A memory-efficient pure-real quaternion with component values of type long.
Definition: Quaternion.hpp:1307
Quaternion< long > LQuaternion
General 4-component quaternion with component values of type long.
Definition: Quaternion.hpp:1287
The namespace of the Chemical Data Processing Library.
Selects a concrete temporary quaternion type compatible with the quaternion expression Q.
Definition: TypeTraits.hpp:351