There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?
ConvertRgbToHsv(Color c) returns an HSV with the H component == NaN if all R,G, and B components are equal (eg. gray color). Here's how the implementation should look like, I guess:
double h = max == min ? 0
: max == r && g >= b ? 60 * (g - b) / (max - min)
: max == r && g < b ? 60 * (g - b) / (max - min) + 360
: max == g ? 60 * (b - r) / (max - min) + 120
: max == b ? 60 * (r - g) / (max - min) + 240 : 0;