header_utils
Loading...
Searching...
No Matches
ray.h
1
4
5#pragma once
6
7#include "geometry_common.h"
8
10{
11
12 template <std::floating_point T>
13 struct tray
14 {
15 using tvec = glm::tvec2<T>;
16 using value_type = T;
17
18 tvec start{};
19 tvec dir{};
20
22
23 tray from_dir(tvec const& start, tvec const& dir) noexcept { return { start, glm::normalize(dir) }; }
24 tray from_points(tvec const& start, tvec const& second) noexcept { return from_dir(start, second - start); }
25
26 tsegment& set_position(tvec const& pos) noexcept { start = pos; return *this; }
27 tsegment& operator+=(tvec const& offs) noexcept { start += offs; return *this; }
28 tsegment& operator-=(tvec const& offs) noexcept { start -= offs; return *this; }
29 tsegment& translate(tvec const& offs) noexcept { return this->operator+=(offs); }
30
31 tvec edge_point_alpha(T t) const { return start + dir * t; }
32 tvec projected(tvec const& pt) const
33 {
34 const auto a = projected_alpha(pt);
35 if (a < T(0)) return start;
36 return start + dir * a;
37 }
38 T projected_alpha(tvec const& pt) const
39 {
40 const auto d = pt - start;
41 return glm::dot(d, dir);
42 }
43 };
44
45 using ray = tray<float>;
46
47}
constexpr auto bit_count
Equal to the number of bits in the type.
Definition bits.h:33