|
| 1 | +using System; |
| 2 | +using System.Globalization; |
| 3 | + |
| 4 | +namespace UnitsNet |
| 5 | +{ |
| 6 | + /// <summary> |
| 7 | + /// A class for representing revolution. |
| 8 | + /// </summary> |
| 9 | + public struct RotationalSpeed : IComparable, IComparable<RotationalSpeed> |
| 10 | + { |
| 11 | + private const double MinuteToSecondRatio = 0.0166666666666667; |
| 12 | + private const double SecondToMinuteRatio = 60; |
| 13 | + |
| 14 | + public readonly double RevolutionsPerSecond; |
| 15 | + |
| 16 | + private RotationalSpeed(double revolutionsPerSecond) |
| 17 | + : this() |
| 18 | + { |
| 19 | + RevolutionsPerSecond = revolutionsPerSecond; |
| 20 | + } |
| 21 | + |
| 22 | + public double RevolutionsPerMinute |
| 23 | + { |
| 24 | + get { return RevolutionsPerSecond * SecondToMinuteRatio; } |
| 25 | + } |
| 26 | + |
| 27 | + #region Static |
| 28 | + |
| 29 | + public static RotationalSpeed Zero |
| 30 | + { |
| 31 | + get { return new RotationalSpeed(); } |
| 32 | + } |
| 33 | + |
| 34 | + public static RotationalSpeed FromRevolutionsPerMinute(double revolutionsPerMinute) |
| 35 | + { |
| 36 | + return new RotationalSpeed(revolutionsPerMinute * MinuteToSecondRatio); |
| 37 | + } |
| 38 | + |
| 39 | + public static RotationalSpeed FromRevolutionsPerSecond(double revolutionsPerSecond) |
| 40 | + { |
| 41 | + return new RotationalSpeed(revolutionsPerSecond); |
| 42 | + } |
| 43 | + |
| 44 | + #endregion |
| 45 | + |
| 46 | + #region Equality / IComparable |
| 47 | + |
| 48 | + public int CompareTo(object obj) |
| 49 | + { |
| 50 | + if (obj == null) throw new ArgumentNullException("obj"); |
| 51 | + if (!(obj is RotationalSpeed)) throw new ArgumentException("Expected type RotationalSpeed.", "obj"); |
| 52 | + return CompareTo((RotationalSpeed)obj); |
| 53 | + } |
| 54 | + |
| 55 | + public int CompareTo(RotationalSpeed other) |
| 56 | + { |
| 57 | + return RevolutionsPerSecond.CompareTo(other.RevolutionsPerSecond); |
| 58 | + } |
| 59 | + |
| 60 | + public static bool operator <=(RotationalSpeed left, RotationalSpeed right) |
| 61 | + { |
| 62 | + return left.RevolutionsPerSecond <= right.RevolutionsPerSecond; |
| 63 | + } |
| 64 | + |
| 65 | + public static bool operator >=(RotationalSpeed left, RotationalSpeed right) |
| 66 | + { |
| 67 | + return left.RevolutionsPerSecond >= right.RevolutionsPerSecond; |
| 68 | + } |
| 69 | + |
| 70 | + public static bool operator <(RotationalSpeed left, RotationalSpeed right) |
| 71 | + { |
| 72 | + return left.RevolutionsPerSecond < right.RevolutionsPerSecond; |
| 73 | + } |
| 74 | + |
| 75 | + public static bool operator >(RotationalSpeed left, RotationalSpeed right) |
| 76 | + { |
| 77 | + return left.RevolutionsPerSecond > right.RevolutionsPerSecond; |
| 78 | + } |
| 79 | + |
| 80 | + public static bool operator ==(RotationalSpeed left, RotationalSpeed right) |
| 81 | + { |
| 82 | + return left.RevolutionsPerSecond == right.RevolutionsPerSecond; |
| 83 | + } |
| 84 | + |
| 85 | + public static bool operator !=(RotationalSpeed left, RotationalSpeed right) |
| 86 | + { |
| 87 | + return left.RevolutionsPerSecond != right.RevolutionsPerSecond; |
| 88 | + } |
| 89 | + |
| 90 | + public override bool Equals(object obj) |
| 91 | + { |
| 92 | + if (obj == null || GetType() != obj.GetType()) |
| 93 | + { |
| 94 | + return false; |
| 95 | + } |
| 96 | + |
| 97 | + return RevolutionsPerSecond.Equals(((RotationalSpeed)obj).RevolutionsPerSecond); |
| 98 | + } |
| 99 | + |
| 100 | + public override int GetHashCode() |
| 101 | + { |
| 102 | + return RevolutionsPerSecond.GetHashCode(); |
| 103 | + } |
| 104 | + #endregion |
| 105 | + |
| 106 | + #region Arithmetic operators |
| 107 | + |
| 108 | + public static RotationalSpeed operator -(RotationalSpeed right) |
| 109 | + { |
| 110 | + return new RotationalSpeed(-right.RevolutionsPerSecond); |
| 111 | + } |
| 112 | + |
| 113 | + public static RotationalSpeed operator +(RotationalSpeed left, RotationalSpeed right) |
| 114 | + { |
| 115 | + return new RotationalSpeed(left.RevolutionsPerSecond + right.RevolutionsPerSecond); |
| 116 | + } |
| 117 | + |
| 118 | + public static RotationalSpeed operator -(RotationalSpeed left, RotationalSpeed right) |
| 119 | + { |
| 120 | + return new RotationalSpeed(left.RevolutionsPerSecond - right.RevolutionsPerSecond); |
| 121 | + } |
| 122 | + |
| 123 | + public static RotationalSpeed operator *(double left, RotationalSpeed right) |
| 124 | + { |
| 125 | + return new RotationalSpeed(left * right.RevolutionsPerSecond); |
| 126 | + } |
| 127 | + |
| 128 | + public static RotationalSpeed operator *(RotationalSpeed left, double right) |
| 129 | + { |
| 130 | + return new RotationalSpeed(left.RevolutionsPerSecond * right); |
| 131 | + } |
| 132 | + |
| 133 | + public static RotationalSpeed operator /(RotationalSpeed left, double right) |
| 134 | + { |
| 135 | + return new RotationalSpeed(left.RevolutionsPerSecond / right); |
| 136 | + } |
| 137 | + |
| 138 | + public static double operator /(RotationalSpeed left, RotationalSpeed right) |
| 139 | + { |
| 140 | + return left.RevolutionsPerSecond / right.RevolutionsPerSecond; |
| 141 | + } |
| 142 | + |
| 143 | + #endregion |
| 144 | + |
| 145 | + public override string ToString() |
| 146 | + { |
| 147 | + return string.Format("{0:0.##} {1}", RevolutionsPerSecond, UnitSystem.Create().GetDefaultAbbreviation(Unit.RevolutionsPerSecond)); |
| 148 | + } |
| 149 | + } |
| 150 | +} |
0 commit comments