Skip to content

Commit

Permalink
refactor: remove build warnings (closes #17)
Browse files Browse the repository at this point in the history
  • Loading branch information
InioX committed Sep 17, 2023
1 parent 153e456 commit 96df512
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 50 deletions.
7 changes: 4 additions & 3 deletions material-color-utilities-rs/src/htc/cam16.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Fully ported

use crate::htc::viewing_conditions::ViewingConditions;
use crate::util::color::{argb_from_xyz, linearized, xyz_from_argb};
use crate::util::color::{argb_from_xyz, xyz_from_argb};
use crate::util::math::matrix_multiply;
use std::f64::consts::PI;

Expand Down Expand Up @@ -37,8 +37,8 @@ impl Cam16 {
let d_a = self.astar() - other.astar();
let d_b = self.bstar() - other.bstar();
let d_eprime = (d_j * d_j + d_a * d_a + d_b * d_b).sqrt();
let d_e = 1.41 * d_eprime.powf(0.63);
d_e

1.41 * d_eprime.powf(0.63)
}

/// Hue in CAM16
Expand Down Expand Up @@ -116,6 +116,7 @@ impl Cam16 {
/// * `jstar`: CAM16-UCS J coordinate
/// * `astar`: CAM16-UCS a coordinate
/// * `bstar`: CAM16-UCS b coordinate
#[allow(dead_code)]
fn new(
hue: f64,
chroma: f64,
Expand Down
2 changes: 1 addition & 1 deletion material-color-utilities-rs/src/palettes/tonal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl TonalPalette {
*cached
} else {
let color = Hct::from(self.hue, self.chroma, tone as f64).to_int();
self.cache.insert(tone, color.clone());
self.cache.insert(tone, color);
color
}
}
Expand Down
4 changes: 2 additions & 2 deletions material-color-utilities-rs/src/quantize/quantizer_wsmeans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl QuantizerWsmeans {
}

let mut cluster_count = max_colors.min(point_count);
if starting_clusters.len() > 0 {
if !starting_clusters.is_empty() {
cluster_count = cluster_count.min(starting_clusters.len())
}

Expand All @@ -77,7 +77,7 @@ impl QuantizerWsmeans {
);

let additional_clusters_needed = cluster_count - clusters.len();
if starting_clusters.len() == 0 && additional_clusters_needed > 0 {
if starting_clusters.is_empty() && additional_clusters_needed > 0 {
for _ in 0..additional_clusters_needed {
let l = rand::random::<f64>() * 100.0;
let a = rand::random::<f64>() * (100.0 - (-100.0) + 1.0) + -100.0;
Expand Down
14 changes: 7 additions & 7 deletions material-color-utilities-rs/src/quantize/quantizer_wu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ where
T: AsPrimitive<usize>,
{
fn inner(r: usize, g: usize, b: usize) -> usize {
((r << (INDEX_BITS * 2)) + (r << (INDEX_BITS + 1)) + r + (g << INDEX_BITS) + g + b).into()
(r << (INDEX_BITS * 2)) + (r << (INDEX_BITS + 1)) + r + (g << INDEX_BITS) + g + b
}
inner(r.as_(), g.as_(), b.as_())
}
Expand Down Expand Up @@ -122,7 +122,7 @@ impl QuantizerWu {
(blue >> BITS_TO_REMOVE) + 1,
);

let (red, green, blue, count) = (red as u32, green as u32, blue as u32, count as u32);
let (red, green, blue, count) = (red as u32, green as u32, blue as u32, count);

self.weights[index] += count;
self.moments_r[index] += count * red;
Expand Down Expand Up @@ -230,15 +230,15 @@ impl QuantizerWu {
fn create_result(&self, color_count: usize) -> Vec<ARGB> {
Vec::from_iter((0..color_count).filter_map(|i| {
let cube = &self.cubes[i];
let weight = self.volume(&cube, &self.weights);
let weight = self.volume(cube, &self.weights);

if weight == 0 {
return None;
}

let r = self.volume(&cube, &self.moments_r) / weight;
let g = self.volume(&cube, &self.moments_g) / weight;
let b = self.volume(&cube, &self.moments_b) / weight;
let r = self.volume(cube, &self.moments_r) / weight;
let g = self.volume(cube, &self.moments_g) / weight;
let b = self.volume(cube, &self.moments_b) / weight;

Some([0xff, r as u8, g as u8, b as u8])
}))
Expand Down Expand Up @@ -316,7 +316,7 @@ impl QuantizerWu {
}
};

two.pixels.1 = one.pixels.1.clone();
two.pixels.1 = one.pixels.1;

match direction {
Direction::Red => {
Expand Down
23 changes: 7 additions & 16 deletions src/util/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl SchemeExt for Scheme {
"inverse_surface" => &self.inverse_surface,
"inverse_on_surface" => &self.inverse_on_surface,
"inverse_primary" => &self.inverse_primary,
"source_color" => &source_color,
"source_color" => source_color,
_ => panic!(),
}
}
Expand All @@ -124,7 +124,7 @@ pub trait SchemeAndroidExt {
impl SchemeAndroidExt for SchemeAndroid {
fn get_value<'a>(&'a self, field: &str, source_color: &'a [u8; 4]) -> &[u8; 4] {
match field {
"source_color" => &source_color,
"source_color" => source_color,
"color_accent_primary" => &self.color_accent_primary,
"color_accent_primary_variant" => &self.color_accent_primary_variant,
"color_accent_secondary" => &self.color_accent_secondary,
Expand Down Expand Up @@ -184,7 +184,7 @@ pub fn show_color(schemes: &Schemes, source_color: &[u8; 4]) {
let color_amoled: Color =
Color::new(*Scheme::get_value(&schemes.amoled, field, source_color));

generate_table_rows(&mut table, &field, color_light, color_dark, color_amoled);
generate_table_rows(&mut table, field, color_light, color_dark, color_amoled);
}

let mut table_android: Table = generate_table_format();
Expand All @@ -208,7 +208,7 @@ pub fn show_color(schemes: &Schemes, source_color: &[u8; 4]) {

generate_table_rows(
&mut table_android,
&field,
field,
color_light,
color_dark,
color_amoled,
Expand Down Expand Up @@ -362,15 +362,12 @@ fn generate_table_rows(
Cell::new(field).style_spec(""),
// Light scheme
Cell::new(
format!(
"{}",
format_argb_as_rgb([
format_argb_as_rgb([
color_light.alpha,
color_light.red,
color_light.green,
color_light.blue
])
)
.to_uppercase()
.as_str(),
)
Expand All @@ -379,15 +376,12 @@ fn generate_table_rows(
.style_spec("c"),
// Dark scheme
Cell::new(
format!(
"{}",
format_argb_as_rgb([
format_argb_as_rgb([
color_dark.alpha,
color_dark.red,
color_dark.green,
color_dark.blue
])
)
.to_uppercase()
.as_str(),
)
Expand All @@ -396,15 +390,12 @@ fn generate_table_rows(
.style_spec("c"),
// Amoled theme
Cell::new(
format!(
"{}",
format_argb_as_rgb([
format_argb_as_rgb([
color_amoled.alpha,
color_amoled.red,
color_amoled.green,
color_amoled.blue
])
)
.to_uppercase()
.as_str(),
)
Expand Down
10 changes: 5 additions & 5 deletions src/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ impl ConfigFile {
};

match toml::from_str(&content) {
Ok(res) => return Ok(res),
Err(e) => return Err(Report::new(e).suggestion(ERROR_TEXT)),
Ok(res) => Ok(res),
Err(e) => Err(Report::new(e).suggestion(ERROR_TEXT)),
}
}

Expand All @@ -86,15 +86,15 @@ impl ConfigFile {

let content: String = fs::read_to_string(config_file).unwrap();
match toml::from_str(&content) {
Ok(res) => return Ok(res),
Err(e) => return Err(Report::new(e).suggestion(ERROR_TEXT)),
Ok(res) => Ok(res),
Err(e) => Err(Report::new(e).suggestion(ERROR_TEXT)),
}
} else {
Ok(Self::read_from_fallback_path()?)
}
}

fn read_from_fallback_path() -> Result<ConfigFile, Report> {
Ok(toml::from_str(&DEFAULT_CONFIG)?)
Ok(toml::from_str(DEFAULT_CONFIG)?)
}
}
30 changes: 14 additions & 16 deletions src/util/template.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use color_eyre::{eyre::Result, Report};

use colorsys::Hsl;
use regex::Captures;
use regex::Match;
use regex::Regex;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -96,7 +94,7 @@ impl Template {
Source::Color { .. } => None,
};

let regexvec: Patterns = generate_patterns(&schemes, prefix, image, source_color)?;
let regexvec: Patterns = generate_patterns(schemes, prefix, image, source_color)?;

for (name, template) in &config.templates {
let input_path_absolute = template.input_path.try_resolve()?;
Expand All @@ -113,8 +111,8 @@ impl Template {
&regexvec,
&mut data,
&template.mode,
&schemes,
&default_scheme,
schemes,
default_scheme,
);

let mut output_file = OpenOptions::new()
Expand Down Expand Up @@ -156,11 +154,11 @@ fn replace_matches(
}
};

replace_single_match(&regex.patterns.light, data, &regex.replacements.light);
replace_single_match(&regex.patterns.dark, data, &regex.replacements.dark);
replace_single_match(&regex.patterns.amoled, data, &regex.replacements.amoled);
let _ = replace_single_match(&regex.patterns.light, data, &regex.replacements.light);
let _ = replace_single_match(&regex.patterns.dark, data, &regex.replacements.dark);
let _ = replace_single_match(&regex.patterns.amoled, data, &regex.replacements.amoled);

if let Err(()) = replace_single_match(&regex.patterns.default, data, &default_replacement) {
if let Err(()) = replace_single_match(&regex.patterns.default, data, default_replacement) {
continue;
}
}
Expand All @@ -173,7 +171,7 @@ fn replace_single_match(
data: &mut String,
replacement: &ColorReplacement,
) -> Result<(), ()> {
let captures = pattern.captures(&data);
let captures = pattern.captures(data);

if captures.is_none() {
return Err(());
Expand Down Expand Up @@ -230,7 +228,7 @@ fn generate_patterns<'a>(
generate_single_pattern(
&mut regexvec,
prefix,
&field,
field,
color_light,
color_dark,
color_amoled,
Expand All @@ -257,7 +255,7 @@ fn generate_patterns<'a>(
generate_single_pattern(
&mut regexvec,
prefix,
&field,
field,
color_light,
color_dark,
color_amoled,
Expand Down Expand Up @@ -285,25 +283,25 @@ fn generate_single_pattern<'a>(
patterns: RegexPatterns {
default: Regex::new(
&format!(r#"\{prefix}\{{{field}(\.hex|\.rgb|\.rgba|\.strip|\.hsla|\.hsl)?}}"#)
.to_string(),
,
)?,
light: Regex::new(
&format!(
r#"\{prefix}\{{{field}\.light(\.hex|\.rgb|\.rgba|\.strip|\.hsla|\.hsl)?}}"#
)
.to_string(),
,
)?,
dark: Regex::new(
&format!(
r#"\{prefix}\{{{field}\.dark(\.hex|\.rgb|\.rgba|\.strip|\.hsla|\.hsl)?}}"#
)
.to_string(),
,
)?,
amoled: Regex::new(
&format!(
r#"\{prefix}\{{{field}\.amoled(\.hex|\.rgb|\.rgba|\.strip|\.hsla|\.hsl)?}}"#
)
.to_string(),
,
)?,
},
replacements: ColorReplacements {
Expand Down

0 comments on commit 96df512

Please sign in to comment.