Skip to content

Features/pressure mega newton per square meter #418

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 1 commit into from
Mar 21, 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
4 changes: 3 additions & 1 deletion UnitsNet.Tests/CustomCode/PressureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class PressureTests : PressureTestsBase

protected override double MetersOfHeadInOnePascal => 0.00010199773339984054;

protected override double MeganewtonsPerSquareMeterInOnePascal => 1E-6;

protected override double NewtonsPerSquareCentimeterInOnePascal => 1E-4;

protected override double NewtonsPerSquareMeterInOnePascal => 1;
Expand Down Expand Up @@ -113,4 +115,4 @@ public void PressureTimesAreaEqualsForce()
Assert.Equal(force, Force.FromNewtons(60));
}
}
}
}
6 changes: 6 additions & 0 deletions UnitsNet.Tests/GeneratedCode/PressureTestsBase.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public abstract partial class PressureTestsBase
protected abstract double KilopoundsForcePerSquareFootInOnePascal { get; }
protected abstract double KilopoundsForcePerSquareInchInOnePascal { get; }
protected abstract double MegabarsInOnePascal { get; }
protected abstract double MeganewtonsPerSquareMeterInOnePascal { get; }
protected abstract double MegapascalsInOnePascal { get; }
protected abstract double MetersOfHeadInOnePascal { get; }
protected abstract double MicropascalsInOnePascal { get; }
Expand Down Expand Up @@ -111,6 +112,7 @@ public abstract partial class PressureTestsBase
protected virtual double KilopoundsForcePerSquareFootTolerance { get { return 1e-5; } }
protected virtual double KilopoundsForcePerSquareInchTolerance { get { return 1e-5; } }
protected virtual double MegabarsTolerance { get { return 1e-5; } }
protected virtual double MeganewtonsPerSquareMeterTolerance { get { return 1e-5; } }
protected virtual double MegapascalsTolerance { get { return 1e-5; } }
protected virtual double MetersOfHeadTolerance { get { return 1e-5; } }
protected virtual double MicropascalsTolerance { get { return 1e-5; } }
Expand Down Expand Up @@ -154,6 +156,7 @@ public void PascalToPressureUnits()
AssertEx.EqualTolerance(KilopoundsForcePerSquareFootInOnePascal, pascal.KilopoundsForcePerSquareFoot, KilopoundsForcePerSquareFootTolerance);
AssertEx.EqualTolerance(KilopoundsForcePerSquareInchInOnePascal, pascal.KilopoundsForcePerSquareInch, KilopoundsForcePerSquareInchTolerance);
AssertEx.EqualTolerance(MegabarsInOnePascal, pascal.Megabars, MegabarsTolerance);
AssertEx.EqualTolerance(MeganewtonsPerSquareMeterInOnePascal, pascal.MeganewtonsPerSquareMeter, MeganewtonsPerSquareMeterTolerance);
AssertEx.EqualTolerance(MegapascalsInOnePascal, pascal.Megapascals, MegapascalsTolerance);
AssertEx.EqualTolerance(MetersOfHeadInOnePascal, pascal.MetersOfHead, MetersOfHeadTolerance);
AssertEx.EqualTolerance(MicropascalsInOnePascal, pascal.Micropascals, MicropascalsTolerance);
Expand Down Expand Up @@ -196,6 +199,7 @@ public void FromValueAndUnit()
AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.KilopoundForcePerSquareFoot).KilopoundsForcePerSquareFoot, KilopoundsForcePerSquareFootTolerance);
AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.KilopoundForcePerSquareInch).KilopoundsForcePerSquareInch, KilopoundsForcePerSquareInchTolerance);
AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Megabar).Megabars, MegabarsTolerance);
AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.MeganewtonPerSquareMeter).MeganewtonsPerSquareMeter, MeganewtonsPerSquareMeterTolerance);
AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Megapascal).Megapascals, MegapascalsTolerance);
AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.MeterOfHead).MetersOfHead, MetersOfHeadTolerance);
AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Micropascal).Micropascals, MicropascalsTolerance);
Expand Down Expand Up @@ -239,6 +243,7 @@ public void As()
AssertEx.EqualTolerance(KilopoundsForcePerSquareFootInOnePascal, pascal.As(PressureUnit.KilopoundForcePerSquareFoot), KilopoundsForcePerSquareFootTolerance);
AssertEx.EqualTolerance(KilopoundsForcePerSquareInchInOnePascal, pascal.As(PressureUnit.KilopoundForcePerSquareInch), KilopoundsForcePerSquareInchTolerance);
AssertEx.EqualTolerance(MegabarsInOnePascal, pascal.As(PressureUnit.Megabar), MegabarsTolerance);
AssertEx.EqualTolerance(MeganewtonsPerSquareMeterInOnePascal, pascal.As(PressureUnit.MeganewtonPerSquareMeter), MeganewtonsPerSquareMeterTolerance);
AssertEx.EqualTolerance(MegapascalsInOnePascal, pascal.As(PressureUnit.Megapascal), MegapascalsTolerance);
AssertEx.EqualTolerance(MetersOfHeadInOnePascal, pascal.As(PressureUnit.MeterOfHead), MetersOfHeadTolerance);
AssertEx.EqualTolerance(MicropascalsInOnePascal, pascal.As(PressureUnit.Micropascal), MicropascalsTolerance);
Expand Down Expand Up @@ -282,6 +287,7 @@ public void ConversionRoundTrip()
AssertEx.EqualTolerance(1, Pressure.FromKilopoundsForcePerSquareFoot(pascal.KilopoundsForcePerSquareFoot).Pascals, KilopoundsForcePerSquareFootTolerance);
AssertEx.EqualTolerance(1, Pressure.FromKilopoundsForcePerSquareInch(pascal.KilopoundsForcePerSquareInch).Pascals, KilopoundsForcePerSquareInchTolerance);
AssertEx.EqualTolerance(1, Pressure.FromMegabars(pascal.Megabars).Pascals, MegabarsTolerance);
AssertEx.EqualTolerance(1, Pressure.FromMeganewtonsPerSquareMeter(pascal.MeganewtonsPerSquareMeter).Pascals, MeganewtonsPerSquareMeterTolerance);
AssertEx.EqualTolerance(1, Pressure.FromMegapascals(pascal.Megapascals).Pascals, MegapascalsTolerance);
AssertEx.EqualTolerance(1, Pressure.FromMetersOfHead(pascal.MetersOfHead).Pascals, MetersOfHeadTolerance);
AssertEx.EqualTolerance(1, Pressure.FromMicropascals(pascal.Micropascals).Pascals, MicropascalsTolerance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,40 @@ public static class NumberToPressureExtensions

#endregion

#region MeganewtonPerSquareMeter

/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double)"/>
public static Pressure MeganewtonsPerSquareMeter(this int value) => Pressure.FromMeganewtonsPerSquareMeter(value);

