Skip to content

Commit c4e3314

Browse files
dschuermansangularsen
authored andcommitted
Add mega prefix to SpecificWeight.NewtonsPerCubicMeter (#420)
1 parent a66dcdf commit c4e3314

File tree

7 files changed

+85
-2
lines changed

7 files changed

+85
-2
lines changed

UnitsNet.Tests/CustomCode/SpecificWeightTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,7 @@ public class SpecificWeightTests : SpecificWeightTestsBase
5454
protected override double TonnesForcePerCubicMeterInOneNewtonPerCubicMeter => 1.02e-4;
5555

5656
protected override double TonnesForcePerCubicMillimeterInOneNewtonPerCubicMeter => 1.02e-10;
57+
58+
protected override double MeganewtonsPerCubicMeterInOneNewtonPerCubicMeter => 1e-6;
5759
}
58-
}
60+
}

UnitsNet.Tests/GeneratedCode/SpecificWeightTestsBase.g.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public abstract partial class SpecificWeightTestsBase
6060
protected abstract double KilonewtonsPerCubicMillimeterInOneNewtonPerCubicMeter { get; }
6161
protected abstract double KilopoundsForcePerCubicFootInOneNewtonPerCubicMeter { get; }
6262
protected abstract double KilopoundsForcePerCubicInchInOneNewtonPerCubicMeter { get; }
63+
protected abstract double MeganewtonsPerCubicMeterInOneNewtonPerCubicMeter { get; }
6364
protected abstract double NewtonsPerCubicCentimeterInOneNewtonPerCubicMeter { get; }
6465
protected abstract double NewtonsPerCubicMeterInOneNewtonPerCubicMeter { get; }
6566
protected abstract double NewtonsPerCubicMillimeterInOneNewtonPerCubicMeter { get; }
@@ -78,6 +79,7 @@ public abstract partial class SpecificWeightTestsBase
7879
protected virtual double KilonewtonsPerCubicMillimeterTolerance { get { return 1e-5; } }
7980
protected virtual double KilopoundsForcePerCubicFootTolerance { get { return 1e-5; } }
8081
protected virtual double KilopoundsForcePerCubicInchTolerance { get { return 1e-5; } }
82+
protected virtual double MeganewtonsPerCubicMeterTolerance { get { return 1e-5; } }
8183
protected virtual double NewtonsPerCubicCentimeterTolerance { get { return 1e-5; } }
8284
protected virtual double NewtonsPerCubicMeterTolerance { get { return 1e-5; } }
8385
protected virtual double NewtonsPerCubicMillimeterTolerance { get { return 1e-5; } }
@@ -100,6 +102,7 @@ public void NewtonPerCubicMeterToSpecificWeightUnits()
100102
AssertEx.EqualTolerance(KilonewtonsPerCubicMillimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.KilonewtonsPerCubicMillimeter, KilonewtonsPerCubicMillimeterTolerance);
101103
AssertEx.EqualTolerance(KilopoundsForcePerCubicFootInOneNewtonPerCubicMeter, newtonpercubicmeter.KilopoundsForcePerCubicFoot, KilopoundsForcePerCubicFootTolerance);
102104
AssertEx.EqualTolerance(KilopoundsForcePerCubicInchInOneNewtonPerCubicMeter, newtonpercubicmeter.KilopoundsForcePerCubicInch, KilopoundsForcePerCubicInchTolerance);
105+
AssertEx.EqualTolerance(MeganewtonsPerCubicMeterInOneNewtonPerCubicMeter, newtonpercubicmeter.MeganewtonsPerCubicMeter, MeganewtonsPerCubicMeterTolerance);
103106
AssertEx.EqualTolerance(NewtonsPerCubicCentimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.NewtonsPerCubicCentimeter, NewtonsPerCubicCentimeterTolerance);
104107
AssertEx.EqualTolerance(NewtonsPerCubicMeterInOneNewtonPerCubicMeter, newtonpercubicmeter.NewtonsPerCubicMeter, NewtonsPerCubicMeterTolerance);
105108
AssertEx.EqualTolerance(NewtonsPerCubicMillimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.NewtonsPerCubicMillimeter, NewtonsPerCubicMillimeterTolerance);
@@ -121,6 +124,7 @@ public void FromValueAndUnit()
121124
AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.KilonewtonPerCubicMillimeter).KilonewtonsPerCubicMillimeter, KilonewtonsPerCubicMillimeterTolerance);
122125
AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.KilopoundForcePerCubicFoot).KilopoundsForcePerCubicFoot, KilopoundsForcePerCubicFootTolerance);
123126
AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.KilopoundForcePerCubicInch).KilopoundsForcePerCubicInch, KilopoundsForcePerCubicInchTolerance);
127+
AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.MeganewtonPerCubicMeter).MeganewtonsPerCubicMeter, MeganewtonsPerCubicMeterTolerance);
124128
AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.NewtonPerCubicCentimeter).NewtonsPerCubicCentimeter, NewtonsPerCubicCentimeterTolerance);
125129
AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.NewtonPerCubicMeter).NewtonsPerCubicMeter, NewtonsPerCubicMeterTolerance);
126130
AssertEx.EqualTolerance(1, SpecificWeight.From(1, SpecificWeightUnit.NewtonPerCubicMillimeter).NewtonsPerCubicMillimeter, NewtonsPerCubicMillimeterTolerance);
@@ -143,6 +147,7 @@ public void As()
143147
AssertEx.EqualTolerance(KilonewtonsPerCubicMillimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.KilonewtonPerCubicMillimeter), KilonewtonsPerCubicMillimeterTolerance);
144148
AssertEx.EqualTolerance(KilopoundsForcePerCubicFootInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.KilopoundForcePerCubicFoot), KilopoundsForcePerCubicFootTolerance);
145149
AssertEx.EqualTolerance(KilopoundsForcePerCubicInchInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.KilopoundForcePerCubicInch), KilopoundsForcePerCubicInchTolerance);
150+
AssertEx.EqualTolerance(MeganewtonsPerCubicMeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.MeganewtonPerCubicMeter), MeganewtonsPerCubicMeterTolerance);
146151
AssertEx.EqualTolerance(NewtonsPerCubicCentimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.NewtonPerCubicCentimeter), NewtonsPerCubicCentimeterTolerance);
147152
AssertEx.EqualTolerance(NewtonsPerCubicMeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.NewtonPerCubicMeter), NewtonsPerCubicMeterTolerance);
148153
AssertEx.EqualTolerance(NewtonsPerCubicMillimeterInOneNewtonPerCubicMeter, newtonpercubicmeter.As(SpecificWeightUnit.NewtonPerCubicMillimeter), NewtonsPerCubicMillimeterTolerance);
@@ -165,6 +170,7 @@ public void ConversionRoundTrip()
165170
AssertEx.EqualTolerance(1, SpecificWeight.FromKilonewtonsPerCubicMillimeter(newtonpercubicmeter.KilonewtonsPerCubicMillimeter).NewtonsPerCubicMeter, KilonewtonsPerCubicMillimeterTolerance);
166171
AssertEx.EqualTolerance(1, SpecificWeight.FromKilopoundsForcePerCubicFoot(newtonpercubicmeter.KilopoundsForcePerCubicFoot).NewtonsPerCubicMeter, KilopoundsForcePerCubicFootTolerance);
167172
AssertEx.EqualTolerance(1, SpecificWeight.FromKilopoundsForcePerCubicInch(newtonpercubicmeter.KilopoundsForcePerCubicInch).NewtonsPerCubicMeter, KilopoundsForcePerCubicInchTolerance);
173+
AssertEx.EqualTolerance(1, SpecificWeight.FromMeganewtonsPerCubicMeter(newtonpercubicmeter.MeganewtonsPerCubicMeter).NewtonsPerCubicMeter, MeganewtonsPerCubicMeterTolerance);
168174
AssertEx.EqualTolerance(1, SpecificWeight.FromNewtonsPerCubicCentimeter(newtonpercubicmeter.NewtonsPerCubicCentimeter).NewtonsPerCubicMeter, NewtonsPerCubicCentimeterTolerance);
169175
AssertEx.EqualTolerance(1, SpecificWeight.FromNewtonsPerCubicMeter(newtonpercubicmeter.NewtonsPerCubicMeter).NewtonsPerCubicMeter, NewtonsPerCubicMeterTolerance);
170176
AssertEx.EqualTolerance(1, SpecificWeight.FromNewtonsPerCubicMillimeter(newtonpercubicmeter.NewtonsPerCubicMillimeter).NewtonsPerCubicMeter, NewtonsPerCubicMillimeterTolerance);

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,40 @@ public static class NumberToSpecificWeightExtensions
316316

