Skip to content

Adding support for micro/milli newtons, as well as ounce force #535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions Common/GeneratedCode/Quantities/Force.Common.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,26 @@ public static BaseDimensions BaseDimensions
/// </summary>
public double Meganewtons => As(ForceUnit.Meganewton);

/// <summary>
/// Get Force in Micronewtons.
/// </summary>
public double Micronewtons => As(ForceUnit.Micronewton);

/// <summary>
/// Get Force in Millinewtons.
/// </summary>
public double Millinewtons => As(ForceUnit.Millinewton);

/// <summary>
/// Get Force in Newtons.
/// </summary>
public double Newtons => As(ForceUnit.Newton);

/// <summary>
/// Get Force in OunceForce.
/// </summary>
public double OunceForce => As(ForceUnit.OunceForce);

/// <summary>
/// Get Force in Poundals.
/// </summary>
Expand Down Expand Up @@ -304,6 +319,34 @@ public static Force FromMeganewtons(QuantityValue meganewtons)
return new Force(value, ForceUnit.Meganewton);
}

/// <summary>
/// Get Force from Micronewtons.
/// </summary>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static Force FromMicronewtons(double micronewtons)
#else
public static Force FromMicronewtons(QuantityValue micronewtons)
#endif
{
double value = (double) micronewtons;
return new Force(value, ForceUnit.Micronewton);
}

/// <summary>
/// Get Force from Millinewtons.
/// </summary>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static Force FromMillinewtons(double millinewtons)
#else
public static Force FromMillinewtons(QuantityValue millinewtons)
#endif
{
double value = (double) millinewtons;
return new Force(value, ForceUnit.Millinewton);
}

/// <summary>
/// Get Force from Newtons.
/// </summary>
Expand All @@ -318,6 +361,20 @@ public static Force FromNewtons(QuantityValue newtons)
return new Force(value, ForceUnit.Newton);
}

/// <summary>
/// Get Force from OunceForce.
/// </summary>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static Force FromOunceForce(double ounceforce)
#else
public static Force FromOunceForce(QuantityValue ounceforce)
#endif
{
double value = (double) ounceforce;
return new Force(value, ForceUnit.OunceForce);
}

/// <summary>
/// Get Force from Poundals.
/// </summary>
Expand Down Expand Up @@ -538,7 +595,10 @@ private double AsBaseUnit()
case ForceUnit.Kilonewton: return (_value) * 1e3d;
case ForceUnit.KiloPond: return _value*9.80665002864;
case ForceUnit.Meganewton: return (_value) * 1e6d;
case ForceUnit.Micronewton: return (_value) * 1e-6d;
case ForceUnit.Millinewton: return (_value) * 1e-3d;
case ForceUnit.Newton: return _value;
case ForceUnit.OunceForce: return _value*2.780138509537812e-1;
case ForceUnit.Poundal: return _value*0.13825502798973041652092282466083;
case ForceUnit.PoundForce: return _value*4.4482216152605095551842641431421;
case ForceUnit.TonneForce: return _value*9.80665002864e3;
Expand All @@ -562,7 +622,10 @@ private double AsBaseNumericType(ForceUnit unit)
case ForceUnit.Kilonewton: return (baseUnitValue) / 1e3d;
case ForceUnit.KiloPond: return baseUnitValue/9.80665002864;
case ForceUnit.Meganewton: return (baseUnitValue) / 1e6d;
case ForceUnit.Micronewton: return (baseUnitValue) / 1e-6d;
case ForceUnit.Millinewton: return (baseUnitValue) / 1e-3d;
case ForceUnit.Newton: return baseUnitValue;
case ForceUnit.OunceForce: return baseUnitValue/2.780138509537812e-1;
case ForceUnit.Poundal: return baseUnitValue/0.13825502798973041652092282466083;
case ForceUnit.PoundForce: return baseUnitValue/4.4482216152605095551842641431421;
case ForceUnit.TonneForce: return baseUnitValue/9.80665002864e3;
Expand Down
14 changes: 13 additions & 1 deletion Common/UnitDefinitions/Force.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"PluralName": "Newtons",
"FromUnitToBaseFunc": "x",
"FromBaseToUnitFunc": "x",
"Prefixes": [ "Deca", "Kilo", "Mega" ],
"Prefixes": [ "Micro", "Milli", "Deca", "Kilo", "Mega" ],
"Localization": [
{
"Culture": "en-US",
Expand Down Expand Up @@ -121,6 +121,18 @@
"Abbreviations": [ "фунт-сила" ]
}
]
},
{
"SingularName": "OunceForce",
"PluralName": "OunceForce",
"FromUnitToBaseFunc": "x*2.780138509537812e-1",
"FromBaseToUnitFunc": "x/2.780138509537812e-1",
"Localization": [
{
"Culture": "en-US",
"Abbreviations": [ "ozf" ]
}
]
}
]
}
6 changes: 6 additions & 0 deletions UnitsNet.Tests/CustomCode/ForceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public class ForceTests : ForceTestsBase

