Skip to content

Commit 183a76c

Browse files
committed
renamed asfloat overloads to tofloat to avoid confusion between cast and bitpattern transfer between types
1 parent 86d66c4 commit 183a76c

5 files changed

Lines changed: 158 additions & 160 deletions

File tree

Runtime/_Experimental/XNoiseLibrary.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ private static float3 bcc4_grad(float hash)
682682
// Also a cuboctahedral vertex
683683
// And corresponds to the face of its dual, the rhombic dodecahedron
684684
var cuboct = cube;
685-
cuboct *= (f3(0, 1, 2) != (int)(hash / 16)).asfloat();
685+
cuboct *= (f3(0, 1, 2) != (int)(hash / 16)).tofloat();
686686

687687
// In a funky way, pick one of the four points on the rhombic face
688688
var type = ((hash / 8).floor() * 0.5f).frac() * 2;
@@ -705,7 +705,7 @@ private static float4 Bcc4NoiseBase(float3 X)
705705
var v1 = round(X);
706706
var d1 = X - v1;
707707
var score1 = d1.abs();
708-
var dir1 = (score1.yzx.max(score1.zxy) < score1).asfloat();
708+
var dir1 = (score1.yzx.max(score1.zxy) < score1).tofloat();
709709
var v2 = v1 + dir1 * (d1 < 0).select(-1, 1);
710710
var d2 = X - v2;
711711

@@ -714,7 +714,7 @@ private static float4 Bcc4NoiseBase(float3 X)
714714
var v3 = round(X2);
715715
var d3 = X2 - v3;
716716
var score2 = d3.abs();
717-
var dir2 = (score2.yzx.max(score2.zxy) < score2).asfloat();
717+
var dir2 = (score2.yzx.max(score2.zxy) < score2).tofloat();
718718
var v4 = v3 + dir2 * (d3 < 0).select(-1, 1);
719719
var d4 = X2 - v4;
720720

Runtime/mathx.conversion.common.cs

Lines changed: 89 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -21,108 +21,106 @@ public static partial class mathx
2121
#region asint
2222

