diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..7530651 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +max_width = 120 diff --git a/src/lib.rs b/src/lib.rs index 29cbf38..f4c54dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,10 +25,7 @@ pub fn unweave(slice: &[f32]) -> [Box<[f32]>; N] { .unwrap(); slice.chunks_exact(N).for_each(|chunk| { - chunk - .iter() - .zip(result.iter_mut()) - .for_each(|(v, arr)| arr.push(*v)); + chunk.iter().zip(result.iter_mut()).for_each(|(v, arr)| arr.push(*v)); }); result.map(|v| v.into_boxed_slice()) @@ -703,12 +700,7 @@ pub fn convert_space_sliced(from: Space, to: Space, pixels: &mut [f32]) { /// /// Returns 0 on success, 1 on invalid `from`, 2 on invalid `to`, 3 on invalid `pixels` #[no_mangle] -pub extern "C" fn convert_space_ffi( - from: *const c_char, - to: *const c_char, - pixels: *mut f32, - len: usize, -) -> i32 { +pub extern "C" fn convert_space_ffi(from: *const c_char, to: *const c_char, pixels: *mut f32, len: usize) -> i32 { let from = unsafe { if from.is_null() { return 1; @@ -754,13 +746,7 @@ pub extern "C" fn convert_space_ffi( /// Same as `convert_space`, ignores the 4th value in `pixel`. pub fn convert_space_alpha(from: Space, to: Space, pixel: &mut [f32; 4]) { - unsafe { - convert_space( - from, - to, - pixel.get_unchecked_mut(0..3).try_into().unwrap_unchecked(), - ) - } + unsafe { convert_space(from, to, pixel.get_unchecked_mut(0..3).try_into().unwrap_unchecked()) } } // ### Convert Space ### }}} @@ -805,14 +791,10 @@ pub fn str2col(mut s: &str) -> Option<(Space, [f32; 3])> { let seps = [',', ':', ';']; // Find Space at front then trim - if let Some(i) = - s.find(|c: char| c.is_whitespace() || seps.contains(&c) || ['(', '[', '{'].contains(&c)) - { + if let Some(i) = s.find(|c: char| c.is_whitespace() || seps.contains(&c) || ['(', '[', '{'].contains(&c)) { if let Ok(sp) = Space::try_from(&s[..i]) { space = sp; - s = rm_paren( - s[i..].trim_start_matches(|c: char| c.is_whitespace() || seps.contains(&c)), - ); + s = rm_paren(s[i..].trim_start_matches(|c: char| c.is_whitespace() || seps.contains(&c))); } } @@ -1400,11 +1382,7 @@ mod tests { pix_cmp(&input, reference, epsilon, skips); } - fn func_cmp( - input: &[[f32; 3]], - reference: &[[f32; 3]], - function: extern "C" fn(&mut [f32; 3]), - ) { + fn func_cmp(input: &[[f32; 3]], reference: &[[f32; 3]], function: extern "C" fn(&mut [f32; 3])) { func_cmp_full(input, reference, function, 1e-3, &[]) } @@ -1421,20 +1399,8 @@ mod tests { pix_cmp(&input, reference, epsilon, skips) } - fn conv_cmp( - input_space: Space, - input: &[[f32; 3]], - reference_space: Space, - reference: &[[f32; 3]], - ) { - conv_cmp_full( - input_space, - input, - reference_space, - reference, - 1e-2, - &[0, 7], - ) + fn conv_cmp(input_space: Space, input: &[[f32; 3]], reference_space: Space, reference: &[[f32; 3]]) { + conv_cmp_full(input_space, input, reference_space, reference, 1e-2, &[0, 7]) } // ### Comparison FNs ### }}} @@ -1447,8 +1413,7 @@ mod tests { #[test] fn irgb_from() { let mut srgb = irgb_to_srgb(IRGB); - srgb.iter_mut() - .for_each(|c| *c = (*c * 100.0).round() / 100.0); + srgb.iter_mut().for_each(|c| *c = (*c * 100.0).round() / 100.0); assert_eq!([0.2, 0.35, 0.95], srgb) } @@ -1638,11 +1603,7 @@ mod tests { assert_eq!(deinterleaved[0].len(), deinterleaved[1].len()); assert_eq!(deinterleaved[0].len(), deinterleaved[2].len()); let chunked: Vec<[f32; 3]> = (0..deinterleaved[0].len()).fold(Vec::new(), |mut acc, it| { - acc.push([ - deinterleaved[0][it], - deinterleaved[1][it], - deinterleaved[2][it], - ]); + acc.push([deinterleaved[0][it], deinterleaved[1][it], deinterleaved[2][it]]); acc }); @@ -1719,10 +1680,7 @@ mod tests { // ### Str2Col ### {{{ #[test] fn str2col_base() { - assert_eq!( - str2col("0.2, 0.5, 0.6"), - Some((Space::SRGB, [0.2, 0.5, 0.6])) - ) + assert_eq!(str2col("0.2, 0.5, 0.6"), Some((Space::SRGB, [0.2, 0.5, 0.6]))) } #[test] @@ -1732,10 +1690,7 @@ mod tests { #[test] fn str2col_base_lop() { - assert_eq!( - str2col("0.2,0.5, 0.6"), - Some((Space::SRGB, [0.2, 0.5, 0.6])) - ) + assert_eq!(str2col("0.2,0.5, 0.6"), Some((Space::SRGB, [0.2, 0.5, 0.6]))) } #[test] @@ -1745,26 +1700,17 @@ mod tests { #[test] fn str2col_base_bare_fat() { - assert_eq!( - str2col(" 0.2 0.5 0.6 "), - Some((Space::SRGB, [0.2, 0.5, 0.6])) - ) + assert_eq!(str2col(" 0.2 0.5 0.6 "), Some((Space::SRGB, [0.2, 0.5, 0.6]))) } #[test] fn str2col_base_paren() { - assert_eq!( - str2col("(0.2 0.5 0.6)"), - Some((Space::SRGB, [0.2, 0.5, 0.6])) - ) + assert_eq!(str2col("(0.2 0.5 0.6)"), Some((Space::SRGB, [0.2, 0.5, 0.6]))) } #[test] fn str2col_base_paren2() { - assert_eq!( - str2col("{ 0.2 : 0.5 : 0.6 }"), - Some((Space::SRGB, [0.2, 0.5, 0.6])) - ) + assert_eq!(str2col("{ 0.2 : 0.5 : 0.6 }"), Some((Space::SRGB, [0.2, 0.5, 0.6]))) } #[test] @@ -1789,50 +1735,32 @@ mod tests { #[test] fn str2col_lch() { - assert_eq!( - str2col("lch(50, 30, 160)"), - Some((Space::CIELCH, [50.0, 30.0, 160.0])) - ) + assert_eq!(str2col("lch(50, 30, 160)"), Some((Space::CIELCH, [50.0, 30.0, 160.0]))) } #[test] fn str2col_lch_space() { - assert_eq!( - str2col("lch 50, 30, 160"), - Some((Space::CIELCH, [50.0, 30.0, 160.0])) - ) + assert_eq!(str2col("lch 50, 30, 160"), Some((Space::CIELCH, [50.0, 30.0, 160.0]))) } #[test] fn str2col_lch_colon() { - assert_eq!( - str2col("lch:50:30:160"), - Some((Space::CIELCH, [50.0, 30.0, 160.0])) - ) + assert_eq!(str2col("lch:50:30:160"), Some((Space::CIELCH, [50.0, 30.0, 160.0]))) } #[test] fn str2col_lch_semicolon() { - assert_eq!( - str2col("lch;50;30;160"), - Some((Space::CIELCH, [50.0, 30.0, 160.0])) - ) + assert_eq!(str2col("lch;50;30;160"), Some((Space::CIELCH, [50.0, 30.0, 160.0]))) } #[test] fn str2col_lch_mixed() { - assert_eq!( - str2col("lch; (50,30,160)"), - Some((Space::CIELCH, [50.0, 30.0, 160.0])) - ) + assert_eq!(str2col("lch; (50,30,160)"), Some((Space::CIELCH, [50.0, 30.0, 160.0]))) } #[test] fn str2col_lch_mixed2() { - assert_eq!( - str2col("lch(50; 30; 160)"), - Some((Space::CIELCH, [50.0, 30.0, 160.0])) - ) + assert_eq!(str2col("lch(50; 30; 160)"), Some((Space::CIELCH, [50.0, 30.0, 160.0]))) } #[test] @@ -1854,11 +1782,7 @@ mod tests { str2col("oklch 100% 100% 100%"), Some(( Space::OKLCH, - [ - Space::OKLCH.srgb_quant100()[0], - Space::OKLCH.srgb_quant100()[1], - 360.0, - ] + [Space::OKLCH.srgb_quant100()[0], Space::OKLCH.srgb_quant100()[1], 360.0] )) ) } @@ -1884,11 +1808,7 @@ mod tests { str2col("oklch 0% 0% 0%"), Some(( Space::OKLCH, - [ - Space::OKLCH.srgb_quant0()[0], - Space::OKLCH.srgb_quant0()[1], - 0.0, - ] + [Space::OKLCH.srgb_quant0()[0], Space::OKLCH.srgb_quant0()[1], 0.0] )) ) } @@ -1899,11 +1819,7 @@ mod tests { str2col("oklab 0.5 100.000% 0%"), Some(( Space::OKLAB, - [ - 0.5, - Space::OKLAB.srgb_quant100()[1], - Space::OKLAB.srgb_quant0()[2], - ] + [0.5, Space::OKLAB.srgb_quant100()[1], Space::OKLAB.srgb_quant0()[2]] )) ) } @@ -1925,8 +1841,7 @@ mod tests { #[test] fn str2space_base() { - let pix = str2space("oklch : 0.62792590, 0.25768453, 29.22319405", Space::SRGB) - .expect("STR2SPACE_BASE FAIL"); + let pix = str2space("oklch : 0.62792590, 0.25768453, 29.22319405", Space::SRGB).expect("STR2SPACE_BASE FAIL"); let reference = [1.00000000, 0.00000000, 0.00000000]; pix_cmp(&[pix], &[reference], 1e-3, &[]); }