protected override double TonnesForceInOneNewton => 1.019716212977928e-4;

protected override double MillinewtonsInOneNewton => 1.0e3;

protected override double MicronewtonsInOneNewton => 1.0e6;

protected override double OunceForceInOneNewton => 3.596943089595368;

[Fact]
public void ForceDividedByAreaEqualsPressure()
{
Expand Down
30 changes: 30 additions & 0 deletions UnitsNet.Tests/GeneratedCode/ForceTestsBase.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public abstract partial class ForceTestsBase
protected abstract double KilonewtonsInOneNewton { get; }
protected abstract double KiloPondsInOneNewton { get; }
protected abstract double MeganewtonsInOneNewton { get; }
protected abstract double MicronewtonsInOneNewton { get; }
protected abstract double MillinewtonsInOneNewton { get; }
protected abstract double NewtonsInOneNewton { get; }
protected abstract double OunceForceInOneNewton { get; }
protected abstract double PoundalsInOneNewton { get; }
protected abstract double PoundsForceInOneNewton { get; }
protected abstract double TonnesForceInOneNewton { get; }
Expand All @@ -71,7 +74,10 @@ public abstract partial class ForceTestsBase
protected virtual double KilonewtonsTolerance { get { return 1e-5; } }
protected virtual double KiloPondsTolerance { get { return 1e-5; } }
protected virtual double MeganewtonsTolerance { get { return 1e-5; } }
protected virtual double MicronewtonsTolerance { get { return 1e-5; } }
protected virtual double MillinewtonsTolerance { get { return 1e-5; } }
protected virtual double NewtonsTolerance { get { return 1e-5; } }
protected virtual double OunceForceTolerance { get { return 1e-5; } }
protected virtual double PoundalsTolerance { get { return 1e-5; } }
protected virtual double PoundsForceTolerance { get { return 1e-5; } }
protected virtual double TonnesForceTolerance { get { return 1e-5; } }
Expand All @@ -87,7 +93,10 @@ public void NewtonToForceUnits()
AssertEx.EqualTolerance(KilonewtonsInOneNewton, newton.Kilonewtons, KilonewtonsTolerance);
AssertEx.EqualTolerance(KiloPondsInOneNewton, newton.KiloPonds, KiloPondsTolerance);
AssertEx.EqualTolerance(MeganewtonsInOneNewton, newton.Meganewtons, MeganewtonsTolerance);
AssertEx.EqualTolerance(MicronewtonsInOneNewton, newton.Micronewtons, MicronewtonsTolerance);
AssertEx.EqualTolerance(MillinewtonsInOneNewton, newton.Millinewtons, MillinewtonsTolerance);
AssertEx.EqualTolerance(NewtonsInOneNewton, newton.Newtons, NewtonsTolerance);
AssertEx.EqualTolerance(OunceForceInOneNewton, newton.OunceForce, OunceForceTolerance);
AssertEx.EqualTolerance(PoundalsInOneNewton, newton.Poundals, PoundalsTolerance);
AssertEx.EqualTolerance(PoundsForceInOneNewton, newton.PoundsForce, PoundsForceTolerance);
AssertEx.EqualTolerance(TonnesForceInOneNewton, newton.TonnesForce, TonnesForceTolerance);
Expand All @@ -102,7 +111,10 @@ public void FromValueAndUnit()
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Kilonewton).Kilonewtons, KilonewtonsTolerance);
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.KiloPond).KiloPonds, KiloPondsTolerance);
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Meganewton).Meganewtons, MeganewtonsTolerance);
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Micronewton).Micronewtons, MicronewtonsTolerance);
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Millinewton).Millinewtons, MillinewtonsTolerance);
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Newton).Newtons, NewtonsTolerance);
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.OunceForce).OunceForce, OunceForceTolerance);
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.Poundal).Poundals, PoundalsTolerance);
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.PoundForce).PoundsForce, PoundsForceTolerance);
AssertEx.EqualTolerance(1, Force.From(1, ForceUnit.TonneForce).TonnesForce, TonnesForceTolerance);
Expand All @@ -118,7 +130,10 @@ public void As()
AssertEx.EqualTolerance(KilonewtonsInOneNewton, newton.As(ForceUnit.Kilonewton), KilonewtonsTolerance);
AssertEx.EqualTolerance(KiloPondsInOneNewton, newton.As(ForceUnit.KiloPond), KiloPondsTolerance);
AssertEx.EqualTolerance(MeganewtonsInOneNewton, newton.As(ForceUnit.Meganewton), MeganewtonsTolerance);
AssertEx.EqualTolerance(MicronewtonsInOneNewton, newton.As(ForceUnit.Micronewton), MicronewtonsTolerance);
AssertEx.EqualTolerance(MillinewtonsInOneNewton, newton.As(ForceUnit.Millinewton), MillinewtonsTolerance);
AssertEx.EqualTolerance(NewtonsInOneNewton, newton.As(ForceUnit.Newton), NewtonsTolerance);
AssertEx.EqualTolerance(OunceForceInOneNewton, newton.As(ForceUnit.OunceForce), OunceForceTolerance);
AssertEx.EqualTolerance(PoundalsInOneNewton, newton.As(ForceUnit.Poundal), PoundalsTolerance);
AssertEx.EqualTolerance(PoundsForceInOneNewton, newton.As(ForceUnit.PoundForce), PoundsForceTolerance);
AssertEx.EqualTolerance(TonnesForceInOneNewton, newton.As(ForceUnit.TonneForce), TonnesForceTolerance);
Expand Down Expand Up @@ -153,10 +168,22 @@ public void ToUnit()
AssertEx.EqualTolerance(MeganewtonsInOneNewton, (double)meganewtonQuantity.Value, MeganewtonsTolerance);
Assert.Equal(ForceUnit.Meganewton, meganewtonQuantity.Unit);

