diff options
author | Samuel Fadel <samuel@nihil.ws> | 2023-06-04 13:02:14 +0200 |
---|---|---|
committer | Samuel Fadel <samuel@nihil.ws> | 2023-06-04 13:02:14 +0200 |
commit | fb23c8d47f6dcef429423256d8dddcc0f7184fc4 (patch) | |
tree | 34e0032f28df5807e4abd90d6b1b4baad24d2991 /continuouscolorscale.cpp | |
parent | 0f34fd437efb936ef29ac91186321aa7251fbfb1 (diff) |
Further advances in nuklear port.
Rendering now looks similar to Qt version, needs a few tweaks:
* Proper multisampling
* Background
Missing features:
* Barcharts
* Interactivity (e.g. brushing/linking in all objects)
* History view of interactions
Diffstat (limited to 'continuouscolorscale.cpp')
-rw-r--r-- | continuouscolorscale.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/continuouscolorscale.cpp b/continuouscolorscale.cpp index c729c6b..b7f2c93 100644 --- a/continuouscolorscale.cpp +++ b/continuouscolorscale.cpp @@ -9,8 +9,12 @@ ContinuousColorScale::ContinuousColorScale(std::initializer_list<QColor> colors) QColor ContinuousColorScale::color(float t) const { - if (t < m_min || t > m_max) { - return Color(); + if (t <= m_min) { + return m_colors.front(); + } + + if (t >= m_max) { + return m_colors.back(); } // normalize t @@ -18,14 +22,10 @@ QColor ContinuousColorScale::color(float t) const // find which colors in the scale are adjacent to ours float step = 1.0 / m_colors.size(); - int i = static_cast<int>(t / step); - - if (i >= m_colors.size() - 1) { - return m_colors.back(); - } + size_t i = static_cast<size_t>(t * m_colors.size()); // normalize t between the two colors - int j = i + 1; + size_t j = i + 1; t = (t - i*step) / (j*step - i*step); return m_colors[i + round(t)]; } |