Allow clamping vectors and colors
This commit is contained in:
@ -256,6 +256,27 @@ namespace Godot
|
||||
return res;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new color with all components clamped between the
|
||||
/// components of `min` and `max` using
|
||||
/// <see cref="Mathf.Clamp(float, float, float)"/>.
|
||||
/// </summary>
|
||||
/// <param name="min">The color with minimum allowed values.</param>
|
||||
/// <param name="max">The color with maximum allowed values.</param>
|
||||
/// <returns>The color with all components clamped.</returns>
|
||||
public Color Clamp(Color? min = null, Color? max = null)
|
||||
{
|
||||
Color minimum = min ?? new Color(0, 0, 0, 0);
|
||||
Color maximum = max ?? new Color(1, 1, 1, 1);
|
||||
return new Color
|
||||
(
|
||||
(float)Mathf.Clamp(r, minimum.r, maximum.r),
|
||||
(float)Mathf.Clamp(g, minimum.g, maximum.g),
|
||||
(float)Mathf.Clamp(b, minimum.b, maximum.b),
|
||||
(float)Mathf.Clamp(a, minimum.a, maximum.a)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new color resulting from making this color darker
|
||||
/// by the specified ratio (on the range of 0 to 1).
|
||||
|
||||
@ -159,6 +159,23 @@ namespace Godot
|
||||
return new Vector2(Mathf.Ceil(x), Mathf.Ceil(y));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new vector with all components clamped between the
|
||||
/// components of `min` and `max` using
|
||||
/// <see cref="Mathf.Clamp(real_t, real_t, real_t)"/>.
|
||||
/// </summary>
|
||||
/// <param name="min">The vector with minimum allowed values.</param>
|
||||
/// <param name="max">The vector with maximum allowed values.</param>
|
||||
/// <returns>The vector with all components clamped.</returns>
|
||||
public Vector2 Clamp(Vector2 min, Vector2 max)
|
||||
{
|
||||
return new Vector2
|
||||
(
|
||||
Mathf.Clamp(x, min.x, max.x),
|
||||
Mathf.Clamp(y, min.y, max.y)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cross product of this vector and `b`.
|
||||
/// </summary>
|
||||
|
||||
@ -119,6 +119,23 @@ namespace Godot
|
||||
return x / (real_t)y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new vector with all components clamped between the
|
||||
/// components of `min` and `max` using
|
||||
/// <see cref="Mathf.Clamp(int, int, int)"/>.
|
||||
/// </summary>
|
||||
/// <param name="min">The vector with minimum allowed values.</param>
|
||||
/// <param name="max">The vector with maximum allowed values.</param>
|
||||
/// <returns>The vector with all components clamped.</returns>
|
||||
public Vector2i Clamp(Vector2i min, Vector2i max)
|
||||
{
|
||||
return new Vector2i
|
||||
(
|
||||
Mathf.Clamp(x, min.x, max.x),
|
||||
Mathf.Clamp(y, min.y, max.y)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cross product of this vector and `b`.
|
||||
/// </summary>
|
||||
|
||||
@ -139,6 +139,24 @@ namespace Godot
|
||||
return new Vector3(Mathf.Ceil(x), Mathf.Ceil(y), Mathf.Ceil(z));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new vector with all components clamped between the
|
||||
/// components of `min` and `max` using
|
||||
/// <see cref="Mathf.Clamp(real_t, real_t, real_t)"/>.
|
||||
/// </summary>
|
||||
/// <param name="min">The vector with minimum allowed values.</param>
|
||||
/// <param name="max">The vector with maximum allowed values.</param>
|
||||
/// <returns>The vector with all components clamped.</returns>
|
||||
public Vector3 Clamp(Vector3 min, Vector3 max)
|
||||
{
|
||||
return new Vector3
|
||||
(
|
||||
Mathf.Clamp(x, min.x, max.x),
|
||||
Mathf.Clamp(y, min.y, max.y),
|
||||
Mathf.Clamp(z, min.z, max.z)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cross product of this vector and `b`.
|
||||
/// </summary>
|
||||
|
||||
@ -88,6 +88,24 @@ namespace Godot
|
||||
return new Vector3i(Mathf.Abs(x), Mathf.Abs(y), Mathf.Abs(z));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new vector with all components clamped between the
|
||||
/// components of `min` and `max` using
|
||||
/// <see cref="Mathf.Clamp(int, int, int)"/>.
|
||||
/// </summary>
|
||||
/// <param name="min">The vector with minimum allowed values.</param>
|
||||
/// <param name="max">The vector with maximum allowed values.</param>
|
||||
/// <returns>The vector with all components clamped.</returns>
|
||||
public Vector3i Clamp(Vector3i min, Vector3i max)
|
||||
{
|
||||
return new Vector3i
|
||||
(
|
||||
Mathf.Clamp(x, min.x, max.x),
|
||||
Mathf.Clamp(y, min.y, max.y),
|
||||
Mathf.Clamp(z, min.z, max.z)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the squared distance between this vector and `b`.
|
||||
/// This method runs faster than <see cref="DistanceTo"/>, so prefer it if
|
||||
|
||||
Reference in New Issue
Block a user