2323
/// Returns an equivalent int-type
24-
[MethodImpl(IL)] public static int4 asint(this float4 f) => (int4)f;
25-
/// <inheritdoc cref="asint(float4)"/>>
26-
[MethodImpl(IL)] public static int3 asint(this float3 f) => (int3)f;
27-
/// <inheritdoc cref="asint(float4)"/>>
28-
[MethodImpl(IL)] public static int2 asint(this float2 f) => (int2)f;
29-
/// <inheritdoc cref="asint(float4)"/>>
30-
[MethodImpl(IL)] public static int asint(this float f) => (int) f;
31-
32-
/// <inheritdoc cref="asint(float4)"/>>
33-
[MethodImpl(IL)] public static int4 asint(this Vector4 f) => new ((int)f.x, (int)f.y, (int)f.z, (int)f.w);
34-
/// <inheritdoc cref="asint(float4)"/>>
35-
[MethodImpl(IL)] public static int3 asint(this Vector3 f) => new ((int)f.x, (int)f.y, (int)f.z);
36-
/// <inheritdoc cref="asint(float4)"/>>
37-
[MethodImpl(IL)] public static int2 asint(this Vector2 f) => new ((int)f.x, (int)f.y);
38-
39-
/// <inheritdoc cref="asint(float4)"/>>
40-
[MethodImpl(IL)] public static int3 asint(this Vector3Int f) => new(f.x, f.y, f.z);
41-
/// <inheritdoc cref="asint(float4)"/>>
42-
[MethodImpl(IL)] public static int2 asint(this Vector2Int f) => new(f.x, f.y);
43-
44-
/// <inheritdoc cref="asint(float4)"/>>
45-
[MethodImpl(IL)] public static int4 asint(this double4 f) => (int4) f;
46-
/// <inheritdoc cref="asint(float4)"/>>
47-
[MethodImpl(IL)] public static int3 asint(this double3 f) => (int3) f;
48-
/// <inheritdoc cref="asint(float4)"/>>
49-
[MethodImpl(IL)] public static int2 asint(this double2 f) => (int2) f;
50-
/// <inheritdoc cref="asint(float4)"/>>
51-
[MethodImpl(IL)] public static int asint(this double f) => (int) f;
24+
[MethodImpl(IL)] public static int4 toint(this float4 f) => (int4)f;
25+
/// <inheritdoc cref="toint"/>>
26+
[MethodImpl(IL)] public static int3 toint(this float3 f) => (int3)f;
27+
/// <inheritdoc cref="toint"/>>
28+
[MethodImpl(IL)] public static int2 toint(this float2 f) => (int2)f;
29+
/// <inheritdoc cref="toint"/>>
30+
[MethodImpl(IL)] public static int toint(this float f) => (int) f;
31+
32+
/// <inheritdoc cref="toint"/>>
33+
[MethodImpl(IL)] public static int4 toint(this Vector4 f) => new ((int)f.x, (int)f.y, (int)f.z, (int)f.w);
34+
/// <inheritdoc cref="toint"/>>
35+
[MethodImpl(IL)] public static int3 toint(this Vector3 f) => new ((int)f.x, (int)f.y, (int)f.z);
36+
/// <inheritdoc cref="toint"/>>
37+
[MethodImpl(IL)] public static int2 toint(this Vector2 f) => new ((int)f.x, (int)f.y);
38+
39+
/// <inheritdoc cref="toint"/>>
40+
[MethodImpl(IL)] public static int3 toint(this Vector3Int f) => new(f.x, f.y, f.z);
41+
/// <inheritdoc cref="toint"/>>
42+
[MethodImpl(IL)] public static int2 toint(this Vector2Int f) => new(f.x, f.y);
43+
44+
/// <inheritdoc cref="toint"/>>
45+
[MethodImpl(IL)] public static int4 toint(this double4 f) => (int4) f;
46+
/// <inheritdoc cref="toint"/>>
47+
[MethodImpl(IL)] public static int3 toint(this double3 f) => (int3) f;
48+
/// <inheritdoc cref="toint"/>>
49+
[MethodImpl(IL)] public static int2 toint(this double2 f) => (int2) f;
50+
/// <inheritdoc cref="toint"/>>
51+
[MethodImpl(IL)] public static int toint(this double f) => (int) f;
5252

5353
/// Returns 1 when true, zero otherwise, componentwise
54-
[MethodImpl(IL)] public static int4 asint(this bool4 b) => (int4) b;
55-
/// <inheritdoc cref="asint(bool4)"/>
56-
[MethodImpl(IL)] public static int3 asint(this bool3 b) => (int3) b;
57-
/// <inheritdoc cref="asfloat(bool4)"/>
58-
[MethodImpl(IL)] public static int2 asint(this bool2 b) => (int2) b;
54+
[MethodImpl(IL)] public static int4 toint(this bool4 b) => (int4) b;
55+
/// <inheritdoc cref="toint(Unity.Mathematics.bool4)"/>
56+
[MethodImpl(IL)] public static int3 toint(this bool3 b) => (int3) b;
57+
/// <inheritdoc cref="tofloat(Unity.Mathematics.bool4)"/>
58+
[MethodImpl(IL)] public static int2 toint(this bool2 b) => (int2) b;
5959
/// Returns 1 when true, zero otherwise
60-
[MethodImpl(IL)] public static int asint(this bool b) => b ? 1 : 0;
60+
[MethodImpl(IL)] public static int toint(this bool b) => b ? 1 : 0;
6161

