Commit 5f40a738 authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

STYLE: adjust comments in quaternion

- make I/O operators global (non-member)
parent 661d1f53
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -153,12 +153,8 @@ Foam::quaternion Foam::pow(const quaternion& q, const scalar power)
Foam::Istream& Foam::operator>>(Istream& is, quaternion& q)
{
// Read beginning of quaternion
is.readBegin("quaternion");
is >> q.w() >> q.v();
// Read end of quaternion
is.readEnd("quaternion");
is.check(FUNCTION_NAME);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -49,20 +49,13 @@ SourceFiles
namespace Foam
{
// Forward declaration of friend functions and operators
class quaternion;
Istream& operator>>(Istream& is, quaternion&);
Ostream& operator<<(Ostream& os, const quaternion& C);
/*---------------------------------------------------------------------------*\
Class quaternion Declaration
\*---------------------------------------------------------------------------*/
class quaternion
{
// private data
// Private Data
//- Scalar part of the quaternion ( = cos(theta/2) for rotation)
scalar w_;
......@@ -107,13 +100,13 @@ public:
};
// Member constants
// Member Constants
//- Rank of quaternion is 1
static constexpr direction rank = 1;
// Static data members
// Static Data Members
static const char* const typeName;
......@@ -134,7 +127,7 @@ public:
inline quaternion(const vector& d, const scalar theta);
//- Construct a rotation quaternion given the direction d
// and cosine angle cosTheta and a if d is normalized
//- and cosine angle cosTheta and a if d is normalized
inline quaternion
(
const vector& d,
......@@ -146,93 +139,87 @@ public:
inline explicit quaternion(const scalar w);
//- Construct a pure imaginary quaternion given the vector part,
// the scalar part = 0
//- the scalar part = 0
inline explicit quaternion(const vector& v);
//- Return the unit quaternion (versor) from the given vector
// (w = sqrt(1 - |sqr(v)|))
//- (w = sqrt(1 - |sqr(v)|))
static inline quaternion unit(const vector& v);
//- Construct a quaternion given the three Euler angles
inline quaternion
(
const rotationSequence rs,
const vector& angles
);
//- Construct from three Euler angles
inline quaternion(const rotationSequence rs, const vector& angles);
//- Construct a quaternion from a rotation tensor
//- Construct from a rotation tensor
inline explicit quaternion(const tensor& rotationTensor);
//- Construct from Istream
quaternion(Istream&);
// Member functions
explicit quaternion(Istream& is);
// Access
//- Scalar part of the quaternion ( = cos(theta/2) for rotation)
inline scalar w() const;
// Member Functions
//- Vector part of the quaternion ( = axis of rotation)
inline const vector& v() const;
// Access
//- The rotation tensor corresponding the quaternion
inline tensor R() const;
//- Scalar part of the quaternion ( = cos(theta/2) for rotation)
inline scalar w() const;
//- Return a vector of euler angles corresponding to the
// specified rotation sequence
inline vector eulerAngles(const rotationSequence rs) const;
//- Vector part of the quaternion ( = axis of rotation)
inline const vector& v() const;
inline quaternion normalized() const;
//- The rotation tensor corresponding the quaternion
inline tensor R() const;
//- Return a vector of euler angles corresponding to the
//- specified rotation sequence
inline vector eulerAngles(const rotationSequence rs) const;
// Edit
//- Return the quaternion normalized by its magnitude
inline quaternion normalized() const;
//- Scalar part of the quaternion ( = cos(theta/2) for rotation)
inline scalar& w();
//- Vector part of the quaternion ( = axis of rotation)
inline vector& v();
// Edit
inline void normalize();
//- Scalar part of the quaternion ( = cos(theta/2) for rotation)
inline scalar& w();
//- Vector part of the quaternion ( = axis of rotation)
inline vector& v();
// Transform
//- Normalize the quaternion by its magnitude
inline void normalize();
//- Rotate the given vector
inline vector transform(const vector& v) const;
//- Rotate the given vector anti-clockwise
inline vector invTransform(const vector& v) const;
// Transform
//- Rotate the given quaternion (and normalize)
inline quaternion transform(const quaternion& q) const;
//- Rotate the given vector
inline vector transform(const vector& v) const;
//- Rotate the given quaternion anti-clockwise (and normalize)
inline quaternion invTransform(const quaternion& q) const;
//- Rotate the given vector anti-clockwise
inline vector invTransform(const vector& v) const;
//- Rotate the given quaternion (and normalize)
inline quaternion transform(const quaternion& q) const;
// Member operators
//- Rotate the given quaternion anti-clockwise (and normalize)
inline quaternion invTransform(const quaternion& q) const;
inline void operator=(const quaternion&);
inline void operator+=(const quaternion&);
inline void operator-=(const quaternion&);
inline void operator*=(const quaternion&);
inline void operator/=(const quaternion&);
inline void operator=(const scalar);
// Member Operators
inline void operator=(const vector&);
inline void operator=(const quaternion& q);
inline void operator+=(const quaternion& q);
inline void operator-=(const quaternion& q);
inline void operator*=(const quaternion& q);
inline void operator/=(const quaternion& q);
inline void operator*=(const scalar);
inline void operator/=(const scalar);
//- Change scalar portion
inline void operator=(const scalar s);
//- Change vector portion
inline void operator=(const vector& v);
// IOstream operators
friend Istream& operator>>(Istream& is, quaternion&);
friend Ostream& operator<<(Ostream& os, const quaternion& C);
inline void operator*=(const scalar s);
inline void operator/=(const scalar s);
};
......@@ -284,6 +271,9 @@ inline bool contiguous<quaternion>() {return true;}
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
Istream& operator>>(Istream& is, quaternion& q);
Ostream& operator<<(Ostream& os, const quaternion& q);
inline bool operator==(const quaternion& q1, const quaternion& q2);
inline bool operator!=(const quaternion& q1, const quaternion& q2);
inline quaternion operator+(const quaternion& q1, const quaternion& q2);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment