Closed sharkdp closed 5 years ago
Instead of this:
let color = match matches.value_of("colorspace").expect("required argument") { "rgb" => start.mix::<RGBA<f64>>(&stop, fraction), "hsl" => start.mix::<HSLA>(&stop, fraction), "lab" => start.mix::<Lab>(&stop, fraction), "lch" => start.mix::<LCh>(&stop, fraction), _ => unimplemented!("Unknown color space"), };
write a function to get a Box<dyn ColorSpace> from a &str. Something like:
Box<dyn ColorSpace>
&str
fn get_representation(colorspace_name: &str, c: &Color) -> Box<dyn ColorSpace> { match colorspace_name { "RGB" => Box::new(RGB::from_color(c)), "HSL" => Box::new(HSL::from_color(c)), _ => unreachable!("Unknown color space"), } }
Then, instead of calling Color::mix::<...>, directly call .mix(..) on the colorspace representations of "from" and "to" (in case of the gradient subcomand).
Color::mix::<...>
.mix(..)
gradient
Instead of this:
write a function to get a
Box<dyn ColorSpace>
from a&str
. Something like:Then, instead of calling
Color::mix::<...>
, directly call.mix(..)
on the colorspace representations of "from" and "to" (in case of thegradient
subcomand).