HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
translate3.hpp
1// Copyright Take Vos 2021-2022.
2// Distributed under the Boost Software License, Version float{1}.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "translate2.hpp"
8#include "point3.hpp"
9#include "../macros.hpp"
10#include <concepts>
11
12namespace hi { inline namespace v1 {
13
14class translate3;
15[[nodiscard]] constexpr point3 operator*(translate3 const& lhs, point3 const& rhs) noexcept;
16
17
19public:
20 using array_type = simd<float, 4>;
21 using value_type = array_type::value_type;
22
23 constexpr translate3(translate3 const&) noexcept = default;
24 constexpr translate3(translate3&&) noexcept = default;
25 constexpr translate3& operator=(translate3 const&) noexcept = default;
26 constexpr translate3& operator=(translate3&&) noexcept = default;
27
28 [[nodiscard]] constexpr translate3() noexcept : _v(0.0f, 0.0f, 0.0f, 0.0f) {}
29
30 [[nodiscard]] constexpr explicit operator array_type() const noexcept
31 {
32 return _v;
33 }
34
35 [[nodiscard]] constexpr explicit translate3(array_type const& other) noexcept : _v(other)
36 {
37 hi_axiom(holds_invariant());
38 }
39
40 [[nodiscard]] constexpr explicit translate3(aarectangle const& other) noexcept :
41 _v(static_cast<array_type>(get<0>(other)).xy00())
42 {
43 }
44
45 [[nodiscard]] constexpr explicit translate3(aarectangle const& other, float z) noexcept
46 : _v(static_cast<array_type>(get<0>(other)).xy00())
47 {
48 _v.z() = z;
49 }
50
51 [[nodiscard]] constexpr translate3(translate2 const& other) noexcept : _v(static_cast<array_type>(other))
52 {
53 }
54
55 [[nodiscard]] constexpr translate3(translate2 const& other, float z) noexcept : _v(static_cast<array_type>(other))
56 {
57 _v.z() = z;
58 }
59
60 [[nodiscard]] constexpr explicit operator translate2() const noexcept
61 {
62 auto tmp = _v;
63 tmp.z() = 0.0f;
64 return translate2{tmp};
65 }
66
67 [[nodiscard]] constexpr explicit translate3(vector3 const& other) noexcept
68 : _v(static_cast<array_type>(other))
69 {
70 }
71
72 [[nodiscard]] constexpr explicit translate3(point3 const& other) noexcept
73 : _v(static_cast<array_type>(other).xyz0())
74 {
75 }
76
77 [[nodiscard]] constexpr translate3(float x, float y, float z = 0.0f) noexcept
78 : _v(x, y, z, 0.0f)
79 {
80 }
81
82 [[nodiscard]] constexpr float x() const noexcept
83 {
84 return _v.x();
85 }
86
87 [[nodiscard]] constexpr float y() const noexcept
88 {
89 return _v.y();
90 }
91
92 [[nodiscard]] constexpr float z() const noexcept
93 {
94 return _v.z();
95 }
96
97 [[nodiscard]] constexpr float& x() noexcept
98 {
99 return _v.x();
100 }
101
102 [[nodiscard]] constexpr float& y() noexcept
103 {
104 return _v.y();
105 }
106
107 [[nodiscard]] constexpr float& z() noexcept
108 {
109 return _v.z();
110 }
111
118 [[nodiscard]] constexpr static translate3 align(
121 alignment alignment) noexcept
122 {
123 auto x = float{0};
125 x = dst_rectangle.left();
126
128 x = dst_rectangle.right() - src_rectangle.width();
129
131 x = dst_rectangle.center() - src_rectangle.width() * 0.5f;
132
133 } else {
134 hi_no_default();
135 }
136
137 auto y = float{0};
139 y = dst_rectangle.bottom();
140
141 } else if (alignment == vertical_alignment::top) {
142 y = dst_rectangle.top() - src_rectangle.height();
143
145 y = dst_rectangle.middle() - src_rectangle.height() * 0.5f;
146
147 } else {
148 hi_no_default();
149 }
150
151 return translate3{x - src_rectangle.left(), y - src_rectangle.bottom()};
152 }
153
154 [[nodiscard]] constexpr friend bool operator==(translate3 const& lhs, translate3 const& rhs) noexcept
155 {
156 return equal(lhs._v, rhs._v);
157 }
158
159 [[nodiscard]] constexpr translate3 operator~() const noexcept
160 {
161 return translate3{-_v};
162 }
163
164 [[nodiscard]] constexpr bool holds_invariant() const noexcept
165 {
166 return _v.w() == 0.0f;
167 }
168
169 [[nodiscard]] friend constexpr translate3 round(translate3 const& rhs) noexcept
170 {
171 return translate3{round(rhs._v)};
172 }
173
174private:
175 array_type _v;
176};
177
178[[nodiscard]] constexpr translate3 translate_z(float z) noexcept
179{
180 return translate3{0.0f, 0.0f, z};
181}
182
183}} // namespace hi::inline v1
@ middle
Align to the vertical-middle.
@ bottom
Align to the bottom.
@ top
Align to the top.
@ 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.
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
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:29
Horizontal/Vertical alignment combination.
Definition alignment.hpp:242
Definition translate2.hpp:14
Definition translate3.hpp:18
static constexpr translate3 align(aarectangle src_rectangle, aarectangle dst_rectangle, alignment alignment) noexcept
Align a rectangle within another rectangle.
Definition translate3.hpp:118
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector3.hpp:20