317317
#endregion
318318

319+
#region MeganewtonPerCubicMeter
320+
321+
/// <inheritdoc cref="SpecificWeight.FromMeganewtonsPerCubicMeter(double)"/>
322+
public static SpecificWeight MeganewtonsPerCubicMeter(this int value) => SpecificWeight.FromMeganewtonsPerCubicMeter(value);
323+
324+
/// <inheritdoc cref="SpecificWeight.FromMeganewtonsPerCubicMeter(double?)"/>
325+
public static SpecificWeight? MeganewtonsPerCubicMeter(this int? value) => SpecificWeight.FromMeganewtonsPerCubicMeter(value);
326+
327+
/// <inheritdoc cref="SpecificWeight.FromMeganewtonsPerCubicMeter(double)"/>
328+
public static SpecificWeight MeganewtonsPerCubicMeter(this long value) => SpecificWeight.FromMeganewtonsPerCubicMeter(value);
329+
330+
/// <inheritdoc cref="SpecificWeight.FromMeganewtonsPerCubicMeter(double?)"/>
331+
public static SpecificWeight? MeganewtonsPerCubicMeter(this long? value) => SpecificWeight.FromMeganewtonsPerCubicMeter(value);
332+
333+
/// <inheritdoc cref="SpecificWeight.FromMeganewtonsPerCubicMeter(double)"/>
334+
public static SpecificWeight MeganewtonsPerCubicMeter(this double value) => SpecificWeight.FromMeganewtonsPerCubicMeter(value);
335+
336+
/// <inheritdoc cref="SpecificWeight.FromMeganewtonsPerCubicMeter(double?)"/>
337+
public static SpecificWeight? MeganewtonsPerCubicMeter(this double? value) => SpecificWeight.FromMeganewtonsPerCubicMeter(value);
338+
339+
/// <inheritdoc cref="SpecificWeight.FromMeganewtonsPerCubicMeter(double)"/>
340+
public static SpecificWeight MeganewtonsPerCubicMeter(this float value) => SpecificWeight.FromMeganewtonsPerCubicMeter(value);
341+
342+
/// <inheritdoc cref="SpecificWeight.FromMeganewtonsPerCubicMeter(double?)"/>
343+
public static SpecificWeight? MeganewtonsPerCubicMeter(this float? value) => SpecificWeight.FromMeganewtonsPerCubicMeter(value);
344+
345+
/// <inheritdoc cref="SpecificWeight.FromMeganewtonsPerCubicMeter(double)"/>
346+
public static SpecificWeight MeganewtonsPerCubicMeter(this decimal value) => SpecificWeight.FromMeganewtonsPerCubicMeter(Convert.ToDouble(value));
347+
348+
/// <inheritdoc cref="SpecificWeight.FromMeganewtonsPerCubicMeter(double?)"/>
349+
public static SpecificWeight? MeganewtonsPerCubicMeter(this decimal? value) => SpecificWeight.FromMeganewtonsPerCubicMeter(value == null ? (double?)null : Convert.ToDouble(value.Value));
350+
351+
#endregion
352+
319353
#region NewtonPerCubicCentimeter
320354