6262
/// Cast to int4
63-
[MethodImpl(IL)] public static int4 asint(this uint4 b) => (int4)b;
63+
[MethodImpl(IL)] public static int4 toint(this uint4 b) => (int4)b;
6464
/// Cast to int3
65-
[MethodImpl(IL)] public static int3 asint(this uint3 b) => (int3)b;
65+
[MethodImpl(IL)] public static int3 toint(this uint3 b) => (int3)b;
6666
/// Cast to int2
67-
[MethodImpl(IL)] public static int2 asint(this uint2 b) => (int2)b;
67+
[MethodImpl(IL)] public static int2 toint(this uint2 b) => (int2)b;
6868
/// Cast to int
69-
[MethodImpl(IL)] public static int asint(this uint b) => (int)b;
69+
[MethodImpl(IL)] public static int toint(this uint b) => (int)b;
7070

7171
#endregion
7272

7373
#region asbool
7474

7575
/// Return an equivalent bool-type
76-
[MethodImpl(IL)] public static bool4 asbool(this int4 f) => f != 0;
77-
/// <inheritdoc cref="asbool(int4)"/>
78-
[MethodImpl(IL)] public static bool3 asbool(this int3 f) => f != 0;
79-
/// <inheritdoc cref="asbool(int4)"/>
80-
[MethodImpl(IL)] public static bool2 asbool(this int2 f) => f != 0;
81-
/// <inheritdoc cref="asbool(int4)"/>
82-
[MethodImpl(IL)] public static bool asbool(this int f) => f != 0;
76+
[MethodImpl(IL)] public static bool4 tobool(this int4 f) => f != 0;
77+
/// <inheritdoc cref="tobool(int4)"/>
78+
[MethodImpl(IL)] public static bool3 tobool(this int3 f) => f != 0;
79+
/// <inheritdoc cref="tobool(int4)"/>
80+
[MethodImpl(IL)] public static bool2 tobool(this int2 f) => f != 0;
81+
/// <inheritdoc cref="tobool(int4)"/>
82+
[MethodImpl(IL)] public static bool tobool(this int f) => f != 0;
8383

8484
/// Returns 1 when true, zero otherwise componentwise
85-
[MethodImpl(IL)] public static bool4 asbool(this uint4 b) => b != 0;
86-
/// <inheritdoc cref="asuint(bool4)"/>
87-
[MethodImpl(IL)] public static bool3 asbool(this uint3 b) => b != 0;
88-
/// <inheritdoc cref="asuint(bool4)"/>
89-
[MethodImpl(IL)] public static bool2 asbool(this uint2 b) => b != 0;
85+
[MethodImpl(IL)] public static bool4 tobool(this uint4 b) => b != 0;
86+
/// <inheritdoc cref="tobool(Unity.Mathematics.uint4)"/>
87+
[MethodImpl(IL)] public static bool3 tobool(this uint3 b) => b != 0;
88+
/// <inheritdoc cref="tobool(Unity.Mathematics.uint4)"/>
89+
[MethodImpl(IL)] public static bool2 tobool(this uint2 b) => b != 0;
9090
/// Returns true when not zero
91-
[MethodImpl(IL)] public static bool asbool(this uint b) => b != 0;
91+
[MethodImpl(IL)] public static bool tobool(this uint b) => b != 0;
9292

9393

9494
/// Returns 1 when true, zero otherwise componentwise
95-
[MethodImpl(IL)] public static bool4 asbool(this byte4 b) => b != 0;
96-
/// <inheritdoc cref="asuint(bool4)"/>
97-
[MethodImpl(IL)] public static bool3 asbool(this byte3 b) => b != 0;
98-
/// <inheritdoc cref="asuint(bool4)"/>
99-
[MethodImpl(IL)] public static bool2 asbool(this byte2 b) => b != 0;
95+
[MethodImpl(IL)] public static bool4 tobool(this byte4 b) => b != 0;
96+
/// <inheritdoc cref="touint(Unity.Mathematics.bool4)"/>
97+
[MethodImpl(IL)] public static bool3 tobool(this byte3 b) => b != 0;
98+
/// <inheritdoc cref="touint(Unity.Mathematics.bool4)"/>
99+
[MethodImpl(IL)] public static bool2 tobool(this byte2 b) => b != 0;
100100
/// Returns true when not zero
101-
[MethodImpl(IL)] public static bool asbool(this byte1 b) => b != 0;
101+
[MethodImpl(IL)] public static bool tobool(this byte1 b) => b != 0;
102102
/// Returns true when not zero
103-
[MethodImpl(IL)] public static bool asbool(this byte b) => b != 0;
103+
[MethodImpl(IL)] public static bool tobool(this byte b) => b != 0;
104104

