Skip to content

Commit b721294

Browse files
committed
Use safe min and max methods for generic colors
1 parent f3f7b69 commit b721294

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

AssetRipper.TextureDecoder.ColorGenerator/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ private static void WriteColorBaseStaticProperties(IndentedTextWriter writer, bo
140140
private static void WriteGenericColor(IndentedTextWriter writer, string name, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha)
141141
{
142142
const string typeName = "T";
143-
const string minValue = $"NumericConversion.GetMinimumValue<T>()";
144-
const string maxValue = $"NumericConversion.GetMaximumValue<T>()";
143+
const string minValue = $"NumericConversion.GetMinimumValueSafe<T>()";
144+
const string maxValue = $"NumericConversion.GetMaximumValueSafe<T>()";
145145

146146
writer.WriteGeneratedCodeWarning();
147147
writer.WriteLineNoTabs();

AssetRipper.TextureDecoder/Rgb/Formats/ColorA.g.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ public partial struct ColorA<T> : IColor<T> where T : unmanaged, INumberBase<T>,
66
{
77
public readonly T R
88
{
9-
get => NumericConversion.GetMinimumValue<T>();
9+
get => NumericConversion.GetMinimumValueSafe<T>();
1010
set { }
1111
}
1212

1313
public readonly T G
1414
{
15-
get => NumericConversion.GetMinimumValue<T>();
15+
get => NumericConversion.GetMinimumValueSafe<T>();
1616
set { }
1717
}
1818

1919
public readonly T B
2020
{
21-
get => NumericConversion.GetMinimumValue<T>();
21+
get => NumericConversion.GetMinimumValueSafe<T>();
2222
set { }
2323
}
2424

AssetRipper.TextureDecoder/Rgb/Formats/ColorR.g.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ public partial struct ColorR<T> : IColor<T> where T : unmanaged, INumberBase<T>,
88

99
public readonly T G
1010
{
11-
get => NumericConversion.GetMinimumValue<T>();
11+
get => NumericConversion.GetMinimumValueSafe<T>();
1212
set { }
1313
}
1414

1515
public readonly T B
1616
{
17-
get => NumericConversion.GetMinimumValue<T>();
17+
get => NumericConversion.GetMinimumValueSafe<T>();
1818
set { }
1919
}
2020

2121
public readonly T A
2222
{
23-
get => NumericConversion.GetMaximumValue<T>();
23+
get => NumericConversion.GetMaximumValueSafe<T>();
2424
set { }
2525
}
2626

AssetRipper.TextureDecoder/Rgb/Formats/ColorRG.g.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ public partial struct ColorRG<T> : IColor<T> where T : unmanaged, INumberBase<T>
1010

1111
public readonly T B
1212
{
13-
get => NumericConversion.GetMinimumValue<T>();
13+
get => NumericConversion.GetMinimumValueSafe<T>();
1414
set { }
1515
}
1616

1717
public readonly T A
1818
{
19-
get => NumericConversion.GetMaximumValue<T>();
19+
get => NumericConversion.GetMaximumValueSafe<T>();
2020
set { }
2121
}
2222

AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB.g.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public partial struct ColorRGB<T> : IColor<T> where T : unmanaged, INumberBase<T
1212

1313
public readonly T A
1414
{
15-
get => NumericConversion.GetMaximumValue<T>();
15+
get => NumericConversion.GetMaximumValueSafe<T>();
1616
set { }
1717
}
1818

AssetRipper.TextureDecoder/Rgb/NumericConversion.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ namespace AssetRipper.TextureDecoder.Rgb;
44
public static partial class NumericConversion
55
{
66
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
7-
private static T GetMinimumValueSafe<T>() where T : unmanaged, INumberBase<T>, IMinMaxValue<T>
7+
internal static T GetMinimumValueSafe<T>() where T : unmanaged, INumberBase<T>, IMinMaxValue<T>
88
{
99
return typeof(T) == typeof(Half) || typeof(T) == typeof(float) || typeof(T) == typeof(NFloat) || typeof(T) == typeof(double) || typeof(T) == typeof(decimal)
1010
? T.Zero
1111
: T.MinValue;
1212
}
1313

1414
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
15-
private static T GetMaximumValueSafe<T>() where T : unmanaged, INumberBase<T>, IMinMaxValue<T>
15+
internal static T GetMaximumValueSafe<T>() where T : unmanaged, INumberBase<T>, IMinMaxValue<T>
1616
{
1717
return typeof(T) == typeof(Half) || typeof(T) == typeof(float) || typeof(T) == typeof(NFloat) || typeof(T) == typeof(double) || typeof(T) == typeof(decimal)
1818
? T.One

0 commit comments

Comments
 (0)