mirror of
https://github.com/godotengine/godot.git
synced 2026-02-07 19:32:36 +00:00
[Core] Add scalar versions of Vector* min/max/clamp/snap(ped)
Convenience for a number of cases operating on single values
This commit is contained in:
@@ -171,12 +171,25 @@ void Vector4::snap(const Vector4 &p_step) {
|
||||
w = Math::snapped(w, p_step.w);
|
||||
}
|
||||
|
||||
void Vector4::snapf(real_t p_step) {
|
||||
x = Math::snapped(x, p_step);
|
||||
y = Math::snapped(y, p_step);
|
||||
z = Math::snapped(z, p_step);
|
||||
w = Math::snapped(w, p_step);
|
||||
}
|
||||
|
||||
Vector4 Vector4::snapped(const Vector4 &p_step) const {
|
||||
Vector4 v = *this;
|
||||
v.snap(p_step);
|
||||
return v;
|
||||
}
|
||||
|
||||
Vector4 Vector4::snappedf(real_t p_step) const {
|
||||
Vector4 v = *this;
|
||||
v.snapf(p_step);
|
||||
return v;
|
||||
}
|
||||
|
||||
Vector4 Vector4::inverse() const {
|
||||
return Vector4(1.0f / x, 1.0f / y, 1.0f / z, 1.0f / w);
|
||||
}
|
||||
@@ -189,6 +202,14 @@ Vector4 Vector4::clamp(const Vector4 &p_min, const Vector4 &p_max) const {
|
||||
CLAMP(w, p_min.w, p_max.w));
|
||||
}
|
||||
|
||||
Vector4 Vector4::clampf(real_t p_min, real_t p_max) const {
|
||||
return Vector4(
|
||||
CLAMP(x, p_min, p_max),
|
||||
CLAMP(y, p_min, p_max),
|
||||
CLAMP(z, p_min, p_max),
|
||||
CLAMP(w, p_min, p_max));
|
||||
}
|
||||
|
||||
Vector4::operator String() const {
|
||||
return "(" + String::num_real(x, false) + ", " + String::num_real(y, false) + ", " + String::num_real(z, false) + ", " + String::num_real(w, false) + ")";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user