nngn
Loading...
Searching...
No Matches
debug.h
Go to the documentation of this file.
1#ifndef NNGN_DEBUG_H
2#define NNGN_DEBUG_H
3
4#include <ostream>
5#include <sstream>
6#include <utility>
7#include <vector>
8
9#include "graphics/graphics.h"
10#include "math/mat3.h"
11#include "math/mat4.h"
12
13namespace std {
14
15template<typename T0, typename T1>
16requires(requires (ostream &o, T0 t0, T1 t1) { o << t0; o << t1; })
17ostream &operator<<(ostream &o, const pair<T0, T1> &p) {
18 return o << '{' << p.first << ", " << p.second << '}';
19}
20
21template<typename T, size_t N>
22requires(requires (ostream &o, T t) { o << t; })
23ostream &operator<<(ostream &o, const array<T, N> &v) {
24 if(v.empty())
25 return o << "{}";
26 o << '{' << v[0];
27 for(auto b = cbegin(v) + 1, e = cend(v); b != e; ++b)
28 o << ", " << *b;
29 return o << '}';
30}
31
32template<typename T, typename A>
33requires(requires (ostream &o, T t) { o << t; })
34ostream &operator<<(ostream &o, const vector<T, A> &v) {
35 if(v.empty())
36 return o << "{}";
37 o << '{' << v[0];
38 for(auto b = cbegin(v) + 1, e = cend(v); b != e; ++b)
39 o << ", " << *b;
40 return o << '}';
41}
42
43}
44
45namespace nngn {
46
47struct Vertex;
48
49template<template<typename> typename V, typename T, std::size_t N>
50std::ostream &operator <<(std::ostream &os, const vec<V, T, N> &v);
51std::ostream &operator <<(std::ostream &os, const mat4 &m);
52std::ostream &operator <<(std::ostream &os, const Vertex &v);
53
54template<template<typename> typename V, typename T, std::size_t N>
55inline std::ostream &operator <<(std::ostream &os, const vec<V, T, N> &v) {
56 os << "{" << v[0];
57 for(std::size_t i = 1; i < N; ++i)
58 os << ", " << v[i];
59 return os << "}";
60}
61
62inline std::ostream &operator <<(std::ostream &os, const mat3 &m) {
63 return os << "{" << m[0] << ", " << m[1] << ", " << m[2] << "}";
64}
65
66inline std::ostream &operator <<(std::ostream &os, const mat4 &m) {
67 return os
68 << "{"
69 << m[0] << ", " << m[1] << ", "
70 << m[2] << ", " << m[3]
71 << "}";
72}
73
74inline std::ostream &operator <<(std::ostream &os, const Vertex &v) {
75 return os << "{" << v.pos << ", " << v.norm << ", " << v.color << "}";
76}
77
78}
79
80template<typename T0, typename T1>
81inline std::string vdiff(const T0 &v0, const T1 &v1);
82
83template<typename T0, typename T1>
84inline std::string vdiff(const T0 &v0, const T1 &v1) {
85 using std::cbegin;
86 using std::cend;
87 const auto b0 = cbegin(v0), e0 = cend(v0);
88 const auto e1 = cend(v1);
89 auto p0 = b0;
90 auto p1 = cbegin(v1);
91 while(p0 != e0 && *p0 == *p1) { ++p0; ++p1; }
92 if(p0 == e0 && p1 == e1)
93 return "";
94 const auto i = p0 - b0;
95 std::stringstream s;
96 const auto fmt = [&s, i](const char *n, auto p, const auto e) {
97 s << "\n" << n << "[" << i << ":]:";
98 while(p != e)
99 s << " " << *p++;
100 };
101 fmt("v0", p0, e0);
102 fmt("v1", p1, e1);
103 s << '\n';
104 return s.str();
105}
106
107#endif
for i
Definition: font.lua:5
N
Definition: gamma.lua:5
std::string vdiff(const T0 &v0, const T1 &v1)
Definition: debug.h:72
n
Definition: dump_lights.lua:5
m
Definition: input.lua:23
p
Definition: input.lua:29
v[1]
Definition: math.lua:19
function fmt(name, size, n, max)
std::chrono::seconds s
Definition: timing.cpp:6
#define T(f0, f1, f2)
e
Definition: math.lua:4
Definition: audio.cpp:7
std::ostream & operator<<(std::ostream &os, Log::record r)
Definition: log.cpp:29
mat4_base< float > mat4
Definition: mat4.h:62
Definition: debug.h:13
Definition: graphics.h:136
Definition: mat3.h:12
Definition: vec.h:22