forked from spacechase0/GenericModConfigMenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil.cs
37 lines (32 loc) · 937 Bytes
/
Util.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GenericModConfigMenu
{
public struct Range<T>
{
public T Minimum;
public T Maximum;
}
public class Util
{
public static T Clamp< T >(T min, T t, T max)
{
if (Comparer<T>.Default.Compare(min, t) > 0)
return min;
if (Comparer<T>.Default.Compare(max, t) < 0)
return max;
return t;
}
public static T Adjust<T>(T value, T interval)
{
if (value is float vFloat && interval is float iFloat)
value = (T)(object)(float)((decimal) vFloat - ((decimal) vFloat % (decimal) iFloat));
if (value is int vInt && interval is int iInt)
value = (T)(object)(vInt - vInt % iInt);
return value;
}
}
}