var micronewtonQuantity = newton.ToUnit(ForceUnit.Micronewton);
AssertEx.EqualTolerance(MicronewtonsInOneNewton, (double)micronewtonQuantity.Value, MicronewtonsTolerance);
Assert.Equal(ForceUnit.Micronewton, micronewtonQuantity.Unit);

var millinewtonQuantity = newton.ToUnit(ForceUnit.Millinewton);
AssertEx.EqualTolerance(MillinewtonsInOneNewton, (double)millinewtonQuantity.Value, MillinewtonsTolerance);
Assert.Equal(ForceUnit.Millinewton, millinewtonQuantity.Unit);

var newtonQuantity = newton.ToUnit(ForceUnit.Newton);
AssertEx.EqualTolerance(NewtonsInOneNewton, (double)newtonQuantity.Value, NewtonsTolerance);
Assert.Equal(ForceUnit.Newton, newtonQuantity.Unit);

var ounceforceQuantity = newton.ToUnit(ForceUnit.OunceForce);
AssertEx.EqualTolerance(OunceForceInOneNewton, (double)ounceforceQuantity.Value, OunceForceTolerance);
Assert.Equal(ForceUnit.OunceForce, ounceforceQuantity.Unit);

var poundalQuantity = newton.ToUnit(ForceUnit.Poundal);
AssertEx.EqualTolerance(PoundalsInOneNewton, (double)poundalQuantity.Value, PoundalsTolerance);
Assert.Equal(ForceUnit.Poundal, poundalQuantity.Unit);
Expand All @@ -180,7 +207,10 @@ public void ConversionRoundTrip()
AssertEx.EqualTolerance(1, Force.FromKilonewtons(newton.Kilonewtons).Newtons, KilonewtonsTolerance);
AssertEx.EqualTolerance(1, Force.FromKiloPonds(newton.KiloPonds).Newtons, KiloPondsTolerance);
AssertEx.EqualTolerance(1, Force.FromMeganewtons(newton.Meganewtons).Newtons, MeganewtonsTolerance);
AssertEx.EqualTolerance(1, Force.FromMicronewtons(newton.Micronewtons).Newtons, MicronewtonsTolerance);
AssertEx.EqualTolerance(1, Force.FromMillinewtons(newton.Millinewtons).Newtons, MillinewtonsTolerance);
AssertEx.EqualTolerance(1, Force.FromNewtons(newton.Newtons).Newtons, NewtonsTolerance);
AssertEx.EqualTolerance(1, Force.FromOunceForce(newton.OunceForce).Newtons, OunceForceTolerance);
AssertEx.EqualTolerance(1, Force.FromPoundals(newton.Poundals).Newtons, PoundalsTolerance);
AssertEx.EqualTolerance(1, Force.FromPoundsForce(newton.PoundsForce).Newtons, PoundsForceTolerance);
AssertEx.EqualTolerance(1, Force.FromTonnesForce(newton.TonnesForce).Newtons, TonnesForceTolerance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,28 @@ public static class NumberToForceExtensions

#endregion

#region Micronewton

/// <inheritdoc cref="Force.FromMicronewtons(UnitsNet.QuantityValue)" />
public static Force Micronewtons<T>(this T value) => Force.FromMicronewtons(Convert.ToDouble(value));

/// <inheritdoc cref="Force.FromMicronewtons(UnitsNet.QuantityValue)" />
[Obsolete("Nullable type support has been deprecated and will be removed in a future release.")]
public static Force? Micronewtons<T>(this T? value) where T : struct => Force.FromMicronewtons(value == null ? (double?)null : Convert.ToDouble(value.Value));

#endregion

#region Millinewton

/// <inheritdoc cref="Force.FromMillinewtons(UnitsNet.QuantityValue)" />
public static Force Millinewtons<T>(this T value) => Force.FromMillinewtons(Convert.ToDouble(value));

/// <inheritdoc cref="Force.FromMillinewtons(UnitsNet.QuantityValue)" />
[Obsolete("Nullable type support has been deprecated and will be removed in a future release.")]
public static Force? Millinewtons<T>(this T? value) where T : struct => Force.FromMillinewtons(value == null ? (double?)null : Convert.ToDouble(value.Value));

#endregion

#region Newton

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

#endregion

#region OunceForce

/// <inheritdoc cref="Force.FromOunceForce(UnitsNet.QuantityValue)" />
public static Force OunceForce<T>(this T value) => Force.FromOunceForce(Convert.ToDouble(value));

/// <inheritdoc cref="Force.FromOunceForce(UnitsNet.QuantityValue)" />
[Obsolete("Nullable type support has been deprecated and will be removed in a future release.")]
public static Force? OunceForce<T>(this T? value) where T : struct => Force.FromOunceForce(value == null ? (double?)null : Convert.ToDouble(value.Value));

#endregion

#region Poundal

/// <inheritdoc cref="Force.FromPoundals(UnitsNet.QuantityValue)" />
Expand Down
27 changes: 27 additions & 0 deletions UnitsNet/GeneratedCode/Quantities/Force.NetFramework.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@ public partial struct Force : IComparable, IComparable<Force>
return meganewtons.HasValue ? FromMeganewtons(meganewtons.Value) : default(Force?);
}

