Skip to content

Commit 45eed33

Browse files
dschuermansangularsen
authored andcommitted
Add Pressure.MeganewtonPerSquareMeter (#418)
1 parent c4e3314 commit 45eed33

File tree

7 files changed

+88
-4
lines changed

7 files changed

+88
-4
lines changed

UnitsNet.Tests/CustomCode/PressureTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public class PressureTests : PressureTestsBase
5252

5353
protected override double MetersOfHeadInOnePascal => 0.00010199773339984054;
5454

55+
protected override double MeganewtonsPerSquareMeterInOnePascal => 1E-6;
56+
5557
protected override double NewtonsPerSquareCentimeterInOnePascal => 1E-4;
5658

5759
protected override double NewtonsPerSquareMeterInOnePascal => 1;
@@ -113,4 +115,4 @@ public void PressureTimesAreaEqualsForce()
113115
Assert.Equal(force, Force.FromNewtons(60));
114116
}
115117
}
116-
}
118+
}

UnitsNet.Tests/GeneratedCode/PressureTestsBase.g.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public abstract partial class PressureTestsBase
7272
protected abstract double KilopoundsForcePerSquareFootInOnePascal { get; }
7373
protected abstract double KilopoundsForcePerSquareInchInOnePascal { get; }
7474
protected abstract double MegabarsInOnePascal { get; }
75+
protected abstract double MeganewtonsPerSquareMeterInOnePascal { get; }
7576
protected abstract double MegapascalsInOnePascal { get; }
7677
protected abstract double MetersOfHeadInOnePascal { get; }
7778
protected abstract double MicropascalsInOnePascal { get; }
@@ -111,6 +112,7 @@ public abstract partial class PressureTestsBase
111112
protected virtual double KilopoundsForcePerSquareFootTolerance { get { return 1e-5; } }
112113
protected virtual double KilopoundsForcePerSquareInchTolerance { get { return 1e-5; } }
113114
protected virtual double MegabarsTolerance { get { return 1e-5; } }
115+
protected virtual double MeganewtonsPerSquareMeterTolerance { get { return 1e-5; } }
114116
protected virtual double MegapascalsTolerance { get { return 1e-5; } }
115117
protected virtual double MetersOfHeadTolerance { get { return 1e-5; } }
116118
protected virtual double MicropascalsTolerance { get { return 1e-5; } }
@@ -154,6 +156,7 @@ public void PascalToPressureUnits()
154156
AssertEx.EqualTolerance(KilopoundsForcePerSquareFootInOnePascal, pascal.KilopoundsForcePerSquareFoot, KilopoundsForcePerSquareFootTolerance);
155157
AssertEx.EqualTolerance(KilopoundsForcePerSquareInchInOnePascal, pascal.KilopoundsForcePerSquareInch, KilopoundsForcePerSquareInchTolerance);
156158
AssertEx.EqualTolerance(MegabarsInOnePascal, pascal.Megabars, MegabarsTolerance);
159+
AssertEx.EqualTolerance(MeganewtonsPerSquareMeterInOnePascal, pascal.MeganewtonsPerSquareMeter, MeganewtonsPerSquareMeterTolerance);
157160
AssertEx.EqualTolerance(MegapascalsInOnePascal, pascal.Megapascals, MegapascalsTolerance);
158161
AssertEx.EqualTolerance(MetersOfHeadInOnePascal, pascal.MetersOfHead, MetersOfHeadTolerance);
159162
AssertEx.EqualTolerance(MicropascalsInOnePascal, pascal.Micropascals, MicropascalsTolerance);
@@ -196,6 +199,7 @@ public void FromValueAndUnit()
196199
AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.KilopoundForcePerSquareFoot).KilopoundsForcePerSquareFoot, KilopoundsForcePerSquareFootTolerance);
197200
AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.KilopoundForcePerSquareInch).KilopoundsForcePerSquareInch, KilopoundsForcePerSquareInchTolerance);
198201
AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Megabar).Megabars, MegabarsTolerance);
202+
AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.MeganewtonPerSquareMeter).MeganewtonsPerSquareMeter, MeganewtonsPerSquareMeterTolerance);
199203
AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Megapascal).Megapascals, MegapascalsTolerance);
200204
AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.MeterOfHead).MetersOfHead, MetersOfHeadTolerance);
201205
AssertEx.EqualTolerance(1, Pressure.From(1, PressureUnit.Micropascal).Micropascals, MicropascalsTolerance);
@@ -239,6 +243,7 @@ public void As()
239243
AssertEx.EqualTolerance(KilopoundsForcePerSquareFootInOnePascal, pascal.As(PressureUnit.KilopoundForcePerSquareFoot), KilopoundsForcePerSquareFootTolerance);
240244
AssertEx.EqualTolerance(KilopoundsForcePerSquareInchInOnePascal, pascal.As(PressureUnit.KilopoundForcePerSquareInch), KilopoundsForcePerSquareInchTolerance);
241245
AssertEx.EqualTolerance(MegabarsInOnePascal, pascal.As(PressureUnit.Megabar), MegabarsTolerance);
246+
AssertEx.EqualTolerance(MeganewtonsPerSquareMeterInOnePascal, pascal.As(PressureUnit.MeganewtonPerSquareMeter), MeganewtonsPerSquareMeterTolerance);
242247
AssertEx.EqualTolerance(MegapascalsInOnePascal, pascal.As(PressureUnit.Megapascal), MegapascalsTolerance);
243248
AssertEx.EqualTolerance(MetersOfHeadInOnePascal, pascal.As(PressureUnit.MeterOfHead), MetersOfHeadTolerance);
244249
AssertEx.EqualTolerance(MicropascalsInOnePascal, pascal.As(PressureUnit.Micropascal), MicropascalsTolerance);
@@ -282,6 +287,7 @@ public void ConversionRoundTrip()
282287
AssertEx.EqualTolerance(1, Pressure.FromKilopoundsForcePerSquareFoot(pascal.KilopoundsForcePerSquareFoot).Pascals, KilopoundsForcePerSquareFootTolerance);
283288
AssertEx.EqualTolerance(1, Pressure.FromKilopoundsForcePerSquareInch(pascal.KilopoundsForcePerSquareInch).Pascals, KilopoundsForcePerSquareInchTolerance);
284289
AssertEx.EqualTolerance(1, Pressure.FromMegabars(pascal.Megabars).Pascals, MegabarsTolerance);
290+
AssertEx.EqualTolerance(1, Pressure.FromMeganewtonsPerSquareMeter(pascal.MeganewtonsPerSquareMeter).Pascals, MeganewtonsPerSquareMeterTolerance);
285291
AssertEx.EqualTolerance(1, Pressure.FromMegapascals(pascal.Megapascals).Pascals, MegapascalsTolerance);
286292
AssertEx.EqualTolerance(1, Pressure.FromMetersOfHead(pascal.MetersOfHead).Pascals, MetersOfHeadTolerance);
287293
AssertEx.EqualTolerance(1, Pressure.FromMicropascals(pascal.Micropascals).Pascals, MicropascalsTolerance);

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,40 @@ public static class NumberToPressureExtensions
724724

