From ac09f4da75416dba5796965797b082d2ec665abb Mon Sep 17 00:00:00 2001 From: Beinsezii Date: Sat, 27 Jan 2024 20:06:23 -0800 Subject: [PATCH] Rustfmt --- examples/quantiles.rs | 51 +++++++++++++++++++++++++++++-------------- examples/spectrum.rs | 25 +++++++++++++-------- 2 files changed, 51 insertions(+), 25 deletions(-) diff --git a/examples/quantiles.rs b/examples/quantiles.rs index c12f610..e60092d 100644 --- a/examples/quantiles.rs +++ b/examples/quantiles.rs @@ -1,4 +1,4 @@ -use colcon::{Space, convert_space_chunked}; +use colcon::{convert_space_chunked, Space}; fn main() { const QUANTILES: [usize; 8] = [0, 1, 5, 10, 90, 95, 99, 100]; @@ -18,11 +18,28 @@ fn main() { (Space::JZCZHZ, "Space::JZCZHZ"), ]; - assert!(Space::ALL.iter().all(|s| spaces.iter().map(|(sp, _st)| sp).find(|sp| sp == &s).is_some())); - - let srgb = (0..=STEPS).map(move |a| (0..=STEPS).map(move |b| (0..=STEPS).map(move |c| - [a as f32 / stepsf, b as f32 / stepsf, c as f32 / stepsf] - ).collect::>()).collect::>>()).collect::>>>().into_iter().flatten().flatten().collect::>().into_boxed_slice(); + assert!(Space::ALL.iter().all(|s| spaces + .iter() + .map(|(sp, _st)| sp) + .find(|sp| sp == &s) + .is_some())); + + let srgb = (0..=STEPS) + .map(move |a| { + (0..=STEPS) + .map(move |b| { + (0..=STEPS) + .map(move |c| [a as f32 / stepsf, b as f32 / stepsf, c as f32 / stepsf]) + .collect::>() + }) + .collect::>>() + }) + .collect::>>>() + .into_iter() + .flatten() + .flatten() + .collect::>() + .into_boxed_slice(); assert_eq!(srgb.len() / 100 * 100, srgb.len() - 1); @@ -41,15 +58,15 @@ fn main() { for (qn, q) in QUANTILES.iter().enumerate() { quantiles[qn][c] = channel[channel.len() / 100 * q] } - } // disable hue and enforce 0 chroma floor if Space::UCS_POLAR.contains(space) { quantiles.iter_mut().for_each(|q| q[2] = f32::INFINITY); quantiles[0][1] = 0.0; + } else if space == &Space::HSV { + quantiles.iter_mut().for_each(|q| q[0] = f32::INFINITY) } - else if space == &Space::HSV { quantiles.iter_mut().for_each(|q| q[0] = f32::INFINITY) } // enforce 0 lightness floor if Space::UCS.contains(space) || Space::UCS_POLAR.contains(space) { @@ -62,21 +79,23 @@ fn main() { let mut formatted = String::new(); for (qn, q) in QUANTILES.iter().enumerate() { - formatted += &format!( -" + formatted += &format!(" /// Retrieves the {} quantile for mapping a given Space back to SRGB. /// This is useful for things like creating adjustable values in Space /// that represent most of the SRGB range without clipping. /// Wrapping Hue values are set to f32::INFINITY pub const fn srgb_quant{}(&self) -> [f32; 3] {{ - match self {{", q, q); + match self {{", + q, q + ); for (n, (_space, space_str)) in spaces.iter().enumerate() { - formatted += &format!( -" - &{} => {:?},", space_str, results[n][qn]).replace("inf", "f32::INFINITY"); + formatted += &format!(" + &{} => {:?},", + space_str, results[n][qn] + ) + .replace("inf", "f32::INFINITY"); } - formatted += -" + formatted += " } }" } diff --git a/examples/spectrum.rs b/examples/spectrum.rs index ab75c02..251c1f2 100644 --- a/examples/spectrum.rs +++ b/examples/spectrum.rs @@ -24,15 +24,22 @@ fn main() { (Space::OKLCH, "oklab"), (Space::JZCZHZ, "jzazbz"), ] { - let mut data: Vec<[f32; 3]> = (0..HEIGHT).map(|h| - (0..WIDTH).map(|w| [ - match space { - Space::OKLCH => 0.70, - Space::JZCZHZ => 0.50, - _ => 0.65, - }, - 1.0 - h as f32 / 100.0, w as f32 ] - ).collect::>()) + let mut data: Vec<[f32; 3]> = (0..HEIGHT) + .map(|h| { + (0..WIDTH) + .map(|w| { + [ + match space { + Space::OKLCH => 0.70, + Space::JZCZHZ => 0.50, + _ => 0.65, + }, + 1.0 - h as f32 / 100.0, + w as f32, + ] + }) + .collect::>() + }) .flatten() .collect();