321355
/// <inheritdoc cref="SpecificWeight.FromNewtonsPerCubicCentimeter(double)"/>

UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ public SpecificWeight(double newtonspercubicmeter)
195195
/// </summary>
196196
public double KilopoundsForcePerCubicInch => As(SpecificWeightUnit.KilopoundForcePerCubicInch);
197197
/// <summary>
198+
/// Get SpecificWeight in MeganewtonsPerCubicMeter.
199+
/// </summary>
200+
public double MeganewtonsPerCubicMeter => As(SpecificWeightUnit.MeganewtonPerCubicMeter);
201+
/// <summary>
198202
/// Get SpecificWeight in NewtonsPerCubicCentimeter.
199203
/// </summary>
200204
public double NewtonsPerCubicCentimeter => As(SpecificWeightUnit.NewtonPerCubicCentimeter);
@@ -345,6 +349,20 @@ public static SpecificWeight FromKilopoundsForcePerCubicInch(QuantityValue kilop
345349
return new SpecificWeight(value, SpecificWeightUnit.KilopoundForcePerCubicInch);
346350
}
347351

352+
/// <summary>
353+
/// Get SpecificWeight from MeganewtonsPerCubicMeter.
354+
/// </summary>
355+
#if WINDOWS_UWP
356+
[Windows.Foundation.Metadata.DefaultOverload]
357+
public static SpecificWeight FromMeganewtonsPerCubicMeter(double meganewtonspercubicmeter)
358+
#else
359+
public static SpecificWeight FromMeganewtonsPerCubicMeter(QuantityValue meganewtonspercubicmeter)
360+
#endif
361+
{
362+
double value = (double) meganewtonspercubicmeter;
363+
return new SpecificWeight(value, SpecificWeightUnit.MeganewtonPerCubicMeter);
364+
}
365+
348366
/// <summary>
349367
/// Get SpecificWeight from NewtonsPerCubicCentimeter.
350368
/// </summary>
@@ -579,6 +597,21 @@ public static SpecificWeight FromTonnesForcePerCubicMillimeter(QuantityValue ton
579597
}
580598
}
581599