/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double?)"/>
public static Pressure? MeganewtonsPerSquareMeter(this int? value) => Pressure.FromMeganewtonsPerSquareMeter(value);

/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double)"/>
public static Pressure MeganewtonsPerSquareMeter(this long value) => Pressure.FromMeganewtonsPerSquareMeter(value);

/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double?)"/>
public static Pressure? MeganewtonsPerSquareMeter(this long? value) => Pressure.FromMeganewtonsPerSquareMeter(value);

/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double)"/>
public static Pressure MeganewtonsPerSquareMeter(this double value) => Pressure.FromMeganewtonsPerSquareMeter(value);

/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double?)"/>
public static Pressure? MeganewtonsPerSquareMeter(this double? value) => Pressure.FromMeganewtonsPerSquareMeter(value);

/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double)"/>
public static Pressure MeganewtonsPerSquareMeter(this float value) => Pressure.FromMeganewtonsPerSquareMeter(value);

/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double?)"/>
public static Pressure? MeganewtonsPerSquareMeter(this float? value) => Pressure.FromMeganewtonsPerSquareMeter(value);

/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double)"/>
public static Pressure MeganewtonsPerSquareMeter(this decimal value) => Pressure.FromMeganewtonsPerSquareMeter(Convert.ToDouble(value));

/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double?)"/>
public static Pressure? MeganewtonsPerSquareMeter(this decimal? value) => Pressure.FromMeganewtonsPerSquareMeter(value == null ? (double?)null : Convert.ToDouble(value.Value));

#endregion

#region Megapascal

/// <inheritdoc cref="Pressure.FromMegapascals(double)"/>
Expand Down
35 changes: 35 additions & 0 deletions UnitsNet/GeneratedCode/Quantities/Pressure.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ public Pressure(double pascals)
/// </summary>
public double Megabars => As(PressureUnit.Megabar);
/// <summary>
/// Get Pressure in MeganewtonsPerSquareMeter.
/// </summary>
public double MeganewtonsPerSquareMeter => As(PressureUnit.MeganewtonPerSquareMeter);
/// <summary>
/// Get Pressure in Megapascals.
/// </summary>
public double Megapascals => As(PressureUnit.Megapascal);
Expand Down Expand Up @@ -598,6 +602,20 @@ public static Pressure FromMegabars(QuantityValue megabars)
return new Pressure(value, PressureUnit.Megabar);
}

