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
11#include "../macros.hpp"
12#include <hikocpu/hikocpu.hpp>
13#include <cstddef>
14#include <exception>
15#include <compare>
16
17hi_export_module(hikogui.geometry : corner_radii);
18
19hi_export namespace hi {
20inline namespace v1 {
21
27public:
28 using array_type = f32x4;
29
30 constexpr corner_radii(corner_radii const &) noexcept = default;
31 constexpr corner_radii(corner_radii &&) noexcept = default;
32 constexpr corner_radii &operator=(corner_radii const &) noexcept = default;
33 constexpr corner_radii &operator=(corner_radii &&) noexcept = default;
34
36 [[nodiscard]] constexpr corner_radii(float radius) noexcept : _v(radius, radius, radius, radius) {}
37 [[nodiscard]] constexpr corner_radii(float lb, float rb, float lt, float rt) noexcept : _v(lb, rb, lt, rt) {}
38
43 [[nodiscard]] constexpr explicit corner_radii(f32x4 v) noexcept : _v(v) {}
44
45 [[nodiscard]] constexpr explicit operator f32x4() const noexcept
46 {
47 return _v;
48 }
49
50 [[nodiscard]] constexpr float left_bottom() const noexcept
51 {
52 return _v.x();
53 }
54
55 [[nodiscard]] constexpr float right_bottom() const noexcept
56 {
57 return _v.y();
58 }
59
60 [[nodiscard]] constexpr float left_top() const noexcept
61 {
62 return _v.z();
63 }
64
65 [[nodiscard]] constexpr float right_top() const noexcept
66 {
67 return _v.w();
68 }
69
75 template<int I>
76 [[nodiscard]] constexpr friend float get(corner_radii const &rhs) noexcept
77 {
78 return get<I>(rhs._v);
79 }
80
86 [[nodiscard]] constexpr float operator[](std::size_t i) const noexcept
87 {
88 return _v[i];
89 }
90
91 [[nodiscard]] constexpr friend corner_radii operator+(corner_radii const &lhs, float rhs) noexcept
92 {
93 return corner_radii{f32x4{lhs} + array_type::broadcast(rhs)};
94 }
95
96 [[nodiscard]] constexpr friend corner_radii operator-(corner_radii const &lhs, float rhs) noexcept
97 {
98 return corner_radii{f32x4{lhs} - array_type::broadcast(rhs)};
99 }
100
101
102private:
103 f32x4 _v;
104};
105
106}} // namespace hi::inline v1
107
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The 4 radii of the corners of a quad or rectangle.
Definition corner_radii.hpp:26
constexpr friend float get(corner_radii const &rhs) noexcept
Get the corner radius by index.
Definition corner_radii.hpp:76
constexpr float operator[](std::size_t i) const noexcept
Get the corner radius by index.
Definition corner_radii.hpp:86
constexpr corner_radii(f32x4 v) noexcept
Construct a corner_radii from a simd.
Definition corner_radii.hpp:43