HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
corner_radii.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
11namespace hi { inline namespace v1 {
12namespace geo {
13
18template<typename T>
20public:
21 using value_type = T;
22 using array_type = simd<value_type, 4>;
23
24 constexpr corner_radii(corner_radii const&) noexcept = default;
25 constexpr corner_radii(corner_radii&&) noexcept = default;
26 constexpr corner_radii& operator=(corner_radii const&) noexcept = default;
27 constexpr corner_radii& operator=(corner_radii&&) noexcept = default;
28
29 [[nodiscard]] constexpr corner_radii() noexcept : corner_radii(-std::numeric_limits<value_type>::lowest()) {}
30 [[nodiscard]] constexpr corner_radii(value_type radius) noexcept : _v(radius, radius, radius, radius) {}
31 [[nodiscard]] constexpr corner_radii(value_type lb, value_type rb, value_type lt, value_type rt) noexcept : _v(lb, rb, lt, rt)
32 {
33 }
34
39 [[nodiscard]] constexpr explicit corner_radii(array_type v) noexcept : _v(v) {}
40
41 [[nodiscard]] constexpr explicit operator array_type() const noexcept
42 {
43 return _v;
44 }
45
46 [[nodiscard]] constexpr value_type left_bottom() const noexcept
47 {
48 return _v.x();
49 }
50
51 [[nodiscard]] constexpr value_type right_bottom() const noexcept
52 {
53 return _v.y();
54 }
55
56 [[nodiscard]] constexpr value_type left_top() const noexcept
57 {
58 return _v.z();
59 }
60
61 [[nodiscard]] constexpr value_type right_top() const noexcept
62 {
63 return _v.w();
64 }
65
66 [[nodiscard]] constexpr value_type& left_bottom() noexcept
67 {
68 return _v.x();
69 }
70
71 [[nodiscard]] constexpr value_type& right_bottom() noexcept
72 {
73 return _v.y();
74 }
75
76 [[nodiscard]] constexpr value_type& left_top() noexcept
77 {
78 return _v.z();
79 }
80
81 [[nodiscard]] constexpr value_type& right_top() noexcept
82 {
83 return _v.w();
84 }
85
91 template<int I>
92 [[nodiscard]] constexpr friend float get(corner_radii const& rhs) noexcept
93 {
94 return get<I>(rhs._v);
95 }
96
102 [[nodiscard]] constexpr float operator[](std::size_t i) const noexcept
103 {
104 return _v[i];
105 }
106
107 [[nodiscard]] constexpr friend corner_radii operator+(corner_radii const& lhs, value_type rhs) noexcept
108 {
109 return corner_radii{array_type{lhs} + rhs};
110 }
111
112 [[nodiscard]] constexpr friend corner_radii operator-(corner_radii const& lhs, value_type rhs) noexcept
113 {
114 return corner_radii{array_type{lhs} - rhs};
115 }
116
117private:
118 array_type _v;
119};
120
121} // namespace geo
122
123using corner_radii = geo::corner_radii<float>;
124using corner_radiii = geo::corner_radii<int>;
125
126template<>
127[[nodiscard]] constexpr corner_radii narrow_cast(corner_radiii const& rhs) noexcept
128{
129 return {
130 narrow_cast<float>(rhs.left_bottom()),
131 narrow_cast<float>(rhs.right_bottom()),
132 narrow_cast<float>(rhs.left_top()),
133 narrow_cast<float>(rhs.right_top())};
134}
135
136}} // namespace hi::v1
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
The 4 radii of the corners of a quad or rectangle.
Definition corner_radii.hpp:19
constexpr friend float get(corner_radii const &rhs) noexcept
Get the corner radius by index.
Definition corner_radii.hpp:92
constexpr float operator[](std::size_t i) const noexcept
Get the corner radius by index.
Definition corner_radii.hpp:102
constexpr corner_radii(array_type v) noexcept
Construct a corner_radii from a simd.
Definition corner_radii.hpp:39