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#include <exception>
12#include <compare>
13
14hi_export_module(hikogui.geometry : translate3);
15
16hi_export namespace hi { inline namespace v1 {
17
18class translate3;
19[[nodiscard]] constexpr point3 operator*(translate3 const& lhs, point3 const& rhs) noexcept;
20
21
23public:
24 using array_type = simd<float, 4>;
25 using value_type = array_type::value_type;
26
27 constexpr translate3(translate3 const&) noexcept = default;
28 constexpr translate3(translate3&&) noexcept = default;
29 constexpr translate3& operator=(translate3 const&) noexcept = default;
30 constexpr translate3& operator=(translate3&&) noexcept = default;
31
32 [[nodiscard]] constexpr translate3() noexcept : _v(0.0f, 0.0f, 0.0f, 0.0f) {}
33
34 [[nodiscard]] constexpr explicit operator array_type() const noexcept
35 {
36 return _v;
37 }
38
39 [[nodiscard]] constexpr explicit translate3(array_type const& other) noexcept : _v(other)
40 {
41 hi_axiom(holds_invariant());
42 }
43
44 [[nodiscard]] constexpr explicit translate3(aarectangle const& other) noexcept :
45 _v(static_cast<array_type>(get<0>(other)).xy00())
46 {
47 }
48
49 [[nodiscard]] constexpr explicit translate3(aarectangle const& other, float z) noexcept
50 : _v(static_cast<array_type>(get<0>(other)).xy00())
51 {
52 _v.z() = z;
53 }
54
55 [[nodiscard]] constexpr translate3(translate2 const& other) noexcept : _v(static_cast<array_type>(other))
56 {
57 }
58
59 [[nodiscard]] constexpr translate3(translate2 const& other, float z) noexcept : _v(static_cast<array_type>(other))
60 {
61 _v.z() = z;
62 }
63
64 [[nodiscard]] constexpr explicit operator translate2() const noexcept
65 {
66 auto tmp = _v;
67 tmp.z() = 0.0f;
68 return translate2{tmp};
69 }
70
71 [[nodiscard]] constexpr explicit translate3(vector3 const& other) noexcept
72 : _v(static_cast<array_type>(other))
73 {
74 }
75
76 [[nodiscard]] constexpr explicit translate3(point3 const& other) noexcept
77 : _v(static_cast<array_type>(other).xyz0())
78 {
79 }
80
81 [[nodiscard]] constexpr translate3(float x, float y, float z = 0.0f) noexcept
82 : _v(x, y, z, 0.0f)
83 {
84 }
85
86 [[nodiscard]] constexpr float x() const noexcept
87 {
88 return _v.x();
89 }
90
91 [[nodiscard]] constexpr float y() const noexcept
92 {
93 return _v.y();
94 }
95
96 [[nodiscard]] constexpr float z() const noexcept
97 {
98 return _v.z();
99 }
100
101 [[nodiscard]] constexpr float& x() noexcept
102 {
103 return _v.x();
104 }
105
106 [[nodiscard]] constexpr float& y() noexcept
107 {
108 return _v.y();
109 }
110
111 [[nodiscard]] constexpr float& z() noexcept
112 {
113 return _v.z();
114 }
115
122 [[nodiscard]] constexpr static translate3 align(
123 aarectangle src_rectangle,
124 aarectangle dst_rectangle,
125 alignment alignment) noexcept
126 {
127 auto x = float{0};
129 x = dst_rectangle.left();
130
132 x = dst_rectangle.right() - src_rectangle.width();
133
135 x = dst_rectangle.center() - src_rectangle.width() * 0.5f;
136
137 } else {
138 hi_no_default();
139 }
140
141 auto y = float{0};
143 y = dst_rectangle.bottom();
144
145 } else if (alignment == vertical_alignment::top) {
146 y = dst_rectangle.top() - src_rectangle.height();
147
149 y = dst_rectangle.middle() - src_rectangle.height() * 0.5f;
150
151 } else {
152 hi_no_default();
153 }
154
155 return translate3{x - src_rectangle.left(), y - src_rectangle.bottom()};
156 }
157
158 [[nodiscard]] constexpr friend bool operator==(translate3 const& lhs, translate3 const& rhs) noexcept
159 {
160 return equal(lhs._v, rhs._v);
161 }
162
163 [[nodiscard]] constexpr translate3 operator~() const noexcept
164 {
165 return translate3{-_v};
166 }
167
168 [[nodiscard]] constexpr bool holds_invariant() const noexcept
169 {
170 return _v.w() == 0.0f;
171 }
172
173 [[nodiscard]] friend constexpr translate3 round(translate3 const& rhs) noexcept
174 {
175 return translate3{round(rhs._v)};
176 }
177
178private:
179 array_type _v;
180};
181
182[[nodiscard]] constexpr translate3 translate_z(float z) noexcept
183{
184 return translate3{0.0f, 0.0f, z};
185}
186
187}} // 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.
The HikoGUI namespace.
Definition array_generic.hpp:20
constexpr matrix2 operator*(matrix2 const &lhs, matrix2 const &rhs) noexcept
Matrix/Matrix multiplication.
Definition transform.hpp:69
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition simd_intf.hpp:18
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:33
Horizontal/Vertical alignment combination.
Definition alignment.hpp:244
Definition translate2.hpp:18
Definition translate3.hpp:22
static constexpr translate3 align(aarectangle src_rectangle, aarectangle dst_rectangle, alignment alignment) noexcept
Align a rectangle within another rectangle.
Definition translate3.hpp:122
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector3.hpp:26