generic Calc.Approach

This commit is contained in:
Matt Thorson 2020-09-22 20:57:43 -07:00
parent 7603c2e795
commit 658624a73d
2 changed files with 10 additions and 3 deletions

View File

@ -6,7 +6,6 @@ namespace Strawberry
public class Scene
{
public float TimeStarted { get; private set; }
public Rect Bounds;
private List<Entity> entities;
private HashSet<Entity> toRemove;

View File

@ -21,14 +21,22 @@ namespace Strawberry
//Move toward a target value without crossing it
[Inline]
static public float Approach(float value, float target, float maxDelta)
static public T Approach<T>(T value, T target, T maxDelta)
where bool : operator T < T
where bool : operator T > T
where T : operator T - T
where T : operator T + T
{
return value > target ? Math.Max(value - maxDelta, target) : Math.Min(value + maxDelta, target);
}
//Move toward a target value without crossing it
[Inline]
static public void Approach(float* value, float target, float maxDelta)
static public void Approach<T>(T* value, T target, T maxDelta)
where bool : operator T < T
where bool : operator T > T
where T : operator T - T
where T : operator T + T
{
*value = *value > target ? Math.Max(*value - maxDelta, target) : Math.Min(*value + maxDelta, target);
}