Skip to content

Commit db10372

Browse files
tmilnthorpangularsen
authored andcommitted
Adding support for micro/milli newtons, as well as ounce force (#535)
* Adding support for micro/milli newtons, as well as ounce force * Fix for plural name and abbreviations for ounce force.
1 parent 2a2730c commit db10372

File tree

8 files changed

+194
-3
lines changed

8 files changed

+194
-3
lines changed

Common/GeneratedCode/Quantities/Force.Common.g.cs

+63
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,26 @@ public static BaseDimensions BaseDimensions
191191
/// </summary>
192192
public double Meganewtons => As(ForceUnit.Meganewton);
193193

194+
/// <summary>
195+
/// Get Force in Micronewtons.
196+
/// </summary>
197+
public double Micronewtons => As(ForceUnit.Micronewton);
198+
199+
/// <summary>
200+
/// Get Force in Millinewtons.
201+
/// </summary>
202+
public double Millinewtons => As(ForceUnit.Millinewton);
203+
194204
/// <summary>
195205
/// Get Force in Newtons.
196206
/// </summary>
197207
public double Newtons => As(ForceUnit.Newton);
198208

209+
/// <summary>
210+
/// Get Force in OunceForce.
211+
/// </summary>
212+
public double OunceForce => As(ForceUnit.OunceForce);
213+
199214
/// <summary>
200215
/// Get Force in Poundals.
201216
/// </summary>
@@ -304,6 +319,34 @@ public static Force FromMeganewtons(QuantityValue meganewtons)
304319
return new Force(value, ForceUnit.Meganewton);
305320
}
306321

322+
/// <summary>
323+
/// Get Force from Micronewtons.
324+
/// </summary>
325+
#if WINDOWS_UWP
326+
[Windows.Foundation.Metadata.DefaultOverload]
327+
public static Force FromMicronewtons(double micronewtons)
328+
#else
329+
public static Force FromMicronewtons(QuantityValue micronewtons)
330+
#endif
331+
{
332+
double value = (double) micronewtons;
333+
return new Force(value, ForceUnit.Micronewton);
334+
}
335+
336+
/// <summary>
337+
/// Get Force from Millinewtons.
338+
/// </summary>
339+
#if WINDOWS_UWP
340+
[Windows.Foundation.Metadata.DefaultOverload]
341+
public static Force FromMillinewtons(double millinewtons)
342+
#else
343+
public static Force FromMillinewtons(QuantityValue millinewtons)
344+
#endif
345+
{
346+
double value = (double) millinewtons;
347+
return new Force(value, ForceUnit.Millinewton);
348+
}
349+
307350
/// <summary>
308351
/// Get Force from Newtons.
309352
/// </summary>
@@ -318,6 +361,20 @@ public static Force FromNewtons(QuantityValue newtons)
318361
return new Force(value, ForceUnit.Newton);
319362
}
320363

364+
/// <summary>
365+
/// Get Force from OunceForce.
366+
/// </summary>
367+
#if WINDOWS_UWP
368+
[Windows.Foundation.Metadata.DefaultOverload]
369+
public static Force FromOunceForce(double ounceforce)
370+
#else
371+
public static Force FromOunceForce(QuantityValue ounceforce)
372+
#endif
373+
{
374+
double value = (double) ounceforce;
375+
return new Force(value, ForceUnit.OunceForce);
376+
}
377+
321378
/// <summary>
322379
/// Get Force from Poundals.
323380
/// </summary>
@@ -538,7 +595,10 @@ private double AsBaseUnit()
538595
case ForceUnit.Kilonewton: return (_value) * 1e3d;
539596
case ForceUnit.KiloPond: return _value*9.80665002864;
540597
case ForceUnit.Meganewton: return (_value) * 1e6d;
598+
case ForceUnit.Micronewton: return (_value) * 1e-6d;
599+
case ForceUnit.Millinewton: return (_value) * 1e-3d;
541600
case ForceUnit.Newton: return _value;
601+
case ForceUnit.OunceForce: return _value*2.780138509537812e-1;
542602
case ForceUnit.Poundal: return _value*0.13825502798973041652092282466083;
543603
case ForceUnit.PoundForce: return _value*4.4482216152605095551842641431421;
544604
case ForceUnit.TonneForce: return _value*9.80665002864e3;
@@ -562,7 +622,10 @@ private double AsBaseNumericType(ForceUnit unit)
562622
case ForceUnit.Kilonewton: return (baseUnitValue) / 1e3d;
563623
case ForceUnit.KiloPond: return baseUnitValue/9.80665002864;
564624
case ForceUnit.Meganewton: return (baseUnitValue) / 1e6d;
625+
case ForceUnit.Micronewton: return (baseUnitValue) / 1e-6d;
626+
case ForceUnit.Millinewton: return (baseUnitValue) / 1e-3d;
565627
case ForceUnit.Newton: return baseUnitValue;
628+
case ForceUnit.OunceForce: return baseUnitValue/2.780138509537812e-1;
566629
case ForceUnit.Poundal: return baseUnitValue/0.13825502798973041652092282466083;
567630
case ForceUnit.PoundForce: return baseUnitValue/4.4482216152605095551842641431421;
568631
case ForceUnit.TonneForce: return baseUnitValue/9.80665002864e3;

