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

Method emitColumns

app/src/UI/Widgets/PlotAreaFill.cpp:394–444  ·  view source on GitHub ↗

* @brief Emits one six-vertex column per filled column (peak quad above the baseline, * valley quad below, sharing the baseline edge where the alpha pinches to * kMinAlpha), stitched into a single strip with two degenerate vertices. */

Source from the content-addressed store, hash-verified

392 * kMinAlpha), stitched into a single strip with two degenerate vertices.
393 */
394void Widgets::PlotAreaFill::emitColumns(QSGGeometry::ColoredPoint2D* vertices,
395 const int vertexCount,
396 const double w,
397 const double h,
398 const double refPositive,
399 const double refNegative) const
400{
401 Q_ASSERT(vertices != nullptr);
402 Q_ASSERT(refPositive > 0.0);
403 Q_ASSERT(refNegative > 0.0);
404
405 const double sy = h / (m_yMax - m_yMin);
406 const float base_y = static_cast<float>((m_yMax - m_baseline) * sy);
407
408 auto ramp = [](const double dev, const double ref) -> double {
409 return kMinAlpha + (kMaxAlpha - kMinAlpha) * std::min(1.0, dev / ref);
410 };
411
412 int j = 0;
413 const std::size_t cols = m_colMin.size();
414 for (std::size_t c = 0; c < cols; ++c) {
415 const double lo = m_colMin[c];
416 const double hi = m_colMax[c];
417 if (hi < lo)
418 continue;
419
420 const double a_top = hi > m_baseline ? ramp(hi - m_baseline, refPositive) : kMinAlpha;
421 const double a_bot = lo < m_baseline ? ramp(m_baseline - lo, refNegative) : kMinAlpha;
422
423 const float x0 = static_cast<float>(c);
424 const float x1 = static_cast<float>(std::min(static_cast<double>(c + 1), w));
425 const float y_top = static_cast<float>((m_yMax - std::max(hi, m_baseline)) * sy);
426 const float y_bot = static_cast<float>((m_yMax - std::min(lo, m_baseline)) * sy);
427
428 if (j > 0) {
429 vertices[j] = vertices[j - 1];
430 ++j;
431 setVertexColor(vertices[j++], x0, y_top, m_fillColor, a_top);
432 }
433
434 setVertexColor(vertices[j++], x0, y_top, m_fillColor, a_top);
435 setVertexColor(vertices[j++], x1, y_top, m_fillColor, a_top);
436 setVertexColor(vertices[j++], x0, base_y, m_fillColor, kMinAlpha);
437 setVertexColor(vertices[j++], x1, base_y, m_fillColor, kMinAlpha);
438 setVertexColor(vertices[j++], x0, y_bot, m_fillColor, a_bot);
439 setVertexColor(vertices[j++], x1, y_bot, m_fillColor, a_bot);
440 }
441
442 Q_ASSERT(j == vertexCount);
443 Q_UNUSED(vertexCount)
444}
445
446/**
447 * @brief Rebuilds the fill from the per-column envelopes: one O(points) accumulation

Callers

nothing calls this directly

Calls 2

setVertexColorFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected