From e00551288d06fc7d913aab6473dcab8fa9934410 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Thu, 3 Sep 2015 17:05:54 -0300 Subject: Code standardization and new builtin continuous color scales scheme. --- colorscale.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'colorscale.cpp') diff --git a/colorscale.cpp b/colorscale.cpp index 50fedae..85c036d 100644 --- a/colorscale.cpp +++ b/colorscale.cpp @@ -24,8 +24,9 @@ ColorScale::~ColorScale() void ColorScale::setExtents(qreal min, qreal max) { - if (min >= max) + if (min >= max) { return; + } m_min = min; m_max = max; @@ -48,23 +49,26 @@ static QColor lerp(const QColor &c1, const QColor &c2, qreal t) QColor ColorScale::color(qreal t) const { - if (t < m_min || t > m_max) + if (t < m_min || t > m_max) { return QColor(); + } // normalize t t = (t - m_min) / (m_max - m_min); // two colors, use a simpler solution - if (m_colors.size() == 2) + if (m_colors.size() == 2) { return lerp(m_colors.first(), m_colors.last(), t); + } // find which colors in the scale are adjacent to ours qreal step = 1.0 / m_colors.size(); int i = (int) (t / step); int j = i + 1; - if (i >= m_colors.size() - 1) + if (i >= m_colors.size() - 1) { return QColor(m_colors.last()); + } // normalize t between the two colors t = (t - i*step) / (j*step - i*step); -- cgit v1.2.3