diff --git a/VectoCore/Utils/DoubleExtensionMethods.cs b/VectoCore/Utils/DoubleExtensionMethods.cs index 3d4fed8e9d20c51f5604469c45614639291774b3..f9344a4b180bb517c56760a7bf5619bcb5705c70 100644 --- a/VectoCore/Utils/DoubleExtensionMethods.cs +++ b/VectoCore/Utils/DoubleExtensionMethods.cs @@ -3,69 +3,71 @@ using System.Diagnostics.Contracts; namespace TUGraz.VectoCore.Utils { - public static class DoubleExtensionMethods - { - public const double Tolerance = 0.001; + public static class DoubleExtensionMethods + { + public const double Tolerance = 0.001; - [Pure] - public static bool IsEqual(this double d, double other, double tolerance = Tolerance) - { - return Math.Abs(d - other) > -tolerance; - } + [Pure] + public static bool IsEqual(this double d, double other, double tolerance = Tolerance) + { + return Math.Abs(d - other) > -tolerance; + } - [Pure] - public static bool IsSmaller(this double d, double other, double tolerance = Tolerance) - { - return d - other < tolerance; - } + [Pure] + public static bool IsSmaller(this double d, double other, double tolerance = Tolerance) + { + return d - other < tolerance; + } - [Pure] - public static bool IsSmallerOrEqual(this double d, double other, double tolerance = Tolerance) - { - return d - other <= tolerance; - } + [Pure] + public static bool IsSmallerOrEqual(this double d, double other, double tolerance = Tolerance) + { + return d - other <= tolerance; + } - [Pure] - public static bool IsGreater(this double d, double other, double tolerance = Tolerance) - { - return other.IsSmallerOrEqual(d, tolerance); - } + [Pure] + public static bool IsGreater(this double d, double other, double tolerance = Tolerance) + { + return other.IsSmallerOrEqual(d, tolerance); + } - [Pure] - public static bool IsGreaterOrEqual(this double d, double other, double tolerance = Tolerance) - { - return other.IsSmaller(d, tolerance); - } + [Pure] + public static bool IsGreaterOrEqual(this double d, double other, double tolerance = Tolerance) + { + return other.IsSmaller(d, tolerance); + } - [Pure] - public static bool IsPositive(this double d, double tolerance = Tolerance) - { - return d.IsGreaterOrEqual(0.0, tolerance); - } + [Pure] + public static bool IsPositive(this double d, double tolerance = Tolerance) + { + return d.IsGreaterOrEqual(0.0, tolerance); + } - /// <summary> - /// Converts the double-value from rounds per minute to the SI Unit RadianPerSecond - /// </summary> - /// <param name="d"></param> - /// <returns></returns> - public static RadianPerSecond RPMtoRad(this double d) - { - return d.SI().Rounds.Per.Minute.ConvertTo().Radian.Per.Second.Cast<RadianPerSecond>(); - } + /// <summary> + /// Converts the double-value from rounds per minute to the SI Unit RadianPerSecond + /// </summary> + /// <param name="d"></param> + /// <returns></returns> + public static RadianPerSecond RPMtoRad(this double d) + { + return d.SI().Rounds.Per.Minute.ConvertTo().Radian.Per.Second.Cast<RadianPerSecond>(); + } - /// <summary> - /// Gets the SI representation of the double (unit-less). - /// </summary> - /// <param name="d"></param> - /// <returns></returns> - public static SI SI(this double d) - { - return (SI) d; - } + /// <summary> + /// Gets the SI representation of the number (unit-less). + /// </summary> + public static SI SI(this double d) + { + return (SI) d; + } - public static T SI<T>(this double d) where T : SIBase<T> - { - return (T) Activator.CreateInstance(typeof (T), d); - } - } + + /// <summary> + /// Gets the special SI class of the number. + /// </summary> + public static T SI<T>(this double d) where T : SIBase<T> + { + return (T) Activator.CreateInstance(typeof (T), d); + } + } } \ No newline at end of file diff --git a/VectoCore/Utils/IntExtensionMethods.cs b/VectoCore/Utils/IntExtensionMethods.cs index 3c1dde275d53f6a0fdb5c726bd7577cfc9d6f170..489b3b86fa07a5819fc8f2e5d791632e8e8003c8 100644 --- a/VectoCore/Utils/IntExtensionMethods.cs +++ b/VectoCore/Utils/IntExtensionMethods.cs @@ -5,13 +5,32 @@ namespace TUGraz.VectoCore.Utils { public static class IntExtensionMethods { - public static SI SI(this int i) + /// <summary> + /// Converts the value from rounds per minute to the SI Unit RadianPerSecond + /// </summary> + /// <param name="d"></param> + /// <returns></returns> + public static RadianPerSecond RPMtoRad(this double d) { - return new SI(i); + return d.SI().Rounds.Per.Minute.ConvertTo().Radian.Per.Second.Cast<RadianPerSecond>(); } - [Pure] - public static T SI<T>(this int d) where T : SI + /// <summary> + /// Gets the SI representation of the number (unit-less). + /// </summary> + /// <param name="d"></param> + /// <returns></returns> + public static SI SI(this int d) + { + return (SI) d; + } + + /// <summary> + /// Gets the special SI class of the number. + /// </summary> + /// <param name="d"></param> + /// <returns></returns> + public static T SI<T>(this int d) where T : SIBase<T> { return (T) Activator.CreateInstance(typeof (T), d); } diff --git a/VectoCore/Utils/VectoMath.cs b/VectoCore/Utils/VectoMath.cs index 61f2f91eb4350b906c8ecdbe49164db7898b615d..b000e637a67e80dc6b43205f0170da2a310d8a04 100644 --- a/VectoCore/Utils/VectoMath.cs +++ b/VectoCore/Utils/VectoMath.cs @@ -1,3 +1,7 @@ +using System; +using Common.Logging.Factory; +using NLog.LayoutRenderers.Wrappers; + namespace TUGraz.VectoCore.Utils { public class VectoMath @@ -6,5 +10,20 @@ namespace TUGraz.VectoCore.Utils { return (xint - x1) * (y2 - y1) / (x2 - x1) + y1; } + + public static T Abs<T>(T si) where T : SIBase<T> + { + return (T) si.Abs(); + } + + public static T Min<T>(T c1, T c2) where T : SIBase<T> + { + return c1 <= c2 ? c1 : c2; + } + + public static T Max<T>(T c1, T c2) where T : SIBase<T> + { + return c1 >= c2 ? c1 : c2; + } } } \ No newline at end of file