From 658624a73dbdc34ac84ccf4c8fd0ca68cf556a93 Mon Sep 17 00:00:00 2001 From: Matt Thorson Date: Tue, 22 Sep 2020 20:57:43 -0700 Subject: [PATCH] generic Calc.Approach --- src/Core/Scene.bf | 1 - src/Static/Calc.bf | 12 ++++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Core/Scene.bf b/src/Core/Scene.bf index 646f1f8..a9a7909 100644 --- a/src/Core/Scene.bf +++ b/src/Core/Scene.bf @@ -6,7 +6,6 @@ namespace Strawberry public class Scene { public float TimeStarted { get; private set; } - public Rect Bounds; private List entities; private HashSet toRemove; diff --git a/src/Static/Calc.bf b/src/Static/Calc.bf index b4c7b4c..c47d2de 100644 --- a/src/Static/Calc.bf +++ b/src/Static/Calc.bf @@ -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 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* 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); }