Common/UnitDefinitions/Force.json

+13-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"PluralName": "Newtons",
6262
"FromUnitToBaseFunc": "x",
6363
"FromBaseToUnitFunc": "x",
64-
"Prefixes": [ "Deca", "Kilo", "Mega" ],
64+
"Prefixes": [ "Micro", "Milli", "Deca", "Kilo", "Mega" ],
6565
"Localization": [
6666
{
6767
"Culture": "en-US",
@@ -121,6 +121,18 @@
121121
"Abbreviations": [ "фунт-сила" ]
122122
}
123123
]
124+
},
125+
{
126+
"SingularName": "OunceForce",
127+
"PluralName": "OunceForce",
128+
"FromUnitToBaseFunc": "x*2.780138509537812e-1",
129+
"FromBaseToUnitFunc": "x/2.780138509537812e-1",
130+
"Localization": [
131+
{
132+
"Culture": "en-US",
133+
"Abbreviations": [ "ozf" ]
134+
}
135+
]
124136
}
125137
]
126138
}

UnitsNet.Tests/CustomCode/ForceTests.cs

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public class ForceTests : ForceTestsBase
4343

4444
protected override double TonnesForceInOneNewton => 1.019716212977928e-4;
4545

46+
protected override double MillinewtonsInOneNewton => 1.0e3;
47+
48+
protected override double MicronewtonsInOneNewton => 1.0e6;
49+
50+
protected override double OunceForceInOneNewton => 3.596943089595368;
51+
4652
[Fact]
4753
public void ForceDividedByAreaEqualsPressure()
4854
{

UnitsNet.Tests/GeneratedCode/ForceTestsBase.g.cs

+30
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ public abstract partial class ForceTestsBase
5959
protected abstract double KilonewtonsInOneNewton { get; }
6060
protected abstract double KiloPondsInOneNewton { get; }
6161
protected abstract double MeganewtonsInOneNewton { get; }
62+
protected abstract double MicronewtonsInOneNewton { get; }
63+
protected abstract double MillinewtonsInOneNewton { get; }
6264
protected abstract double NewtonsInOneNewton { get; }
65+
protected abstract double OunceForceInOneNewton { get; }
6366
protected abstract double PoundalsInOneNewton { get; }
6467
protected abstract double PoundsForceInOneNewton { get; }
6568
protected abstract double TonnesForceInOneNewton { get; }
@@ -71,7 +74,10 @@ public abstract partial class ForceTestsBase
7174
protected virtual double KilonewtonsTolerance { get { return 1e-5; } }
7275
protected virtual double KiloPondsTolerance { get { return 1e-5; } }
7376
protected virtual double MeganewtonsTolerance { get { return 1e-5; } }
77+
protected virtual double MicronewtonsTolerance { get { return 1e-5; } }
78+
protected virtual double MillinewtonsTolerance { get { return 1e-5; } }
7479
protected virtual double NewtonsTolerance { get { return 1e-5; } }
80+
protected virtual double OunceForceTolerance { get { return 1e-5; } }
7581
protected virtual double PoundalsTolerance { get { return 1e-5; } }
7682
protected virtual double PoundsForceTolerance { get { return 1e-5; } }
7783
protected virtual double TonnesForceTolerance { get { return 1e-5; } }
@@ -87,7 +93,10 @@ public void NewtonToForceUnits()
8793
AssertEx.EqualTolerance(KilonewtonsInOneNewton, newton.Kilonewtons, KilonewtonsTolerance);
8894
AssertEx.EqualTolerance(KiloPondsInOneNewton, newton.KiloPonds, KiloPondsTolerance);
8995
AssertEx.EqualTolerance(MeganewtonsInOneNewton, newton.Meganewtons, MeganewtonsTolerance);
96+
AssertEx.EqualTolerance(MicronewtonsInOneNewton, newton.Micronewtons, MicronewtonsTolerance);
97+
AssertEx.EqualTolerance(MillinewtonsInOneNewton, newton.Millinewtons, MillinewtonsTolerance);
9098
AssertEx.EqualTolerance(NewtonsInOneNewton, newton.Newtons, NewtonsTolerance);
99+
AssertEx.EqualTolerance(OunceForceInOneNewton, newton.OunceForce, OunceForceTolerance);
91100
AssertEx.EqualTolerance(PoundalsInOneNewton, newton.Poundals, PoundalsTolerance);
92101
AssertEx.EqualTolerance(PoundsForceInOneNewton, newton.PoundsForce, PoundsForceTolerance);
93102
AssertEx.EqualTolerance(TonnesForceInOneNewton, newton.TonnesForce, TonnesForceTolerance);
@@ -102,7 +111,10 @@ public void FromValueAndUnit()
102111
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Kilonewton).Kilonewtons, KilonewtonsTolerance);
103112
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.KiloPond).KiloPonds, KiloPondsTolerance);
104113
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Meganewton).Meganewtons, MeganewtonsTolerance);
114+
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Micronewton).Micronewtons, MicronewtonsTolerance);
115+
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Millinewton).Millinewtons, MillinewtonsTolerance);
105116
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Newton).Newtons, NewtonsTolerance);
117+
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.OunceForce).OunceForce, OunceForceTolerance);
106118
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Poundal).Poundals, PoundalsTolerance);
107119
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.PoundForce).PoundsForce, PoundsForceTolerance);
108120
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.TonneForce).TonnesForce, TonnesForceTolerance);
@@ -118,7 +130,10 @@ public void As()
118130
AssertEx.EqualTolerance(KilonewtonsInOneNewton, newton.As(ForceUnit.Kilonewton), KilonewtonsTolerance);
119131
AssertEx.EqualTolerance(KiloPondsInOneNewton, newton.As(ForceUnit.KiloPond), KiloPondsTolerance);
120132
AssertEx.EqualTolerance(MeganewtonsInOneNewton, newton.As(ForceUnit.Meganewton), MeganewtonsTolerance);
133+
AssertEx.EqualTolerance(MicronewtonsInOneNewton, newton.As(ForceUnit.Micronewton), MicronewtonsTolerance);
134+
AssertEx.EqualTolerance(MillinewtonsInOneNewton, newton.As(ForceUnit.Millinewton), MillinewtonsTolerance);
121135
AssertEx.EqualTolerance(NewtonsInOneNewton, newton.As(ForceUnit.Newton), NewtonsTolerance);
136+
AssertEx.EqualTolerance(OunceForceInOneNewton, newton.As(ForceUnit.OunceForce), OunceForceTolerance);
122137
AssertEx.EqualTolerance(PoundalsInOneNewton, newton.As(ForceUnit.Poundal), PoundalsTolerance);
123138
AssertEx.EqualTolerance(PoundsForceInOneNewton, newton.As(ForceUnit.PoundForce), PoundsForceTolerance);
124139
AssertEx.EqualTolerance(TonnesForceInOneNewton, newton.As(ForceUnit.TonneForce), TonnesForceTolerance);
@@ -153,10 +168,22 @@ public void ToUnit()
153168
AssertEx.EqualTolerance(MeganewtonsInOneNewton, (double)meganewtonQuantity.Value, MeganewtonsTolerance);
154169
Assert.Equal(ForceUnit.Meganewton, meganewtonQuantity.Unit);
155170

