library: light: ambient: add deserialization

This commit is contained in:
Bruno BELANYI 2020-03-18 14:35:19 +01:00
parent 9dcce9218f
commit 85f274a0b1

View file

@ -1,9 +1,10 @@
use super::Light; use super::Light;
use crate::core::LinearColor; use crate::core::LinearColor;
use crate::Point; use crate::Point;
use serde::Deserialize;
/// Represent an ambient lighting which is equal in all points of the scene. /// Represent an ambient lighting which is equal in all points of the scene.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Deserialize)]
pub struct AmbientLight { pub struct AmbientLight {
color: LinearColor, color: LinearColor,
} }
@ -38,4 +39,11 @@ mod test {
let lum = light.illumination(&Point::new(1., 1., 1.)); let lum = light.illumination(&Point::new(1., 1., 1.));
assert_eq!(lum, LinearColor::new(1., 1., 1.)) assert_eq!(lum, LinearColor::new(1., 1., 1.))
} }
#[test]
fn deserialization_works() {
let yaml = "color: {r: 1.0, g: 0.5, b: 0.2}";
let light: AmbientLight = serde_yaml::from_str(yaml).unwrap();
assert_eq!(light, AmbientLight::new(LinearColor::new(1., 0.5, 0.2)))
}
} }