MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
quaternion.h
1 // © Copyright 2010 - 2014 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _quaternion_h
41 #define _quaternion_h
42 
43 #include "crossplatformexport.h"
44 #include "datatypes.h"
45 
46 #ifndef SWIG
47  #include "XML/xml.h"
48  #include <limits>
49 #endif
50 
51 class btQuaternion;
52 namespace Ogre
53 {
54  class Quaternion;
55 }
56 
57 namespace Mezzanine
58 {
59  class Vector3;
60  class Matrix3x3;
61  ///////////////////////////////////////////////////////////////////////////////
62  /// @class Quaternion
63  /// @headerfile quaternion.h
64  /// @brief This is used to store information about rotation in 3d space
65  /// @details This is used to store information about rotation in 3d space. The
66  /// X, Y and Z are used to identify a ray from the origin (0,0,0), about which
67  /// W represents an amount of rotation.
69  {
70  public:
71  ///////////////////////////////////////////////////////////////////////////////
72  // Data Members
73 
74  /// @brief The X component of the Axis.
76  /// @brief The Y component of the Axis.
78  /// @brief The Z component of the Axis.
80  /// @brief Rotation on the Axis X, Y and Z defined.
82 
83  ///////////////////////////////////////////////////////////////////////////////
84  // Constructors
85 
86  /// @brief Blank Constructor.
87  /// @details Basic no-initialization constructor.
88  Quaternion();
89  /// @brief Constructor.
90  /// @details Constructor that sets all four axis' of rotation.
91  /// @param X The X component of the Axis.
92  /// @param Y The Y component of the Axis.
93  /// @param Z The Z component of the Axis.
94  /// @param W Rotation on the Axis X, Y and Z defined.
95  Quaternion(const Real& X, const Real& Y, const Real& Z, const Real& W);
96  /// @brief Axis and Rotation Constructor.
97  /// @details This assembles a quaternion based on an axis and a rotation in radians.
98  /// @param Angle Real representing the angle to be applied along the axis in radians.
99  /// @param Axis Vector3 representing the axis to apply the rotation.
100  Quaternion(const Real& Angle, const Vector3& Axis);
101  /// @brief Rotation Matrix Constructor.
102  /// @param Mat The matrix to set this quaternion from.
103  Quaternion(const Matrix3x3& Mat);
104  /// @brief Axes Constructor.
105  /// @param AxisX The vector expressing the X axis.
106  /// @param AxisY The vector expressing the Y axis.
107  /// @param AxisZ The vector expressing the Z axis.
108  Quaternion(const Vector3& AxisX, const Vector3& AxisY, const Vector3& AxisZ);
109  /// @brief Bullet Quaternion constructor.
110  /// @details Constructor that sets all values to match the Bullet quaternion.
111  /// @param Theirs The quaternion to be copied to make this quaternion.
112  explicit Quaternion(const btQuaternion& Theirs);
113  /// @brief Ogre Quaternion constructor.
114  /// @details Constructor that sets all values to match the Ogre quaternion.
115  /// @param Theirs The quaternion to be copied to make this quaternion.
116  explicit Quaternion(const Ogre::Quaternion& Theirs);
117  /// @brief Copy Constructor.
118  /// @param Other The Quaternion to copy.
119  Quaternion(const Mezzanine::Quaternion& Other);
120  /// @brief XML Constructor.
121  /// @param OneNode The XML node to deserialize from.
122  explicit Quaternion(const XML::Node& OneNode);
123 
124  ///////////////////////////////////////////////////////////////////////////////
125  // Fancy Math and Utilities
126 
127  /// @brief Sets default/identity values to the members of this quaternion.
128  void SetIdentity();
129 
130  /// @brief Sets the individual values of this quaterion directly.
131  void SetValues(const Real& X, const Real& Y, const Real& Z, const Real& W);
132 
133  /// @brief Generates and sets the values of this quaternion to a rotation from an axis and angle on that axis.
134  /// @param Angle Real representing the angle to be applied along the axis in radians.
135  /// @param Axis Vector3 representing the axis to apply the rotation.
136  void SetFromAxisAngle(const Real& Angle, const Vector3& Axis);
137 
138  /// @brief Sets this quaternions values to express the same rotation as a Matrix3x3.
139  /// @param Mat The matrix to set this quaternion from.
140  void SetFromMatrix3x3(const Matrix3x3& Mat);
141 
142  /// @brief Generates and sets the values of this quaternion from 3 Axis vectors.
143  /// @param AxisX The vector expressing the X axis.
144  /// @param AxisY The vector expressing the Y axis.
145  /// @param AxisZ The vector expressing the Z axis.
146  void SetFromAxes(const Vector3& AxisX, const Vector3& AxisY, const Vector3& AxisZ);
147 
148  /// @brief Gets the Dot Product of this quaternion and another quaternion.
149  /// @param Other The other quaternion to calculate the dot product from.
150  /// @return Returns a Real that is the Dot Product of the two quaternions.
151  Real DotProduct(const Quaternion& Other) const;
152 
153  /// @brief Gets the length of the quaternion.
154  /// @return Returns a Real representing the length of the quaternion.
155  Real Length() const;
156 
157  /// @brief Gets the squared length(len^2) of the quaternion.
158  /// @return Returns a Real representing the squared length(len^2) of the quaternion.
159  Real LengthSqrd() const;
160 
161  /// @brief Normalizes this Quaternion.
162  /// @return Returns a normalized reference of this quaternion.
163  Quaternion& Normalize();
164 
165  /// @brief Get a normalized copy of this Quaternion without changing this one.
166  /// @return A Copy of this Quaternion after the copy has been normalized.
167  Quaternion GetNormalizedCopy() const;
168 
169  /// @brief Inverses this Quaternion.
170  /// @return Returns a quaternion that is a copy of this one after it has been inversed.
171  Quaternion GetInverse() const;
172 
173  ///////////////////////////////////////////////////////////////////////////////
174  // Explicit Conversion
175 
176  /// @brief Gets a Bullet quaternion.
177  /// @details Creates a Bullet quaternion with values equal to this class and returns it.
178  /// @param normalize Whether or not you want this function to normalize the quaternion for you.
179  /// @return A btQuaternion that has the same contents as this Mezzanine::Quaternion.
180  btQuaternion GetBulletQuaternion(bool normalize=false) const;
181 
182  /// @brief Copies an existing Bullet quaternion.
183  /// @details This function will copy the values stored in an existing Bullet quaternion
184  /// and set the values of this class to be the same.
185  /// @param Ours The quaternion to be extracted.
186  void ExtractBulletQuaternion(const btQuaternion &Ours);
187 
188  /// @brief Gets a Ogre quaternion.
189  /// @details Creates a Ogre quaternion with values equal to this class and returns it.
190  /// @param normalize Whether or not you want this function to normalize the quaternion for you.
191  Ogre::Quaternion GetOgreQuaternion(bool normalize=false) const;
192 
193  /// @brief Copies an existing Ogre quaternion.
194  /// @details This function will copy the values stored in an existing Ogre quaternion
195  /// and set the values of this class to be the same.
196  /// @param Ours The quaternion to be extracted.
197  void ExtractOgreQuaternion(const Ogre::Quaternion &Ours);
198 
199  ///////////////////////////////////////////////////////////////////////////////
200  // Access Operators
201 
202  /// @brief Allows Array style access to the members of this class.
203  /// @param Index The number corresponding to the Index you want. 0 = X, 1 = Y, 2 = Z, 3 = W.
204  /// @return Returns a copy of the number at the index requested.
205  Real operator[](const Whole& Index) const;
206 
207  /// @brief Allows Array style access to the members of this class.
208  /// @param Index The number corresponding to the Index you want. 0 = X, 1 = Y, 2 = Z, 3 = W.
209  /// @return Returns a writable reference to the number at the index requested.
210  Real& operator[](const Whole& Index);
211 
212  ///////////////////////////////////////////////////////////////////////////////
213  // Arithmetic By Real Operators
214 
215  /// @brief Scaling by multiplication.
216  /// @param Scalar This is the amount to scale the quaternion by.
217  /// @return Returns a scaled quaternion.
218  Quaternion operator* (const Real& Scalar) const;
219 
220  /// @brief Scaling by division.
221  /// @param Scalar This is the amount to scale the quaternion by.
222  /// @return Returns a scaled quaternion.
223  Quaternion operator/ (const Real& Scalar) const;
224 
225  ///////////////////////////////////////////////////////////////////////////////
226  // Left Hand Basic Arithmetic Operators
227 
228  /// @brief Addition operator with Mezzanine::Quaternion and Mezzanine::Quaternion.
229  /// @param Other The other Quaternion to add to this one.
230  /// @return A Mezzanine::Quaternion with the sum.
231  Quaternion operator+ (const Mezzanine::Quaternion& Other) const;
232 
233  /// @brief Addition operator with Mezzanine::Quaternion and Ogre::Quaternion.
234  /// @param Other The other Quaternion to add to this one.
235  /// @return A Mezzanine::Quaternion with the sum.
236  Quaternion operator+ (const Ogre::Quaternion& Other) const;
237 
238  /// @brief Addition operator with Mezzanine::Quaternion and btQuaternion.
239  /// @param Other The other Quaternion to add to this one.
240  /// @return A Mezzanine::Quaternion with the sum.
241  Quaternion operator+ (const btQuaternion& Other) const;
242 
243  /// @brief Subtraction operator with Mezzanine::Quaternion and Mezzanine::Quaternion.
244  /// @param Other The other Quaternion to subtract from this one.
245  /// @return A Mezzanine::Quaternion with the difference.
246  Quaternion operator- (const Mezzanine::Quaternion& Other) const;
247 
248  /// @brief Subtraction operator with Mezzanine::Quaternion and Ogre::Quaternion.
249  /// @param Other The other Quaternion to subtract from this one.
250  /// @return A Mezzanine::Quaternion with the difference.
251  Quaternion operator- (const Ogre::Quaternion& Other) const;
252 
253  /// @brief Subtraction operator with Mezzanine::Quaternion and btQuaternion.
254  /// @param Other The other Quaternion to subtract from this one.
255  /// @return A Mezzanine::Quaternion with the difference.
256  Quaternion operator- (const btQuaternion& Other) const;
257 
258  /// @brief Multiplication operator with Mezzanine::Quaternion and Mezzanine::Quaternion.
259  /// @param Other The other Quaternion to multiply from this one.
260  /// @return A Mezzanine::Quaternion with the result.
261  Quaternion operator* (const Mezzanine::Quaternion& Other) const;
262 
263  /// @brief Multiplication operator with Mezzanine::Quaternion and Ogre::Quaternion.
264  /// @param Other The other Quaternion to multiply from this one.
265  /// @return A Mezzanine::Quaternion with the result.
266  Quaternion operator* (const Ogre::Quaternion& Other) const;
267 
268  /// @brief Multiplication operator with Mezzanine::Quaternion and btQuaternion.
269  /// @param Other The other Quaternion to multiply from this one.
270  /// @return A Mezzanine::Quaternion with the result.
271  Quaternion operator* (const btQuaternion& Other) const;
272 
273  ///////////////////////////////////////////////////////////////////////////////
274  // Vector Rotation Operators
275 
276  /// @brief Rotates a vector by the provided quaternion.
277  /// @param Other The vector to rotate.
278  /// @return Returns a rotated version of the provided vector.
279  Vector3 operator* (const Vector3& Other) const;
280 
281  ///////////////////////////////////////////////////////////////////////////////
282  // Increment and Decrement Operators
283 
284  /// @brief Incrementing operator with Mezzanine::Quaternion and Mezzanine::Quaternion.
285  /// @param Other The other Quaternion to add to this one.
286  /// @return This Mezzanine::Quaternion with the sum.
287  Quaternion& operator+= (const Mezzanine::Quaternion& Other);
288 
289  /// @brief Incrementing operator with Mezzanine::Quaternion and Ogre::Quaternion.
290  /// @param Other The other Quaternion to add to this one.
291  /// @return This Mezzanine::Quaternion with the sum.
292  Quaternion& operator+= (const Ogre::Quaternion& Other);
293 
294  /// @brief Incrementing operator with Mezzanine::Quaternion and btQuaternion.
295  /// @param Other The other Quaternion to add to this one.
296  /// @return This Mezzanine::Quaternion with the sum.
297  Quaternion& operator+= (const btQuaternion& Other);
298 
299  /// @brief Decrementing operator with Mezzanine::Quaternion and Mezzanine::Quaternion.
300  /// @param Other The other Quaternion to subtract from this one.
301  /// @return This Mezzanine::Quaternion with the difference.
302  Quaternion& operator-= (const Mezzanine::Quaternion& Other);
303 
304  /// @brief Decrementing operator with Mezzanine::Quaternion and Ogre::Quaternion.
305  /// @param Other The other Quaternion to subtract from this one.
306  /// @return This Mezzanine::Quaternion with the difference.
307  Quaternion& operator-= (const Ogre::Quaternion& Other);
308 
309  /// @brief Decrementing operator with Mezzanine::Quaternion and btQuaternion.
310  /// @param Other The other Quaternion to subtract from this one.
311  /// @return This Mezzanine::Quaternion with the difference.
312  Quaternion& operator-= (const btQuaternion& Other);
313 
314  ///////////////////////////////////////////////////////////////////////////////
315  // Assignment Operators
316 
317  /// @brief Assignment Operator from Mezzanine::Quaternion.
318  /// @param Other The other quaternion to overwrite this one.
319  /// @return This Quaternion after being assigned fresh values.
320  Quaternion& operator= (const Mezzanine::Quaternion& Other);
321 
322  /// @brief Assignment Operator from Ogre::Quaternion.
323  /// @param Other The other quaternion to overwrite this one.
324  /// @return This Quaternion after being assigned fresh values.
325  Quaternion& operator= (const Ogre::Quaternion& Other);
326 
327  /// @brief Assignment Operator from btQuaternion.
328  /// @param Other The other quaternion to overwrite this one.
329  /// @return This Quaternion after being assigned fresh values.
330  Quaternion& operator= (const btQuaternion& Other);
331 
332  ///////////////////////////////////////////////////////////////////////////////
333  // Equality Comparison Operators
334 
335  /// @brief Equality Comparison Operator from Mezzanine::Quaternion.
336  /// @param Other The other quaternion to compare with.
337  /// @return True if the Quaternions are semantically equal, false otherwise.
338  bool operator==(const Mezzanine::Quaternion& Other) const;
339  /// @brief Equality Comparison Operator from Ogre::Quaternion.
340  /// @param Other The other quaternion to compare with.
341  /// @return True if the Quaternions are semantically equal, false otherwise.
342  bool operator==(const Ogre::Quaternion& Other) const;
343  /// @brief Equality Comparison Operator from btQuaternion.
344  /// @param Other The other quaternion to compare with.
345  /// @return True if the Quaternions are semantically equal, false otherwise.
346  bool operator==(const btQuaternion& Other) const;
347 
348  /// @brief Inequality Comparison Operator from Mezzanine::Quaternion.
349  /// @param Other The other quaternion to compare with.
350  /// @return True if the Quaternions are not semantically equal, false otherwise.
351  bool operator!=(const Mezzanine::Quaternion& Other) const;
352  /// @brief Inequality Comparison Operator from Ogre::Quaternion.
353  /// @param Other The other quaternion to compare with.
354  /// @return True if the Quaternions are not semantically equal, false otherwise.
355  bool operator!=(const Ogre::Quaternion& Other) const;
356  /// @brief Inequality Comparison Operator from btQuaternion.
357  /// @param Other The other quaternion to compare with.
358  /// @return True if the Quaternions are not semantically equal, false otherwise.
359  bool operator!=(const btQuaternion& Other) const;
360 
361  /// @brief Is every value in this Quaternion less than or equal to its corresponding value in another.
362  /// @param Other The Quaternion on the right hand side of the sign.
363  /// @note Used primarily for testing. This is not implemented for use with other kinds of Quaternion implementations as it is widely considered useless.
364  bool operator<= (const Mezzanine::Quaternion& Other) const;
365  /// @brief Is every value in this Quaternion greater than or equal to its corresponding value in another.
366  /// @param Other The Quaternion on the right hand side of the sign.
367  /// @note Used primarily for testing. This is not implemented for use with other kinds of Quaternion implementations as it is widely considered useless.
368  bool operator>= (const Mezzanine::Quaternion& Other) const;
369 
370  ///////////////////////////////////////////////////////////////////////////////
371  // Serialization
372 
373  // Serializable
374  /// @brief Convert this class to an XML::Node ready for serialization
375  /// @param CurrentRoot The point in the XML hierarchy that all this quaternion should be appended to.
376  void ProtoSerialize(XML::Node& CurrentRoot) const;
377 
378  // DeSerializable
379  /// @brief Take the data stored in an XML and overwrite this instance of this object with it
380  /// @param OneNode and XML::Node containing the data.
381  void ProtoDeSerialize(const XML::Node& OneNode);
382 
383  /// @brief Get the name of the the XML tag this class will leave behind as its instances are serialized.
384  /// @return A string containing "Quaternion"
385  static String SerializableName();
386 
387  };//Quaternion
388 }//Mezzanine
389 
390 ///////////////////////////////////////////////////////////////////////////////
391 // Right Hand Arithmetic Operators
392 
393 /// @brief Addition operator with Mezzanine::Quaternion and Ogre::Quaternion.
394 /// @param Other The first Quaternion to add.
395 /// @param Other2 The Mezzanine::Quaternion to add.
396 /// @return A Mezzanine::Quaternion with the sum.
397 Mezzanine::Quaternion MEZZ_LIB operator+ (const Ogre::Quaternion& Other, const Mezzanine::Quaternion& Other2);
398 
399 /// @brief Addition operator with Mezzanine::Quaternion and btQuaternion.
400 /// @param Other The first Quaternion to add.
401 /// @param Other2 The Mezzanine::Quaternion to add.
402 /// @return A Mezzanine::Quaternion with the sum.
403 Mezzanine::Quaternion MEZZ_LIB operator+ (const btQuaternion& Other, const Mezzanine::Quaternion& Other2);
404 
405 /// @brief Subtraction operator with Mezzanine::Quaternion and Ogre::Quaternion.
406 /// @param Other The first Quaternion to subtract from.
407 /// @param Other2 The Mezzanine::Quaternion to subtract.
408 /// @return A Mezzanine::Quaternion with the sum.
409 Mezzanine::Quaternion MEZZ_LIB operator- (const Ogre::Quaternion& Other, const Mezzanine::Quaternion& Other2);
410 
411 /// @brief Subtraction operator with Mezzanine::Quaternion and btQuaternion.
412 /// @param Other The first Quaternion to subtract from.
413 /// @param Other2 The Mezzanine::Quaternion to subtract.
414 /// @return A Mezzanine::Quaternion with the sum.
415 Mezzanine::Quaternion MEZZ_LIB operator- (const btQuaternion& Other, const Mezzanine::Quaternion& Other2);
416 
417 
418 ///////////////////////////////////////////////////////////////////////////////
419 // Class External << Operators for streaming or assignment
420 
421 #ifndef SWIG
422 /// @brief Conversion operator to btQuaternion.
423 /// @param Other The Quaternion to store the fresh contents.
424 /// @param Other2 The Quaternion to be converted.
425 /// @return A btQuaternion containing the contents of the converted Quaternion.
426 btQuaternion& MEZZ_LIB operator<< ( btQuaternion& Other, const Mezzanine::Quaternion& Other2);
427 
428 /// @brief Conversion operator to btQuaternion.
429 /// @param Other The Quaternion to store the fresh contents.
430 /// @param Other2 The Quaternion to be converted.
431 /// @return A btQuaternion containing the contents of the converted Quaternion.
432 btQuaternion& MEZZ_LIB operator<< ( btQuaternion& Other, const Ogre::Quaternion& Other2);
433 
434 /// @brief Conversion operator to Mezzanine::Quaternion.
435 /// @param Other The Quaternion to store the fresh contents.
436 /// @param Other2 The Quaternion to be converted.
437 /// @return A Mezzanine::Quaternion containing the contents of the converted Quaternion.
438 Mezzanine::Quaternion& MEZZ_LIB operator<< ( Mezzanine::Quaternion& Other, const Ogre::Quaternion& Other2);
439 
440 /// @brief Conversion operator to btQuaternion.
441 /// @param Other The Quaternion to store the fresh contents.
442 /// @param Other2 The Quaternion to be converted.
443 /// @return A btQuaternion containing the contents of the converted Quaternion.
444 Mezzanine::Quaternion& MEZZ_LIB operator<< ( Mezzanine::Quaternion& Other, const btQuaternion& Other2);
445 
446 /// @brief Conversion operator to Ogre::Quaternion.
447 /// @param Other The Quaternion to store the fresh contents.
448 /// @param Other2 The Quaternion to be converted.
449 /// @return A Ogre::Quaternion containing the contents of the converted Quaternion.
450 Ogre::Quaternion& MEZZ_LIB operator<< ( Ogre::Quaternion& Other, const Mezzanine::Quaternion& Other2);
451 
452 /// @brief Conversion operator to Ogre::Quaternion.
453 /// @param Other The Quaternion to store the fresh contents.
454 /// @param Other2 The Quaternion to be converted.
455 /// @return A Ogre::Quaternion containing the contents of the converted Quaternion.
456 Ogre::Quaternion& MEZZ_LIB operator<< ( Ogre::Quaternion& Other, const btQuaternion& Other2);
457 
458 /// @brief Used to Serialize an Mezzanine::Quaternion to a human readable stream
459 /// @details This puts proper XML output to the output stream,
460 /// including versioning information which will be used to maintain backwards compatibility. The current XML format
461 /// will create one node with no child nodes. The name of the xml node will be "Quaternion". It will have 5 attributes.
462 /// "Version", will be set to a value of 1, indicating if came from version 1 compatible Quaternion. It will also have an "X", "Y",
463 /// "Z" and "W" attributes will values set appropriately. For example '<Quaternion Version="1" X="1" Y="2" Z="3" W="0" />'.
464 /// @param x The Mezzanine::Quaternion to be converted to characters.
465 /// @param stream The place to send the characters, that define the Mezzanine::Quaternion.
466 /// @return Get an std::ostream that was written to, this allow chaining of the << operators.
467 std::ostream& MEZZ_LIB operator << (std::ostream& stream, const Mezzanine::Quaternion& x);
468 
469 /// @brief Used to de-serialize an Mezzanine::Quaternion from a stream
470 /// @details This reads in the xml and sets the target vector according to values
471 /// from the stream.
472 /// @param Vec The Mezzanine::Quaternion that will accept the values from the xml
473 /// @param stream The place to get the characters from, that define the Mezzanine::Quaternion.
474 /// @return Get an std::ostream that was read from, this allow chaining of the >> operators.
475 /// @throw Can throw any exception that any function in the Mezzanine::xml namespace could throw in addition to a Mezzanine::Exception if the serialization version doesn't match.
476 std::istream& MEZZ_LIB operator >> (std::istream& stream, Mezzanine::Quaternion& Vec);
477 
478 /// @brief Converts an XML node into a Mezzanine::Quaternion
479 /// @details This will convert an XML::Node will a valid serialized Mezzanine::Quaternion into a Mezzanine::Quaternion
480 /// @param OneNode An XML Node containing the the text of a Quaternion
481 /// @param Vec the Mezzanine::Quaternion to store the deserialized Quaternion
482 /// @return This returns a reference to the XML::Node for operator chaining or whatever.
483 /// @throw Can throw any exception that any function in the Mezzanine::xml namespace could throw in addition to a Mezzanine::Exception if the serialization version doesn't match.
484 void MEZZ_LIB operator >> (const Mezzanine::XML::Node& OneNode, Mezzanine::Quaternion& Vec);
485 #endif // \ SWIG
486 
487 namespace std
488 {
489  /// @brief Get Numeric details on Quaternion
490  template<>
491  class numeric_limits<Mezzanine::Quaternion>
492  {
493  public:
494  /// @brief Does this class (numeric_limits<Mezzanine::Quaternion>) exist
495  static const bool is_specialized = true;
496  /// @brief Does this support negative values?
497  static const bool is_signed = true;
498  /// @brief Can this only store integer types.
499  static const bool is_integer = false;
500  /// @brief The Quaternion uses Real, which is typically a machine dependedant which can be inexact
501  static const bool is_exact = std::numeric_limits<Mezzanine::Real>::is_exact;
502  /// @brief Can This represent an infinitely large value in X, Y or Z?
503  static const bool has_infinity = std::numeric_limits<Mezzanine::Real>::has_infinity;
504  /// @brief ??? Required by std::numeric to be compliant
505  /// @todo Learn why this exists and document it.
506  static const bool has_quiet_NaN = std::numeric_limits<Mezzanine::Real>::has_quiet_NaN;
507  /// @brief ??? Required by std::numeric to be compliant
508  /// @todo Learn why this exists and document it.
509  static const bool has_signaling_NaN = std::numeric_limits<Mezzanine::Real>::has_signaling_NaN;
510  /// @brief Does this support exceptionally small numbers near 0?
511  static const std::float_denorm_style has_denorm = std::numeric_limits<Mezzanine::Real>::has_denorm;
512  /// @brief When extra precision near 0 is lost, can this type distinguish that from other imprecision.
513  static const bool has_denorm_loss = std::numeric_limits<Mezzanine::Real>::has_denorm_loss;
514  /// @brief How items that fit between the precise amount a Real can represent will be adapted.
515  static const std::float_round_style round_style = std::numeric_limits<Mezzanine::Real>::round_style;
516  /// @brief Do X, Y and Z adhere to iec 559?
517  static const bool is_iec559 = std::numeric_limits<Mezzanine::Real>::is_iec559;
518  /// @brief Is overflow of this type handle by modulo overflow?
519  static const bool is_modulo = std::numeric_limits<Mezzanine::Real>::is_modulo;
520  /// @brief How many integer digits(in machine base) of precision can this handle in each X, Y or Z without floating point component or error?
521  static const int digits = std::numeric_limits<Mezzanine::Real>::digits;
522  /// @brief How many integer digits in base 10 of precision can this handle in each X, Y or Z without floating point component or error?
523  static const int digits10 = std::numeric_limits<Mezzanine::Real>::digits10;
524  /// @brief The base of the number system that this is implemented in
525  static const int radix = std::numeric_limits<Mezzanine::Real>::radix;
526  /// @brief The smallest power of the radix that is valid floating point value
527  static const int min_exponent = std::numeric_limits<Mezzanine::Real>::min_exponent;
528  /// @brief The smallest power of 10 that is valid floating point value
529  static const int min_exponent10 = std::numeric_limits<Mezzanine::Real>::min_exponent10;
530  /// @brief The largest power of the radix that is valid floating point value
531  static const int max_exponent = std::numeric_limits<Mezzanine::Real>::max_exponent;
532  /// @brief The largest power of 10 that is valid floating point value
533  static const int max_exponent10 = std::numeric_limits<Mezzanine::Real>::max_exponent10;
534  /// @brief Can this generate a trap?
535  static const bool traps = std::numeric_limits<Mezzanine::Real>::traps;
536  /// @brief Are tiny values respected during rounding?
537  static const bool tinyness_before = std::numeric_limits<Mezzanine::Real>::tinyness_before;
538 
539  /// @brief Get the lowest positive finite value this can represent
540  /// @return A Quaternion with 4 very small numbers
542  {
543  return Mezzanine::Quaternion(std::numeric_limits<Mezzanine::Real>::min(),
544  std::numeric_limits<Mezzanine::Real>::min(),
545  std::numeric_limits<Mezzanine::Real>::min(),
546  std::numeric_limits<Mezzanine::Real>::min()
547  );
548  }
549 
550  /// @brief Get the highest positive finite value this can represent
551  /// @return A Quaternion with 4 very large numbers
553  {
554  return Mezzanine::Quaternion(std::numeric_limits<Mezzanine::Real>::max(),
555  std::numeric_limits<Mezzanine::Real>::max(),
556  std::numeric_limits<Mezzanine::Real>::max(),
557  std::numeric_limits<Mezzanine::Real>::max()
558  );
559  }
560 
561  /// @brief The smallest value representable from 1.0,1.0,1.0 to the next value
562  /// @return A Quaternion with very small numbers
564  {
565  return Mezzanine::Quaternion(std::numeric_limits<Mezzanine::Real>::epsilon(),
566  std::numeric_limits<Mezzanine::Real>::epsilon(),
567  std::numeric_limits<Mezzanine::Real>::epsilon(),
568  std::numeric_limits<Mezzanine::Real>::epsilon()
569  );
570  }
571 
572  /// @brief Get the largest possible rounding error
573  /// @return A Quaternion containing 4 values indicating how much they could be rounded.
575  {
576  return Mezzanine::Quaternion(std::numeric_limits<Mezzanine::Real>::round_error(),
577  std::numeric_limits<Mezzanine::Real>::round_error(),
578  std::numeric_limits<Mezzanine::Real>::round_error(),
579  std::numeric_limits<Mezzanine::Real>::round_error()
580  );
581  }
582 
583  /// @brief Get the special value "Positive infinity"
584  /// @return A Quaternion containing 4 values.
586  {
587  return Mezzanine::Quaternion(std::numeric_limits<Mezzanine::Real>::infinity(),
588  std::numeric_limits<Mezzanine::Real>::infinity(),
589  std::numeric_limits<Mezzanine::Real>::infinity(),
590  std::numeric_limits<Mezzanine::Real>::infinity()
591  );
592  }
593 
594  /// @brief Get the special value "Quiet Not actual Number"
595  /// @return A Quaternion containing 4 values.
597  {
598  return Mezzanine::Quaternion(std::numeric_limits<Mezzanine::Real>::quiet_NaN(),
599  std::numeric_limits<Mezzanine::Real>::quiet_NaN(),
600  std::numeric_limits<Mezzanine::Real>::quiet_NaN(),
601  std::numeric_limits<Mezzanine::Real>::quiet_NaN()
602  );
603  }
604 
605  /// @brief Get the special value "Signaling Not actual Number"
606  /// @return A Quaternion containing 4 special values.
608  {
609  return Mezzanine::Quaternion(std::numeric_limits<Mezzanine::Real>::signaling_NaN(),
610  std::numeric_limits<Mezzanine::Real>::signaling_NaN(),
611  std::numeric_limits<Mezzanine::Real>::signaling_NaN(),
612  std::numeric_limits<Mezzanine::Real>::signaling_NaN()
613  );
614  }
615 
616  /// @brief Get the closest value to 0 that is not 0 this can represent, including extra precision for being close to 0 if supported.
617  /// @return A vector containing 3 very small values.
619  {
620  return Mezzanine::Quaternion(std::numeric_limits<Mezzanine::Real>::denorm_min(),
621  std::numeric_limits<Mezzanine::Real>::denorm_min(),
622  std::numeric_limits<Mezzanine::Real>::denorm_min(),
623  std::numeric_limits<Mezzanine::Real>::denorm_min()
624  );
625  }
626 
627  }; //Numeric Limits
628 
629 } // std
630 
631 
632 #endif