From 2f7833765325a6272d1c5a539b2a419666d92ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=BD=B3=E6=B6=9B?= Date: Sat, 6 May 2023 10:21:25 +0800 Subject: [PATCH] fix: improve rgb2hsv precision --- README.md | 4 ++-- src/conversion/hsv.rs | 2 +- tests/color_channel.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 620758d..559bcd6 100644 --- a/README.md +++ b/README.md @@ -189,8 +189,8 @@ color.saturation(); // 0.68 color.lightness(); // 0.8039 color.hsv_hue(); // 210.0 -color.hsv_saturation(); // 0.28 -color.hsv_value(); // 0.94 +color.hsv_saturation(); // 0.2845 +color.hsv_value(); // 0.9373 color.luma(); // 0.59 color.luminance(); // 0.79 diff --git a/src/conversion/hsv.rs b/src/conversion/hsv.rs index f39a1e3..7a4ab14 100644 --- a/src/conversion/hsv.rs +++ b/src/conversion/hsv.rs @@ -50,7 +50,7 @@ pub fn rgb2hsv(color: (f64, f64, f64)) -> (f64, f64, f64) { s = delta / max; } - (round(h, 2), round(s, 2), round(v, 2)) + (round(h, 4), round(s, 4), round(v, 4)) } #[cfg(test)] diff --git a/tests/color_channel.rs b/tests/color_channel.rs index a5dce75..63074d4 100644 --- a/tests/color_channel.rs +++ b/tests/color_channel.rs @@ -15,8 +15,8 @@ fn test_color_channel() { assert_eq!(color.lightness(), 0.8039); assert_eq!(color.hsv_hue(), 210.0); - assert_eq!(color.hsv_saturation(), 0.28); - assert_eq!(color.hsv_value(), 0.94); + assert_eq!(color.hsv_saturation(), 0.2845); + assert_eq!(color.hsv_value(), 0.9373); assert_eq!(color.luma(), 0.59); assert_eq!(color.luminance(), 0.79);