concinnity_asset/
point_light.rs1#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
20#[serde(default)]
21pub struct PointLight {
22 pub position: [f32; 3],
24 pub color: [f32; 3],
26 pub intensity: f32,
28 pub range: f32,
30}
31
32impl Default for PointLight {
33 fn default() -> Self {
34 Self {
35 position: [0.0, 2.5, 0.0],
36 color: [1.0, 1.0, 1.0],
37 intensity: 8.0,
38 range: 6.0,
39 }
40 }
41}
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46
47 #[test]
48 fn the_default_lamp_hangs_above_head_height_with_a_room_sized_reach() {
49 let l = PointLight::default();
50 assert_eq!(l.position, [0.0, 2.5, 0.0]);
51 assert_eq!(l.color, [1.0, 1.0, 1.0]);
52 assert_eq!(l.intensity, 8.0);
53 assert_eq!(l.range, 6.0);
54 }
55
56 #[test]
57 fn an_authored_lamp_parses_and_round_trips_through_postcard() {
58 let l: PointLight = serde_json::from_str(
59 r#"{"position":[2,2.5,-3],"color":[1,0.8,0.5],"intensity":12,"range":9}"#,
60 )
61 .unwrap();
62 assert_eq!(l.position, [2.0, 2.5, -3.0]);
63 assert_eq!(l.color, [1.0, 0.8, 0.5]);
64
65 let bytes = postcard::to_allocvec(&l).unwrap();
66 let back: PointLight = postcard::from_bytes(&bytes).unwrap();
67 assert_eq!(back.intensity, 12.0);
68 assert_eq!(back.range, 9.0);
69 }
70}