725725
#endregion
726726

727+
#region MeganewtonPerSquareMeter
728+
729+
/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double)"/>
730+
public static Pressure MeganewtonsPerSquareMeter(this int value) => Pressure.FromMeganewtonsPerSquareMeter(value);
731+
732+
/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double?)"/>
733+
public static Pressure? MeganewtonsPerSquareMeter(this int? value) => Pressure.FromMeganewtonsPerSquareMeter(value);
734+
735+
/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double)"/>
736+
public static Pressure MeganewtonsPerSquareMeter(this long value) => Pressure.FromMeganewtonsPerSquareMeter(value);
737+
738+
/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double?)"/>
739+
public static Pressure? MeganewtonsPerSquareMeter(this long? value) => Pressure.FromMeganewtonsPerSquareMeter(value);
740+
741+
/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double)"/>
742+
public static Pressure MeganewtonsPerSquareMeter(this double value) => Pressure.FromMeganewtonsPerSquareMeter(value);
743+
744+
/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double?)"/>
745+
public static Pressure? MeganewtonsPerSquareMeter(this double? value) => Pressure.FromMeganewtonsPerSquareMeter(value);
746+
747+
/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double)"/>
748+
public static Pressure MeganewtonsPerSquareMeter(this float value) => Pressure.FromMeganewtonsPerSquareMeter(value);
749+
750+
/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double?)"/>
751+
public static Pressure? MeganewtonsPerSquareMeter(this float? value) => Pressure.FromMeganewtonsPerSquareMeter(value);
752+
753+
/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double)"/>
754+
public static Pressure MeganewtonsPerSquareMeter(this decimal value) => Pressure.FromMeganewtonsPerSquareMeter(Convert.ToDouble(value));
755+
756+
/// <inheritdoc cref="Pressure.FromMeganewtonsPerSquareMeter(double?)"/>
757+
public static Pressure? MeganewtonsPerSquareMeter(this decimal? value) => Pressure.FromMeganewtonsPerSquareMeter(value == null ? (double?)null : Convert.ToDouble(value.Value));
758+
759+
#endregion
760+
727761
#region Megapascal
728762

