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);
void SignalDrawer::drawLeadingSubticks(const RulerDrawData& rd, std::function<void (const double, const double, const TickType)> 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);
}
void SignalDrawer::drawScaleBySubticks(const RulerDrawData& rd, std::function<void (const double, const double, const TickType)> 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);
}
}
/* Draw subticks ticks */
if (drawSubTicks)
- drawScaleBySubticks(rd, drawFunc, rel, absVal, rel + rd.relStep);
+ drawScaleBySubticks(rd, drawFunc, rel + subStep(rd.relStep), absVal, rel + rd.relStep);
absVal += rd.step;
}
}
}
+double SignalDrawer::subStep(const double step)
+{
+ return step / 10;
+}
+
SignalDrawer::~SignalDrawer()
{
delete m_pixmap;