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 <concepts>
10
11namespace hi { inline namespace v1 {
12
13class translate3;
14[[nodiscard]] constexpr point3 operator*(translate3 const& lhs, point3 const& rhs) noexcept;
15
16
18public:
19 using array_type = simd<float, 4>;
20 using value_type = array_type::value_type;
21
22 constexpr translate3(translate3 const&) noexcept = default;
23 constexpr translate3(translate3&&) noexcept = default;
24 constexpr translate3& operator=(translate3 const&) noexcept = default;
25 constexpr translate3& operator=(translate3&&) noexcept = default;
26
27 [[nodiscard]] constexpr translate3() noexcept : _v(0.0f, 0.0f, 0.0f, 0.0f) {}
28
29 [[nodiscard]] constexpr explicit operator array_type() const noexcept
30 {
31 return _v;
32 }
33
34 [[nodiscard]] constexpr explicit translate3(array_type const& other) noexcept : _v(other)
35 {
36 hi_axiom(holds_invariant());
37 }
38
39 [[nodiscard]] constexpr explicit translate3(aarectangle const& other) noexcept :
40 _v(static_cast<array_type>(get<0>(other)).xy00())
41 {
42 }
43
44 [[nodiscard]] constexpr explicit translate3(aarectangle const& other, float z) noexcept
45 : _v(static_cast<array_type>(get<0>(other)).xy00())
46 {
47 _v.z() = z;
48 }
49
50 [[nodiscard]] constexpr translate3(translate2 const& other) noexcept : _v(static_cast<array_type>(other))
51 {
52 }
53
54 [[nodiscard]] constexpr translate3(translate2 const& other, float z) noexcept : _v(static_cast<array_type>(other))
55 {
56 _v.z() = z;
57 }
58
59 [[nodiscard]] constexpr explicit operator translate2() const noexcept
60 {
61 auto tmp = _v;
62 tmp.z() = 0.0f;
63 return translate2{tmp};
64 }
65
66 [[nodiscard]] constexpr explicit translate3(vector3 const& other) noexcept
67 : _v(static_cast<array_type>(other))
68 {
69 }
70
71 [[nodiscard]] constexpr explicit translate3(point3 const& other) noexcept
72 : _v(static_cast<array_type>(other).xyz0())
73 {
74 }
75
76 [[nodiscard]] constexpr translate3(float x, float y, float z = 0.0f) noexcept
77 : _v(x, y, z, 0.0f)
78 {
79 }
80
81 [[nodiscard]] constexpr float x() const noexcept
82 {
83 return _v.x();
84 }
85
86 [[nodiscard]] constexpr float y() const noexcept
87 {
88 return _v.y();
89 }
90
91 [[nodiscard]] constexpr float z() const noexcept
92 {
93 return _v.z();
94 }
95
96 [[nodiscard]] constexpr float& x() noexcept
97 {
98 return _v.x();
99 }
100
101 [[nodiscard]] constexpr float& y() noexcept
102 {
103 return _v.y();
104 }
105
106 [[nodiscard]] constexpr float& z() noexcept
107 {
108 return _v.z();
109 }
110
117 [[nodiscard]] constexpr static translate3 align(
118 aarectangle src_rectangle,
119 aarectangle dst_rectangle,
120 alignment alignment) noexcept
121 {
122 auto x = float{0};
124 x = dst_rectangle.left();
125
127 x = dst_rectangle.right() - src_rectangle.width();
128
130 x = dst_rectangle.center() - src_rectangle.width() * 0.5f;
131
132 } else {
134 }
135
136 auto y = float{0};
138 y = dst_rectangle.bottom();
139
140 } else if (alignment == vertical_alignment::top) {
141 y = dst_rectangle.top() - src_rectangle.height();
142
144 y = dst_rectangle.middle() - src_rectangle.height() * 0.5f;
145
146 } else {
148 }
149
150 return translate3{x - src_rectangle.left(), y - src_rectangle.bottom()};
151 }
152
153 [[nodiscard]] constexpr friend bool operator==(translate3 const& lhs, translate3 const& rhs) noexcept
154 {
155 return equal(lhs._v, rhs._v);
156 }
157
158 [[nodiscard]] constexpr translate3 operator~() const noexcept
159 {
160 return translate3{-_v};
161 }
162
163 [[nodiscard]] constexpr bool holds_invariant() const noexcept
164 {
165 return _v.w() == 0.0f;
166 }
167
168 [[nodiscard]] friend constexpr translate3 round(translate3 const& rhs) noexcept
169 {
170 return translate3{round(rhs._v)};
171 }
172
173private:
174 array_type _v;
175};
176
177[[nodiscard]] constexpr translate3 translate_z(float z) noexcept
178{
179 return translate3{0.0f, 0.0f, z};
180}
181
182}} // namespace hi::inline v1
#define hi_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:279
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
@ 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:13
geometry/margins.hpp
Definition cache.hpp:11
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:26
Horizontal/Vertical alignment combination.
Definition alignment.hpp:239
Definition translate2.hpp:13
Definition translate3.hpp:17
static constexpr translate3 align(aarectangle src_rectangle, aarectangle dst_rectangle, alignment alignment) noexcept
Align a rectangle within another rectangle.
Definition translate3.hpp:117
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector3.hpp:19