mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2024-11-25 16:18:56 +08:00
generic Calc.Approach
This commit is contained in:
parent
7603c2e795
commit
658624a73d
|
@ -6,7 +6,6 @@ namespace Strawberry
|
||||||
public class Scene
|
public class Scene
|
||||||
{
|
{
|
||||||
public float TimeStarted { get; private set; }
|
public float TimeStarted { get; private set; }
|
||||||
public Rect Bounds;
|
|
||||||
|
|
||||||
private List<Entity> entities;
|
private List<Entity> entities;
|
||||||
private HashSet<Entity> toRemove;
|
private HashSet<Entity> toRemove;
|
||||||
|
|
|
@ -21,14 +21,22 @@ namespace Strawberry
|
||||||
|
|
||||||
//Move toward a target value without crossing it
|
//Move toward a target value without crossing it
|
||||||
[Inline]
|
[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);
|
return value > target ? Math.Max(value - maxDelta, target) : Math.Min(value + maxDelta, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Move toward a target value without crossing it
|
//Move toward a target value without crossing it
|
||||||
[Inline]
|
[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);
|
*value = *value > target ? Math.Max(*value - maxDelta, target) : Math.Min(*value + maxDelta, target);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user