SA_Maths
Sapphire Suite's C++ Maths Library
Loading...
Searching...
No Matches
TransformUScale.hpp
Go to the documentation of this file.
1// Copyright (c) 2023 Sapphire Development Team. All Rights Reserved.
2
3#pragma once
4
5#ifndef SAPPHIRE_MATHS_TRANSFORM_USCALE_GUARD
6#define SAPPHIRE_MATHS_TRANSFORM_USCALE_GUARD
7
9
20namespace SA
21{
27 template <typename T>
28 struct TrUScale
29 {
31 T uScale = T(1);
32
33
34 //{ Constructors
35
37 TrUScale() = default;
38
44 TrUScale(T _uscale) noexcept :
45 uScale{ _uscale }
46 {
47 }
48
49 //}
50
51
52 //{ Cast
53
60 template <typename TOut>
61 operator TrUScale<TOut>() const noexcept
62 {
63 return TrUScale<TOut>(uScale);
64 }
65
66 //}
67
68 protected:
69
70 //{ Equals
71
77 constexpr bool IsZero() const noexcept
78 {
79 return SA::Maths::Equals0(uScale);
80 }
81
88 constexpr bool IsIdentity() const noexcept
89 {
90 return SA::Maths::Equals1(uScale);
91 }
92
101 constexpr bool Equals(const TrUScale& _other,
102 T _epsilon = std::numeric_limits<T>::epsilon()) const noexcept
103 {
104 return Maths::Equals(uScale, _other.uScale, _epsilon);
105 }
106
107 //}
108
109
110 //{ Lerp
111
120 static TrUScale LerpUnclamped(const TrUScale& _start, const TrUScale& _end, float _alpha) noexcept
121 {
122 return TrUScale{ Maths::LerpUnclamped(_start.uScale, _end.uScale, _alpha) };
123 }
124
125 //}
126
127
128 //{ Operators
129
138 template <typename RhsT>
139 static TrUScale Multiply(const TrUScale& _lhs, const RhsT& _rhs) noexcept
140 {
141 if constexpr (TrTHasComponent(RhsT)<SA::TrUScale>())
142 {
143 // UScale component found.
144
145 return TrUScale{ _lhs.uScale * _rhs.uScale };
146 }
147 else
148 {
149 // Default: forward component (lhs always has this component).
150
151 return _lhs;
152 }
153 }
154
163 template <typename RhsT>
164 static TrUScale Divide(const TrUScale& _lhs, const RhsT& _rhs) noexcept
165 {
166 if constexpr (TrTHasComponent(RhsT)<SA::TrUScale>())
167 {
168 // UScale component found.
169
170 return TrUScale{ _lhs.uScale / _rhs.uScale };
171 }
172 else
173 {
174 // Default: forward component (lhs always has this component).
175
176 return _lhs;
177 }
178 }
179
180 //}
181
182 #if SA_LOGGER_IMPL
183
189 std::string ToString() const
190 {
191 return "UScale: " + SA::ToString(uScale);
192 }
193
194 #endif
195
196 };
197}
198
199
202#endif // GUARD
Transform Component base helper definition.
#define TrTHasComponent(_trT)
Helper macro for transform HasComponent check in templated functions.
Definition TransformComponent.hpp:21
Transform uniform scale component.
Definition TransformUScale.hpp:29
static TrUScale Multiply(const TrUScale &_lhs, const RhsT &_rhs) noexcept
Transform multiplication implementation for uniform scale component.
Definition TransformUScale.hpp:139
static TrUScale LerpUnclamped(const TrUScale &_start, const TrUScale &_end, float _alpha) noexcept
LerpUnclamped component implementation.
Definition TransformUScale.hpp:120
TrUScale(T _uscale) noexcept
Constructor from T.
Definition TransformUScale.hpp:44
static TrUScale Divide(const TrUScale &_lhs, const RhsT &_rhs) noexcept
Transform division implementation for uniform scale component.
Definition TransformUScale.hpp:164
constexpr bool Equals(const TrUScale &_other, T _epsilon=std::numeric_limits< T >::epsilon()) const noexcept
Equals component implementation.
Definition TransformUScale.hpp:101
constexpr bool IsZero() const noexcept
IsZero component implementation.
Definition TransformUScale.hpp:77
T uScale
Handled uniform scale.
Definition TransformUScale.hpp:31
constexpr bool IsIdentity() const noexcept
IsIdentity component implementation. uniform scale must == 1 for identity transform.
Definition TransformUScale.hpp:88
TrUScale()=default
Default constructor.