From a7c1a4ad4e39d59785f312e86d1ddb339f20bb09 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Fri, 10 Oct 2014 17:32:20 +0200 Subject: [PATCH] Fix tick drawing logic --- signalcontroller.cpp | 11 ++++++++--- signaldrawer.cpp | 23 ++++++++++++++--------- signaldrawer.h | 1 + 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/signalcontroller.cpp b/signalcontroller.cpp index 87913bc..da3e5c3 100644 --- a/signalcontroller.cpp +++ b/signalcontroller.cpp @@ -192,11 +192,16 @@ RulerDrawData SignalController::getRulerDrawData(const double from, const double diffAbs = toAbs - fromAbs; step = 1 / pow(10, floor(log10(1 / (diffAbs))) + 1); // Magic - you want to love it but you better not touch! relStep = (diffRel * step) / (diffAbs); - //qDebug() << __QFUNC__ << "Step" << step << "RelStep" << relStep << "relDiff" << diffRel; + //qDebug() << __QFUNC__ << "Step" << step << "RelStep" << relStep << "relDiff" << diffRel << fromAbs; /* Calculate position of the first major tick */ - firstTickAbs = ceil(fromAbs / step) * step; - firstTickRel = (diffRel / diffAbs) * (firstTickAbs - fromAbs) + from; + if (from == 0.0) { + firstTickAbs = fromAbs; + firstTickRel = from; + } else { + firstTickAbs = fromAbs + (step - fmod(fromAbs, step)); + firstTickRel = from + (relStep - fmod(from, relStep)); + } //qDebug() << __QFUNC__ << "First tick Abs:" << firstTickAbs << "Rel:" << firstTickRel; return RulerDrawData(firstTickAbs, firstTickRel, step, relStep); diff --git a/signaldrawer.cpp b/signaldrawer.cpp index a68ee0c..f74546a 100644 --- a/signaldrawer.cpp +++ b/signaldrawer.cpp @@ -229,10 +229,10 @@ bool SignalDrawer::drawPeaks(QPixmap* const target) void SignalDrawer::drawLeadingSubticks(const RulerDrawData& rd, std::function drawFunc, const double relMin) { - double subRelMin = rd.firstTickRel; - double subAbsMin = rd.firstTickAbs; - while ((subRelMin -= rd.relStep / 10) >= relMin) - subAbsMin -= rd.step / 10; + const double subRelStep = subStep(rd.relStep); + const double subRelRem = fmod(relMin, subRelStep); + const double subRelMin = relMin + (subRelStep - subRelRem); + const double subAbsMin = (rd.firstTickRel - subRelMin) * (subStep(rd.step)) / subRelStep; drawScaleBySubticks(rd, drawFunc, subRelMin, subAbsMin, rd.firstTickRel); } @@ -240,17 +240,17 @@ void SignalDrawer::drawLeadingSubticks(const RulerDrawData& rd, std::function drawFunc, const double fromSubRel, const double fromAbsVal, const double toSubRel) { - const double subRelStep = rd.relStep / 10; - const double subAbsStep = rd.step / 10; + const double subRelStep = subStep(rd.relStep); + const double subAbsStep = subStep(rd.step); double subRel = fromSubRel; double absVal = fromAbsVal; - int ctr = 11 - ((toSubRel - fromSubRel) / subRelStep); + int ctr = 10 - ((toSubRel - fromSubRel) / subRelStep); while (subRel < toSubRel) { + drawFunc(subRel, absVal, (ctr++ == 5) ? TickType::TICK : TickType::SUBTICK); subRel += subRelStep; absVal += subAbsStep; - drawFunc(subRel, absVal, (ctr++ == 5) ? TickType::TICK : TickType::SUBTICK); } } @@ -262,7 +262,7 @@ void SignalDrawer::drawScaleByTicks(const RulerDrawData& rd, std::function