/src/OpenFOAM/primitives/septernion/septernion.C

https://gitlab.com/johnvarv/OpenFOAM-3.0.x · C · 102 lines · 48 code · 22 blank · 32 comment · 0 complexity · 88702e120ab8f3ec36524f77a6193e87 MD5 · raw file

  1. /*---------------------------------------------------------------------------*\
  2. ========= |
  3. \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
  4. \\ / O peration |
  5. \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
  6. \\/ M anipulation |
  7. -------------------------------------------------------------------------------
  8. License
  9. This file is part of OpenFOAM.
  10. OpenFOAM is free software: you can redistribute it and/or modify it
  11. under the terms of the GNU General Public License as published by
  12. the Free Software Foundation, either version 3 of the License, or
  13. (at your option) any later version.
  14. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
  15. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  17. for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
  20. \*---------------------------------------------------------------------------*/
  21. #include "septernion.H"
  22. #include "IOstreams.H"
  23. #include "OStringStream.H"
  24. // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
  25. const char* const Foam::septernion::typeName = "septernion";
  26. const Foam::septernion Foam::septernion::zero
  27. (
  28. vector(0, 0, 0),
  29. quaternion(0, vector(0, 0, 0))
  30. );
  31. const Foam::septernion Foam::septernion::I
  32. (
  33. vector(0, 0, 0),
  34. quaternion(1, vector(0, 0, 0))
  35. );
  36. // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
  37. Foam::septernion::septernion(Istream& is)
  38. {
  39. is >> *this;
  40. }
  41. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  42. Foam::word Foam::name(const septernion& s)
  43. {
  44. OStringStream buf;
  45. buf << '(' << s.t() << ',' << s.r() << ')';
  46. return buf.str();
  47. }
  48. Foam::septernion Foam::slerp
  49. (
  50. const septernion& qa,
  51. const septernion& qb,
  52. const scalar t
  53. )
  54. {
  55. return septernion((1.0-t)*qa.t()+t*qb.t(), slerp(qa.r(), qb.r(), t));
  56. }
  57. // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
  58. Foam::Istream& Foam::operator>>(Istream& is, septernion& s)
  59. {
  60. // Read beginning of septernion
  61. is.readBegin("septernion");
  62. is >> s.t() >> s.r();
  63. // Read end of septernion
  64. is.readEnd("septernion");
  65. // Check state of Istream
  66. is.check("operator>>(Istream&, septernion&)");
  67. return is;
  68. }
  69. Foam::Ostream& Foam::operator<<(Ostream& os, const septernion& s)
  70. {
  71. os << token::BEGIN_LIST
  72. << s.t() << token::SPACE << s.r()
  73. << token::END_LIST;
  74. return os;
  75. }
  76. // ************************************************************************* //