171+
var micronewtonQuantity = newton.ToUnit(ForceUnit.Micronewton);
172+
AssertEx.EqualTolerance(MicronewtonsInOneNewton, (double)micronewtonQuantity.Value, MicronewtonsTolerance);
173+
Assert.Equal(ForceUnit.Micronewton, micronewtonQuantity.Unit);
174+
175+
var millinewtonQuantity = newton.ToUnit(ForceUnit.Millinewton);
176+
AssertEx.EqualTolerance(MillinewtonsInOneNewton, (double)millinewtonQuantity.Value, MillinewtonsTolerance);
177+
Assert.Equal(ForceUnit.Millinewton, millinewtonQuantity.Unit);
178+
156179
var newtonQuantity = newton.ToUnit(ForceUnit.Newton);
157180
AssertEx.EqualTolerance(NewtonsInOneNewton, (double)newtonQuantity.Value, NewtonsTolerance);
158181
Assert.Equal(ForceUnit.Newton, newtonQuantity.Unit);
159182

183+
var ounceforceQuantity = newton.ToUnit(ForceUnit.OunceForce);
184+
AssertEx.EqualTolerance(OunceForceInOneNewton, (double)ounceforceQuantity.Value, OunceForceTolerance);
185+
Assert.Equal(ForceUnit.OunceForce, ounceforceQuantity.Unit);
186+
160187
var poundalQuantity = newton.ToUnit(ForceUnit.Poundal);
161188
AssertEx.EqualTolerance(PoundalsInOneNewton, (double)poundalQuantity.Value, PoundalsTolerance);
162189
Assert.Equal(ForceUnit.Poundal, poundalQuantity.Unit);
@@ -180,7 +207,10 @@ public void ConversionRoundTrip()
180207
AssertEx.EqualTolerance(1, Force.FromKilonewtons(newton.Kilonewtons).Newtons, KilonewtonsTolerance);
181208
AssertEx.EqualTolerance(1, Force.FromKiloPonds(newton.KiloPonds).Newtons, KiloPondsTolerance);
182209
AssertEx.EqualTolerance(1, Force.FromMeganewtons(newton.Meganewtons).Newtons, MeganewtonsTolerance);
210+
AssertEx.EqualTolerance(1, Force.FromMicronewtons(newton.Micronewtons).Newtons, MicronewtonsTolerance);
211+
AssertEx.EqualTolerance(1, Force.FromMillinewtons(newton.Millinewtons).Newtons, MillinewtonsTolerance);
183212
AssertEx.EqualTolerance(1, Force.FromNewtons(newton.Newtons).Newtons, NewtonsTolerance);
213+
AssertEx.EqualTolerance(1, Force.FromOunceForce(newton.OunceForce).Newtons, OunceForceTolerance);
184214
AssertEx.EqualTolerance(1, Force.FromPoundals(newton.Poundals).Newtons, PoundalsTolerance);
185215
AssertEx.EqualTolerance(1, Force.FromPoundsForce(newton.PoundsForce).Newtons, PoundsForceTolerance);
186216
AssertEx.EqualTolerance(1, Force.FromTonnesForce(newton.TonnesForce).Newtons, TonnesForceTolerance);

