Browse Source

Merge pull request #1399 from evouga/hsv

Allows hsv_to_rgb to work on negative hues
Jérémie Dumas 6 years ago
parent
commit
56f129e440
2 changed files with 3 additions and 2 deletions
  1. 2 1
      include/igl/hsv_to_rgb.cpp
  2. 1 1
      include/igl/hsv_to_rgb.h

+ 2 - 1
include/igl/hsv_to_rgb.cpp

@@ -25,7 +25,8 @@ IGL_INLINE void igl::hsv_to_rgb(
   // From medit
   double f,p,q,t,hh;
   int    i;
-  hh = ((int)h % 360) / 60.;
+  // shift the hue to the range [0, 360] before performing calculations
+  hh = ((360 + ((int)h % 360)) % 360) / 60.;
   i = (int)std::floor(hh);    /* largest int <= h     */
   f = hh - i;                    /* fractional part of h */
   p = v * (1.0 - s);

+ 1 - 1
include/igl/hsv_to_rgb.h

@@ -14,7 +14,7 @@ namespace igl
   // Convert RGB to HSV
   //
   // Inputs:
-  //   h  hue value (degrees: [0,360])
+  //   h  hue value (degrees: [0,360]. Values outside this range will be mapped periodically to [0,360].)
   //   s  saturation value ([0,1])
   //   v  value value ([0,1])
   // Outputs: