library: light: point: add deserialization

This commit is contained in:
Bruno BELANYI 2020-03-18 14:36:28 +01:00
parent 42abfed3fa
commit ebe00365d1

View file

@ -1,9 +1,10 @@
use super::{Light, SpatialLight};
use crate::core::LinearColor;
use crate::{Point, Vector};
use serde::Deserialize;
/// Represent a light emanating from a point in space, following the square distance law.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Deserialize)]
pub struct PointLight {
position: Point,
color: LinearColor,
@ -63,4 +64,14 @@ mod test {
let expected = (Vector::new(-1., 0., 0.), 1.);
assert_eq!(ans, expected);
}
#[test]
fn deserialization_works() {
let yaml = "{position: [1.0, 1.0, 1.0], color: {r: 1.0, g: 0.5, b: 0.2}}";
let light: PointLight = serde_yaml::from_str(yaml).unwrap();
assert_eq!(
light,
PointLight::new(Point::new(1., 1., 1.), LinearColor::new(1., 0.5, 0.2))
)
}
}