diff --git a/src/light/ambient_light.rs b/src/light/ambient_light.rs index d76c10c..a6668a7 100644 --- a/src/light/ambient_light.rs +++ b/src/light/ambient_light.rs @@ -1,9 +1,10 @@ use super::Light; use crate::core::LinearColor; use crate::Point; +use serde::Deserialize; /// Represent an ambient lighting which is equal in all points of the scene. -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Deserialize)] pub struct AmbientLight { color: LinearColor, } @@ -38,4 +39,11 @@ mod test { let lum = light.illumination(&Point::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))) + } }