diff options
author | 2020-03-31 17:36:09 -0500 | |
---|---|---|
committer | 2020-04-24 15:13:22 -0500 | |
commit | 408e9e566f740a4a9eb564492e96714dd5db4cc3 (patch) | |
tree | 218e30b501b8be6026251538cd276bb36966a377 /core | |
parent | 7b15e4b0e29c64d53a00fbe6709ff2069630fec5 (diff) | |
download | iced-408e9e566f740a4a9eb564492e96714dd5db4cc3.tar.gz iced-408e9e566f740a4a9eb564492e96714dd5db4cc3.tar.bz2 iced-408e9e566f740a4a9eb564492e96714dd5db4cc3.zip |
Add palette test for Color <-> Srgba & manipulation
Diffstat (limited to 'core')
-rw-r--r-- | core/src/color.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/core/src/color.rs b/core/src/color.rs index be1a2870..67433ded 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -180,3 +180,44 @@ impl From<Color> for Srgba { Srgba::new(c.r, c.g, c.b, c.a) } } + +#[cfg(feature = "palette")] +#[cfg(test)] +mod tests { + use super::*; + use palette::Blend; + + #[test] + fn srgba_traits() { + let c = Color::from_rgb(0.5, 0.4, 0.3); + // Round-trip conversion to the palette:Srgba type + let s: Srgba = c.into(); + let r: Color = s.into(); + assert_eq!(c, r); + } + + #[test] + fn color_manipulation() { + let c1 = Color::from_rgb(0.5, 0.4, 0.3); + let c2 = Color::from_rgb(0.2, 0.5, 0.3); + + // Convert to linear color for manipulation + let l1 = c1.into_srgba().into_linear(); + let l2 = c2.into_srgba().into_linear(); + + // Take the lighter of each of the RGB components + let lighter = l1.lighten(l2); + + // Convert back to our Color + let r: Color = Srgba::from_linear(lighter).into(); + assert_eq!( + r, + Color { + r: 0.5, + g: 0.5, + b: 0.3, + a: 1.0 + } + ); + } +} |