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:
58  typedef Q QuaternionType;
60  typedef typename Q::ValueType ValueType;
62  typedef typename std::conditional<std::is_const<Q>::value,
63  typename Q::ConstReference,
64  typename Q::Reference>::type Reference;
66  typedef typename Q::ConstReference ConstReference;
70  typedef const SelfType ConstClosureType;
71 
77  data(q) {}
78 
84  {
85  return data.getC1();
86  }
87 
93  {
94  return data.getC2();
95  }
96 
102  {
103  return data.getC3();
104  }
105 
111  {
112  return data.getC4();
113  }
114 
120  {
121  return data.getC1();
122  }
123 
129  {
130  return data.getC2();
131  }
132 
138  {
139  return data.getC3();
140  }
141 
147  {
148  return data.getC4();
149  }
150 
155  const QuaternionType& getData() const
156  {
157  return data;
158  }
159 
165  {
166  return data;
167  }
168 
175  {
176  data.operator=(r.data);
177  return *this;
178  }
179 
186  template <typename E>
188  {
189  data.operator=(e);
190  return *this;
191  }
192 
199  template <typename T>
200  typename std::enable_if<IsScalar<T>::value, QuaternionReference>::type&
201  operator=(const T& t)
202  {
203  data.operator=(t);
204  return *this;
205  }
206 
213  template <typename E>
215  {
216  data.operator+=(e);
217  return *this;
218  }
219 
226  template <typename T>
227  typename std::enable_if<IsScalar<T>::value, QuaternionReference>::type&
228  operator+=(const T& t)
229  {
230  data.operator+=(t);
231  return *this;
232  }
233 
240  template <typename E>
242  {
243  data.operator-=(e);
244  return *this;
245  }
246 
253  template <typename T>
254  typename std::enable_if<IsScalar<T>::value, QuaternionReference>::type&
255  operator-=(const T& t)
256  {
257  data.operator-=(t);
258  return *this;
259  }
260 
267  template <typename E>
269  {
270  data.operator*=(e);
271  return *this;
272  }
273 
280  template <typename T>
281  typename std::enable_if<IsScalar<T>::value, QuaternionReference>::type&
282  operator*=(const T& t)
283  {
284  data.operator*=(t);
285  return *this;
286  }
287 
294  template <typename E>
296  {
297  data.operator/=(e);
298  return *this;
299  }
300 
307  template <typename T>
308  typename std::enable_if<IsScalar<T>::value, QuaternionReference>::type&
309  operator/=(const T& t)
310  {
311  data.operator/=(t);
312  return *this;
313  }
314 
321  template <typename E>
323  {
324  data.assign(e);
325  return *this;
326  }
327 
334  template <typename E>
336  {
337  data.plusAssign(e);
338  return *this;
339  }
340 
347  template <typename E>
349  {
350  data.minusAssign(e);
351  return *this;
352  }
353 
359  {
360  data.swap(r.data);
361  }
362 
369  {
370  r1.swap(r2);
371  }
372 
380  void set(const ValueType& c1 = ValueType(), const ValueType& c2 = ValueType(),
381  const ValueType& c3 = ValueType(), const ValueType& c4 = ValueType())
382  {
383  data.set(c1, c2, c3, c4);
384  }
385 
386  private:
387  QuaternionType& data;
388  };
389 
394  template <typename T>
395  class Quaternion : public QuaternionContainer<Quaternion<T> >
396  {
397 
398  typedef Quaternion<T> SelfType;
399 
400  public:
402  typedef T ValueType;
404  typedef T& Reference;
406  typedef const T& ConstReference;
408  typedef ValueType ArrayType[4];
410  typedef T* Pointer;
412  typedef const T* ConstPointer;
419 
424 
432  explicit Quaternion(const ValueType& c1, const ValueType& c2 = ValueType(),
433  const ValueType& c3 = ValueType(), const ValueType& c4 = ValueType())
434  {
435  data[0] = c1;
436  data[1] = c2;
437  data[2] = c3;
438  data[3] = c4;
439  }
440 
446  {
447  std::copy(q.data, q.data + 4, data);
448  }
449 
455  template <typename E>
457  {
458  quaternionAssignQuaternion<ScalarAssignment>(*this, e);
459  }
460 
466  {
467  return data;
468  }
469 
475  {
476  return data;
477  }
478 
484  {
485  return data[0];
486  }
487 
493  {
494  return data[1];
495  }
496 
502  {
503  return data[2];
504  }
505 
511  {
512  return data[3];
513  }
514 
520  {
521  return data[0];
522  }
523 
529  {
530  return data[1];
531  }
532 
538  {
539  return data[2];
540  }
541 
547  {
548  return data[3];
549  }
550 
558  void set(const ValueType& c1 = ValueType(), const ValueType& c2 = ValueType(),
559  const ValueType& c3 = ValueType(), const ValueType& c4 = ValueType())
560  {
561  data[0] = c1;
562  data[1] = c2;
563  data[2] = c3;
564  data[3] = c4;
565  }
566 
573  {
574  if (this != &q)
575  std::copy(q.data, q.data + 4, data);
576 
577  return *this;
578  }
579 
586  template <typename C>
588  {
589  return assign(c);
590  }
591 
598  template <typename E>
600  {
601  Quaternion tmp(e);
602 
603  return this->operator=(tmp);
604  }
605 
612  template <typename T1>
613  typename std::enable_if<IsScalar<T1>::value, Quaternion>::type&
614  operator=(const T1& t)
615  {
616  data[0] = t;
617  data[1] = ValueType();
618  data[2] = ValueType();
619  data[3] = ValueType();
620 
621  return *this;
622  }
623 
630  template <typename T1>
631  typename std::enable_if<IsScalar<T1>::value, Quaternion>::type&
632  operator+=(const T1& t)
633  {
634  data[0] += t;
635  return *this;
636  }
637 
644  template <typename C>
646  {
647  return plusAssign(c);
648  }
649 
656  template <typename E>
658  {
659  Quaternion tmp(*this + e);
660 
661  return this->operator=(tmp);
662  }
663 
670  template <typename T1>
671  typename std::enable_if<IsScalar<T1>::value, Quaternion>::type&
672  operator-=(const T1& t)
673  {
674  data[0] -= t;
675  return *this;
676  }
677 
684  template <typename C>
686  {
687  return minusAssign(c);
688  }
689 
696  template <typename E>
698  {
699  Quaternion tmp(*this - e);
700 
701  return this->operator=(tmp);
702  }
703 
710  template <typename T1>
711  typename std::enable_if<IsScalar<T1>::value, Quaternion>::type&
712  operator*=(const T1& t)
713  {
714  quaternionAssignScalar<ScalarMultiplicationAssignment>(*this, t);
715  return *this;
716  }
717 
724  template <typename E>
726  {
727  Quaternion tmp(*this * e);
728 
729  return this->operator=(tmp);
730  }
731 
738  template <typename T1>
739  typename std::enable_if<IsScalar<T1>::value, Quaternion>::type&
740  operator/=(const T1& t)
741  {
742  quaternionAssignScalar<ScalarDivisionAssignment>(*this, t);
743  return *this;
744  }
745 
752  template <typename E>
754  {
755  Quaternion tmp(*this / e);
756 
757  return this->operator=(tmp);
758  }
759 
766  template <typename E>
768  {
769  quaternionAssignQuaternion<ScalarAssignment>(*this, e);
770  return *this;
771  }
772 
779  template <typename E>
781  {
782  quaternionAssignQuaternion<ScalarAdditionAssignment>(*this, e);
783  return *this;
784  }
785 
792  template <typename E>
794  {
795  quaternionAssignQuaternion<ScalarSubtractionAssignment>(*this, e);
796  return *this;
797  }
798 
803  void swap(Quaternion& q)
804  {
805  if (this != &q)
806  std::swap_ranges(data, data + 4, q.data);
807  }
808 
814  friend void swap(Quaternion& q1, Quaternion& q2)
815  {
816  q1.swap(q2);
817  }
818 
819  private:
820  ArrayType data;
821  };
822 
827  template <typename T>
828  class RealQuaternion : public QuaternionContainer<RealQuaternion<T> >
829  {
830 
831  typedef RealQuaternion<T> SelfType;
832 
833  public:
835  typedef T ValueType;
837  typedef const T& Reference;
839  typedef const T& ConstReference;
846 
851  value() {}
852 
858  value(r) {}
859 
865  template <typename T1>
867  value(q.getC1())
868  {}
869 
875  {
876  return value;
877  }
878 
884  {
885  return zero;
886  }
887 
893  {
894  return zero;
895  }
896 
902  {
903  return zero;
904  }
905 
910  operator ValueType() const
911  {
912  return value;
913  }
914 
921  {
922  value = q.value;
923  return *this;
924  }
925 
932  template <typename T1>
934  {
935  value = q.getC1();
936  return *this;
937  }
938 
945  template <typename T1>
946  typename std::enable_if<IsScalar<T1>::value, RealQuaternion>::type&
947  operator=(const T1& t)
948  {
949  value = t;
950  return *this;
951  }
952 
959  template <typename T1>
961  {
962  value += q.getC1();
963  return *this;
964  }
965 
972  template <typename T1>
973  typename std::enable_if<IsScalar<T1>::value, RealQuaternion>::type&
974  operator+=(const T1& t)
975  {
976  value += t;
977  return *this;
978  }
979 
986  template <typename T1>
988  {
989  value -= q.getC1();
990  return *this;
991  }
992 
999  template <typename T1>
1000  typename std::enable_if<IsScalar<T1>::value, RealQuaternion>::type&
1001  operator-=(const T1& t)
1002  {
1003  value -= t;
1004  return *this;
1005  }
1006 
1013  template <typename T1>
1015  {
1016  value *= q.getC1();
1017  return *this;
1018  }
1019 
1026  template <typename T1>
1027  typename std::enable_if<IsScalar<T1>::value, RealQuaternion>::type&
1028  operator*=(const T1& t)
1029  {
1030  value *= t;
1031  return *this;
1032  }
1033 
1040  template <typename T1>
1042  {
1043  value /= q.getC1();
1044  return *this;
1045  }
1046 
1053  template <typename T1>
1054  typename std::enable_if<IsScalar<T1>::value, RealQuaternion>::type&
1055  operator/=(const T1& t)
1056  {
1057  value /= t;
1058  return *this;
1059  }
1060 
1067  template <typename T1>
1069  {
1070  value = q.getC1();
1071  return *this;
1072  }
1073 
1080  template <typename T1>
1082  {
1083  value += q.getC1();
1084  return *this;
1085  }
1086 
1093  template <typename T1>
1095  {
1096  value -= q.getC1();
1097  return *this;
1098  }
1099 
1105  {
1106  if (this != &q)
1107  std::swap(value, q.value);
1108  }
1109 
1115  friend void swap(RealQuaternion& q1, RealQuaternion& q2)
1116  {
1117  q1.swap(q2);
1118  }
1119 
1120  private:
1121  ValueType value;
1122  static const ValueType zero;
1123  };
1124 
1125  template <typename T>
1126  const typename RealQuaternion<T>::ValueType RealQuaternion<T>::zero = RealQuaternion<T>::ValueType();
1127 
1132  template <typename Q>
1134  {};
1135 
1140  template <typename Q>
1142  {};
1143 
1150  template <typename T>
1151  typename std::enable_if<IsScalar<T>::value, RealQuaternion<T> >::type
1152  quat(const T& t)
1153  {
1154  return RealQuaternion<T>(t);
1155  }
1156 
1165  template <typename T1, typename T2>
1166  Quaternion<typename CommonType<T1, T2>::Type>
1167  quat(const T1& t1, const T2& t2)
1168  {
1169  typedef Quaternion<typename CommonType<T1, T2>::Type> QuaternionType;
1170 
1171  return QuaternionType(t1, t2);
1172  }
1173 
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)
1187  {
1188  typedef Quaternion<typename CommonType<typename CommonType<T1, T2>::Type, T3>::Type> QuaternionType;
1189 
1190  return QuaternionType(t1, t2, t3);
1191  }
1192 
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)
1208  {
1210 
1211  return QuaternionType(t1, t2, t3, t4);
1212  }
1213 
1218 
1223 
1228 
1233 
1238 
1243 
1248 
1253  } // namespace Math
1254 } // namespace CDPL
1255 
1256 #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: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