105105
#endregion
106106

107107
#region asfloat
108108

109109
/// Returns equivalent float-type
110110
/// <inheritdoc cref="asfloat(int4)"/>
111-
[MethodImpl(IL)] public static float3 asfloat(this Vector3Int f) => new(f.x, f.y, f.z);
111+
[MethodImpl(IL)] public static float3 tofloat(this Vector3Int f) => new(f.x, f.y, f.z);
112112
/// <inheritdoc cref="asfloat(int4)"/>
113-
[MethodImpl(IL)] public static float2 asfloat(this Vector2Int f) => new(f.x, f.y);
114-
113+
[MethodImpl(IL)] public static float2 tofloat(this Vector2Int f) => new(f.x, f.y);
114+
115+
116+
/// <returns>The float-type vector with the same bit pattern as the input.</returns>
115117
[MethodImpl(IL)] public static float4 asfloat(this int4 f) => math.asfloat(f);
116118
/// <inheritdoc cref="asfloat(int4)"/>
117119
[MethodImpl(IL)] public static float3 asfloat(this int3 f) => math.asfloat(f);
118120
/// <inheritdoc cref="asfloat(int4)"/>
119121
[MethodImpl(IL)] public static float2 asfloat(this int2 f) => math.asfloat(f);
120122
/// <inheritdoc cref="asfloat(int4)"/>
121123
[MethodImpl(IL)] public static float asfloat(this int f) => math.asfloat(f);
122-
123-
124-
/// Returns a float-type equivalent
125-
126124

127125

128126
/// <returns>The float-type vector with the same bit pattern as the input.</returns>
@@ -139,59 +137,59 @@ public static partial class mathx
139137

140138

141139
/// Returns 1 when true, zero otherwise, componentwise
142-
[MethodImpl(IL)] public static float4 asfloat(this bool4 b) => (float4) b;
143-
/// <inheritdoc cref="asfloat(bool4)"/>
144-
[MethodImpl(IL)] public static float3 asfloat(this bool3 b) => (float3) b;
145-
/// <inheritdoc cref="asfloat(bool4)"/>
146-
[MethodImpl(IL)] public static float2 asfloat(this bool2 b) => (float2) b;
140+
[MethodImpl(IL)] public static float4 tofloat(this bool4 b) => (float4) b;
141+
/// <inheritdoc cref="tofloat(Unity.Mathematics.bool4)"/>
142+
[MethodImpl(IL)] public static float3 tofloat(this bool3 b) => (float3) b;
143+
/// <inheritdoc cref="tofloat(Unity.Mathematics.bool4)"/>
144+
[MethodImpl(IL)] public static float2 tofloat(this bool2 b) => (float2) b;
147145
/// Returns 1 when true, zero otherwise
148-
[MethodImpl(IL)] public static float asfloat(this bool b) => b ? 1 : 0;
146+
[MethodImpl(IL)] public static float tofloat(this bool b) => b ? 1 : 0;
149147

150148

