HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
line_segment.hpp
Go to the documentation of this file.
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
9#pragma once
10
11#include "point3.hpp"
12#include "vector3.hpp"
13#include "../macros.hpp"
14
15namespace hi {
16inline namespace v1 {
17
22public:
23 constexpr line_segment(line_segment const &) noexcept = default;
24 constexpr line_segment(line_segment &&) noexcept = default;
25 constexpr line_segment &operator=(line_segment const &) noexcept = default;
26 constexpr line_segment &operator=(line_segment &&) noexcept = default;
27
28 [[nodiscard]] constexpr line_segment(point3 p, vector3 v) noexcept : _p(p), _v(v) {}
29
30 [[nodiscard]] constexpr line_segment(point3 p0, point3 p1) noexcept : line_segment(p0, p1 - p0) {}
31
32 [[nodiscard]] constexpr point3 origin() const noexcept
33 {
34 return _p;
35 }
36
37 [[nodiscard]] constexpr vector3 direction() const noexcept
38 {
39 return _v;
40 }
41
42 [[nodiscard]] friend float hypot(line_segment const &rhs) noexcept
43 {
44 return hypot(rhs._v);
45 }
46
47 template<std::size_t I>
48 [[nodiscard]] constexpr friend point3 get(line_segment const &rhs) noexcept
49 {
50 if constexpr (I == 0) {
51 return rhs._p;
52 } else if constexpr (I == 1) {
53 return rhs._p + rhs._v;
54 } else {
55 hi_static_no_default();
56 }
57 }
58
59 [[nodiscard]] constexpr friend point3 midpoint(line_segment const &rhs) noexcept
60 {
61 return rhs._p + rhs._v * 0.5f;
62 }
63
64private:
65 point3 _p;
66 vector3 _v;
67};
68
69
70}}
71
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Line segment.
Definition line_segment.hpp:21
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector3.hpp:20