list.h 714 Bytes
Newer Older
TheNumbat's avatar
TheNumbat committed
1
2
3
4
5
6
7
8

#pragma once

#include "../lib/mathlib.h"
#include "trace.h"

namespace PT {

TheNumbat's avatar
TheNumbat committed
9
template <typename Primitive> class List {
TheNumbat's avatar
TheNumbat committed
10
11
public:
    List() {}
TheNumbat's avatar
TheNumbat committed
12
    List(std::vector<Primitive> &&primitives) : prims(primitives) {}
TheNumbat's avatar
TheNumbat committed
13
14
15

    BBox bbox() const {
        BBox ret;
TheNumbat's avatar
TheNumbat committed
16
        for (const auto &p : prims) {
TheNumbat's avatar
TheNumbat committed
17
18
19
20
21
            ret.enclose(p.bbox());
        }
        return ret;
    }

TheNumbat's avatar
TheNumbat committed
22
    Trace hit(const Ray &ray) const {
TheNumbat's avatar
TheNumbat committed
23
        Trace ret;
TheNumbat's avatar
TheNumbat committed
24
        for (const auto &p : prims) {
TheNumbat's avatar
TheNumbat committed
25
26
27
28
29
30
            Trace test = p.hit(ray);
            ret = Trace::min(ret, test);
        }
        return ret;
    }

TheNumbat's avatar
TheNumbat committed
31
    void append(Primitive &&prim) { prims.push_back(std::move(prim)); }
TheNumbat's avatar
TheNumbat committed
32
33
34
35
36

private:
    std::vector<Primitive> prims;
};

TheNumbat's avatar
TheNumbat committed
37
} // namespace PT