HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
corner_shapes.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
7namespace tt {
8
10public:
11 constexpr corner_shapes(corner_shapes const &) noexcept = default;
12 constexpr corner_shapes(corner_shapes &&) noexcept = default;
13 constexpr corner_shapes &operator=(corner_shapes const &) noexcept = default;
14 constexpr corner_shapes &operator=(corner_shapes &&) noexcept = default;
15
16 [[nodiscard]] explicit constexpr corner_shapes() noexcept : _v() {}
17 [[nodiscard]] explicit constexpr corner_shapes(float radius) noexcept : _v(radius, radius, radius, radius) {}
18 [[nodiscard]] explicit constexpr corner_shapes(float lb, float rb, float lt, float rt) noexcept : _v(lb, rb, lt, rt) {}
19
20 [[nodiscard]] explicit constexpr operator f32x4() const noexcept
21 {
22 return _v;
23 }
24
25 [[nodiscard]] constexpr float left_bottom() const noexcept
26 {
27 return _v.x();
28 }
29
30 [[nodiscard]] constexpr float right_bottom() const noexcept
31 {
32 return _v.y();
33 }
34
35 [[nodiscard]] constexpr float left_top() const noexcept
36 {
37 return _v.z();
38 }
39
40 [[nodiscard]] constexpr float right_top() const noexcept
41 {
42 return _v.w();
43 }
44
45 template<int I>
46 [[nodiscard]] constexpr friend float get(corner_shapes const &rhs) noexcept
47 {
48 return get<I>(rhs._v);
49 }
50
51 [[nodiscard]] constexpr float operator[](size_t i) const noexcept
52 {
53 return _v[i];
54 }
55
56 [[nodiscard]] constexpr friend corner_shapes operator+(corner_shapes const &lhs, float rhs) noexcept
57 {
58 auto r = corner_shapes{};
59
60 for (size_t i = 0; i != lhs._v.size(); ++i) {
61 if (lhs._v[i] >= 0) {
62 r._v[i] = std::max(0.0f, lhs._v[i] + rhs);
63 } else {
64 r._v[i] = std::min(0.0f, lhs._v[i] - rhs);
65 }
66 }
67
68 return r;
69 }
70
71 [[nodiscard]] constexpr friend corner_shapes operator-(corner_shapes const &lhs, float rhs) noexcept
72 {
73 return lhs + -rhs;
74 }
75
76private:
77 f32x4 _v;
78};
79
80
81}
Definition corner_shapes.hpp:9
T max(T... args)
T min(T... args)