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