Skip to content

Commit 185348d

Browse files
committed
Replace Math with MathF
1 parent a8bb6c7 commit 185348d

File tree

10 files changed

+41
-40
lines changed

10 files changed

+41
-40
lines changed

AssetStudio/AssetStudio.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
1616
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
1717
<PackageReference Include="System.Text.Json" Version="9.0.0" />
18+
<PackageReference Include="Microsoft.Bcl.Numerics" Version="9.0.1" />
1819
</ItemGroup>
1920

2021
</Project>

AssetStudio/Classes/AnimationClip.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public Quaternion[] UnpackQuats()
256256
}
257257

258258
int lastComponent = (int)(flags & 3);
259-
q[lastComponent] = (float)Math.Sqrt(1 - sum);
259+
q[lastComponent] = MathF.Sqrt(1 - sum);
260260
if ((flags & 4) != 0u)
261261
q[lastComponent] = -q[lastComponent];
262262
data[i] = q;

AssetStudio/Classes/Mesh.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ private void DecompressCompressedMesh()
10061006
var zsqr = 1 - x * x - y * y;
10071007
float z;
10081008
if (zsqr >= 0f)
1009-
z = (float)Math.Sqrt(zsqr);
1009+
z = MathF.Sqrt(zsqr);
10101010
else
10111011
{
10121012
z = 0;
@@ -1036,7 +1036,7 @@ private void DecompressCompressedMesh()
10361036
var zsqr = 1 - x * x - y * y;
10371037
float z;
10381038
if (zsqr >= 0f)
1039-
z = (float)Math.Sqrt(zsqr);
1039+
z = MathF.Sqrt(zsqr);
10401040
else
10411041
{
10421042
z = 0;

AssetStudio/Classes/Texture2D.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,19 @@ private int GetImageDataSize(TextureFormat textureFormat)
181181
{
182182
case TextureFormat.ASTC_RGBA_5x5:
183183
// https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_astc/
184-
imgDataSize = (int)(Math.Floor((m_Width + 4) / 5f) * Math.Floor((m_Height + 4) / 5f) * 16);
184+
imgDataSize = (int)(MathF.Floor((m_Width + 4) / 5f) * MathF.Floor((m_Height + 4) / 5f) * 16);
185185
break;
186186
case TextureFormat.ASTC_RGBA_6x6:
187-
imgDataSize = (int)(Math.Floor((m_Width + 5) / 6f) * Math.Floor((m_Height + 5) / 6f) * 16);
187+
imgDataSize = (int)(MathF.Floor((m_Width + 5) / 6f) * MathF.Floor((m_Height + 5) / 6f) * 16);
188188
break;
189189
case TextureFormat.ASTC_RGBA_8x8:
190-
imgDataSize = (int)(Math.Floor((m_Width + 7) / 8f) * Math.Floor((m_Height + 7) / 8f) * 16);
190+
imgDataSize = (int)(MathF.Floor((m_Width + 7) / 8f) * MathF.Floor((m_Height + 7) / 8f) * 16);
191191
break;
192192
case TextureFormat.ASTC_RGBA_10x10:
193-
imgDataSize = (int)(Math.Floor((m_Width + 9) / 10f) * Math.Floor((m_Height + 9) / 10f) * 16);
193+
imgDataSize = (int)(MathF.Floor((m_Width + 9) / 10f) * MathF.Floor((m_Height + 9) / 10f) * 16);
194194
break;
195195
case TextureFormat.ASTC_RGBA_12x12:
196-
imgDataSize = (int)(Math.Floor((m_Width + 11) / 12f) * Math.Floor((m_Height + 11) / 12f) * 16);
196+
imgDataSize = (int)(MathF.Floor((m_Width + 11) / 12f) * MathF.Floor((m_Height + 11) / 12f) * 16);
197197
break;
198198
case TextureFormat.DXT1:
199199
case TextureFormat.EAC_R:

AssetStudio/Math/Vector2.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public override int GetHashCode()
4545

4646
public override bool Equals(object other)
4747
{
48-
if (!(other is Vector2))
48+
if (!(other is Vector2 vector2))
4949
return false;
50-
return Equals((Vector2)other);
50+
return Equals(vector2);
5151
}
5252

5353
public bool Equals(Vector2 other)
@@ -73,7 +73,7 @@ public void Normalize()
7373

7474
public float Length()
7575
{
76-
return (float)Math.Sqrt(LengthSquared());
76+
return MathF.Sqrt(LengthSquared());
7777
}
7878

7979
public float LengthSquared()

AssetStudio/Math/Vector3.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ public override int GetHashCode()
4949

5050
public override bool Equals(object other)
5151
{
52-
if (!(other is Vector3))
52+
if (!(other is Vector3 vector3))
5353
return false;
54-
return Equals((Vector3)other);
54+
return Equals(vector3);
5555
}
5656

5757
public bool Equals(Vector3 other)
@@ -79,7 +79,7 @@ public void Normalize()
7979

8080
public float Length()
8181
{
82-
return (float)Math.Sqrt(LengthSquared());
82+
return MathF.Sqrt(LengthSquared());
8383
}
8484

8585
public float LengthSquared()

AssetStudio/Math/Vector4.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public override int GetHashCode()
6161

6262
public override bool Equals(object other)
6363
{
64-
if (!(other is Vector4))
64+
if (!(other is Vector4 vector4))
6565
return false;
66-
return Equals((Vector4)other);
66+
return Equals(vector4);
6767
}
6868

6969
public bool Equals(Vector4 other)
@@ -93,7 +93,7 @@ public void Normalize()
9393

9494
public float Length()
9595
{
96-
return (float)Math.Sqrt(LengthSquared());
96+
return MathF.Sqrt(LengthSquared());
9797
}
9898

9999
public float LengthSquared()

AssetStudioGUI/AssetStudioGUIForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ private void PreviewMesh(Mesh m_Mesh)
13031303
{
13041304
if (m_Mesh.m_VertexCount > 0)
13051305
{
1306-
viewMatrixData = Matrix4.CreateRotationY(-(float)Math.PI / 4) * Matrix4.CreateRotationX(-(float)Math.PI / 6);
1306+
viewMatrixData = Matrix4.CreateRotationY(-MathF.PI / 4) * Matrix4.CreateRotationX(-MathF.PI / 6);
13071307
#region Vertices
13081308
if (m_Mesh.m_Vertices == null || m_Mesh.m_Vertices.Length == 0)
13091309
{

AssetStudioUtility/SpriteHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ private static Image<Bgra32> CutImage(Sprite m_Sprite, Texture2D m_Texture2D, Re
9898
var height = (int)(m_Texture2D.m_Height / downscaleMultiplier);
9999
originalImage.Mutate(x => x.Resize(width, height));
100100
}
101-
var rectX = (int)Math.Floor(textureRect.x);
102-
var rectY = (int)Math.Floor(textureRect.y);
103-
var rectRight = (int)Math.Ceiling(textureRect.x + textureRect.width);
104-
var rectBottom = (int)Math.Ceiling(textureRect.y + textureRect.height);
101+
var rectX = (int)MathF.Floor(textureRect.x);
102+
var rectY = (int)MathF.Floor(textureRect.y);
103+
var rectRight = (int)MathF.Ceiling(textureRect.x + textureRect.width);
104+
var rectBottom = (int)MathF.Ceiling(textureRect.y + textureRect.height);
105105
rectRight = Math.Min(rectRight, originalImage.Width);
106106
rectBottom = Math.Min(rectBottom, originalImage.Height);
107107
var rect = new Rectangle(rectX, rectY, rectRight - rectX, rectBottom - rectY);

AssetStudioUtility/Texture2DConverter.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ private bool DecodeRHalf(byte[] image_data, byte[] buff)
440440
{
441441
buff[i] = 0;
442442
buff[i + 1] = 0;
443-
buff[i + 2] = (byte)Math.Round(Half.ToHalf(image_data, i / 2) * 255f);
443+
buff[i + 2] = (byte)MathF.Round(Half.ToHalf(image_data, i / 2) * 255f);
444444
buff[i + 3] = 255;
445445
}
446446
return true;
@@ -451,8 +451,8 @@ private bool DecodeRGHalf(byte[] image_data, byte[] buff)
451451
for (var i = 0; i < outPutDataSize; i += 4)
452452
{
453453
buff[i] = 0;
454-
buff[i + 1] = (byte)Math.Round(Half.ToHalf(image_data, i + 2) * 255f);
455-
buff[i + 2] = (byte)Math.Round(Half.ToHalf(image_data, i) * 255f);
454+
buff[i + 1] = (byte)MathF.Round(Half.ToHalf(image_data, i + 2) * 255f);
455+
buff[i + 2] = (byte)MathF.Round(Half.ToHalf(image_data, i) * 255f);
456456
buff[i + 3] = 255;
457457
}
458458
return true;
@@ -462,10 +462,10 @@ private bool DecodeRGBAHalf(byte[] image_data, byte[] buff)
462462
{
463463
for (var i = 0; i < outPutDataSize; i += 4)
464464
{
465-
buff[i] = (byte)Math.Round(Half.ToHalf(image_data, i * 2 + 4) * 255f);
466-
buff[i + 1] = (byte)Math.Round(Half.ToHalf(image_data, i * 2 + 2) * 255f);
467-
buff[i + 2] = (byte)Math.Round(Half.ToHalf(image_data, i * 2) * 255f);
468-
buff[i + 3] = (byte)Math.Round(Half.ToHalf(image_data, i * 2 + 6) * 255f);
465+
buff[i] = (byte)MathF.Round(Half.ToHalf(image_data, i * 2 + 4) * 255f);
466+
buff[i + 1] = (byte)MathF.Round(Half.ToHalf(image_data, i * 2 + 2) * 255f);
467+
buff[i + 2] = (byte)MathF.Round(Half.ToHalf(image_data, i * 2) * 255f);
468+
buff[i + 3] = (byte)MathF.Round(Half.ToHalf(image_data, i * 2 + 6) * 255f);
469469
}
470470
return true;
471471
}
@@ -476,7 +476,7 @@ private bool DecodeRFloat(byte[] image_data, byte[] buff)
476476
{
477477
buff[i] = 0;
478478
buff[i + 1] = 0;
479-
buff[i + 2] = (byte)Math.Round(BitConverter.ToSingle(image_data, i) * 255f);
479+
buff[i + 2] = (byte)MathF.Round(BitConverter.ToSingle(image_data, i) * 255f);
480480
buff[i + 3] = 255;
481481
}
482482
return true;
@@ -487,8 +487,8 @@ private bool DecodeRGFloat(byte[] image_data, byte[] buff)
487487
for (var i = 0; i < outPutDataSize; i += 4)
488488
{
489489
buff[i] = 0;
490-
buff[i + 1] = (byte)Math.Round(BitConverter.ToSingle(image_data, i * 2 + 4) * 255f);
491-
buff[i + 2] = (byte)Math.Round(BitConverter.ToSingle(image_data, i * 2) * 255f);
490+
buff[i + 1] = (byte)MathF.Round(BitConverter.ToSingle(image_data, i * 2 + 4) * 255f);
491+
buff[i + 2] = (byte)MathF.Round(BitConverter.ToSingle(image_data, i * 2) * 255f);
492492
buff[i + 3] = 255;
493493
}
494494
return true;
@@ -498,10 +498,10 @@ private bool DecodeRGBAFloat(byte[] image_data, byte[] buff)
498498
{
499499
for (var i = 0; i < outPutDataSize; i += 4)
500500
{
501-
buff[i] = (byte)Math.Round(BitConverter.ToSingle(image_data, i * 4 + 8) * 255f);
502-
buff[i + 1] = (byte)Math.Round(BitConverter.ToSingle(image_data, i * 4 + 4) * 255f);
503-
buff[i + 2] = (byte)Math.Round(BitConverter.ToSingle(image_data, i * 4) * 255f);
504-
buff[i + 3] = (byte)Math.Round(BitConverter.ToSingle(image_data, i * 4 + 12) * 255f);
501+
buff[i] = (byte)MathF.Round(BitConverter.ToSingle(image_data, i * 4 + 8) * 255f);
502+
buff[i + 1] = (byte)MathF.Round(BitConverter.ToSingle(image_data, i * 4 + 4) * 255f);
503+
buff[i + 2] = (byte)MathF.Round(BitConverter.ToSingle(image_data, i * 4) * 255f);
504+
buff[i + 3] = (byte)MathF.Round(BitConverter.ToSingle(image_data, i * 4 + 12) * 255f);
505505
}
506506
return true;
507507
}
@@ -548,13 +548,13 @@ private bool DecodeRGB9e5Float(byte[] image_data, byte[] buff)
548548
{
549549
var n = BitConverter.ToInt32(image_data, i);
550550
var scale = n >> 27 & 0x1f;
551-
var scalef = Math.Pow(2, scale - 24);
551+
var scalef = MathF.Pow(2, scale - 24);
552552
var b = n >> 18 & 0x1ff;
553553
var g = n >> 9 & 0x1ff;
554554
var r = n & 0x1ff;
555-
buff[i] = (byte)Math.Round(b * scalef * 255f);
556-
buff[i + 1] = (byte)Math.Round(g * scalef * 255f);
557-
buff[i + 2] = (byte)Math.Round(r * scalef * 255f);
555+
buff[i] = (byte)MathF.Round(b * scalef * 255f);
556+
buff[i + 1] = (byte)MathF.Round(g * scalef * 255f);
557+
buff[i + 2] = (byte)MathF.Round(r * scalef * 255f);
558558
buff[i + 3] = 255;
559559
}
560560
return true;

0 commit comments

Comments
 (0)