HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
line_segment.hpp
1// Copyright Take Vos 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "point.hpp"
8
9namespace hi::inline v1 {
10
12public:
13 constexpr line_segment(line_segment const &) noexcept = default;
14 constexpr line_segment(line_segment &&) noexcept = default;
15 constexpr line_segment &operator=(line_segment const &) noexcept = default;
16 constexpr line_segment &operator=(line_segment &&) noexcept = default;
17
18 [[nodiscard]] constexpr line_segment(point3 p, vector3 v) noexcept : _p(p), _v(v) {}
19
20 [[nodiscard]] constexpr line_segment(point3 p0, point3 p1) noexcept : line_segment(p0, p1 - p0) {}
21
22 [[nodiscard]] constexpr point3 origin() const noexcept
23 {
24 return _p;
25 }
26
27 [[nodiscard]] constexpr vector3 direction() const noexcept
28 {
29 return _v;
30 }
31
32 [[nodiscard]] constexpr friend float hypot(line_segment const &rhs) noexcept
33 {
34 return hypot(rhs._v);
35 }
36
37 template<std::size_t I>
38 [[nodiscard]] constexpr friend point3 get(line_segment const &rhs) noexcept
39 {
40 if constexpr (I == 0) {
41 return _p;
42 } else if constexpr (I == 1) {
43 return _p + _v;
44 } else {
45 hi_static_no_default();
46 }
47 }
48
49 [[nodiscard]] constexpr friend point3 midpoint(line_segment const &rhs) noexcept
50 {
51 return rhs._p + rhs._v * 0.5f;
52 }
53
54private:
55 point3 _p;
56 vector3 _v;
57};
58
59
60}
61
Definition line_segment.hpp:11