/// <summary>
/// Get nullable Force from nullable Micronewtons.
/// </summary>
[Obsolete("Nullable type support is obsolete and will be removed in a future release.")]
public static Force? FromMicronewtons(QuantityValue? micronewtons)
{
return micronewtons.HasValue ? FromMicronewtons(micronewtons.Value) : default(Force?);
}

/// <summary>
/// Get nullable Force from nullable Millinewtons.
/// </summary>
[Obsolete("Nullable type support is obsolete and will be removed in a future release.")]
public static Force? FromMillinewtons(QuantityValue? millinewtons)
{
return millinewtons.HasValue ? FromMillinewtons(millinewtons.Value) : default(Force?);
}

/// <summary>
/// Get nullable Force from nullable Newtons.
/// </summary>
Expand All @@ -125,6 +143,15 @@ public partial struct Force : IComparable, IComparable<Force>
return newtons.HasValue ? FromNewtons(newtons.Value) : default(Force?);
}

/// <summary>
/// Get nullable Force from nullable OunceForce.
/// </summary>
[Obsolete("Nullable type support is obsolete and will be removed in a future release.")]
public static Force? FromOunceForce(QuantityValue? ounceforce)
{
return ounceforce.HasValue ? FromOunceForce(ounceforce.Value) : default(Force?);
}

