Not Enough Math
Lightweight zero-dependency C++ math library
Loading...
Searching...
No Matches
quat_io.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <iostream>
4#include <string>
5#include <sstream>
6
7#include "quat.hpp"
8
9namespace nem
10{
11 static constexpr const char* QUAT_SEPARATOR = " + ";
12 static constexpr const char* QUAT_L_BRACE = "(";
13 static constexpr const char* QUAT_R_BRACE = ")";
14
15 template<typename T>
16 std::ostream& operator<<(std::ostream& os, const nem::quat_t<T>& q)
17 {
18 os << QUAT_L_BRACE;
19 os << q.s << QUAT_SEPARATOR;
20 os << q.x << "i" << QUAT_SEPARATOR;
21 os << q.y << "j" << QUAT_SEPARATOR;
22 os << q.z << "k";
23 os << QUAT_R_BRACE;
24 return os;
25 }
26
27 template<typename T>
28 std::istream& operator>>(std::istream& is, nem::quat_t<T>& q)
29 {
30 is >> q.s;
31 is >> q.x;
32 is >> q.y;
33 is >> q.z;
34 return is;
35 }
36
37 template<typename T>
38 std::string to_str(const nem::quat_t<T>& q)
39 {
40 std::stringstream ss;
41 ss << QUAT_L_BRACE;
42 ss << q.s << QUAT_SEPARATOR;
43 ss << q.x << "i" << QUAT_SEPARATOR;
44 ss << q.y << "j" << QUAT_SEPARATOR;
45 ss << q.z << "k";
46 ss << QUAT_R_BRACE;
47 return ss.str();
48 }
49}
Definition config.hpp:16
std::string to_str(const nem::quat_t< T > &q)
Definition quat_io.hpp:38
static constexpr const char * QUAT_L_BRACE
Definition quat_io.hpp:12
std::istream & operator>>(std::istream &is, mat< T, C, R > &matrix)
Definition mat_io.hpp:48
static constexpr const char * QUAT_R_BRACE
Definition quat_io.hpp:13
static constexpr const char * QUAT_SEPARATOR
Definition quat_io.hpp:11
std::ostream & operator<<(std::ostream &os, const mat< T, C, R > &matrix)
Definition mat_io.hpp:32