library: texture: uniform: add deserialization

This commit is contained in:
Bruno BELANYI 2020-03-18 14:38:26 +01:00
parent 803b34641d
commit eff133abf3

View file

@ -1,9 +1,10 @@
use super::Texture;
use crate::core::LinearColor;
use crate::Point2D;
use serde::Deserialize;
/// A texture with the same color on all points.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Deserialize)]
pub struct UniformTexture {
color: LinearColor,
}
@ -34,6 +35,7 @@ mod test {
fn simple_texture() -> UniformTexture {
UniformTexture::new(LinearColor::new(0.25, 0.5, 1.))
}
#[test]
fn texel_color_works() {
let texture = simple_texture();
@ -42,4 +44,16 @@ mod test {
LinearColor::new(0.25, 0.5, 1.)
)
}
#[test]
fn deserialization_works() {
let yaml = r#"
color: {r: 1.0, g: 0.5, b: 0.25}
"#;
let texture: UniformTexture = serde_yaml::from_str(yaml).unwrap();
assert_eq!(
texture,
UniformTexture::new(LinearColor::new(1., 0.5, 0.25))
)
}
}