/// <summary>
/// Get Pressure from MeganewtonsPerSquareMeter.
/// </summary>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static Pressure FromMeganewtonsPerSquareMeter(double meganewtonspersquaremeter)
#else
public static Pressure FromMeganewtonsPerSquareMeter(QuantityValue meganewtonspersquaremeter)
#endif
{
double value = (double) meganewtonspersquaremeter;
return new Pressure(value, PressureUnit.MeganewtonPerSquareMeter);
}

/// <summary>
/// Get Pressure from Megapascals.
/// </summary>
Expand Down Expand Up @@ -1138,6 +1156,21 @@ public static Pressure FromTorrs(QuantityValue torrs)
}
}

/// <summary>
/// Get nullable Pressure from nullable MeganewtonsPerSquareMeter.
/// </summary>
public static Pressure? FromMeganewtonsPerSquareMeter(QuantityValue? meganewtonspersquaremeter)
{
if (meganewtonspersquaremeter.HasValue)
{
return FromMeganewtonsPerSquareMeter(meganewtonspersquaremeter.Value);
}
else
{
return null;
}
}

/// <summary>
/// Get nullable Pressure from nullable Megapascals.
/// </summary>
Expand Down Expand Up @@ -1640,6 +1673,7 @@ public double As(PressureUnit unit)
case PressureUnit.KilopoundForcePerSquareFoot: return (baseUnitValue*0.020885432426709) / 1e3d;
case PressureUnit.KilopoundForcePerSquareInch: return (baseUnitValue*0.000145037737730209) / 1e3d;
case PressureUnit.Megabar: return (baseUnitValue/1e5) / 1e6d;
case PressureUnit.MeganewtonPerSquareMeter: return (baseUnitValue) / 1e6d;
case PressureUnit.Megapascal: return (baseUnitValue) / 1e6d;
case PressureUnit.MeterOfHead: return baseUnitValue*0.0001019977334;
case PressureUnit.Micropascal: return (baseUnitValue) / 1e-6d;
Expand Down Expand Up @@ -2040,6 +2074,7 @@ private double AsBaseUnitPascals()
case PressureUnit.KilopoundForcePerSquareFoot: return (_value*47.8802631216372) * 1e3d;
case PressureUnit.KilopoundForcePerSquareInch: return (_value*6894.75729316836) * 1e3d;
case PressureUnit.Megabar: return (_value*1e5) * 1e6d;
case PressureUnit.MeganewtonPerSquareMeter: return (_value) * 1e6d;
case PressureUnit.Megapascal: return (_value) * 1e6d;
case PressureUnit.MeterOfHead: return _value*9804.139432;
case PressureUnit.Micropascal: return (_value) * 1e-6d;
Expand Down
6 changes: 6 additions & 0 deletions UnitsNet/GeneratedCode/UnitSystem.Default.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2956,6 +2956,12 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
new AbbreviationsForCulture("en-US", "Mbar"),
new AbbreviationsForCulture("ru-RU", "Mбар"),
}),
new CulturesForEnumValue((int) PressureUnit.MeganewtonPerSquareMeter,
new[]
{
new AbbreviationsForCulture("en-US", "MN/m²"),
new AbbreviationsForCulture("ru-RU", "Мн/м²"),
}),
new CulturesForEnumValue((int) PressureUnit.Megapascal,
new[]
{
Expand Down
1 change: 1 addition & 0 deletions UnitsNet/GeneratedCode/Units/PressureUnit.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public enum PressureUnit
KilopoundForcePerSquareFoot,
KilopoundForcePerSquareInch,
Megabar,
MeganewtonPerSquareMeter,
Megapascal,
MeterOfHead,
Micropascal,
Expand Down
6 changes: 3 additions & 3 deletions UnitsNet/UnitDefinitions/Pressure.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@
"PluralName": "NewtonsPerSquareMeter",
"FromUnitToBaseFunc": "x",
"FromBaseToUnitFunc": "x",
"Prefixes": [ "Kilo" ],
"Prefixes": [ "Kilo", "Mega" ],
"Localization": [
{
"Culture": "en-US",
"Abbreviations": [ "N/m²" ],
"AbbreviationsWithPrefixes": [ "kN/m²" ]
"AbbreviationsWithPrefixes": [ "kN/m²", "MN/m²" ]
Copy link
Owner

Choose a reason for hiding this comment

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

AbbreviationsWithPrefixes is only needed if prefixing k and M does not work, so for en-US culture it can be removed. I'll remove this in master after merging. Russian still needs to be kept.

Copy link
Owner

Choose a reason for hiding this comment

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

Fixed in #421

},
{
"Culture": "ru-RU",
"Abbreviations": [ "Н/м²" ],
"AbbreviationsWithPrefixes": [ "кН/м²" ]
"AbbreviationsWithPrefixes": [ "кН/м²", "Мн/м²" ]
}
]
},
Expand Down