13#include "../macros.hpp"
17hi_export_module(hikogui.geometry : circle);
19hi_export
namespace hi {
inline namespace v1 {
25 using array_type =
f32x4;
32 constexpr circle() noexcept : _v()
34 hi_axiom(holds_invariant());
37 [[nodiscard]]
constexpr explicit circle(
f32x4 v) noexcept : _v(v)
39 hi_axiom(holds_invariant());
42 [[nodiscard]]
constexpr explicit operator f32x4()
const noexcept
47 [[nodiscard]]
constexpr circle(point3 point,
float radius) noexcept : _v(
f32x4{point})
50 hi_axiom(holds_invariant());
53 [[nodiscard]]
constexpr circle(
float radius) noexcept : _v()
56 hi_axiom(holds_invariant());
61 auto const square_ =
f32x4{square};
64 _v = (addsub_mask<0b0011>(square_.zwzw(), square_.xyxy()) * array_type::broadcast(0.5f)).xy0w();
65 hi_axiom(holds_invariant());
68 [[nodiscard]]
constexpr bool empty()
const noexcept
70 return _v.w() == 0.0f;
73 [[nodiscard]]
explicit operator bool()
const noexcept
78 [[nodiscard]]
constexpr float radius()
const noexcept
83 [[nodiscard]]
constexpr float diameter()
const noexcept
85 return radius() * 2.0f;
88 [[nodiscard]]
constexpr point3 center()
const noexcept
90 return point3{_v.xyz1()};
93 [[nodiscard]]
constexpr friend circle operator+(
circle const& lhs,
float rhs)
noexcept
95 return circle{lhs._v +
f32x4{0.0f, 0.0f, 0.0f, rhs}};
98 [[nodiscard]]
constexpr friend circle operator-(
circle const& lhs,
float rhs)
noexcept
100 return circle{lhs._v -
f32x4{0.0f, 0.0f, 0.0f, rhs}};
103 [[nodiscard]]
constexpr friend circle operator*(
circle const& lhs,
float rhs)
noexcept
105 return circle{lhs._v *
f32x4{1.0f, 1.0f, 1.0f, rhs}};
108 [[nodiscard]]
constexpr friend point3 midpoint(
circle const& rhs)
noexcept
110 return point3{rhs.center()};
113 [[nodiscard]]
constexpr friend aarectangle bounding_rectangle(
circle const& rhs)
noexcept
115 auto const p = rhs._v.xyxy();
116 auto const r = neg_mask<0b0011>(rhs._v.wwww());
130 return haystack.left() + needle.radius();
133 return haystack.right() - needle.radius();
136 return haystack.center();
145 return haystack.bottom() + needle.radius();
148 return haystack.top() - needle.radius();
151 return haystack.middle();
158 return circle{point2{x, y}, needle.radius()};
165 [[nodiscard]]
constexpr bool holds_invariant() const noexcept
167 return _v.w() >= 0.0f;
@ middle
Align to the vertical-middle.
@ bottom
Align to the bottom.
@ right
Align the text to the right side.
@ left
Align the text to the left side.
@ center
Align the text in the center.
@ other
The gui_event does not have associated data.
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:33
Horizontal/Vertical alignment combination.
Definition alignment.hpp:244
A type defining a 2D circle.
Definition circle.hpp:23
friend constexpr circle align(aarectangle haystack, circle needle, alignment alignment) noexcept
Align a rectangle within another rectangle.
Definition circle.hpp:126