Chemical Data Processing Library C++ API - Version 1.4.0
Quaternion.hpp
Go to the documentation of this file.
1 /*
2  * Quaternion.hpp
3  *
4  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
27 #ifndef CDPL_MATH_QUATERNION_HPP
28 #define CDPL_MATH_QUATERNION_HPP
29 
30 #include <algorithm>
31 #include <utility>
32 #include <type_traits>
33 
36 #include "CDPL/Math/Functional.hpp"
37 #include "CDPL/Math/TypeTraits.hpp"
38 
39 
40 namespace CDPL
41 {
42 
43  namespace Math
44  {
45 
50  template <typename Q>
51  class QuaternionReference : public QuaternionExpression<QuaternionReference<Q> >
52  {
53 
55 
56  public:
60  typedef Q QuaternionType;
61 
65  typedef typename Q::ValueType ValueType;
66 
70  typedef typename std::conditional<std::is_const<Q>::value,
71  typename Q::ConstReference,
72  typename Q::Reference>::type Reference;
73 
77  typedef typename Q::ConstReference ConstReference;
78 
83 
87  typedef const SelfType ConstClosureType;
88 
94  data(q) {}
95 
101  {
102  return data.getC1();
103  }
104 
110  {
111  return data.getC2();
112  }
113 
119  {
120  return data.getC3();
121  }
122 
128  {
129  return data.getC4();
130  }
131 
137  {
138  return data.getC1();
139  }
140 
146  {
147  return data.getC2();
148  }
149 
155  {
156  return data.getC3();
157  }
158 
164  {
165  return data.getC4();
166  }
167 
172  const QuaternionType& getData() const
173  {
174  return data;
175  }
176 
182  {
183  return data;
184  }
185 
192  {
193  data.operator=(r.data);
194  return *this;
195  }
196 
203  template <typename E>
205  {
206  data.operator=(e);
207  return *this;
208  }
209 
216  template <typename T>
217  typename std::enable_if<IsScalar<T>::value, QuaternionReference>::type&
218  operator=(const T& t)
219  {
220  data.operator=(t);
221  return *this;
222  }
223 
230  template <typename E>
232  {
233  data.operator+=(e);
234  return *this;
235  }
236 
243  template <typename T>
244  typename std::enable_if<IsScalar<T>::value, QuaternionReference>::type&
245  operator+=(const T& t)
246  {
247  data.operator+=(t);
248  return *this;
249  }
250 
257  template <typename E>
259  {
260  data.operator-=(e);
261  return *this;
262  }
263 
270  template <typename T>
271  typename std::enable_if<IsScalar<T>::value, QuaternionReference>::type&
272  operator-=(const T& t)
273  {
274  data.operator-=(t);
275  return *this;
276  }
277 
284  template <typename E>
286  {
287  data.operator*=(e);
288  return *this;
289  }
290 
297  template <typename T>
298  typename std::enable_if<IsScalar<T>::value, QuaternionReference>::type&
299  operator*=(const T& t)
300  {
301  data.operator*=(t);
302  return *this;
303  }
304 
311  template <typename E>
313  {
314  data.operator/=(e);
315  return *this;
316  }
317 
324  template <typename T>
325  typename std::enable_if<IsScalar<T>::value, QuaternionReference>::type&
326  operator/=(const T& t)
327  {
328  data.operator/=(t);
329  return *this;
330  }
331 
338  template <typename E>
340  {
341  data.assign(e);
342  return *this;
343  }
344 
351  template <typename E>
353  {
354  data.plusAssign(e);
355  return *this;
356  }
357 
364  template <typename E>
366  {
367  data.minusAssign(e);
368  return *this;
369  }
370 
376  {
377  data.swap(r.data);
378  }
379 
386  {
387  r1.swap(r2);
388  }
389 
397  void set(const ValueType& c1 = ValueType(), const ValueType& c2 = ValueType(),
398  const ValueType& c3 = ValueType(), const ValueType& c4 = ValueType())
399  {
400  data.set(c1, c2, c3, c4);
401  }
402 
403  private:
404  QuaternionType& data;
405  };
406 
411  template <typename T>
412  class Quaternion : public QuaternionContainer<Quaternion<T> >
413  {
414 
415  typedef Quaternion<T> SelfType;
416 
417  public:
421  typedef T ValueType;
422 
426  typedef T& Reference;
427 
431  typedef const T& ConstReference;
432 
436  typedef ValueType ArrayType[4];
437 
441  typedef T* Pointer;
442 
446  typedef const T* ConstPointer;
447 
452 
457 
462 
467 
475  explicit Quaternion(const ValueType& c1, const ValueType& c2 = ValueType(),
476  const ValueType& c3 = ValueType(), const ValueType& c4 = ValueType())
477  {
478  data[0] = c1;
479  data[1] = c2;
480  data[2] = c3;
481  data[3] = c4;
482  }
483 
489  {
490  std::copy(q.data, q.data + 4, data);
491  }
492 
498  template <typename E>
500  {
501  quaternionAssignQuaternion<ScalarAssignment>(*this, e);
502  }
503 
509  {
510  return data;
511  }
512 
518  {
519  return data;
520  }
521 
527  {
528  return data[0];
529  }
530 
536  {
537  return data[1];
538  }
539 
545  {
546  return data[2];
547  }
548 
554  {
555  return data[3];
556  }
557 
563  {
564  return data[0];
565  }
566 
572  {
573  return data[1];
574  }
575 
581  {
582  return data[2];
583  }
584 
590  {
591  return data[3];
592  }
593 
601  void set(const ValueType& c1 = ValueType(), const ValueType& c2 = ValueType(),
602  const ValueType& c3 = ValueType(), const ValueType& c4 = ValueType())
603  {
604  data[0] = c1;
605  data[1] = c2;
606  data[2] = c3;
607  data[3] = c4;
608  }
609 
616  {
617  if (this != &q)
618  std::copy(q.data, q.data + 4, data);
619 
620  return *this;
621  }
622 
629  template <typename C>
631  {
632  return assign(c);
633  }
634 
641  template <typename E>
643  {
644  Quaternion tmp(e);
645 
646  return this->operator=(tmp);
647  }
648 
655  template <typename T1>
656  typename std::enable_if<IsScalar<T1>::value, Quaternion>::type&
657  operator=(const T1& t)
658  {
659  data[0] = t;
660  data[1] = ValueType();
661  data[2] = ValueType();
662  data[3] = ValueType();
663 
664  return *this;
665  }
666 
673  template <typename T1>
674  typename std::enable_if<IsScalar<T1>::value, Quaternion>::type&
675  operator+=(const T1& t)
676  {
677  data[0] += t;
678  return *this;
679  }
680 
687  template <typename C>
689  {
690  return plusAssign(c);
691  }
692 
699  template <typename E>
701  {
702  Quaternion tmp(*this + e);
703 
704  return this->operator=(tmp);
705  }
706 
713  template <typename T1>
714  typename std::enable_if<IsScalar<T1>::value, Quaternion>::type&
715  operator-=(const T1& t)
716  {
717  data[0] -= t;
718  return *this;
719  }
720 
727  template <typename C>
729  {
730  return minusAssign(c);
731  }
732 
739  template <typename E>
741  {
742  Quaternion tmp(*this - e);
743 
744  return this->operator=(tmp);
745  }
746 
753  template <typename T1>
754  typename std::enable_if<IsScalar<T1>::value, Quaternion>::type&
755  operator*=(const T1& t)
756  {
757  quaternionAssignScalar<ScalarMultiplicationAssignment>(*this, t);
758  return *this;
759  }
760 
767  template <typename E>
769  {
770  Quaternion tmp(*this * e);
771 
772  return this->operator=(tmp);
773  }
774 
781  template <typename T1>
782  typename std::enable_if<IsScalar<T1>::value, Quaternion>::type&
783  operator/=(const T1& t)
784  {
785  quaternionAssignScalar<ScalarDivisionAssignment>(*this, t);
786  return *this;
787  }
788 
795  template <typename E>
797  {
798  Quaternion tmp(*this / e);
799 
800  return this->operator=(tmp);
801  }
802 
809  template <typename E>
811  {
812  quaternionAssignQuaternion<ScalarAssignment>(*this, e);
813  return *this;
814  }
815 
822  template <typename E>
824  {
825  quaternionAssignQuaternion<ScalarAdditionAssignment>(*this, e);
826  return *this;
827  }
828 
835  template <typename E>
837  {
838  quaternionAssignQuaternion<ScalarSubtractionAssignment>(*this, e);
839  return *this;
840  }
841 
846  void swap(Quaternion& q)
847  {
848  if (this != &q)
849  std::swap_ranges(data, data + 4, q.data);
850  }
851 
857  friend void swap(Quaternion& q1, Quaternion& q2)
858  {
859  q1.swap(q2);
860  }
861 
862  private:
863  ArrayType data;
864  };
865 
870  template <typename T>
871  class RealQuaternion : public QuaternionContainer<RealQuaternion<T> >
872  {
873 
874  typedef RealQuaternion<T> SelfType;
875 
876  public:
880  typedef T ValueType;
881 
885  typedef const T& Reference;
886 
890  typedef const T& ConstReference;
891 
896 
901 
906 
911  value() {}
912 
918  value(r) {}
919 
925  template <typename T1>
927  value(q.getC1())
928  {}
929 
935  {
936  return value;
937  }
938 
944  {
945  return zero;
946  }
947 
953  {
954  return zero;
955  }
956 
962  {
963  return zero;
964  }
965 
970  operator ValueType() const
971  {
972  return value;
973  }
974 
981  {
982  value = q.value;
983  return *this;
984  }
985 
992  template <typename T1>
994  {
995  value = q.getC1();
996  return *this;
997  }
998 
1005  template <typename T1>
1006  typename std::enable_if<IsScalar<T1>::value, RealQuaternion>::type&
1007  operator=(const T1& t)
1008  {
1009  value = t;
1010  return *this;
1011  }
1012 
1019  template <typename T1>
1021  {
1022  value += q.getC1();
1023  return *this;
1024  }
1025 
1032  template <typename T1>
1033  typename std::enable_if<IsScalar<T1>::value, RealQuaternion>::type&
1034  operator+=(const T1& t)
1035  {
1036  value += t;
1037  return *this;
1038  }
1039 
1046  template <typename T1>
1048  {
1049  value -= q.getC1();
1050  return *this;
1051  }
1052 
1059  template <typename T1>
1060  typename std::enable_if<IsScalar<T1>::value, RealQuaternion>::type&
1061  operator-=(const T1& t)
1062  {
1063  value -= t;
1064  return *this;
1065  }
1066 
1073  template <typename T1>
1075  {
1076  value *= q.getC1();
1077  return *this;
1078  }
1079 
1086  template <typename T1>
1087  typename std::enable_if<IsScalar<T1>::value, RealQuaternion>::type&
1088  operator*=(const T1& t)
1089  {
1090  value *= t;
1091  return *this;
1092  }
1093 
1100  template <typename T1>
1102  {
1103  value /= q.getC1();
1104  return *this;
1105  }
1106 
1113  template <typename T1>
1114  typename std::enable_if<IsScalar<T1>::value, RealQuaternion>::type&
1115  operator/=(const T1& t)
1116  {
1117  value /= t;
1118  return *this;
1119  }
1120 
1127  template <typename T1>
1129  {
1130  value = q.getC1();
1131  return *this;
1132  }
1133 
1140  template <typename T1>
1142  {
1143  value += q.getC1();
1144  return *this;
1145  }
1146 
1153  template <typename T1>
1155  {
1156  value -= q.getC1();
1157  return *this;
1158  }
1159 
1165  {
1166  if (this != &q)
1167  std::swap(value, q.value);
1168  }
1169 
1175  friend void swap(RealQuaternion& q1, RealQuaternion& q2)
1176  {
1177  q1.swap(q2);
1178  }
1179 
1180  private:
1181  ValueType value;
1182  static const ValueType zero;
1183  };
1184 
1185  template <typename T>
1186  const typename RealQuaternion<T>::ValueType RealQuaternion<T>::zero = RealQuaternion<T>::ValueType();
1187 
1192  template <typename Q>
1194  {};
1195 
1200  template <typename Q>
1202  {};
1203 
1210  template <typename T>
1211  typename std::enable_if<IsScalar<T>::value, RealQuaternion<T> >::type
1212  quat(const T& t)
1213  {
1214  return RealQuaternion<T>(t);
1215  }
1216 
1225  template <typename T1, typename T2>
1226  Quaternion<typename CommonType<T1, T2>::Type>
1227  quat(const T1& t1, const T2& t2)
1228  {
1229  typedef Quaternion<typename CommonType<T1, T2>::Type> QuaternionType;
1230 
1231  return QuaternionType(t1, t2);
1232  }
1233 
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)
1247  {
1248  typedef Quaternion<typename CommonType<typename CommonType<T1, T2>::Type, T3>::Type> QuaternionType;
1249 
1250  return QuaternionType(t1, t2, t3);
1251  }
1252 
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)
1268  {
1270 
1271  return QuaternionType(t1, t2, t3, t4);
1272  }
1273 
1278 
1283 
1288 
1293 
1298 
1303 
1308 
1313  } // namespace Math
1314 } // namespace CDPL
1315 
1316 #endif // CDPL_MATH_QUATERNION_HPP
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