From 665821700b70f74b0fed9ceb745862afe3bcb9c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Tue, 14 Jan 2025 06:08:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=AD=A3=E9=80=86=E5=90=91=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E6=97=B6=E5=BD=93=E9=A2=9C=E8=89=B2=E5=88=86=E9=87=8F?= =?UTF-8?q?=E4=B8=BA=E9=9B=B6=E6=97=B6=E7=9A=84=E5=A4=84=E7=90=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- color-module/src/reversing.rs | 36 +++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/color-module/src/reversing.rs b/color-module/src/reversing.rs index c9e364f..90137c6 100644 --- a/color-module/src/reversing.rs +++ b/color-module/src/reversing.rs @@ -13,9 +13,21 @@ pub struct MixReversing { impl MixReversing { pub fn from_tint_rgb(basic_color: Rgb, mixed_result: Rgb) -> Self { - let r_factor = (mixed_result.red - basic_color.red) / (1.0 - basic_color.red); - let g_factor = (mixed_result.green - basic_color.green) / (1.0 - basic_color.green); - let b_factor = (mixed_result.blue - basic_color.blue) / (1.0 - basic_color.blue); + let r_factor = if basic_color.red == 1.0 { + 0.0 + } else { + (mixed_result.red - basic_color.red) / (1.0 - basic_color.red) + }; + let g_factor = if basic_color.green == 1.0 { + 0.0 + } else { + (mixed_result.green - basic_color.green) / (1.0 - basic_color.green) + }; + let b_factor = if basic_color.blue == 1.0 { + 0.0 + } else { + (mixed_result.blue - basic_color.blue) / (1.0 - basic_color.blue) + }; let average = (r_factor + g_factor + b_factor) / 3.0; MixReversing { @@ -27,9 +39,21 @@ impl MixReversing { } pub fn from_shade_rgb(basic_color: Rgb, mixed_result: Rgb) -> Self { - let r_factor = (basic_color.red - mixed_result.red) / (0.0 - basic_color.red); - let g_factor = (basic_color.green - mixed_result.green) / (0.0 - basic_color.green); - let b_factor = (basic_color.blue - mixed_result.blue) / (0.0 - basic_color.blue); + let r_factor = if basic_color.red == 0.0 { + 0.0 + } else { + (basic_color.red - mixed_result.red) / (0.0 - basic_color.red) + }; + let g_factor = if basic_color.green == 0.0 { + 0.0 + } else { + (basic_color.green - mixed_result.green) / (0.0 - basic_color.green) + }; + let b_factor = if basic_color.blue == 0.0 { + 0.0 + } else { + (basic_color.blue - mixed_result.blue) / (0.0 - basic_color.blue) + }; let average = (r_factor + g_factor + b_factor) / 3.0; MixReversing {