Skip to content

Commit

Permalink
toString utils, math helper
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Jan 24, 2025
1 parent 84df804 commit f4d2c43
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
14 changes: 12 additions & 2 deletions CSMath/MathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,20 @@ public static T FixZero<T>(T vector, double threshold)
/// Convert a value from radian to degree
/// </summary>
/// <param name="value">Value in radians</param>
/// <param name="absolute">Calculates the negative values in a 0-360 range.</param>
/// <returns>The radian value</returns>
public static double RadToDeg(double value)
public static double RadToDeg(double value, bool absolute = true)
{
return value * RadToDegFactor;
var result = value * RadToDegFactor;

result %= 360;

if (result < 0)
{
result = 360 + result;
}

return result;
}

/// <summary>
Expand Down
12 changes: 12 additions & 0 deletions CSMath/XY.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;

namespace CSMath
{
Expand Down Expand Up @@ -115,5 +116,16 @@ public override string ToString()
{
return $"{X},{Y}";
}

/// <summary>
/// Converts the numeric value of this instance to its equivalent string representation
/// using the specified culture-specific format information.
/// </summary>
/// <param name="cultureInfo">An object that supplies culture-specific formatting information.</param>
/// <returns>The string representation of the value of this instance as specified by provider.</returns>
public string ToString(IFormatProvider? cultureInfo)
{
return $"{X.ToString(cultureInfo)},{Y.ToString(cultureInfo)}";
}
}
}
11 changes: 11 additions & 0 deletions CSMath/XYZ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,16 @@ public override string ToString()
{
return $"{X},{Y},{Z}";
}

/// <summary>
/// Converts the numeric value of this instance to its equivalent string representation
/// using the specified culture-specific format information.
/// </summary>
/// <param name="cultureInfo">An object that supplies culture-specific formatting information.</param>
/// <returns>The string representation of the value of this instance as specified by provider.</returns>
public string ToString(IFormatProvider? cultureInfo)
{
return $"{X.ToString(cultureInfo)},{Y.ToString(cultureInfo)},{Z.ToString(cultureInfo)}";
}
}
}
11 changes: 11 additions & 0 deletions CSMath/XYZM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,16 @@ public override string ToString()
{
return $"{X},{Y},{Z},{M}";
}

/// <summary>
/// Converts the numeric value of this instance to its equivalent string representation
/// using the specified culture-specific format information.
/// </summary>
/// <param name="cultureInfo">An object that supplies culture-specific formatting information.</param>
/// <returns>The string representation of the value of this instance as specified by provider.</returns>
public string ToString(IFormatProvider? cultureInfo)
{
return $"{X.ToString(cultureInfo)},{Y.ToString(cultureInfo)},{Z.ToString(cultureInfo)},{M.ToString(cultureInfo)}";
}
}
}

0 comments on commit f4d2c43

Please sign in to comment.