diff --git a/CSMath/MathHelper.cs b/CSMath/MathHelper.cs index 23ffa57..23282e9 100644 --- a/CSMath/MathHelper.cs +++ b/CSMath/MathHelper.cs @@ -73,10 +73,20 @@ public static T FixZero(T vector, double threshold) /// Convert a value from radian to degree /// /// Value in radians + /// Calculates the negative values in a 0-360 range. /// The radian value - 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; } /// diff --git a/CSMath/XY.cs b/CSMath/XY.cs index f34837c..41d0eac 100644 --- a/CSMath/XY.cs +++ b/CSMath/XY.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; namespace CSMath { @@ -115,5 +116,16 @@ public override string ToString() { return $"{X},{Y}"; } + + /// + /// Converts the numeric value of this instance to its equivalent string representation + /// using the specified culture-specific format information. + /// + /// An object that supplies culture-specific formatting information. + /// The string representation of the value of this instance as specified by provider. + public string ToString(IFormatProvider? cultureInfo) + { + return $"{X.ToString(cultureInfo)},{Y.ToString(cultureInfo)}"; + } } } diff --git a/CSMath/XYZ.cs b/CSMath/XYZ.cs index b2d906c..da840d7 100644 --- a/CSMath/XYZ.cs +++ b/CSMath/XYZ.cs @@ -166,5 +166,16 @@ public override string ToString() { return $"{X},{Y},{Z}"; } + + /// + /// Converts the numeric value of this instance to its equivalent string representation + /// using the specified culture-specific format information. + /// + /// An object that supplies culture-specific formatting information. + /// The string representation of the value of this instance as specified by provider. + public string ToString(IFormatProvider? cultureInfo) + { + return $"{X.ToString(cultureInfo)},{Y.ToString(cultureInfo)},{Z.ToString(cultureInfo)}"; + } } } diff --git a/CSMath/XYZM.cs b/CSMath/XYZM.cs index f92498b..c034641 100644 --- a/CSMath/XYZM.cs +++ b/CSMath/XYZM.cs @@ -132,5 +132,16 @@ public override string ToString() { return $"{X},{Y},{Z},{M}"; } + + /// + /// Converts the numeric value of this instance to its equivalent string representation + /// using the specified culture-specific format information. + /// + /// An object that supplies culture-specific formatting information. + /// The string representation of the value of this instance as specified by provider. + public string ToString(IFormatProvider? cultureInfo) + { + return $"{X.ToString(cultureInfo)},{Y.ToString(cultureInfo)},{Z.ToString(cultureInfo)},{M.ToString(cultureInfo)}"; + } } }