cirnogodot/GTweensGodot/GTweens/Source/Extensions/MathExtensions.cs
2025-02-24 11:52:50 +01:00

27 lines
No EOL
624 B
C#

using System;
namespace GTweens.Extensions;
public static class MathExtensions
{
public const float Deg2Rad = 0.01745329f;
public const float Rad2Deg = 57.29578f;
public static float SafeDivide(float v1, float v2)
{
if (v2 == 0f)
{
return 0f;
}
return v1 / v2;
}
/// <summary>
/// Loops the value t, so that it is never larger than length and never smaller than 0.
/// </summary>
public static float Repeat(float t, float length)
{
return Math.Clamp(t - (float)Math.Floor(t / length) * length, 0.0f, length);
}
}