mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-06 01:00:16 +00:00
add clamp option to map function
This commit is contained in:
parent
3178074803
commit
40e1c948dd
@ -412,7 +412,7 @@ namespace QSB.TimeSync
|
||||
return;
|
||||
}
|
||||
|
||||
var mappedTimescale = diff.Map(-PauseOrFastForwardThreshold, PauseOrFastForwardThreshold, 1 + TimescaleBounds, 1 - TimescaleBounds);
|
||||
var mappedTimescale = diff.Map(-PauseOrFastForwardThreshold, PauseOrFastForwardThreshold, 1 + TimescaleBounds, 1 - TimescaleBounds, true);
|
||||
if (mappedTimescale > 100f)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - CheckTimeDifference() returned over 100 - should have switched into fast-forward!", MessageType.Warning);
|
||||
|
@ -100,8 +100,14 @@ namespace QSB.Utility
|
||||
}
|
||||
}
|
||||
|
||||
public static float Map(this float value, float inputFrom, float inputTo, float outputFrom, float outputTo)
|
||||
=> ((value - inputFrom) / (inputTo - inputFrom) * (outputTo - outputFrom)) + outputFrom;
|
||||
public static float Map(this float value, float inputFrom, float inputTo, float outputFrom, float outputTo, bool clamp)
|
||||
{
|
||||
var mappedValue = ((value - inputFrom) / (inputTo - inputFrom) * (outputTo - outputFrom)) + outputFrom;
|
||||
|
||||
return clamp
|
||||
? Mathf.Clamp(mappedValue, outputTo, outputFrom)
|
||||
: mappedValue;
|
||||
}
|
||||
|
||||
public static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> action)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user