UnitsNet/GeneratedCode/Extensions/Number/NumberToForceExtensions.g.cs

+33
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,28 @@ public static class NumberToForceExtensions
110110

111111
#endregion
112112

113+
#region Micronewton
114+
115+
/// <inheritdoc cref="Force.FromMicronewtons(UnitsNet.QuantityValue)" />
116+
public static Force Micronewtons<T>(this T value) => Force.FromMicronewtons(Convert.ToDouble(value));
117+
118+
/// <inheritdoc cref="Force.FromMicronewtons(UnitsNet.QuantityValue)" />
119+
[Obsolete("Nullable type support has been deprecated and will be removed in a future release.")]
120+
public static Force? Micronewtons<T>(this T? value) where T : struct => Force.FromMicronewtons(value == null ? (double?)null : Convert.ToDouble(value.Value));
121+
122+
#endregion
123+
124+
#region Millinewton
125+
126+
/// <inheritdoc cref="Force.FromMillinewtons(UnitsNet.QuantityValue)" />
127+
public static Force Millinewtons<T>(this T value) => Force.FromMillinewtons(Convert.ToDouble(value));
128+
129+
/// <inheritdoc cref="Force.FromMillinewtons(UnitsNet.QuantityValue)" />
130+
[Obsolete("Nullable type support has been deprecated and will be removed in a future release.")]
131+
public static Force? Millinewtons<T>(this T? value) where T : struct => Force.FromMillinewtons(value == null ? (double?)null : Convert.ToDouble(value.Value));
132+
133+
#endregion
134+
113135
#region Newton
114136

115137
/// <inheritdoc cref="Force.FromNewtons(UnitsNet.QuantityValue)" />
@@ -121,6 +143,17 @@ public static class NumberToForceExtensions
121143

122144
#endregion
123145

146+
#region OunceForce
147+
148+
/// <inheritdoc cref="Force.FromOunceForce(UnitsNet.QuantityValue)" />
149+
public static Force OunceForce<T>(this T value) => Force.FromOunceForce(Convert.ToDouble(value));
150+
151+
/// <inheritdoc cref="Force.FromOunceForce(UnitsNet.QuantityValue)" />
152+
[Obsolete("Nullable type support has been deprecated and will be removed in a future release.")]
153+
public static Force? OunceForce<T>(this T? value) where T : struct => Force.FromOunceForce(value == null ? (double?)null : Convert.ToDouble(value.Value));
154+
155+
#endregion
156+
124157
#region Poundal
125158

