HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
scale3.hpp
1// Copyright Take Vos 2021-2022.
2// Distributed under the Boost Software License, Version 1.0.
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 "scale2.hpp"
8#include "vector3.hpp"
9#include "extent3.hpp"
10#include "../macros.hpp"
11#include <algorithm>
12#include <exception>
13#include <compare>
14
15hi_export_module(hikogui.geometry : scale3);
16
17hi_export namespace hi { inline namespace v1 {
18
19class scale3 {
20public:
21 using array_type = simd<float, 4>;
22 using value_type = array_type::value_type;
23
24 constexpr scale3(scale3 const&) noexcept = default;
25 constexpr scale3(scale3&&) noexcept = default;
26 constexpr scale3& operator=(scale3 const&) noexcept = default;
27 constexpr scale3& operator=(scale3&&) noexcept = default;
28
29 [[nodiscard]] constexpr scale3(scale2 const& other) noexcept : _v(f32x4{other}) {}
30
31 [[nodiscard]] constexpr explicit operator scale2() const noexcept
32 {
33 auto tmp = _v;
34 tmp.z() = 1.0f;
35 return scale2{tmp};
36 }
37
38 [[nodiscard]] constexpr explicit operator f32x4() const noexcept
39 {
40 return _v;
41 }
42
43 [[nodiscard]] constexpr explicit scale3(f32x4 const& v) noexcept : _v(v)
44 {
45 hi_axiom(holds_invariant());
46 }
47
48 [[nodiscard]] constexpr explicit scale3(vector3 const& v) noexcept : _v(static_cast<f32x4>(v).xyz1()) {}
49
50 [[nodiscard]] constexpr scale3() noexcept : _v(1.0f, 1.0f, 1.0f, 1.0f) {}
51
52 [[nodiscard]] constexpr scale3(float value) noexcept : _v(value, value, value, 1.0f) {}
53
54 [[nodiscard]] constexpr scale3(float x, float y, float z = 1.0f) noexcept : _v(x, y, z, 1.0f) {}
55
61 [[nodiscard]] constexpr static scale3 uniform(extent3 src_extent, extent3 dst_extent) noexcept
62 {
63 auto const non_uniform_scale = static_cast<f32x4>(dst_extent).xyzx() / static_cast<f32x4>(src_extent).xyzx();
64 auto const uniform_scale = std::min({non_uniform_scale.x(), non_uniform_scale.y(), non_uniform_scale.z()});
65 return scale3{uniform_scale};
66 }
67
68 [[nodiscard]] constexpr friend bool operator==(scale3 const& lhs, scale3 const& rhs) noexcept
69 {
70 return equal(lhs._v, rhs._v);
71 }
72
73 [[nodiscard]] constexpr bool holds_invariant() const noexcept
74 {
75 return _v.w() == 1.0f;
76 }
77
78 [[nodiscard]] constexpr float& x() noexcept
79 {
80 return _v.x();
81 }
82
83 [[nodiscard]] constexpr float& y() noexcept
84 {
85 return _v.y();
86 }
87
88 [[nodiscard]] constexpr float& z() noexcept
89 {
90 return _v.z();
91 }
92
93 [[nodiscard]] constexpr float x() const noexcept
94 {
95 return _v.x();
96 }
97
98 [[nodiscard]] constexpr float y() const noexcept
99 {
100 return _v.y();
101 }
102
103 [[nodiscard]] constexpr float z() const noexcept
104 {
105 return _v.z();
106 }
107
108private:
109 array_type _v;
110};
111
112[[nodiscard]] constexpr scale3 operator/(extent3 const& lhs, extent3 const& rhs) noexcept
113{
114 return scale3{f32x4{lhs}.xyz1() / f32x4{rhs}.xyz1()};
115}
116
117}} // namespace hi::v1
Defined the geo::extent, extent2 and extent3 types.
@ other
The gui_event does not have associated data.
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition simd_intf.hpp:18
A high-level geometric extent.
Definition extent3.hpp:33
Definition scale2.hpp:18
Definition scale3.hpp:19
static constexpr scale3 uniform(extent3 src_extent, extent3 dst_extent) noexcept
Get a uniform-scale-transform to scale an extent to another extent.
Definition scale3.hpp:61
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector3.hpp:26
T min(T... args)