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, typename A>
22requires(requires (ostream &o, T t) { o << t; })
23ostream &operator<<(ostream &o, const vector<T, A> &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
32}
33
34namespace nngn {
35 struct Vertex;
36}
37
38template<template<typename> typename V, typename T, std::size_t N>
39std::ostream &operator <<(std::ostream &os, const nngn::vec<V, T, N> &v);
40std::ostream &operator <<(std::ostream &os, const nngn::mat4 &m);
41std::ostream &operator <<(std::ostream &os, const nngn::Vertex &v);
42
43template<typename T0, typename T1>
44inline std::string vdiff(const T0 &v0, const T1 &v1);
45
46template<template<typename> typename V, typename T, std::size_t N>
47inline std::ostream &operator <<(
48 std::ostream &os, const nngn::vec<V, T, N> &v)
49{
50 os << "{" << v[0];
51 for(std::size_t i = 1; i < N; ++i)
52 os << ", " << v[i];
53 return os << "}";
54}
55
56inline std::ostream &operator <<(std::ostream &os, const nngn::mat3 &m) {
57 return os << "{" << m[0] << ", " << m[1] << ", " << m[2] << "}";
58}
59
60inline std::ostream &operator <<(std::ostream &os, const nngn::mat4 &m) {
61 return os
62 << "{"
63 << m[0] << ", " << m[1] << ", "
64 << m[2] << ", " << m[3]
65 << "}";
66}
67
68inline std::ostream &operator <<(std::ostream &os, const nngn::Vertex &v)
69 { return os << "{" << v.pos << ", " << v.norm << ", " << v.color << "}"; }
70
71template<typename T0, typename T1>
72inline std::string vdiff(const T0 &v0, const T1 &v1) {
73 using std::cbegin;
74 using std::cend;
75 const auto b0 = cbegin(v0), e0 = cend(v0);
76 const auto e1 = cend(v1);
77 auto p0 = b0;
78 auto p1 = cbegin(v1);
79 while(p0 != e0 && *p0 == *p1) { ++p0; ++p1; }
80 if(p0 == e0 && p1 == e1)
81 return "";
82 const auto i = p0 - b0;
83 std::stringstream s;
84 const auto fmt = [&s, i](const char *n, auto p, const auto e) {
85 s << "\n" << n << "[" << i << ":]:";
86 while(p != e)
87 s << " " << *p++;
88 };
89 fmt("v0", p0, e0);
90 fmt("v1", p1, e1);
91 s << '\n';
92 return s.str();
93}
94
95#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
std::ostream & operator<<(std::ostream &os, const nngn::vec< V, T, N > &v)
Definition: debug.h:47
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
Definition: debug.h:13
Definition: graphics.h:136
Definition: mat3.h:12
Definition: vec.h:22