Well based upon Taw4, i wrote a function that included the HSL hue math.
Its not the onliner check, which i think exists using a mod calculation.
And well i do was looking for that one, but i dont remember it.
I rewrote the logic of the link from Taw4 a bit.
I wrote this as part of my function that checks if an
RGB color is within an HSL range, the S and L factors are quite easy, but i the H got me troubled. I just post the whole thing here, just in case someone needs it.
private Boolean RGBInHSLRange
(int r, int g, int b,
int h,int s,int l,
int RH, int RS, int RL)
{ // r,g,b colors
// h,s,l colors
// ranges for HSL in RH,RS,RL
// note color math is usually done in floats not integers
// if you need floats do a float conversion instead of int
// for me int ewas enough
Color myColor = Color.FromArgb(r, g, b);
int HSLhue = (int)myColor.GetHue();
int HSLsat = (int)(myColor.GetSaturation() * 100);
int HSLlight = (int)(myColor.GetBrightness() * 100);
if (( HSLlight < h -RL) ^ ( HSLlight > h +RL)) return false;
if (( HSLsat < s - RS) ^ ( HSLsat > s + RS)) return false;
int distance = Math.Abs(h - HSLhue);
if (distance > 180) distance = 360 - distance;
if (distance > RH) return false;
return true;
}