HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
translate2.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 "point2.hpp"
8#include "aarectangle.hpp"
9#include <concepts>
10
11namespace hi { inline namespace v1 {
12
14public:
15 using array_type = simd<float, 4>;
16 using value_type = array_type::value_type;
17
18 constexpr translate2(translate2 const&) noexcept = default;
19 constexpr translate2(translate2&&) noexcept = default;
20 constexpr translate2& operator=(translate2 const&) noexcept = default;
21 constexpr translate2& operator=(translate2&&) noexcept = default;
22
23 [[nodiscard]] constexpr translate2() noexcept : _v(0.0f, 0.0f, 0.0f, 0.0f) {}
24
25 [[nodiscard]] constexpr explicit operator array_type() const noexcept
26 {
27 return _v;
28 }
29
30 [[nodiscard]] constexpr explicit translate2(array_type const& other) noexcept : _v(other)
31 {
32 hi_axiom(holds_invariant());
33 }
34
35 [[nodiscard]] constexpr explicit translate2(aarectangle const& other) noexcept :
36 _v(static_cast<array_type>(get<0>(other)).xy00())
37 {
38 }
39
40 [[nodiscard]] constexpr explicit translate2(aarectangle const& other, float z) noexcept :
41 _v(static_cast<array_type>(get<0>(other)).xy00())
42 {
43 _v.z() = z;
44 }
45
46 [[nodiscard]] constexpr explicit translate2(vector2 const& other) noexcept : _v(static_cast<array_type>(other)) {}
47
48 [[nodiscard]] constexpr explicit translate2(point2 const& other) noexcept : _v(static_cast<array_type>(other).xy00()) {}
49
50 [[nodiscard]] constexpr translate2(float x, float y) noexcept : _v(x, y, 0.0f, 0.0f) {}
51
52 [[nodiscard]] constexpr float x() const noexcept
53 {
54 return _v.x();
55 }
56
57 [[nodiscard]] constexpr float y() const noexcept
58 {
59 return _v.y();
60 }
61
62 [[nodiscard]] constexpr float& x() noexcept
63 {
64 return _v.x();
65 }
66
67 [[nodiscard]] constexpr float& y() noexcept
68 {
69 return _v.y();
70 }
71
78 [[nodiscard]] constexpr static translate2
79 align(aarectangle src_rectangle, aarectangle dst_rectangle, alignment alignment) noexcept
80 {
81 auto x = float{0};
83 x = dst_rectangle.left();
84
86 x = dst_rectangle.right() - src_rectangle.width();
87
89 x = dst_rectangle.center() - src_rectangle.width() * 0.5f;
90
91 } else {
93 }
94
95 auto y = float{0};
97 y = dst_rectangle.bottom();
98
99 } else if (alignment == vertical_alignment::top) {
100 y = dst_rectangle.top() - src_rectangle.height();
101
103 y = dst_rectangle.middle() - src_rectangle.height() * 0.5f;
104
105 } else {
107 }
108
109 return translate2{x - src_rectangle.left(), y - src_rectangle.bottom()};
110 }
111
112 [[nodiscard]] constexpr friend bool operator==(translate2 const& lhs, translate2 const& rhs) noexcept
113 {
114 return equal(lhs._v, rhs._v);
115 }
116
117 [[nodiscard]] constexpr translate2 operator~() const noexcept
118 {
119 return translate2{-_v};
120 }
121
122 [[nodiscard]] constexpr bool holds_invariant() const noexcept
123 {
124 return _v.z() == 0.0f and _v.w() == 0.0f;
125 }
126
127 [[nodiscard]] friend constexpr translate2 round(translate2 const& rhs) noexcept
128 {
129 return translate2{round(rhs._v)};
130 }
131
132private:
133 array_type _v;
134};
135
136}} // namespace hi::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
static constexpr translate2 align(aarectangle src_rectangle, aarectangle dst_rectangle, alignment alignment) noexcept
Align a rectangle within another rectangle.
Definition translate2.hpp:79
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector2.hpp:18