From dbd5e7ab6b3d1d115bd022063840a1d7d97f1db5 Mon Sep 17 00:00:00 2001 From: Francesco Giordana Date: Mon, 4 Apr 2022 18:59:00 +0000 Subject: [PATCH] Fixed case of R == G, following original conversion formula (#4383) https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB # Objective Fixes #4382 ## Solution - Describe the solution used to achieve the objective above. Fixed conversion formula to account for red and green component being max and equal --- ## Changelog Fixed RGB -> HSL colorspace conversion ## Migration Guide Co-authored-by: Francesco Giordana --- crates/bevy_render/src/color/colorspace.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/color/colorspace.rs b/crates/bevy_render/src/color/colorspace.rs index 43d3f7986f3c8..3e726315d5d40 100644 --- a/crates/bevy_render/src/color/colorspace.rs +++ b/crates/bevy_render/src/color/colorspace.rs @@ -72,9 +72,9 @@ impl HslRepresentation { let lightness = (x_max + x_min) / 2.0; let hue = if chroma == 0.0 { 0.0 - } else if red > green && red > blue { + } else if red == x_max { 60.0 * (green - blue) / chroma - } else if green > red && green > blue { + } else if green == x_max { 60.0 * (2.0 + (blue - red) / chroma) } else { 60.0 * (4.0 + (red - green) / chroma)