Interesting question. This seems to work well.
extends Node2D
var hue_1: float = 0.1
var hue_2: float = 0.8
func _ready() -> void:
var answer: float = calculate_hue_difference(hue_1, hue_2)
print(answer)
func calculate_hue_difference(value_1: float, value_2: float) -> float:
return min(abs(value_1 - value_2), 1 - abs(value_1 - value_2))
# prints 0.3
But then I was thinking what if you wanted to do it with wrapping of more than 1.0, so added the max option.
func _ready() -> void:
var answer: float = calculate_hue_difference(hue_1, hue_2, 2.0)
print(answer)
func calculate_hue_difference(value_1: float, value_2: float, max_value: float = 1.0) -> float:
return min(abs(value_1 - value_2), max_value - abs(value_1 - value_2))
But I think the first version is fine for just hue’s. (You may want to add a verification that the two values are less than 1, otherwise it can return a -ve number in some cases.)
Hope that helps, not sure it is the best way but it seems to work when I tested it.