Skip to content

Commit

Permalink
FixZero
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Dec 26, 2024
1 parent 6c803a0 commit 84df804
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions CSMath/MathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,35 @@ public static bool IsZero(double number, double threshold)
return number >= -threshold && number <= threshold;
}

public static double FixZero(double number)
{
return FixZero(number, Epsilon);
}

public static double FixZero(double number, double threshold)
{
return IsZero(number, threshold) ? 0 : number;
}

public static T FixZero<T>(T vector)
where T : IVector, new()
{
return FixZero(vector, Epsilon);
}

public static T FixZero<T>(T vector, double threshold)
where T : IVector, new()
{
T result = new T();

for (int i = 0; i < vector.Dimension; i++)
{
result[i] = FixZero(vector[i], threshold);
}

return result;
}

/// <summary>
/// Convert a value from radian to degree
/// </summary>
Expand Down

0 comments on commit 84df804

Please sign in to comment.