You are given the RGB values of a color. Your task is simple: to calculate the hue, in the simplest definition.
Say the channels with highest, middle and lowest value are X, Y, Z (which are either red, green or blue) and their values are x, y, z. The hue of this color is (h(X)-h(Y))*(1 + (x-y)/(x-z))/2 + h(Y), where:
h(red) = 0 (or 360 if one of X or Y is blue) h(green) = 120 h(blue) = 240
The input consists of 3 integers from 0 to 255 which are not all equal, in any consistent order. The output can be floats, or integers rounded either up or down, which doesn't have to be consistent. If the integer part of the output is 0 or 360, you can print either of them.
You cannot call builtins for color space conversions, including implicit conversions such as while manipulating an image.
This is code-golf. Shortest code wins.
Input: 0 182 255 Output: 197 (or 198) Input: 127 247 103 Output: 110 Input: 0 0 1 Output: 240 Input: 255 165 245 Output: 307 (or 306)
You don't have to follow the exact formula, but only have to give the same result as the above formula. I'd like to also see some answers golfing the formula itself.