729763
/// <inheritdoc cref="Pressure.FromMegapascals(double)"/>

UnitsNet/GeneratedCode/Quantities/Pressure.g.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ public Pressure(double pascals)
243243
/// </summary>
244244
public double Megabars => As(PressureUnit.Megabar);
245245
/// <summary>
246+
/// Get Pressure in MeganewtonsPerSquareMeter.
247+
/// </summary>
248+
public double MeganewtonsPerSquareMeter => As(PressureUnit.MeganewtonPerSquareMeter);
249+
/// <summary>
246250
/// Get Pressure in Megapascals.
247251
/// </summary>
248252
public double Megapascals => As(PressureUnit.Megapascal);
@@ -598,6 +602,20 @@ public static Pressure FromMegabars(QuantityValue megabars)
598602
return new Pressure(value, PressureUnit.Megabar);
599603
}
600604

605+
/// <summary>
606+
/// Get Pressure from MeganewtonsPerSquareMeter.
607+
/// </summary>
608+
#if WINDOWS_UWP
609+
[Windows.Foundation.Metadata.DefaultOverload]
610+
public static Pressure FromMeganewtonsPerSquareMeter(double meganewtonspersquaremeter)
611+
#else
612+
public static Pressure FromMeganewtonsPerSquareMeter(QuantityValue meganewtonspersquaremeter)
613+
#endif
614+
{
615+
double value = (double) meganewtonspersquaremeter;
616+
return new Pressure(value, PressureUnit.MeganewtonPerSquareMeter);
617+
}
618+
601619
/// <summary>
602620
/// Get Pressure from Megapascals.
603621
/// </summary>
@@ -1138,6 +1156,21 @@ public static Pressure FromTorrs(QuantityValue torrs)
11381156
}
11391157
}
11401158

