-
Notifications
You must be signed in to change notification settings - Fork 1
/
debuglogger.cpp
94 lines (80 loc) · 2.32 KB
/
debuglogger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "debuglogger.h"
#include "funnel.h"
#include "math_helpers.h"
#include <iostream>
#include <stdexcept>
namespace pathfinder {
DebugLogger& DebugLogger::instance() {
static DebugLogger thisInstance = DebugLogger();
return thisInstance;
}
DebugLogger::DebugLogger() {
}
void DebugLogger::setPointToIndexFunction(const std::function<std::optional<uint32_t>(const Vector &point)> &func) {
pointToIndexFunction_ = func;
initialized_ = true;
}
void DebugLogger::printFunnel(const Funnel &funnel) const {
if (!initialized_) {
throw std::runtime_error("DebugLogger unitialized");
}
std::cout << "[";
for (int i=0; i<funnel.size(); ++i) {
if (i == funnel.apex_index()) {
std::cout << apexToString(funnel.funnel_apex());
} else {
std::cout << pointToString(funnel.at(i));
}
std::cout << ',';
}
std::cout << "]" << std::endl;
}
std::string DebugLogger::pointToString(const Vector &point) const {
if (!initialized_) {
throw std::runtime_error("DebugLogger unitialized");
}
if (startPoint_ && point == *startPoint_) {
return "[FUNNEL START]";
} else if (goalPoint_ && point == *goalPoint_) {
return "[FUNNEL GOAL]";
} else {
const auto pointIndex = pointToIndexFunction_(point);
if (pointIndex) {
if constexpr (std::is_same_v<decltype(pointIndex)::value_type, uint32_t>) {
return "("+std::to_string((*pointIndex)>>16)+","+std::to_string((*pointIndex)&0xFFFF)+")";
} else {
return std::to_string(*pointIndex);
}
} else {
std::string result = "(";
result += std::to_string(point.x());
result += ",";
result += std::to_string(point.y());
result += ")";
return result;
}
}
}
void DebugLogger::setStartPoint(const Vector &point) {
startPoint_ = point;
}
void DebugLogger::setGoalPoint(const Vector &point) {
goalPoint_ = point;
}
void DebugLogger::resetStartPoint() {
startPoint_.reset();
}
void DebugLogger::resetGoalPoint() {
goalPoint_.reset();
}
std::string DebugLogger::apexToString(const Apex &apex) const {
std::string result = "(" + pointToString(apex.apexPoint);
if (apex.apexType == AngleDirection::kClockwise) {
result += ",cw";
} else if (apex.apexType == AngleDirection::kCounterclockwise) {
result += ",ccw";
}
result += ")";
return result;
}
} // namespace pathfinder