151149
/// Returns a float-type equivalent
152-
[MethodImpl(IL)] public static float4 asfloat(this double4 f) => (float4)f;
153-
/// <inheritdoc cref="asfloat(double4)"/>
154-
[MethodImpl(IL)] public static float3 asfloat(this double3 f) => (float3)f;
155-
/// <inheritdoc cref="asfloat(double4)"/>
156-
[MethodImpl(IL)] public static float2 asfloat(this double2 f) => (float2)f;
157-
158-
/// <inheritdoc cref="asfloat(double4)"/>
159-
[MethodImpl(IL)] public static float asfloat(this double f) => (float)f;
150+
[MethodImpl(IL)] public static float4 tofloat(this double4 f) => (float4)f;
151+
/// <inheritdoc cref="tofloat(Unity.Mathematics.double4)"/>
152+
[MethodImpl(IL)] public static float3 tofloat(this double3 f) => (float3)f;
153+
/// <inheritdoc cref="tofloat(Unity.Mathematics.double4)"/>
154+
[MethodImpl(IL)] public static float2 tofloat(this double2 f) => (float2)f;
155+
156+
/// <inheritdoc cref="tofloat(Unity.Mathematics.double4)"/>
157+
[MethodImpl(IL)] public static float tofloat(this double f) => (float)f;
160158

161159

162160

163161

164162
/// Returns a f4 from the quaternion's components
165-
[MethodImpl(IL)] public static float4 asfloat(this quaternion q) => q.value;
163+
[MethodImpl(IL)] public static float4 tofloat(this quaternion q) => q.value;
166164

167165
#endregion
168166

169167
#region asdouble
170168

171169
/// Cast to double4
172-
[MethodImpl(IL)] public static double4 asdouble(this float4 f) => f;
170+
[MethodImpl(IL)] public static double4 todouble(this float4 f) => f;
173171
/// Cast to double3
174-
[MethodImpl(IL)] public static double3 asdouble(this float3 f) => f;
172+
[MethodImpl(IL)] public static double3 todouble(this float3 f) => f;
175173
/// Cast to double2
176-
[MethodImpl(IL)] public static double2 asdouble(this float2 f) => f;
174+
[MethodImpl(IL)] public static double2 todouble(this float2 f) => f;
177175
/// Cast to double
178-
[MethodImpl(IL)] public static double asdouble(this float f) => f;
176+
[MethodImpl(IL)] public static double todouble(this float f) => f;
179177

180178
/// Returns a double2 equivalent
181-
[MethodImpl(IL)] public static double2 asdouble(this Complex f) => new(f.Real, f.Imaginary);
179+
[MethodImpl(IL)] public static double2 todouble(this Complex f) => new(f.Real, f.Imaginary);
182180

183181
#endregion
184182

185183
#region asuint
186184

187185
/// Returns 1 when true, zero otherwise componentwise
188-
[MethodImpl(IL)] public static uint4 asuint(this bool4 b) => (uint4) b;
189-
/// <inheritdoc cref="asuint(bool4)"/>
190-
[MethodImpl(IL)] public static uint3 asuint(this bool3 b) => (uint3) b;
191-
/// <inheritdoc cref="asuint(bool4)"/>
192-
[MethodImpl(IL)] public static uint2 asuint(this bool2 b) => (uint2) b;
186+
[MethodImpl(IL)] public static uint4 touint(this bool4 b) => (uint4) b;
187+
/// <inheritdoc cref="touint(Unity.Mathematics.bool4)"/>
188+
[MethodImpl(IL)] public static uint3 touint(this bool3 b) => (uint3) b;
189+
/// <inheritdoc cref="touint(Unity.Mathematics.bool4)"/>
190+
[MethodImpl(IL)] public static uint2 touint(this bool2 b) => (uint2) b;
193191
/// Returns 1 when true, zero otherwise
194-
[MethodImpl(IL)] public static uint asuint(this bool b) => b ? 1u : 0u;
192+
[MethodImpl(IL)] public static uint touint(this bool b) => b ? 1u : 0u;
195193

196194
/// Cast to uint4
197195
[MethodImpl(IL)] public static uint4 asuint(this int4 f) => math.asuint(f);

0 commit comments

Comments
 (0)