126159
/// <inheritdoc cref="Force.FromPoundals(UnitsNet.QuantityValue)" />

UnitsNet/GeneratedCode/Quantities/Force.NetFramework.g.cs

+27
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@ public partial struct Force : IComparable, IComparable<Force>
116116
return meganewtons.HasValue ? FromMeganewtons(meganewtons.Value) : default(Force?);
117117
}
118118

119+
/// <summary>
120+
/// Get nullable Force from nullable Micronewtons.
121+
/// </summary>
122+
[Obsolete("Nullable type support is obsolete and will be removed in a future release.")]
123+
public static Force? FromMicronewtons(QuantityValue? micronewtons)
124+
{
125+
return micronewtons.HasValue ? FromMicronewtons(micronewtons.Value) : default(Force?);
126+
}
127+
128+
/// <summary>
129+
/// Get nullable Force from nullable Millinewtons.
130+
/// </summary>
131+
[Obsolete("Nullable type support is obsolete and will be removed in a future release.")]
132+
public static Force? FromMillinewtons(QuantityValue? millinewtons)
133+
{
134+
return millinewtons.HasValue ? FromMillinewtons(millinewtons.Value) : default(Force?);
135+
}
136+
119137
/// <summary>
120138
/// Get nullable Force from nullable Newtons.
121139
/// </summary>
@@ -125,6 +143,15 @@ public partial struct Force : IComparable, IComparable<Force>
125143
return newtons.HasValue ? FromNewtons(newtons.Value) : default(Force?);
126144
}
127145

146+
/// <summary>
147+
/// Get nullable Force from nullable OunceForce.
148+
/// </summary>
149+
[Obsolete("Nullable type support is obsolete and will be removed in a future release.")]
150+
public static Force? FromOunceForce(QuantityValue? ounceforce)
151+
{
152+
return ounceforce.HasValue ? FromOunceForce(ounceforce.Value) : default(Force?);
153+
}
154+
128155
/// <summary>
129156
/// Get nullable Force from nullable Poundals.
130157
/// </summary>

UnitsNet/GeneratedCode/UnitSystem.Default.g.cs

+19-2
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
15261526
new[]
15271527
{
15281528
new AbbreviationsForCulture("en-US", "daN"),
1529-
new AbbreviationsForCulture("ru-RU", "даН"),
1529+
new AbbreviationsForCulture("ru-RU", ""),
15301530
}),
15311531
new CulturesForEnumValue((int) ForceUnit.Dyn,
15321532
new[]
@@ -1544,7 +1544,7 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
15441544
new[]
15451545
{
15461546
new AbbreviationsForCulture("en-US", "kN"),
1547-
new AbbreviationsForCulture("ru-RU", "кН"),
1547+
new AbbreviationsForCulture("ru-RU", ""),
15481548
}),
15491549
new CulturesForEnumValue((int) ForceUnit.KiloPond,
15501550
new[]
@@ -1558,12 +1558,29 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
15581558
new AbbreviationsForCulture("en-US", "MN"),
15591559
new AbbreviationsForCulture("ru-RU", ""),
15601560
}),
1561+
new CulturesForEnumValue((int) ForceUnit.Micronewton,
1562+
new[]
1563+
{
1564+
new AbbreviationsForCulture("en-US", "µN"),
1565+
new AbbreviationsForCulture("ru-RU", "даН"),
1566+
}),
1567+
new CulturesForEnumValue((int) ForceUnit.Millinewton,
1568+
new[]
1569+
{
1570+
new AbbreviationsForCulture("en-US", "mN"),
1571+
new AbbreviationsForCulture("ru-RU", "кН"),
1572+
}),
15611573
new CulturesForEnumValue((int) ForceUnit.Newton,
15621574
new[]
15631575
{
15641576
new AbbreviationsForCulture("en-US", "N"),
15651577
new AbbreviationsForCulture("ru-RU", "Н"),
15661578
}),
1579+
new CulturesForEnumValue((int) ForceUnit.OunceForce,
1580+
new[]
1581+
{
1582+
new AbbreviationsForCulture("en-US", "ozf"),
1583+
}),
15671584
new CulturesForEnumValue((int) ForceUnit.Poundal,
15681585
new[]
15691586
{

UnitsNet/GeneratedCode/Units/ForceUnit.g.cs

+3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ public enum ForceUnit
5151
Kilonewton,
5252
KiloPond,
5353
Meganewton,
54+
Micronewton,
55+
Millinewton,
5456
Newton,
57+
OunceForce,
5558
Poundal,
5659
PoundForce,
5760
TonneForce,

0 commit comments

Comments
 (0)