From 85f274a0b1b8e7fa0836977547fe8d5a595c9331 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 18 Mar 2020 14:35:19 +0100 Subject: [PATCH] library: light: ambient: add deserialization --- src/light/ambient_light.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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))) + } }