diff options
author | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2024-03-03 14:37:52 +0100 |
---|---|---|
committer | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2024-05-02 10:31:13 +0200 |
commit | 308dbb8c6359589ce7411027cecd777938e40bd7 (patch) | |
tree | 80a8cf2eff0d0c1ef1e7e0913b8616e0ee4e376a /core/math/vector3.cpp | |
parent | f91db3dc58f1d6a0cb63d591515183b5a45cd3ba (diff) | |
download | redot-engine-308dbb8c6359589ce7411027cecd777938e40bd7.tar.gz |
[Core] Add scalar versions of `Vector*` `min/max/clamp/snap(ped)`
Convenience for a number of cases operating on single values
Diffstat (limited to 'core/math/vector3.cpp')
-rw-r--r-- | core/math/vector3.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp index fad5f2c0fb..1e90002665 100644 --- a/core/math/vector3.cpp +++ b/core/math/vector3.cpp @@ -52,6 +52,13 @@ Vector3 Vector3::clamp(const Vector3 &p_min, const Vector3 &p_max) const { CLAMP(z, p_min.z, p_max.z)); } +Vector3 Vector3::clampf(real_t p_min, real_t p_max) const { + return Vector3( + CLAMP(x, p_min, p_max), + CLAMP(y, p_min, p_max), + CLAMP(z, p_min, p_max)); +} + void Vector3::snap(const Vector3 &p_step) { x = Math::snapped(x, p_step.x); y = Math::snapped(y, p_step.y); @@ -64,6 +71,18 @@ Vector3 Vector3::snapped(const Vector3 &p_step) const { return v; } +void Vector3::snapf(real_t p_step) { + x = Math::snapped(x, p_step); + y = Math::snapped(y, p_step); + z = Math::snapped(z, p_step); +} + +Vector3 Vector3::snappedf(real_t p_step) const { + Vector3 v = *this; + v.snapf(p_step); + return v; +} + Vector3 Vector3::limit_length(real_t p_len) const { const real_t l = length(); Vector3 v = *this; |