Skip to content

Commit

Permalink
refactor: minor nits
Browse files Browse the repository at this point in the history
  • Loading branch information
varovainen committed Mar 14, 2022
1 parent 13e41cb commit 2881907
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/circles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ pub fn calculate_png_data(size_in_pixels: u16, colors: [Color; 19]) -> Vec<u8> {
}
}
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())
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2881907

Please sign in to comment.