Skip to content

Commit f6fbdb3

Browse files
committed
Renamed Revolution to RotationalSpeed as agreed on with George Zhuikov.
1 parent fa1fe18 commit f6fbdb3

File tree

7 files changed

+181
-181
lines changed

7 files changed

+181
-181
lines changed

Src/UnitsNet/Revolution.cs

Lines changed: 0 additions & 150 deletions
This file was deleted.

Src/UnitsNet/RotationalSpeed.cs

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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+
}

Src/UnitsNet/Unit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public enum Unit
171171
CubicMeterPerSecond,
172172
CubicMeterPerHour,
173173

174-
// Revolution
174+
// RotationalSpeed
175175
RevolutionsPerSecond,
176176
RevolutionsPerMinute,
177177
}

Src/UnitsNet/UnitConverter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,9 @@ private static bool TryConvertRevolutions(double value, Unit fromUnit, Unit toUn
383383
switch (fromUnit)
384384
{
385385
case Unit.RevolutionsPerSecond:
386-
return TryConvert(Revolution.FromRevolutionsPerSecond(value), toUnit, out newValue);
386+
return TryConvert(RotationalSpeed.FromRevolutionsPerSecond(value), toUnit, out newValue);
387387
case Unit.RevolutionsPerMinute:
388-
return TryConvert(Revolution.FromRevolutionsPerMinute(value), toUnit, out newValue);
388+
return TryConvert(RotationalSpeed.FromRevolutionsPerMinute(value), toUnit, out newValue);
389389

390390
default:
391391
newValue = 0;
@@ -768,7 +768,7 @@ private static bool TryConvert(Flow p, Unit toUnit, out double newValue)
768768
}
769769
}
770770

771-
private static bool TryConvert(Revolution p, Unit toUnit, out double newValue)
771+
private static bool TryConvert(RotationalSpeed p, Unit toUnit, out double newValue)
772772
{
773773
switch (toUnit)
774774
{

Src/UnitsNet/UnitSystem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ private void CreateRussian()
235235
MapUnitToAbbreviation(Unit.CubicMeterPerSecond, "м³/с");
236236
MapUnitToAbbreviation(Unit.CubicMeterPerHour, "м³/ч");
237237

238-
// Revolution
238+
// RotationalSpeed
239239
MapUnitToAbbreviation(Unit.RevolutionsPerSecond, "об/с");
240240
MapUnitToAbbreviation(Unit.RevolutionsPerMinute, "об/мин");
241241
}
@@ -339,7 +339,7 @@ private void CreateCultureInvariants()
339339
MapUnitToAbbreviation(Unit.CubicMeterPerSecond, "m³/s");
340340
MapUnitToAbbreviation(Unit.CubicMeterPerHour, "m³/h");
341341

342-
// Revolution
342+
// RotationalSpeed
343343
MapUnitToAbbreviation(Unit.RevolutionsPerSecond, "r/s");
344344
MapUnitToAbbreviation(Unit.RevolutionsPerMinute, "r/min");
345345
}

0 commit comments

Comments
 (0)