diff options
-rw-r--r-- | colorscale.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/colorscale.cpp b/colorscale.cpp index f41e7d9..f5afcbb 100644 --- a/colorscale.cpp +++ b/colorscale.cpp @@ -1,5 +1,9 @@ #include "colorscale.h" +#include <cmath> + +const float EPSILON = 1e-3f; + ColorScale::ColorScale(const QColor &firstColor, const QColor &lastColor) : m_colors{{firstColor, lastColor}} { @@ -62,6 +66,14 @@ QColor ColorScale::color(float t) const return lerp(m_colors.first(), m_colors.last(), t); } + if (fabs(t - m_min) < EPSILON) { + return m_colors.first(); + } + + if (fabs(t - m_max) < EPSILON) { + return m_colors.last(); + } + // find which colors in the scale are adjacent to ours int i = int(t * m_colors.size()); int j = i + 1; |