forked from laicasaane/unity-supplements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPseudoProbability.IMath.cs
57 lines (43 loc) · 1.33 KB
/
PseudoProbability.IMath.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
namespace System
{
public partial class PseudoProbability
{
public interface IMath
{
float Abs(float f);
int CeilToInt(float f);
int RoundToInt(float f);
float Min(float a, float b);
float Clamp(float value, float min, float max);
int Clamp(int value, int min, int max);
}
private readonly struct PMath : IMath
{
public float Abs(float f)
=> Math.Abs(f);
public int CeilToInt(float f)
=> (int)Math.Ceiling(f);
public float Clamp(float value, float min, float max)
{
if (value < min)
value = min;
else if (value > max)
value = max;
return value;
}
public int Clamp(int value, int min, int max)
{
if (value < min)
value = min;
else if (value > max)
value = max;
return value;
}
public float Min(float a, float b)
=> a < b ? a : b;
public int RoundToInt(float f)
=> (int)Math.Round(f);
public static PMath Default { get; } = new PMath();
}
}
}