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
58
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditorInternal;
#endif
namespace Mountools.Tools
{
public static class MountoolsMath
{
public static bool IsInRange(int n, int min, int max, bool equals = true)
{
return equals ?
n <= max && n >= min :
n < max && n > min ;
}
public static bool IsInRange(float n, float min, float max, bool equals = true)
{
return equals ?
n <= max && n >= min :
n < max && n > min ;
}
public static int InRange(int n, int min, int max)
{
if (n < min) return min;
if (n > max) return max;
return n;
}
public static float InRange(float n, float min, float max)
{
if (n < min) return min;
if (n > max) return max;
return n;
}
public static float To(float a, float b, float t)
{
if (a > b) return InRange(a - t, b, a);
if (a < b) return InRange(a + t, a, b);
return a;
}
public static int To(int a, int b, int t)
{
if (a > b) return InRange(a - t, b, a);
if (a < b) return InRange(a + t, a, b);
return a;
}
}
}
|