#import <qthing.h>
#include <cmath>

namespace qthing {
  // TODO: should return RGB once that can be casted to RGBW
  RGBW hue(const float hue, const float value) {
      RGBW color;

      if (value <= 0) {
          return color;
      }

      auto h = fmod(hue, 1);
      if (h < 0) {
        h += 1;
      }

      h = h * 3;
      auto v = value > 1 ? 1 : value;
      if (h < 1) {
          color.r = (1 - h) * v;
          color.g = h * v;
      }
      else if (h < 2) {
          h -= 1;
          color.g = (1 - h) * v;
          color.b = h * v;
      }
      else {
          h -= 2;
          color.b = (1 - h) * v;
          color.r = h * v;
      }
      return color;
  }
}