-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmathx.rounding.int.cs
152 lines (112 loc) · 6.88 KB
/
mathx.rounding.int.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#region Header
// ** Copyright (C) 2023 Nicolas Reinhard, @LTMX. All rights reserved.
// ** Github Profile: https://github.com/LTMX
// ** Repository : https://github.com/LTMX/Unity.mathx
#endregion
using MI = System.Runtime.CompilerServices.MethodImplAttribute;
namespace Unity.Mathematics
{
public static partial class mathx
{
// Rounding --------------------------------------------------
// Round
// Clamp
///<inheritdoc cref="math.clamp(int4, int4, int4)"/>
[MI(IL)] public static int4 clamp(this int4 f, int4 min, int4 max) => min.max(max.min(f));
///<inheritdoc cref="math.clamp(int3, int3, int3)"/>
[MI(IL)] public static int3 clamp(this int3 f, int3 min, int3 max) => min.max(max.min(f));
///<inheritdoc cref="math.clamp(int2, int2, int2)"/>
[MI(IL)] public static int2 clamp(this int2 f, int2 min, int2 max) => min.max(max.min(f));
///<inheritdoc cref="math.clamp(int, int, int)"/>
[MI(IL)] public static int clamp(this int f, int min, int max) => min.max(max.min(f));
/// Returns the result of clamping of the value x into the interval [a, b]
[MI(IL)] public static int4 clamp(this int4 f, int min, int max) => min.max(max.min(f));
/// <inheritdoc cref="clamp(int4, int, int)"/>
[MI(IL)] public static int3 clamp(this int3 f, int min, int max) => min.max(max.min(f));
/// <inheritdoc cref="clamp(int4, int, int)"/>
[MI(IL)] public static int2 clamp(this int2 f, int min, int max) => min.max(max.min(f));
/// <inheritdoc cref="math.min(int4,int4)"/>
[MI(IL)] public static int4 min(this int4 f, int4 min) => math.min(f, min);
/// <inheritdoc cref="math.min(int3,int3)"/>
[MI(IL)] public static int3 min(this int3 f, int3 min) => math.min(f, min);
/// <inheritdoc cref="math.min(int2,int2)"/>
[MI(IL)] public static int2 min(this int2 f, int2 min) => math.min(f, min);
/// <inheritdoc cref="math.min(int,int)"/>
[MI(IL)] public static int min(this int f, int y) => math.min(f, y);
/// <inheritdoc cref="math.min(int,int)"/>
[MI(IL)] public static float min(this int f, float y) => math.min(f, y);
#region Max
/// <inheritdoc cref="math.max(int4, int4)"/>
[MI(IL)] public static int4 max(this int4 f, int4 max) => math.max(f, max);
/// <inheritdoc cref="math.max(int3, int3)"/>
[MI(IL)] public static int3 max(this int3 f, int3 max) => math.max(f, max);
/// <inheritdoc cref="math.max(Mathematics.int2, Mathematics.int2)"/>
[MI(IL)] public static int2 max(this int2 f, int2 max) => math.max(f, max);
/// <inheritdoc cref="math.max(int, int)"/>
[MI(IL)] public static int max(this int f, int y) => math.max(f, y);
/// <inheritdoc cref="math.max(int, int)"/>
[MI(IL)] public static float max(this int f, float y) => math.max(f, y);
/// Returns the componentwise maximum of a f4 and a int value
[MI(IL)] public static int4 max(this int4 x, int y) => new (max(x.x, y), max(x.y, y), max(x.z, y), max(x.w, y));
/// Returns the componentwise maximum of a f3 and a int value
[MI(IL)] public static int3 max(this int3 x, int y) => new (max(x.x, y), max(x.y, y), max(x.z, y));
/// Returns the componentwise maximum of a f2 and a int value
[MI(IL)] public static int2 max(this int2 x, int y) => new (max(x.x, y), max(x.y, y));
/// Returns the componentwise maximum of a f4 and a int value
[MI(IL)] public static int4 max(this int x, int4 y) => new (max(x, y.x), max(x, y.y), max(x, y.z), max(x, y.w));
/// Returns the componentwise maximum of a f3 and a int value
[MI(IL)] public static int3 max(this int x, int3 y) => new (max(x, y.x), max(x, y.y), max(x, y.z));
/// Returns the componentwise maximum of a f2 and a int value
[MI(IL)] public static int2 max(this int x, int2 y) => new (max(x, y.x), max(x, y.y));
/// Returns the componentwise minimum of a f4 and a int value
[MI(IL)] public static int4 min(this int4 x, int y) => new (min(x.x, y), min(x.y, y), min(x.z, y), min(x.w, y));
/// Returns the componentwise minimum of a f3 and a int value
[MI(IL)] public static int3 min(this int3 x, int y) => new (min(x.x, y), min(x.y, y), min(x.z, y));
/// Returns the componentwise minimum of a f2 and a int value
[MI(IL)] public static int2 min(this int2 x, int y) => new (min(x.x, y), min(x.y, y));
/// Returns the componentwise minimum of a f4 and a int value
[MI(IL)] public static int4 min(this int x, int4 y) => new (min(x, y.x), min(x, y.y), min(x, y.z), min(x, y.w));
/// Returns the componentwise minimum of a f3 and a int value
[MI(IL)] public static int3 min(this int x, int3 y) => new (min(x, y.x), min(x, y.y), min(x, y.z));
/// Returns the componentwise minimum of a f2 and a int value
[MI(IL)] public static int2 min(this int x, int2 y) => new (min(x, y.x), min(x, y.y));
#endregion
#region Ceil
#endregion
#region CeilToInt
#endregion
#region Floor
#endregion
#region Floor To Int
#endregion
#region Saturate
#endregion
/// Same as max(f, 0); It can be useful to prevent negative values in some cases
/// returns 0 if f is negative, otherwise returns f
[MI(IL)] public static int4 limp(this int4 f) => f.max(0);
/// <inheritdoc cref="limp(int4)" />
[MI(IL)] public static int3 limp(this int3 f) => f.max(0);
/// <inheritdoc cref="limp(int4)" />
[MI(IL)] public static int2 limp(this int2 f) => f.max(0);
/// <inheritdoc cref="limp(int4)" />
[MI(IL)] public static int limp(this int f) => f.max(0);
/// Short for min(f, 0);
/// returns 0 if f is positive, otherwise returns f
[MI(IL)] public static int4 limn(this int4 f) => f.min(0);
/// <inheritdoc cref="limn(int)" />
[MI(IL)] public static int3 limn(this int3 f) => f.min(0);
/// <inheritdoc cref="limn(int4)" />
[MI(IL)] public static int2 limn(this int2 f) => f.min(0);
/// <inheritdoc cref="limn(int4)" />
[MI(IL)] public static int limn(this int f) => f.min(0);
/// Short for min(f, 1);
/// Clamps values over 1 to 1;
[MI(IL)] public static int4 under1(this int4 f) => f.min(1);
/// <inheritdoc cref="under1(int4)" />
[MI(IL)] public static int3 under1(this int3 f) => f.min(1);
/// <inheritdoc cref="under1(int4)" />
[MI(IL)] public static int2 under1(this int2 f) => f.min(1);
/// <inheritdoc cref="under1(int4)" />
[MI(IL)] public static int under1(this int f) => f.min(1);
}
}