From e7e10f2c0fc8a88793d78c6423b4172fe856aafe Mon Sep 17 00:00:00 2001 From: Ben Frankel Date: Thu, 25 Jul 2024 22:44:18 +0300 Subject: [PATCH] Fix hue mixing for `Lcha` and `Oklcha` (#14468) # Objective Fix erroneous hue mixing in `Lcha` and `Oklcha`. Purple + Red == Green is the current behavior. ## Solution Use `crate::color_ops::lerp_hue` to handle the wrap-around at 360 degrees, the same way that `Hsla`, `Hsva`, and `Hwba` do it. ## Testing Game jamming, but tested that the workaround below produces correct-looking colors in my jam game. --- crates/bevy_color/src/lcha.rs | 2 +- crates/bevy_color/src/oklcha.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_color/src/lcha.rs b/crates/bevy_color/src/lcha.rs index b1b63c91ac..e372ff492a 100644 --- a/crates/bevy_color/src/lcha.rs +++ b/crates/bevy_color/src/lcha.rs @@ -118,7 +118,7 @@ impl Mix for Lcha { Self { lightness: self.lightness * n_factor + other.lightness * factor, chroma: self.chroma * n_factor + other.chroma * factor, - hue: self.hue * n_factor + other.hue * factor, + hue: crate::color_ops::lerp_hue(self.hue, other.hue, factor), alpha: self.alpha * n_factor + other.alpha * factor, } } diff --git a/crates/bevy_color/src/oklcha.rs b/crates/bevy_color/src/oklcha.rs index 08f3fac908..165fa0af95 100644 --- a/crates/bevy_color/src/oklcha.rs +++ b/crates/bevy_color/src/oklcha.rs @@ -114,7 +114,7 @@ impl Mix for Oklcha { Self { lightness: self.lightness * n_factor + other.lightness * factor, chroma: self.chroma * n_factor + other.chroma * factor, - hue: self.hue * n_factor + other.hue * factor, + hue: crate::color_ops::lerp_hue(self.hue, other.hue, factor), alpha: self.alpha * n_factor + other.alpha * factor, } }