MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / computeFreqTicks

Method computeFreqTicks

app/src/UI/Widgets/Waterfall.cpp:1198–1223  ·  view source on GitHub ↗

* @brief Picks a {1,2,5}*10^n step for a given range and target tick count. */

Source from the content-addressed store, hash-verified

1196 * @brief Picks a {1,2,5}*10^n step for a given range and target tick count.
1197 */
1198Widgets::Waterfall::AxisTicks Widgets::Waterfall::computeFreqTicks(double maxFreq, int targetCount)
1199{
1200 AxisTicks out{{}, 1.0, maxFreq};
1201 if (!std::isfinite(maxFreq) || maxFreq <= 0.0)
1202 return out;
1203
1204 const double target = std::max(2, targetCount);
1205 const double raw = maxFreq / target;
1206 const double base = fastPow10(std::floor(std::log10(raw)));
1207 const double cands[] = {1.0, 2.0, 5.0, 10.0};
1208
1209 double step = base;
1210 for (double c : cands) {
1211 if (raw <= c * base) {
1212 step = c * base;
1213 break;
1214 }
1215 }
1216
1217 out.step = step;
1218 out.displayMax = std::ceil(maxFreq / step) * step;
1219 for (double v = 0.0; v <= out.displayMax + 1e-6; v += step)
1220 out.values.push_back(v);
1221
1222 return out;
1223}
1224
1225/**
1226 * @brief Same algorithm as computeFreqTicks but for the seconds axis.

Callers

nothing calls this directly

Calls 5

isfiniteFunction · 0.85
floorFunction · 0.85
log10Function · 0.85
ceilFunction · 0.85
fastPow10Function · 0.70

Tested by

no test coverage detected