600+
/// <summary>
601+
/// Get nullable SpecificWeight from nullable MeganewtonsPerCubicMeter.
602+
/// </summary>
603+
public static SpecificWeight? FromMeganewtonsPerCubicMeter(QuantityValue? meganewtonspercubicmeter)
604+
{
605+
if (meganewtonspercubicmeter.HasValue)
606+
{
607+
return FromMeganewtonsPerCubicMeter(meganewtonspercubicmeter.Value);
608+
}
609+
else
610+
{
611+
return null;
612+
}
613+
}
614+
582615
/// <summary>
583616
/// Get nullable SpecificWeight from nullable NewtonsPerCubicCentimeter.
584617
/// </summary>
@@ -934,6 +967,7 @@ public double As(SpecificWeightUnit unit)
934967
case SpecificWeightUnit.KilonewtonPerCubicMillimeter: return (baseUnitValue*0.000000001) / 1e3d;
935968
case SpecificWeightUnit.KilopoundForcePerCubicFoot: return (baseUnitValue*0.00636587980366089) / 1e3d;
936969
case SpecificWeightUnit.KilopoundForcePerCubicInch: return (baseUnitValue*3.68395821971116E-06) / 1e3d;
970+
case SpecificWeightUnit.MeganewtonPerCubicMeter: return (baseUnitValue) / 1e6d;
937971
case SpecificWeightUnit.NewtonPerCubicCentimeter: return baseUnitValue*0.000001;
938972
case SpecificWeightUnit.NewtonPerCubicMeter: return baseUnitValue;
939973
case SpecificWeightUnit.NewtonPerCubicMillimeter: return baseUnitValue*0.000000001;
@@ -1313,6 +1347,7 @@ private double AsBaseUnitNewtonsPerCubicMeter()
13131347
case SpecificWeightUnit.KilonewtonPerCubicMillimeter: return (_value*1000000000) * 1e3d;
13141348
case SpecificWeightUnit.KilopoundForcePerCubicFoot: return (_value*157.087477433193) * 1e3d;
13151349
case SpecificWeightUnit.KilopoundForcePerCubicInch: return (_value*271447.161004558) * 1e3d;
1350+
case SpecificWeightUnit.MeganewtonPerCubicMeter: return (_value) * 1e6d;
13161351
case SpecificWeightUnit.NewtonPerCubicCentimeter: return _value*1000000;
13171352
case SpecificWeightUnit.NewtonPerCubicMeter: return _value;
13181353
case SpecificWeightUnit.NewtonPerCubicMillimeter: return _value*1000000000;

UnitsNet/GeneratedCode/UnitSystem.Default.g.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,6 +3425,11 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
34253425
{
34263426
new AbbreviationsForCulture("en-US", "kipf/in³"),
34273427
}),
3428+
new CulturesForEnumValue((int) SpecificWeightUnit.MeganewtonPerCubicMeter,
3429+
new[]
3430+
{
3431+
new AbbreviationsForCulture("en-US", "MN/m³"),
3432+
}),
34283433
new CulturesForEnumValue((int) SpecificWeightUnit.NewtonPerCubicCentimeter,
34293434
new[]
34303435
{

UnitsNet/GeneratedCode/Units/SpecificWeightUnit.g.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public enum SpecificWeightUnit
5050
KilonewtonPerCubicMillimeter,
5151
KilopoundForcePerCubicFoot,
5252
KilopoundForcePerCubicInch,
53+
MeganewtonPerCubicMeter,
5354
NewtonPerCubicCentimeter,
5455
NewtonPerCubicMeter,
5556
NewtonPerCubicMillimeter,

UnitsNet/UnitDefinitions/SpecificWeight.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"PluralName": "NewtonsPerCubicMeter",
3636
"FromUnitToBaseFunc": "x",
3737
"FromBaseToUnitFunc": "x",
38-
"Prefixes": [ "Kilo" ],
38+
"Prefixes": [ "Kilo", "Mega" ],
3939
"Localization": [
4040
{
4141
"Culture": "en-US",

0 commit comments

Comments
 (0)