SA_Maths
Sapphire Suite's C++ Maths Library
Loading...
Searching...
No Matches
TransformScale.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_SCALE_GUARD
6#define SAPPHIRE_MATHS_TRANSFORM_SCALE_GUARD
7
9
12
23namespace SA
24{
30 template <typename T>
31 struct TrScale
32 {
35
36
37 //{ Constructors
38
40 TrScale() = default;
41
47 TrScale(const Vec3<T>& _scale) noexcept :
48 scale{ _scale }
49 {
50 }
51
52 //}
53
54
55 //{ Cast
56
63 template <typename TOut>
64 operator TrScale<TOut>() const noexcept
65 {
66 return TrScale<TOut>(scale);
67 }
68
69 //}
70
71
72 protected:
73
74 //{ Equals
75
81 constexpr bool IsZero() const noexcept
82 {
83 return scale.IsZero();
84 }
85
92 constexpr bool IsIdentity() const noexcept
93 {
94 return scale == Vec3<T>::One;
95 }
96
105 constexpr bool Equals(const TrScale& _other,
106 T _epsilon = std::numeric_limits<T>::epsilon()) const noexcept
107 {
108 return scale.Equals(_other.scale, _epsilon);
109 }
110
111 //}
112
113
114 //{ Lerp
115
124 static TrScale LerpUnclamped(const TrScale& _start, const TrScale& _end, float _alpha) noexcept
125 {
126 return TrScale{ Vec3<T>::LerpUnclamped(_start.scale, _end.scale, _alpha) };
127 }
128
129 //}
130
131
132 //{ Operators
133
145 template <typename RhsT>
146 static TrScale Multiply(const TrScale& _lhs, const RhsT& _rhs) noexcept
147 {
148 if constexpr (TrTHasComponent(RhsT)<SA::TrScale>())
149 {
150 // Scale component found.
151 return TrScale{ _lhs.scale * _rhs.scale };
152 }
153 else if constexpr (TrTHasComponent(RhsT)<SA::TrUScale>())
154 {
155 // UScale component found instead.
156 return TrScale{ _lhs.scale * _rhs.uScale };
157 }
158 else
159 {
160 // Default: forward component (lhs always has this component).
161
162 return _lhs;
163 }
164 }
165
166
178 template <typename RhsT>
179 static TrScale Divide(const TrScale& _lhs, const RhsT& _rhs) noexcept
180 {
181 if constexpr (TrTHasComponent(RhsT)<SA::TrScale>())
182 {
183 // Scale component found.
184 return TrScale{ _lhs.scale / _rhs.scale };
185 }
186 else if constexpr (TrTHasComponent(RhsT)<SA::TrUScale>())
187 {
188 // UScale component found instead.
189 return TrScale{ _lhs.scale / _rhs.uScale };
190 }
191 else
192 {
193 // Default: forward component (lhs always has this component).
194
195 return _lhs;
196 }
197 }
198
199 //}
200
201 #if SA_LOGGER_IMPL
202
208 std::string ToString() const
209 {
210 return "Scale: " + SA::ToString(scale);
211 }
212
213 #endif
214
215 };
216}
217
218
221#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.
Vector 3 type implementation.
Transform scale component.
Definition TransformScale.hpp:32
TrScale()=default
Default constructor.
constexpr bool IsZero() const noexcept
IsZero component implementation.
Definition TransformScale.hpp:81
constexpr bool IsIdentity() const noexcept
IsIdentity component implementation. scale must be at Vec3::One for identity transform.
Definition TransformScale.hpp:92
constexpr bool Equals(const TrScale &_other, T _epsilon=std::numeric_limits< T >::epsilon()) const noexcept
Equals component implementation.
Definition TransformScale.hpp:105
static TrScale LerpUnclamped(const TrScale &_start, const TrScale &_end, float _alpha) noexcept
LerpUnclamped component implementation.
Definition TransformScale.hpp:124
TrScale(const Vec3< T > &_scale) noexcept
Constructor from Vec3.
Definition TransformScale.hpp:47
static TrScale Divide(const TrScale &_lhs, const RhsT &_rhs) noexcept
Transform division implementation for scale component.
Definition TransformScale.hpp:179
static TrScale Multiply(const TrScale &_lhs, const RhsT &_rhs) noexcept
Transform multiplication implementation for scale component.
Definition TransformScale.hpp:146
Vec3< T > scale
Handled scale.
Definition TransformScale.hpp:34
Transform uniform scale component.
Definition TransformUScale.hpp:29
Vector 3 Sapphire-Maths class.
Definition Vector3.hpp:43
static Vec3 LerpUnclamped(const Vec3 &_start, const Vec3 &_end, float _alpha) noexcept
Unclamped Lerp from _start to _end at _alpha.