1159+
/// <summary>
1160+
/// Get nullable Pressure from nullable MeganewtonsPerSquareMeter.
1161+
/// </summary>
1162+
public static Pressure? FromMeganewtonsPerSquareMeter(QuantityValue? meganewtonspersquaremeter)
1163+
{
1164+
if (meganewtonspersquaremeter.HasValue)
1165+
{
1166+
return FromMeganewtonsPerSquareMeter(meganewtonspersquaremeter.Value);
1167+
}
1168+
else
1169+
{
1170+
return null;
1171+
}
1172+
}
1173+
11411174
/// <summary>
11421175
/// Get nullable Pressure from nullable Megapascals.
11431176
/// </summary>
@@ -1640,6 +1673,7 @@ public double As(PressureUnit unit)
16401673
case PressureUnit.KilopoundForcePerSquareFoot: return (baseUnitValue*0.020885432426709) / 1e3d;
16411674
case PressureUnit.KilopoundForcePerSquareInch: return (baseUnitValue*0.000145037737730209) / 1e3d;
16421675
case PressureUnit.Megabar: return (baseUnitValue/1e5) / 1e6d;
1676+
case PressureUnit.MeganewtonPerSquareMeter: return (baseUnitValue) / 1e6d;
16431677
case PressureUnit.Megapascal: return (baseUnitValue) / 1e6d;
16441678
case PressureUnit.MeterOfHead: return baseUnitValue*0.0001019977334;
16451679
case PressureUnit.Micropascal: return (baseUnitValue) / 1e-6d;
@@ -2040,6 +2074,7 @@ private double AsBaseUnitPascals()
20402074
case PressureUnit.KilopoundForcePerSquareFoot: return (_value*47.8802631216372) * 1e3d;
20412075
case PressureUnit.KilopoundForcePerSquareInch: return (_value*6894.75729316836) * 1e3d;
20422076
case PressureUnit.Megabar: return (_value*1e5) * 1e6d;
2077+
case PressureUnit.MeganewtonPerSquareMeter: return (_value) * 1e6d;
20432078
case PressureUnit.Megapascal: return (_value) * 1e6d;
20442079
case PressureUnit.MeterOfHead: return _value*9804.139432;
20452080
case PressureUnit.Micropascal: return (_value) * 1e-6d;

UnitsNet/GeneratedCode/UnitSystem.Default.g.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,6 +2956,12 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
29562956
new AbbreviationsForCulture("en-US", "Mbar"),
29572957
new AbbreviationsForCulture("ru-RU", "Mбар"),
29582958
}),
2959+
new CulturesForEnumValue((int) PressureUnit.MeganewtonPerSquareMeter,
2960+
new[]
2961+
{
2962+
new AbbreviationsForCulture("en-US", "MN/m²"),
2963+
new AbbreviationsForCulture("ru-RU", "Мн/м²"),
2964+
}),
29592965
new CulturesForEnumValue((int) PressureUnit.Megapascal,
29602966
new[]
29612967
{

UnitsNet/GeneratedCode/Units/PressureUnit.g.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public enum PressureUnit
6262
KilopoundForcePerSquareFoot,
6363
KilopoundForcePerSquareInch,
6464
Megabar,
65+
MeganewtonPerSquareMeter,
6566
Megapascal,
6667
MeterOfHead,
6768
Micropascal,

UnitsNet/UnitDefinitions/Pressure.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,17 @@
107107
"PluralName": "NewtonsPerSquareMeter",
108108
"FromUnitToBaseFunc": "x",
109109
"FromBaseToUnitFunc": "x",
110-
"Prefixes": [ "Kilo" ],
110+
"Prefixes": [ "Kilo", "Mega" ],
111111
"Localization": [
112112
{
113113
"Culture": "en-US",
114114
"Abbreviations": [ "N/m²" ],
115-
"AbbreviationsWithPrefixes": [ "kN/m²" ]
115+
"AbbreviationsWithPrefixes": [ "kN/m²", "MN/m²" ]
116116
},
117117
{
118118
"Culture": "ru-RU",
119119
"Abbreviations": [ "Н/м²" ],
120-
"AbbreviationsWithPrefixes": [ "кН/м²" ]
120+
"AbbreviationsWithPrefixes": [ "кН/м²", "Мн/м²" ]
121121
}
122122
]
123123
},

0 commit comments

Comments
 (0)