library: light: point: add deserialization
This commit is contained in:
parent
42abfed3fa
commit
ebe00365d1
|
@ -1,9 +1,10 @@
|
||||||
use super::{Light, SpatialLight};
|
use super::{Light, SpatialLight};
|
||||||
use crate::core::LinearColor;
|
use crate::core::LinearColor;
|
||||||
use crate::{Point, Vector};
|
use crate::{Point, Vector};
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
/// Represent a light emanating from a point in space, following the square distance law.
|
/// Represent a light emanating from a point in space, following the square distance law.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
pub struct PointLight {
|
pub struct PointLight {
|
||||||
position: Point,
|
position: Point,
|
||||||
color: LinearColor,
|
color: LinearColor,
|
||||||
|
@ -63,4 +64,14 @@ mod test {
|
||||||
let expected = (Vector::new(-1., 0., 0.), 1.);
|
let expected = (Vector::new(-1., 0., 0.), 1.);
|
||||||
assert_eq!(ans, expected);
|
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))
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue