Added fixedpoint 4 (#29834)

* Added fixedpoint 4, which is basically just fixedpoint2 but with 4 points of precision and using a long instead of an int to store values.
This commit is contained in:
Jezithyr
2024-07-22 14:07:31 -07:00
committed by GitHub
parent 65f9cc3155
commit 99492e3e3f
2 changed files with 345 additions and 4 deletions

View File

@@ -48,6 +48,8 @@ namespace Content.Shared.FixedPoint
public static FixedPoint2 FromCents(int value) => new(value);
public static FixedPoint2 FromHundredths(int value) => new(value);
public static FixedPoint2 New(float value)
{
return new((int) ApplyFloatEpsilon(value * ShiftConstant));
@@ -245,14 +247,14 @@ namespace Content.Shared.FixedPoint
return FixedPoint2.Abs(a - b);
}
public static FixedPoint2 Clamp(FixedPoint2 reagent, FixedPoint2 min, FixedPoint2 max)
public static FixedPoint2 Clamp(FixedPoint2 number, FixedPoint2 min, FixedPoint2 max)
{
if (min > max)
{
throw new ArgumentException($"{nameof(min)} {min} cannot be larger than {nameof(max)} {max}");
}
return reagent < min ? min : reagent > max ? max : reagent;
return number < min ? min : number > max ? max : number;
}
public override readonly bool Equals(object? obj)
@@ -274,7 +276,7 @@ namespace Content.Shared.FixedPoint
if (value == "MaxValue")
Value = int.MaxValue;
else
this = New(Parse.Float(value));
this = New(Parse.Double(value));
}
public override readonly string ToString() => $"{ShiftDown().ToString(CultureInfo.InvariantCulture)}";
@@ -314,7 +316,7 @@ namespace Content.Shared.FixedPoint
}
public static class FixedPointEnumerableExt
public static class FixedPoint2EnumerableExt
{
public static FixedPoint2 Sum(this IEnumerable<FixedPoint2> source)
{