From b3f2fded38755a2aff70bcc17a485c1322a34216 Mon Sep 17 00:00:00 2001 From: Andreas Butti Date: Tue, 25 Dec 2018 13:13:30 +0100 Subject: [PATCH] Code cleanup --- src/control/jobs/Scheduler.cpp | 28 +++++-------------- .../shaperecognizer/CircleRecognizer.cpp | 6 ++-- .../shaperecognizer/ShapeRecognizer.cpp | 22 +++++++-------- .../shaperecognizer/ShapeRecognizerConfig.h | 19 ++----------- .../shaperecognizer/ShapeRecognizerResult.cpp | 7 ++--- 5 files changed, 25 insertions(+), 57 deletions(-) diff --git a/src/control/jobs/Scheduler.cpp b/src/control/jobs/Scheduler.cpp index 8bae02e9..8c049ac7 100644 --- a/src/control/jobs/Scheduler.cpp +++ b/src/control/jobs/Scheduler.cpp @@ -1,26 +1,12 @@ #include "Scheduler.h" - #include -#ifdef DEBUG_SHEDULER - -#include -#define SDEBUG(msg) std::cout << bl::format(CONCAT("Scheduler::", msg, "\n")) +#include +#ifdef DEBUG_SHEDULER +#define SDEBUG g_message #else - -//kind of workaround -class no_debug_format -{ -public: - template - no_debug_format& operator%(const T& x) - { - return *this; - } -}; -#define SDEBUG(msg) no_debug_format() - +#define SDEBUG(msg, ...) #endif Scheduler::Scheduler() @@ -120,7 +106,7 @@ void Scheduler::addJob(Job* job, JobPriority priority) g_queue_push_tail(this->jobQueue[priority], job); g_cond_broadcast(&this->jobQueueCond); - SDEBUG("add job: {1}") % (uint64_t) job; + SDEBUG("add job: %" PRId64, (uint64_t) job); g_mutex_unlock(&this->jobQueueMutex); } @@ -297,7 +283,7 @@ gpointer Scheduler::jobThreadCallback(Scheduler* scheduler) hasOnlyRenderJobs = false; } - SDEBUG("get job: {1}") % (uint64_t) job; + SDEBUG("get job: %" PRId64, (uint64_t) job); if (job == NULL) { @@ -319,7 +305,7 @@ gpointer Scheduler::jobThreadCallback(Scheduler* scheduler) continue; } - SDEBUG("do job: {1}") % (uint64_t) job; + SDEBUG("do job: %" PRId64, (uint64_t) job); g_mutex_unlock(&scheduler->jobQueueMutex); diff --git a/src/control/shaperecognizer/CircleRecognizer.cpp b/src/control/shaperecognizer/CircleRecognizer.cpp index db184cb2..592ff07d 100644 --- a/src/control/shaperecognizer/CircleRecognizer.cpp +++ b/src/control/shaperecognizer/CircleRecognizer.cpp @@ -72,13 +72,13 @@ Stroke* CircleRecognizer::recognize(Stroke* stroke) { Inertia s; s.calc(stroke->getPoints(), 0, stroke->getPointCount()); - RDEBUG("Mass={1,p=0}, Center=({2,p=1},{3,p=1}, I=({4,p=0},{5,p=0}, {6,p=0}), Rad={7,p=2}, Det={8,p=4}") - % s.getMass() % s.centerX() % s.centerY() % s.xx() % s.yy() % s.xy() % s.rad() % s.det(); + RDEBUG("Mass=%.0f, Center=(%.1f,%.1f), I=(%.0f,%.0f, %.0f), Rad=%.2f, Det=%.4f", + s.getMass(), s.centerX(), s.centerY(), s.xx(), s.yy(), s.xy(), s.rad(), s.det()); if (s.det() > CIRCLE_MIN_DET) { double score = CircleRecognizer::scoreCircle(stroke, s); - RDEBUG("Circle score: {1,p=2}") % score; + RDEBUG("Circle score: %.2f", score); if (score < CIRCLE_MAX_SCORE) { return CircleRecognizer::makeCircleShape(stroke, s); diff --git a/src/control/shaperecognizer/ShapeRecognizer.cpp b/src/control/shaperecognizer/ShapeRecognizer.cpp index 1c85fee9..06346e7f 100644 --- a/src/control/shaperecognizer/ShapeRecognizer.cpp +++ b/src/control/shaperecognizer/ShapeRecognizer.cpp @@ -201,7 +201,7 @@ Stroke* ShapeRecognizer::tryArrow() alpha[i] -= M_PI; rs[i].reversed = !rs[i].reversed; } - RDEBUG("arrow: alpha[{1}] = {2,p=1} degrees") % i % (alpha[i] * 180 / M_PI); + RDEBUG("arrow: alpha[%d] = %.1f degrees", i, (alpha[i] * 180 / M_PI)); if (fabs(alpha[i]) < ARROW_ANGLE_MIN || fabs(alpha[i]) > ARROW_ANGLE_MAX) { return NULL; @@ -209,8 +209,7 @@ Stroke* ShapeRecognizer::tryArrow() } // check arrow head segments are roughly symmetric - if (alpha[1] * alpha[2] > 0 || - fabs(alpha[1] + alpha[2]) > ARROW_ASYMMETRY_MAX_ANGLE) + if (alpha[1] * alpha[2] > 0 || fabs(alpha[1] + alpha[2]) > ARROW_ASYMMETRY_MAX_ANGLE) { return NULL; } @@ -231,7 +230,7 @@ Stroke* ShapeRecognizer::tryArrow() { double dist = hypot(pt.x - (rs[j].reversed ? rs[j].x1 : rs[j].x2), pt.y - (rs[j].reversed ? rs[j].y1 : rs[j].y2)); - RDEBUG("linear tolerance: tip[{1}] = {2,p=2}") % j % (dist / rs[j].radius); + RDEBUG("linear tolerance: tip[%d] = %.2f", j, (dist / rs[j].radius)); if (dist > ARROW_TIP_LINEAR_TOLERANCE * rs[j].radius) { return NULL; @@ -241,7 +240,7 @@ Stroke* ShapeRecognizer::tryArrow() double dist = (pt.x - x2) * sin(angle) - (pt.y - y2) * cos(angle); dist /= rs[1].radius + rs[2].radius; - RDEBUG("sideways gap tolerance = {1,p=2}") % dist; + RDEBUG("sideways gap tolerance = %.2f", dist); if (fabs(dist) > ARROW_SIDEWAYS_GAP_TOLERANCE) { @@ -251,7 +250,7 @@ Stroke* ShapeRecognizer::tryArrow() dist = (pt.x - x2) * cos(angle) + (pt.y - y2) * sin(angle); dist /= rs[1].radius + rs[2].radius; - RDEBUG("main linear gap = {1,p=2}") % dist; + RDEBUG("main linear gap = %.2f", dist); if (dist < ARROW_MAIN_LINEAR_GAP_MIN || dist > ARROW_MAIN_LINEAR_GAP_MAX) { @@ -561,14 +560,13 @@ ShapeRecognizerResult* ShapeRecognizer::recognizePatterns(Stroke* stroke) { optimizePolygonal(stroke->getPoints(), n, brk, ss); #ifdef DEBUG_RECOGNIZER - cout << endl << boost::format("ShapeReco:: Polygon, %d edges:") % n << endl; + g_message("--"); + g_message("ShapeReco:: Polygon, %d edges:", n); for (int i = 0; i < n; i++) { - cout << boost::format("ShapeReco:: %d-%d (M=%.0f, det=%.4f)") - % brk[i] % brk[i + 1] % ss[i].getMass() % ss[i].det() - << endl; + g_message("ShapeReco:: %d-%d (M=%.0f, det=%.4f)", brk[i], brk[i + 1], ss[i].getMass(), ss[i].det()); } - cout << endl; + g_message("--"); #endif // update recognizer segment queue (most recent at end) while (n + queueLength > MAX_POLYGON_SIDES) @@ -583,7 +581,7 @@ ShapeRecognizerResult* ShapeRecognizer::recognizePatterns(Stroke* stroke) g_memmove(queue, queue + i, queueLength * sizeof(RecoSegment)); } - RDEBUG("Queue now has {1} + {2} edges") % this->queueLength % n; + RDEBUG("Queue now has %i + %i edges", this->queueLength, n); RecoSegment* rs = &this->queue[this->queueLength]; this->queueLength += n; diff --git a/src/control/shaperecognizer/ShapeRecognizerConfig.h b/src/control/shaperecognizer/ShapeRecognizerConfig.h index 3488a0fe..d490eeb5 100644 --- a/src/control/shaperecognizer/ShapeRecognizerConfig.h +++ b/src/control/shaperecognizer/ShapeRecognizerConfig.h @@ -34,22 +34,7 @@ #ifdef DEBUG_RECOGNIZER - -#include -using std::cout; -using std::endl; - -#define RDEBUG(msg) cout << bl::format(CONCAT("ShapeReco::", msg, "\n")) - +#define RDEBUG(msg, ...) g_message("ShapeReco::" msg, ##__VA_ARGS__) #else -class no_debug_format -{ -public: - template - no_debug_format& operator%(const T& x) - { - return *this; - } -}; -#define RDEBUG(msg) no_debug_format() +#define RDEBUG(msg, ...) #endif diff --git a/src/control/shaperecognizer/ShapeRecognizerResult.cpp b/src/control/shaperecognizer/ShapeRecognizerResult.cpp index 3c1ebb7b..d3129ad5 100644 --- a/src/control/shaperecognizer/ShapeRecognizerResult.cpp +++ b/src/control/shaperecognizer/ShapeRecognizerResult.cpp @@ -24,7 +24,7 @@ ShapeRecognizerResult::ShapeRecognizerResult(Stroke* result, ShapeRecognizer* re } } - RDEBUG("source list length: {1}") % this->source.size(); + RDEBUG("source list length: %i", (int)this->source.size()); } ShapeRecognizerResult::~ShapeRecognizerResult() @@ -44,9 +44,8 @@ void ShapeRecognizerResult::addSourceStroke(Stroke* s) { if (s == elem) { - // TODO LOW PRIO: this is a bug in the ShapreRecognizer!! - // g_warning("ShapeRecognizerResult::addSourceStroke() try to add a stroke twice!"); - // Stacktrace::printStracktrace(); + // this is a bug in the ShapreRecognizer + // Ignore return; } }