From 28819076a6651899a65504520d2c48f00f104f26 Mon Sep 17 00:00:00 2001 From: Vera Abramova Date: Mon, 14 Mar 2022 10:44:22 +0200 Subject: [PATCH] refactor: minor nits --- src/circles.rs | 6 +++--- src/colors.rs | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/circles.rs b/src/circles.rs index e47dffb..6bdaaf7 100644 --- a/src/circles.rs +++ b/src/circles.rs @@ -176,11 +176,11 @@ pub fn calculate_png_data(size_in_pixels: u16, colors: [Color; 19]) -> Vec { } } match some_small_circle { - Some(color) => data.extend_from_slice(&color.to_slice()), - None => data.extend_from_slice(&big_circle.rgba_color.to_slice()), + Some(color) => data.extend_from_slice(&color.to_array()), + None => data.extend_from_slice(&big_circle.rgba_color.to_array()), } } else { - data.extend_from_slice(&Color::background().to_slice()) + data.extend_from_slice(&Color::background().to_array()) } } } diff --git a/src/colors.rs b/src/colors.rs index ac15b14..a8f60e4 100644 --- a/src/colors.rs +++ b/src/colors.rs @@ -59,11 +59,12 @@ pub struct Color { } impl Color { - /// convert `Color` into slice, for `png` image pixel-by-pixel generation + /// convert `Color` into `[u8; 4]` array, for `png` image pixel-by-pixel generation #[cfg(feature = "pix")] - pub fn to_slice(&self) -> [u8; 4] { + pub fn to_array(&self) -> [u8; 4] { [self.red, self.green, self.blue, self.alpha] } + /// convert `Color` into hex string, for `svg` image generation #[cfg(feature = "vec")] pub fn to_hex(&self) -> String { @@ -72,6 +73,7 @@ impl Color { hex::encode([self.red, self.green, self.blue]) ) } + /// set `Color` to default background, needed only for `png` images #[cfg(feature = "pix")] pub fn background() -> Self { @@ -82,6 +84,7 @@ impl Color { alpha: 0, } } + /// set `Color` to default color of the large circle enclosing the small ones pub fn foreground() -> Self { Self { @@ -91,6 +94,7 @@ impl Color { alpha: 255, } } + /// function to derive color from `u8` number and saturation component /// calculated elsewhere; /// is accessible and used only for `u8` numbers other than 0 and 255; @@ -222,7 +226,7 @@ pub fn get_colors(into_id: &[u8]) -> [Color; 19] { fn choose_scheme(schemes: [SchemeElement; 7], d: u32) -> SchemeElement { let mut sum = 0; let mut found_scheme = None; - for x in schemes.into_iter() { + for x in schemes { sum += x.freq as u32; if d < sum { found_scheme = Some(x);