OGLplus  (0.59.0) a C++ wrapper for rendering APIs

io.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_MATH_IO_HPP
9 #define EAGINE_MATH_IO_HPP
10 
11 #include "matrix.hpp"
12 #include "primitives.hpp"
13 #include "vector.hpp"
14 #include <iostream>
15 
16 namespace eagine::math {
17 //------------------------------------------------------------------------------
20 template <typename T, int N, bool V>
21 static inline auto operator<<(std::ostream& o, const vector<T, N, V>& v)
22  -> std::ostream& {
23 
24  o << "[" << v._v[0];
25  for(int i = 1; i < N; ++i) {
26  o << ", " << v._v[i];
27  }
28  return o << "]";
29 }
30 //------------------------------------------------------------------------------
33 template <typename T, int C, int R, bool V>
34 static inline auto operator<<(std::ostream& o, const matrix<T, C, R, true, V>& m)
35  -> std::ostream& {
36  o << "|R0[" << m._v[0][0];
37 
38  for(int c = 1; c < C; ++c) {
39  o << ", " << m._v[0][c];
40  }
41  o << "]";
42 
43  for(int r = 1; r < R; ++r) {
44  o << ",R" << r << "[" << m._v[r][0];
45  for(int c = 1; c < C; ++c) {
46  o << ", " << m._v[r][c];
47  }
48  o << "]";
49  }
50  return o << "|";
51 }
52 //------------------------------------------------------------------------------
55 template <typename T, int C, int R, bool V>
56 static inline auto
57 operator<<(std::ostream& o, const matrix<T, C, R, false, V>& m)
58  -> std::ostream& {
59  o << "|C0[" << m._v[0][0];
60 
61  for(int r = 1; r < R; ++r) {
62  o << ", " << m._v[0][r];
63  }
64  o << "]";
65 
66  for(int c = 1; c < C; ++c) {
67  o << ",C" << c << "[" << m._v[c][0];
68  for(int r = 1; r < R; ++r) {
69  o << ", " << m._v[c][r];
70  }
71  o << "]";
72  }
73  return o << "|";
74 }
75 //------------------------------------------------------------------------------
78 template <typename T, int N, bool V>
79 static inline auto operator<<(std::ostream& o, const basic_line<T, N, V>& l)
80  -> std::ostream& {
81  o << '[' << l.origin() << " -> " << l.direction() << ']';
82  return o;
83 }
84 //------------------------------------------------------------------------------
87 template <typename T, int N, bool V>
88 static inline auto operator<<(std::ostream& o, const basic_triangle<T, N, V>& t)
89  -> std::ostream& {
90  o << '[' << t.a() << '|' << t.b() << '|' << t.c() << ']';
91  return o;
92 }
93 //------------------------------------------------------------------------------
96 template <typename T, bool V>
97 static inline auto operator<<(std::ostream& o, const sphere<T, V>& s)
98  -> std::ostream& {
99  o << '[' << s.center() << ')' << s.radius() << ']';
100  return o;
101 }
102 //------------------------------------------------------------------------------
103 } // namespace eagine::math
104 
105 #endif // EAGINE_MATH_IO_HPP
Basic template for spheres in N-dimensional space.
Definition: primitives.hpp:122
Basic template for lines in N-dimensional space.
Definition: primitives.hpp:19
Basic template for triangles in N-dimensional space.
Definition: primitives.hpp:57
static auto operator<<(std::ostream &o, const vector< T, N, V > &v) -> std::ostream &
Operator for writing vector into output stream.
Definition: io.hpp:21
Basic N-dimensional vector implementation template.
Definition: fwd.hpp:19
Math-related code is placed in this namespace.
Definition: eagine.hpp:48
Basic RxC matrix implementation template.
Definition: fwd.hpp:25

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).