aboutsummaryrefslogtreecommitdiff
path: root/src/world/scene.rs
blob: 89540504105b90621f2c8fda38b7a59089a2b04e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use crate::core::{Bound3f, Ray};

use std::iter::IntoIterator;

use super::{Object, container, Hittable, Intersection};

type Container = container::HittableList;

pub struct Scene {
    content: Container,
}

impl Scene {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn add_object(&mut self, obj: Object) {
        self.content.add(obj);
    }

    pub fn add_objects<T>(&mut self, objs: T) 
    where
        T: IntoIterator<Item = Object>,
    {
        for obj in objs.into_iter() {
            self.add_object(obj);
        }
    }
}

impl Hittable for Scene {
    fn intersect(&self, ray: &Ray) -> Option<Intersection> {
        self.content.intersect(ray)
    }

    fn bounding_box(&self) -> Bound3f {
        self.content.bounding_box()
    }
}

impl Default for Scene {
    fn default() -> Self {
        Self {
            content: Container::new(),
        }
    }
}