Browse Source

Fixed Color::FromHCM(). Closes #216.

Lasse Öörni 11 years ago
parent
commit
69690d367f
1 changed files with 5 additions and 4 deletions
  1. 5 4
      Source/Engine/Math/Color.cpp

+ 5 - 4
Source/Engine/Math/Color.cpp

@@ -66,9 +66,9 @@ void Color::FromHSL(float h, float s, float l, float a)
 {
 {
     float c;
     float c;
     if (l < 0.5f)
     if (l < 0.5f)
-        c = (1.0f + (2.0f*l - 1.0f)) * s;
+        c = (1.0f + (2.0f * l - 1.0f)) * s;
     else
     else
-        c = (1.0f - (2.0f*l - 1.0f)) * s;
+        c = (1.0f - (2.0f * l - 1.0f)) * s;
 
 
     float m = l - 0.5f * c;
     float m = l - 0.5f * c;
 
 
@@ -278,10 +278,11 @@ float Color::SaturationHSL(float min, float max) const
 
 
 void Color::FromHCM(float h, float c, float m)
 void Color::FromHCM(float h, float c, float m)
 {
 {
-    assert(h >= 0.0f && h < 1.0f);
+    if (h < 0.0f || h >= 1.0f)
+        h -= floorf(h);
 
 
     float hs = h * 6.0f;
     float hs = h * 6.0f;
-    float x  = c * (1.0f - (hs - std::floor(hs / 2.0f)*2.0f- 1.0f));
+    float x  = c * (1.0f - Abs(fmodf(hs, 2.0f) - 1.0f));
 
 
     // reconstruct r', g', b' from hue
     // reconstruct r', g', b' from hue
     if (hs < 2.0f)
     if (hs < 2.0f)