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
11namespace hi { inline namespace v1 {
12
13class scale3 {
14public:
15 using array_type = simd<float, 4>;
16 using value_type = array_type::value_type;
17
18 constexpr scale3(scale3 const&) noexcept = default;
19 constexpr scale3(scale3&&) noexcept = default;
20 constexpr scale3& operator=(scale3 const&) noexcept = default;
21 constexpr scale3& operator=(scale3&&) noexcept = default;
22
23 [[nodiscard]] constexpr scale3(scale2 const& other) noexcept : _v(f32x4{other}) {}
24
25 [[nodiscard]] constexpr explicit operator scale2() const noexcept
26 {
27 auto tmp = _v;
28 tmp.z() = 1.0f;
29 return scale2{tmp};
30 }
31
32 [[nodiscard]] constexpr explicit operator f32x4() const noexcept
33 {
34 return _v;
35 }
36
37 [[nodiscard]] constexpr explicit scale3(f32x4 const& v) noexcept : _v(v)
38 {
39 hi_axiom(holds_invariant());
40 }
41
42 [[nodiscard]] constexpr explicit scale3(vector3 const& v) noexcept : _v(static_cast<f32x4>(v).xyz1()) {}
43
44 [[nodiscard]] constexpr scale3() noexcept : _v(1.0f, 1.0f, 1.0f, 1.0f) {}
45
46 [[nodiscard]] constexpr scale3(float value) noexcept : _v(value, value, value, 1.0f) {}
47
48 [[nodiscard]] constexpr scale3(float x, float y, float z = 1.0f) noexcept : _v(x, y, z, 1.0f) {}
49
55 [[nodiscard]] static constexpr scale3 uniform(extent3 src_extent, extent3 dst_extent) noexcept
56 {
57 hilet non_uniform_scale = static_cast<f32x4>(dst_extent).xyzx() / static_cast<f32x4>(src_extent).xyzx();
58 hilet uniform_scale = std::min({non_uniform_scale.x(), non_uniform_scale.y(), non_uniform_scale.z()});
59 return scale3{uniform_scale};
60 }
61
62 [[nodiscard]] constexpr friend bool operator==(scale3 const& lhs, scale3 const& rhs) noexcept
63 {
64 return equal(lhs._v, rhs._v);
65 }
66
67 [[nodiscard]] constexpr bool holds_invariant() const noexcept
68 {
69 return _v.w() == 1.0f;
70 }
71
72 [[nodiscard]] constexpr float& x() noexcept
73 {
74 return _v.x();
75 }
76
77 [[nodiscard]] constexpr float& y() noexcept
78 {
79 return _v.y();
80 }
81
82 [[nodiscard]] constexpr float& z() noexcept
83 {
84 return _v.z();
85 }
86
87 [[nodiscard]] constexpr float x() const noexcept
88 {
89 return _v.x();
90 }
91
92 [[nodiscard]] constexpr float y() const noexcept
93 {
94 return _v.y();
95 }
96
97 [[nodiscard]] constexpr float z() const noexcept
98 {
99 return _v.z();
100 }
101
102private:
103 array_type _v;
104};
105
106[[nodiscard]] constexpr scale3 operator/(extent3 const& lhs, extent3 const& rhs) noexcept
107{
108 return scale3{f32x4{lhs}.xyz1() / f32x4{rhs}.xyz1()};
109}
110
111}} // namespace hi::v1
Defined the geo::extent, extent2 and extent3 types.
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
@ other
The gui_event does not have associated data.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
A high-level geometric extent.
Definition extent3.hpp:27
Definition scale2.hpp:12
Definition scale3.hpp:13
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:55
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector3.hpp:19
T min(T... args)