Description
Hi,
While validating the DeltaE
function of this package against several established implementations (including colormath (Python), palette (Rust), and my own implementation at michel-leonard/ciede2000-color-matching), I noticed a systematic deviation in go-colorful
’s results.
Here, the root cause is in the handling of the mean hue angle (hpmean
) when the absolute difference between hp1
and hp2
exceeds 180°:
if math.Abs(hp1-hp2) > 180 {
if hp1+hp2 < 360 {
hpmean += 180
} else {
hpmean -= 180
}
}
This condition incorrectly biases the angular correction and leads to a noticeable precision error, especially in edge cases near the 0°/360° boundary.
Fix:
According to the original paper by Sharma et al. (2005), the correct approach is simply:
if math.Abs(hp1-hp2) > 180 {
hpmean += 180
}
This change alone brings the precision of the DeltaE
function back in line with the reference implementations (error < 1e-12). I've tested this over 100 million randomized samples with perfect numerical consistency.
Please let me know if you'd like me to submit a PR with the fix and a corresponding unit test.
Thanks for maintaining this useful library!
Best,
Michel