From e98849249a3db3aeba8d788a2cd8b3a64b1b775e Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Fri, 22 Feb 2019 16:14:34 +0100 Subject: [PATCH] simplify/fix color interpolation --- rviz_marker_tools/src/marker_creation.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rviz_marker_tools/src/marker_creation.cpp b/rviz_marker_tools/src/marker_creation.cpp index 5ed8994e..3f8a8937 100644 --- a/rviz_marker_tools/src/marker_creation.cpp +++ b/rviz_marker_tools/src/marker_creation.cpp @@ -104,16 +104,18 @@ std_msgs::ColorRGBA &setColor(std_msgs::ColorRGBA &color, Color color_id, double return color; } +// interpolate between start and end with fraction in range from 0..1 double interpolate(double start, double end, double fraction) { - return start * fraction + end * (1.0 - fraction); + return start * (1.0 - fraction) + end * fraction; } std_msgs::ColorRGBA& interpolate(std_msgs::ColorRGBA& color, const std_msgs::ColorRGBA& other, double fraction) { if (fraction < 0.0) fraction = 0.0; if (fraction > 1.0) fraction = 1.0; - color.r += interpolate(other.r-color.r, other.r, fraction); - color.g += interpolate(other.g-color.g, other.g, fraction); - color.b += interpolate(other.b-color.b, other.b, fraction); + color.r = interpolate(color.r, other.r, fraction); + color.g = interpolate(color.g, other.g, fraction); + color.b = interpolate(color.b, other.b, fraction); + color.a = interpolate(color.a, other.a, fraction); return color; }