ray.hh 1.8 KB
Newer Older
1
2
#pragma once

Philip Trettner's avatar
Philip Trettner committed
3
#include <typed-geometry/types/scalars/default.hh>
Philip Trettner's avatar
Philip Trettner committed
4
#include "../dir.hh"
Philip Trettner's avatar
Philip Trettner committed
5
#include "../pos.hh"
6
#include "traits.hh"
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

namespace tg
{
template <int D, class ScalarT>
struct ray;

// Common ray types

using ray1 = ray<1, f32>;
using ray2 = ray<2, f32>;
using ray3 = ray<3, f32>;
using ray4 = ray<4, f32>;

using fray1 = ray<1, f32>;
using fray2 = ray<2, f32>;
using fray3 = ray<3, f32>;
using fray4 = ray<4, f32>;

using dray1 = ray<1, f64>;
using dray2 = ray<2, f64>;
using dray3 = ray<3, f64>;
using dray4 = ray<4, f64>;

using iray1 = ray<1, i32>;
using iray2 = ray<2, i32>;
using iray3 = ray<3, i32>;
using iray4 = ray<4, i32>;

using uray1 = ray<1, u32>;
using uray2 = ray<2, u32>;
using uray3 = ray<3, u32>;
using uray4 = ray<4, u32>;


// ======== IMPLEMENTATION ========

template <int D, class ScalarT>
struct ray
{
46
    using scalar_t = ScalarT;
Aaron Grabowy's avatar
Aaron Grabowy committed
47
48
    using dir_t = tg::dir<D, ScalarT>; // Note: gcc requires the tg:: prefix to distinguish from member variable
    using pos_t = tg::pos<D, ScalarT>;
49

50
    pos_t origin;
Philip Trettner's avatar
Philip Trettner committed
51
    dir_t dir;
52
53

    constexpr ray() = default;
54
    constexpr ray(pos_t origin, dir_t dir) : origin(origin), dir(dir) {}
55

Philip Trettner's avatar
Philip Trettner committed
56
    template <class OtherT>
57
    explicit constexpr ray(ray<D, OtherT> const& v) : origin(v.origin), dir(v.dir)
Philip Trettner's avatar
Philip Trettner committed
58
59
60
    {
    }

61
    [[nodiscard]] constexpr pos_t operator[](ScalarT t) const;
Philip Trettner's avatar
Philip Trettner committed
62

63
64
    [[nodiscard]] bool operator==(ray const& rhs) const { return origin == rhs.origin && dir == rhs.dir; }
    [[nodiscard]] bool operator!=(ray const& rhs) const { return !operator==(rhs); }
65
};
Philip Trettner's avatar
Philip Trettner committed
66
67
68
69
70
71
72

template <class I, int D, class ScalarT>
constexpr void introspect(I&& i, ray<D, ScalarT>& v)
{
    i(v.origin, "origin");
    i(v.dir, "dir");
}
73
74
75
76
77

template <int D, class ScalarT>
struct object_traits<ray<D, ScalarT>> : detail::infinite_object_traits<1, ScalarT, D, default_object_tag>
{
};
78
} // namespace tg