/// <summary>
/// Get nullable Force from nullable Poundals.
/// </summary>
Expand Down
21 changes: 19 additions & 2 deletions UnitsNet/GeneratedCode/UnitSystem.Default.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
new[]
{
new AbbreviationsForCulture("en-US", "daN"),
new AbbreviationsForCulture("ru-RU", "даН"),
new AbbreviationsForCulture("ru-RU", ""),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Will fix this. 😞

}),
new CulturesForEnumValue((int) ForceUnit.Dyn,
new[]
Expand All @@ -1544,7 +1544,7 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
new[]
{
new AbbreviationsForCulture("en-US", "kN"),
new AbbreviationsForCulture("ru-RU", "кН"),
new AbbreviationsForCulture("ru-RU", ""),
}),
new CulturesForEnumValue((int) ForceUnit.KiloPond,
new[]
Expand All @@ -1558,12 +1558,29 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
new AbbreviationsForCulture("en-US", "MN"),
new AbbreviationsForCulture("ru-RU", ""),
}),
new CulturesForEnumValue((int) ForceUnit.Micronewton,
new[]
{
new AbbreviationsForCulture("en-US", "µN"),
new AbbreviationsForCulture("ru-RU", "даН"),
}),
new CulturesForEnumValue((int) ForceUnit.Millinewton,
new[]
{
new AbbreviationsForCulture("en-US", "mN"),
new AbbreviationsForCulture("ru-RU", "кН"),
}),
new CulturesForEnumValue((int) ForceUnit.Newton,
new[]
{
new AbbreviationsForCulture("en-US", "N"),
new AbbreviationsForCulture("ru-RU", "Н"),
}),
new CulturesForEnumValue((int) ForceUnit.OunceForce,
new[]
{
new AbbreviationsForCulture("en-US", "ozf"),
}),
new CulturesForEnumValue((int) ForceUnit.Poundal,
new[]
{
Expand Down
3 changes: 3 additions & 0 deletions UnitsNet/GeneratedCode/Units/ForceUnit.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public enum ForceUnit
Kilonewton,
KiloPond,
Meganewton,
Micronewton,
Millinewton,
Newton,
OunceForce,
Poundal,
PoundForce,
TonneForce,
Expand Down