Skip to content

Commit 0b056db

Browse files
committed
Merge branch 'LengthUnits' of git://github.com/gpetrou/UnitsNet
2 parents 6625b93 + c8c2a51 commit 0b056db

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

Src/UnitsNet/Length.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ public double Nanometers
9090
get { return Meters*1E9; }
9191
}
9292

93+
public double Microinch
94+
{
95+
get { return Meters * 39370078.7; }
96+
}
97+
98+
public double Mil
99+
{
100+
get { return Meters * 39370.0787; }
101+
}
102+
93103
#endregion
94104

95105
#region Static
@@ -170,6 +180,16 @@ public static Length FromNanometers(double nm)
170180
return FromMeters(nm*1E-9);
171181
}
172182

183+
public static Length FromMicroinches(double mi)
184+
{
185+
return FromMeters(mi / 39370078.7);
186+
}
187+
188+
public static Length FromMils(double m)
189+
{
190+
return FromMeters(m / 39370.0787);
191+
}
192+
173193
#endregion
174194

175195
#region Arithmetic operators

Src/UnitsNet/Unit.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public enum Unit
3535
Nanometer,
3636

3737
// Length (imperial)
38+
Microinch,
39+
Mil,
3840
Mile,
3941
Yard,
4042
Foot,

Src/UnitsNet/UnitConverter.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ private static bool TryConvertLength(double value, Unit fromUnit, Unit toUnit, o
218218
return TryConvert(Length.FromFeet(value), toUnit, out newValue);
219219
case Unit.Inch:
220220
return TryConvert(Length.FromInches(value), toUnit, out newValue);
221+
case Unit.Mil:
222+
return TryConvert(Length.FromMils(value), toUnit, out newValue);
223+
case Unit.Microinch:
224+
return TryConvert(Length.FromMicroinches(value), toUnit, out newValue);
221225

222226
default:
223227
newValue = 0;

Tests/LengthTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public void MetersToDistanceUnits()
2525
Assert.AreEqual(1.09361, meter.Yards, Delta);
2626
Assert.AreEqual(3.28084, meter.Feet, Delta);
2727
Assert.AreEqual(39.3701, meter.Inches, Delta);
28+
Assert.AreEqual(39370078.7, meter.Microinch, Delta);
29+
Assert.AreEqual(39370.0787, meter.Mil, Delta);
2830
}
2931

3032
[Test]
@@ -44,6 +46,8 @@ public void DistanceUnitsRoundTrip()
4446
Assert.AreEqual(1, Length.FromYards(meter.Yards).Meters, Delta);
4547
Assert.AreEqual(1, Length.FromFeet(meter.Feet).Meters, Delta);
4648
Assert.AreEqual(1, Length.FromInches(meter.Inches).Meters, Delta);
49+
Assert.AreEqual(1, Length.FromMicroinches(meter.Microinch).Meters, Delta);
50+
Assert.AreEqual(1, Length.FromMils(meter.Mil).Meters, Delta);
4751
}
4852

4953
[Test]

0 commit comments

Comments
 (0)