From b65970860e2cb0b255528553392965b893cbb35f Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Sun, 3 Mar 2024 19:47:59 +0100 Subject: Add scalar versions of `Vector*` `min/max/clamp/snap(ped)` Also added `snapped` to the integer vectors for completeness --- src/variant/vector3.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/variant/vector3.cpp') diff --git a/src/variant/vector3.cpp b/src/variant/vector3.cpp index 6153658..e660185 100644 --- a/src/variant/vector3.cpp +++ b/src/variant/vector3.cpp @@ -54,18 +54,37 @@ 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); z = Math::snapped(z, p_step.z); } +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::snapped(const Vector3 p_step) const { Vector3 v = *this; v.snap(p_step); return v; } +Vector3 Vector3::snappedf(real_t p_step) const { + Vector3 v = *this; + v.snapf(p_step); + return v; +} + Vector3 Vector3::limit_length(const real_t p_len) const { const real_t l = length(); Vector3 v = *this; -- cgit v1.2.3