From 4d6083d16c1821f0be20b387ed4b4eb8a5c4a50f Mon Sep 17 00:00:00 2001 From: JasLieb <34688439+JasLieb@users.noreply.github.com> Date: Fri, 11 Feb 2022 21:21:06 +0100 Subject: [PATCH] Add Angstrom unit (#1042) * Add Angstrom unit --- Common/UnitDefinitions/Length.json | 14 ++ .../GeneratedCode/Quantities/Length.g.cs | 13 ++ .../GeneratedCode/Units/LengthUnit.g.cs | 6 + .../NumberToLengthExtensionsTest.g.cs | 4 + .../NumberToLengthExtensions.g.cs | 4 + UnitsNet.Tests/CustomCode/LengthTests.cs | 2 + .../TestsBase/LengthTestsBase.g.cs | 217 ++++++++++-------- .../GeneratedCode/Quantities/Length.g.cs | 18 ++ .../GeneratedCode/Units/LengthUnit.g.cs | 6 + UnitsNet/GeneratedCode/Quantities/Length.g.cs | 18 ++ UnitsNet/GeneratedCode/Units/LengthUnit.g.cs | 6 + 11 files changed, 206 insertions(+), 102 deletions(-) diff --git a/Common/UnitDefinitions/Length.json b/Common/UnitDefinitions/Length.json index 0621d6a9df..fcc9b4a7e1 100644 --- a/Common/UnitDefinitions/Length.json +++ b/Common/UnitDefinitions/Length.json @@ -398,6 +398,20 @@ "Abbreviations": [ "ch" ] } ] + }, + { + "SingularName": "Angstrom", + "PluralName": "Angstroms", + "FromUnitToBaseFunc": "{x} * 1e-10", + "FromBaseToUnitFunc": "{x} / 1e-10", + "XmlDocSummary": "Angstrom is a metric unit of length equal to 1e-10 meter", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Angstrom", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "Å", "A" ] + } + ] } ] } diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Length.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Length.g.cs index beb23e3f60..7db85b75fd 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Length.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Length.g.cs @@ -77,6 +77,11 @@ public Length(double value, LengthUnit unit) public static Length Zero { get; } = new Length(0, BaseUnit); #region Conversion Properties + /// + /// Gets a value of this quantity converted into + /// + public double Angstroms => As(LengthUnit.Angstrom); + /// /// Gets a value of this quantity converted into /// @@ -251,6 +256,12 @@ public Length(double value, LengthUnit unit) #region Static Factory Methods + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Length FromAngstroms(double angstroms) => new Length(angstroms, LengthUnit.Angstrom); + /// /// Creates a from . /// @@ -496,6 +507,7 @@ private double GetValueInBaseUnit() { return Unit switch { + LengthUnit.Angstrom => _value * 1e-10, LengthUnit.AstronomicalUnit => _value * 1.4959787070e11, LengthUnit.Centimeter => (_value) * 1e-2d, LengthUnit.Chain => _value*20.1168, @@ -543,6 +555,7 @@ private double GetValueAs(LengthUnit unit) return unit switch { + LengthUnit.Angstrom => baseUnitValue / 1e-10, LengthUnit.AstronomicalUnit => baseUnitValue / 1.4959787070e11, LengthUnit.Centimeter => (baseUnitValue) / 1e-2d, LengthUnit.Chain => baseUnitValue/20.1168, diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/LengthUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/LengthUnit.g.cs index 65527fba2d..2fe61e739a 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/LengthUnit.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/LengthUnit.g.cs @@ -27,6 +27,12 @@ public enum LengthUnit { Undefined = 0, + /// + /// Angstrom is a metric unit of length equal to 1e-10 meter + /// + /// https://en.wikipedia.org/wiki/Angstrom + Angstrom, + /// /// One Astronomical Unit is the distance from the solar system Star, the sun, to planet Earth. /// diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToLengthExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToLengthExtensionsTest.g.cs index d53ea66392..d89fb1fdf3 100644 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToLengthExtensionsTest.g.cs +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToLengthExtensionsTest.g.cs @@ -24,6 +24,10 @@ namespace UnitsNet.Tests { public class NumberToLengthExtensionsTests { + [Fact] + public void NumberToAngstromsTest() => + Assert.Equal(Length.FromAngstroms(2), 2.Angstroms()); + [Fact] public void NumberToAstronomicalUnitsTest() => Assert.Equal(Length.FromAstronomicalUnits(2), 2.AstronomicalUnits()); diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToLengthExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToLengthExtensions.g.cs index 7f56f5db64..a5fa687822 100644 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToLengthExtensions.g.cs +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToLengthExtensions.g.cs @@ -28,6 +28,10 @@ namespace UnitsNet.NumberExtensions.NumberToLength /// public static class NumberToLengthExtensions { + /// + public static Length Angstroms(this T value) => + Length.FromAngstroms(Convert.ToDouble(value)); + /// public static Length AstronomicalUnits(this T value) => Length.FromAstronomicalUnits(Convert.ToDouble(value)); diff --git a/UnitsNet.Tests/CustomCode/LengthTests.cs b/UnitsNet.Tests/CustomCode/LengthTests.cs index 87a8d2cae7..b9f5eae22a 100644 --- a/UnitsNet.Tests/CustomCode/LengthTests.cs +++ b/UnitsNet.Tests/CustomCode/LengthTests.cs @@ -78,6 +78,8 @@ public class LengthTests : LengthTestsBase protected override double DecametersInOneMeter => 1e-1; + protected override double AngstromsInOneMeter => 1e10; + [ Fact] public void AreaTimesLengthEqualsVolume() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs index 4770aac121..9a9dbd9d6c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs @@ -38,6 +38,7 @@ namespace UnitsNet.Tests // ReSharper disable once PartialTypeWithSinglePart public abstract partial class LengthTestsBase : QuantityTestsBase { + protected abstract double AngstromsInOneMeter { get; } protected abstract double AstronomicalUnitsInOneMeter { get; } protected abstract double CentimetersInOneMeter { get; } protected abstract double ChainsInOneMeter { get; } @@ -74,6 +75,7 @@ public abstract partial class LengthTestsBase : QuantityTestsBase protected abstract double YardsInOneMeter { get; } // ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double AngstromsTolerance { get { return 1e-5; } } protected virtual double AstronomicalUnitsTolerance { get { return 1e-5; } } protected virtual double CentimetersTolerance { get { return 1e-5; } } protected virtual double ChainsTolerance { get { return 1e-5; } } @@ -114,6 +116,7 @@ public abstract partial class LengthTestsBase : QuantityTestsBase { return unit switch { + LengthUnit.Angstrom => (AngstromsInOneMeter, AngstromsTolerance), LengthUnit.AstronomicalUnit => (AstronomicalUnitsInOneMeter, AstronomicalUnitsTolerance), LengthUnit.Centimeter => (CentimetersInOneMeter, CentimetersTolerance), LengthUnit.Chain => (ChainsInOneMeter, ChainsTolerance), @@ -154,6 +157,7 @@ public abstract partial class LengthTestsBase : QuantityTestsBase public static IEnumerable UnitTypes = new List { + new object[] { LengthUnit.Angstrom }, new object[] { LengthUnit.AstronomicalUnit }, new object[] { LengthUnit.Centimeter }, new object[] { LengthUnit.Chain }, @@ -262,6 +266,7 @@ public void Length_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() public void MeterToLengthUnits() { Length meter = Length.FromMeters(1); + AssertEx.EqualTolerance(AngstromsInOneMeter, meter.Angstroms, AngstromsTolerance); AssertEx.EqualTolerance(AstronomicalUnitsInOneMeter, meter.AstronomicalUnits, AstronomicalUnitsTolerance); AssertEx.EqualTolerance(CentimetersInOneMeter, meter.Centimeters, CentimetersTolerance); AssertEx.EqualTolerance(ChainsInOneMeter, meter.Chains, ChainsTolerance); @@ -301,141 +306,145 @@ public void MeterToLengthUnits() [Fact] public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() { - var quantity00 = Length.From(1, LengthUnit.AstronomicalUnit); - AssertEx.EqualTolerance(1, quantity00.AstronomicalUnits, AstronomicalUnitsTolerance); - Assert.Equal(LengthUnit.AstronomicalUnit, quantity00.Unit); + var quantity00 = Length.From(1, LengthUnit.Angstrom); + AssertEx.EqualTolerance(1, quantity00.Angstroms, AngstromsTolerance); + Assert.Equal(LengthUnit.Angstrom, quantity00.Unit); - var quantity01 = Length.From(1, LengthUnit.Centimeter); - AssertEx.EqualTolerance(1, quantity01.Centimeters, CentimetersTolerance); - Assert.Equal(LengthUnit.Centimeter, quantity01.Unit); + var quantity01 = Length.From(1, LengthUnit.AstronomicalUnit); + AssertEx.EqualTolerance(1, quantity01.AstronomicalUnits, AstronomicalUnitsTolerance); + Assert.Equal(LengthUnit.AstronomicalUnit, quantity01.Unit); - var quantity02 = Length.From(1, LengthUnit.Chain); - AssertEx.EqualTolerance(1, quantity02.Chains, ChainsTolerance); - Assert.Equal(LengthUnit.Chain, quantity02.Unit); + var quantity02 = Length.From(1, LengthUnit.Centimeter); + AssertEx.EqualTolerance(1, quantity02.Centimeters, CentimetersTolerance); + Assert.Equal(LengthUnit.Centimeter, quantity02.Unit); - var quantity03 = Length.From(1, LengthUnit.Decameter); - AssertEx.EqualTolerance(1, quantity03.Decameters, DecametersTolerance); - Assert.Equal(LengthUnit.Decameter, quantity03.Unit); + var quantity03 = Length.From(1, LengthUnit.Chain); + AssertEx.EqualTolerance(1, quantity03.Chains, ChainsTolerance); + Assert.Equal(LengthUnit.Chain, quantity03.Unit); - var quantity04 = Length.From(1, LengthUnit.Decimeter); - AssertEx.EqualTolerance(1, quantity04.Decimeters, DecimetersTolerance); - Assert.Equal(LengthUnit.Decimeter, quantity04.Unit); + var quantity04 = Length.From(1, LengthUnit.Decameter); + AssertEx.EqualTolerance(1, quantity04.Decameters, DecametersTolerance); + Assert.Equal(LengthUnit.Decameter, quantity04.Unit); - var quantity05 = Length.From(1, LengthUnit.DtpPica); - AssertEx.EqualTolerance(1, quantity05.DtpPicas, DtpPicasTolerance); - Assert.Equal(LengthUnit.DtpPica, quantity05.Unit); + var quantity05 = Length.From(1, LengthUnit.Decimeter); + AssertEx.EqualTolerance(1, quantity05.Decimeters, DecimetersTolerance); + Assert.Equal(LengthUnit.Decimeter, quantity05.Unit); - var quantity06 = Length.From(1, LengthUnit.DtpPoint); - AssertEx.EqualTolerance(1, quantity06.DtpPoints, DtpPointsTolerance); - Assert.Equal(LengthUnit.DtpPoint, quantity06.Unit); + var quantity06 = Length.From(1, LengthUnit.DtpPica); + AssertEx.EqualTolerance(1, quantity06.DtpPicas, DtpPicasTolerance); + Assert.Equal(LengthUnit.DtpPica, quantity06.Unit); - var quantity07 = Length.From(1, LengthUnit.Fathom); - AssertEx.EqualTolerance(1, quantity07.Fathoms, FathomsTolerance); - Assert.Equal(LengthUnit.Fathom, quantity07.Unit); + var quantity07 = Length.From(1, LengthUnit.DtpPoint); + AssertEx.EqualTolerance(1, quantity07.DtpPoints, DtpPointsTolerance); + Assert.Equal(LengthUnit.DtpPoint, quantity07.Unit); - var quantity08 = Length.From(1, LengthUnit.Foot); - AssertEx.EqualTolerance(1, quantity08.Feet, FeetTolerance); - Assert.Equal(LengthUnit.Foot, quantity08.Unit); + var quantity08 = Length.From(1, LengthUnit.Fathom); + AssertEx.EqualTolerance(1, quantity08.Fathoms, FathomsTolerance); + Assert.Equal(LengthUnit.Fathom, quantity08.Unit); - var quantity09 = Length.From(1, LengthUnit.Hand); - AssertEx.EqualTolerance(1, quantity09.Hands, HandsTolerance); - Assert.Equal(LengthUnit.Hand, quantity09.Unit); + var quantity09 = Length.From(1, LengthUnit.Foot); + AssertEx.EqualTolerance(1, quantity09.Feet, FeetTolerance); + Assert.Equal(LengthUnit.Foot, quantity09.Unit); - var quantity10 = Length.From(1, LengthUnit.Hectometer); - AssertEx.EqualTolerance(1, quantity10.Hectometers, HectometersTolerance); - Assert.Equal(LengthUnit.Hectometer, quantity10.Unit); + var quantity10 = Length.From(1, LengthUnit.Hand); + AssertEx.EqualTolerance(1, quantity10.Hands, HandsTolerance); + Assert.Equal(LengthUnit.Hand, quantity10.Unit); - var quantity11 = Length.From(1, LengthUnit.Inch); - AssertEx.EqualTolerance(1, quantity11.Inches, InchesTolerance); - Assert.Equal(LengthUnit.Inch, quantity11.Unit); + var quantity11 = Length.From(1, LengthUnit.Hectometer); + AssertEx.EqualTolerance(1, quantity11.Hectometers, HectometersTolerance); + Assert.Equal(LengthUnit.Hectometer, quantity11.Unit); - var quantity12 = Length.From(1, LengthUnit.KilolightYear); - AssertEx.EqualTolerance(1, quantity12.KilolightYears, KilolightYearsTolerance); - Assert.Equal(LengthUnit.KilolightYear, quantity12.Unit); + var quantity12 = Length.From(1, LengthUnit.Inch); + AssertEx.EqualTolerance(1, quantity12.Inches, InchesTolerance); + Assert.Equal(LengthUnit.Inch, quantity12.Unit); - var quantity13 = Length.From(1, LengthUnit.Kilometer); - AssertEx.EqualTolerance(1, quantity13.Kilometers, KilometersTolerance); - Assert.Equal(LengthUnit.Kilometer, quantity13.Unit); + var quantity13 = Length.From(1, LengthUnit.KilolightYear); + AssertEx.EqualTolerance(1, quantity13.KilolightYears, KilolightYearsTolerance); + Assert.Equal(LengthUnit.KilolightYear, quantity13.Unit); - var quantity14 = Length.From(1, LengthUnit.Kiloparsec); - AssertEx.EqualTolerance(1, quantity14.Kiloparsecs, KiloparsecsTolerance); - Assert.Equal(LengthUnit.Kiloparsec, quantity14.Unit); + var quantity14 = Length.From(1, LengthUnit.Kilometer); + AssertEx.EqualTolerance(1, quantity14.Kilometers, KilometersTolerance); + Assert.Equal(LengthUnit.Kilometer, quantity14.Unit); - var quantity15 = Length.From(1, LengthUnit.LightYear); - AssertEx.EqualTolerance(1, quantity15.LightYears, LightYearsTolerance); - Assert.Equal(LengthUnit.LightYear, quantity15.Unit); + var quantity15 = Length.From(1, LengthUnit.Kiloparsec); + AssertEx.EqualTolerance(1, quantity15.Kiloparsecs, KiloparsecsTolerance); + Assert.Equal(LengthUnit.Kiloparsec, quantity15.Unit); - var quantity16 = Length.From(1, LengthUnit.MegalightYear); - AssertEx.EqualTolerance(1, quantity16.MegalightYears, MegalightYearsTolerance); - Assert.Equal(LengthUnit.MegalightYear, quantity16.Unit); + var quantity16 = Length.From(1, LengthUnit.LightYear); + AssertEx.EqualTolerance(1, quantity16.LightYears, LightYearsTolerance); + Assert.Equal(LengthUnit.LightYear, quantity16.Unit); - var quantity17 = Length.From(1, LengthUnit.Megaparsec); - AssertEx.EqualTolerance(1, quantity17.Megaparsecs, MegaparsecsTolerance); - Assert.Equal(LengthUnit.Megaparsec, quantity17.Unit); + var quantity17 = Length.From(1, LengthUnit.MegalightYear); + AssertEx.EqualTolerance(1, quantity17.MegalightYears, MegalightYearsTolerance); + Assert.Equal(LengthUnit.MegalightYear, quantity17.Unit); - var quantity18 = Length.From(1, LengthUnit.Meter); - AssertEx.EqualTolerance(1, quantity18.Meters, MetersTolerance); - Assert.Equal(LengthUnit.Meter, quantity18.Unit); + var quantity18 = Length.From(1, LengthUnit.Megaparsec); + AssertEx.EqualTolerance(1, quantity18.Megaparsecs, MegaparsecsTolerance); + Assert.Equal(LengthUnit.Megaparsec, quantity18.Unit); - var quantity19 = Length.From(1, LengthUnit.Microinch); - AssertEx.EqualTolerance(1, quantity19.Microinches, MicroinchesTolerance); - Assert.Equal(LengthUnit.Microinch, quantity19.Unit); + var quantity19 = Length.From(1, LengthUnit.Meter); + AssertEx.EqualTolerance(1, quantity19.Meters, MetersTolerance); + Assert.Equal(LengthUnit.Meter, quantity19.Unit); - var quantity20 = Length.From(1, LengthUnit.Micrometer); - AssertEx.EqualTolerance(1, quantity20.Micrometers, MicrometersTolerance); - Assert.Equal(LengthUnit.Micrometer, quantity20.Unit); + var quantity20 = Length.From(1, LengthUnit.Microinch); + AssertEx.EqualTolerance(1, quantity20.Microinches, MicroinchesTolerance); + Assert.Equal(LengthUnit.Microinch, quantity20.Unit); - var quantity21 = Length.From(1, LengthUnit.Mil); - AssertEx.EqualTolerance(1, quantity21.Mils, MilsTolerance); - Assert.Equal(LengthUnit.Mil, quantity21.Unit); + var quantity21 = Length.From(1, LengthUnit.Micrometer); + AssertEx.EqualTolerance(1, quantity21.Micrometers, MicrometersTolerance); + Assert.Equal(LengthUnit.Micrometer, quantity21.Unit); - var quantity22 = Length.From(1, LengthUnit.Mile); - AssertEx.EqualTolerance(1, quantity22.Miles, MilesTolerance); - Assert.Equal(LengthUnit.Mile, quantity22.Unit); + var quantity22 = Length.From(1, LengthUnit.Mil); + AssertEx.EqualTolerance(1, quantity22.Mils, MilsTolerance); + Assert.Equal(LengthUnit.Mil, quantity22.Unit); - var quantity23 = Length.From(1, LengthUnit.Millimeter); - AssertEx.EqualTolerance(1, quantity23.Millimeters, MillimetersTolerance); - Assert.Equal(LengthUnit.Millimeter, quantity23.Unit); + var quantity23 = Length.From(1, LengthUnit.Mile); + AssertEx.EqualTolerance(1, quantity23.Miles, MilesTolerance); + Assert.Equal(LengthUnit.Mile, quantity23.Unit); - var quantity24 = Length.From(1, LengthUnit.Nanometer); - AssertEx.EqualTolerance(1, quantity24.Nanometers, NanometersTolerance); - Assert.Equal(LengthUnit.Nanometer, quantity24.Unit); + var quantity24 = Length.From(1, LengthUnit.Millimeter); + AssertEx.EqualTolerance(1, quantity24.Millimeters, MillimetersTolerance); + Assert.Equal(LengthUnit.Millimeter, quantity24.Unit); - var quantity25 = Length.From(1, LengthUnit.NauticalMile); - AssertEx.EqualTolerance(1, quantity25.NauticalMiles, NauticalMilesTolerance); - Assert.Equal(LengthUnit.NauticalMile, quantity25.Unit); + var quantity25 = Length.From(1, LengthUnit.Nanometer); + AssertEx.EqualTolerance(1, quantity25.Nanometers, NanometersTolerance); + Assert.Equal(LengthUnit.Nanometer, quantity25.Unit); - var quantity26 = Length.From(1, LengthUnit.Parsec); - AssertEx.EqualTolerance(1, quantity26.Parsecs, ParsecsTolerance); - Assert.Equal(LengthUnit.Parsec, quantity26.Unit); + var quantity26 = Length.From(1, LengthUnit.NauticalMile); + AssertEx.EqualTolerance(1, quantity26.NauticalMiles, NauticalMilesTolerance); + Assert.Equal(LengthUnit.NauticalMile, quantity26.Unit); - var quantity27 = Length.From(1, LengthUnit.PrinterPica); - AssertEx.EqualTolerance(1, quantity27.PrinterPicas, PrinterPicasTolerance); - Assert.Equal(LengthUnit.PrinterPica, quantity27.Unit); + var quantity27 = Length.From(1, LengthUnit.Parsec); + AssertEx.EqualTolerance(1, quantity27.Parsecs, ParsecsTolerance); + Assert.Equal(LengthUnit.Parsec, quantity27.Unit); - var quantity28 = Length.From(1, LengthUnit.PrinterPoint); - AssertEx.EqualTolerance(1, quantity28.PrinterPoints, PrinterPointsTolerance); - Assert.Equal(LengthUnit.PrinterPoint, quantity28.Unit); + var quantity28 = Length.From(1, LengthUnit.PrinterPica); + AssertEx.EqualTolerance(1, quantity28.PrinterPicas, PrinterPicasTolerance); + Assert.Equal(LengthUnit.PrinterPica, quantity28.Unit); - var quantity29 = Length.From(1, LengthUnit.Shackle); - AssertEx.EqualTolerance(1, quantity29.Shackles, ShacklesTolerance); - Assert.Equal(LengthUnit.Shackle, quantity29.Unit); + var quantity29 = Length.From(1, LengthUnit.PrinterPoint); + AssertEx.EqualTolerance(1, quantity29.PrinterPoints, PrinterPointsTolerance); + Assert.Equal(LengthUnit.PrinterPoint, quantity29.Unit); - var quantity30 = Length.From(1, LengthUnit.SolarRadius); - AssertEx.EqualTolerance(1, quantity30.SolarRadiuses, SolarRadiusesTolerance); - Assert.Equal(LengthUnit.SolarRadius, quantity30.Unit); + var quantity30 = Length.From(1, LengthUnit.Shackle); + AssertEx.EqualTolerance(1, quantity30.Shackles, ShacklesTolerance); + Assert.Equal(LengthUnit.Shackle, quantity30.Unit); - var quantity31 = Length.From(1, LengthUnit.Twip); - AssertEx.EqualTolerance(1, quantity31.Twips, TwipsTolerance); - Assert.Equal(LengthUnit.Twip, quantity31.Unit); + var quantity31 = Length.From(1, LengthUnit.SolarRadius); + AssertEx.EqualTolerance(1, quantity31.SolarRadiuses, SolarRadiusesTolerance); + Assert.Equal(LengthUnit.SolarRadius, quantity31.Unit); - var quantity32 = Length.From(1, LengthUnit.UsSurveyFoot); - AssertEx.EqualTolerance(1, quantity32.UsSurveyFeet, UsSurveyFeetTolerance); - Assert.Equal(LengthUnit.UsSurveyFoot, quantity32.Unit); + var quantity32 = Length.From(1, LengthUnit.Twip); + AssertEx.EqualTolerance(1, quantity32.Twips, TwipsTolerance); + Assert.Equal(LengthUnit.Twip, quantity32.Unit); - var quantity33 = Length.From(1, LengthUnit.Yard); - AssertEx.EqualTolerance(1, quantity33.Yards, YardsTolerance); - Assert.Equal(LengthUnit.Yard, quantity33.Unit); + var quantity33 = Length.From(1, LengthUnit.UsSurveyFoot); + AssertEx.EqualTolerance(1, quantity33.UsSurveyFeet, UsSurveyFeetTolerance); + Assert.Equal(LengthUnit.UsSurveyFoot, quantity33.Unit); + + var quantity34 = Length.From(1, LengthUnit.Yard); + AssertEx.EqualTolerance(1, quantity34.Yards, YardsTolerance); + Assert.Equal(LengthUnit.Yard, quantity34.Unit); } @@ -456,6 +465,7 @@ public void FromMeters_WithNanValue_ThrowsArgumentException() public void As() { var meter = Length.FromMeters(1); + AssertEx.EqualTolerance(AngstromsInOneMeter, meter.As(LengthUnit.Angstrom), AngstromsTolerance); AssertEx.EqualTolerance(AstronomicalUnitsInOneMeter, meter.As(LengthUnit.AstronomicalUnit), AstronomicalUnitsTolerance); AssertEx.EqualTolerance(CentimetersInOneMeter, meter.As(LengthUnit.Centimeter), CentimetersTolerance); AssertEx.EqualTolerance(ChainsInOneMeter, meter.As(LengthUnit.Chain), ChainsTolerance); @@ -550,6 +560,7 @@ public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(LengthUnit unit) public void ConversionRoundTrip() { Length meter = Length.FromMeters(1); + AssertEx.EqualTolerance(1, Length.FromAngstroms(meter.Angstroms).Meters, AngstromsTolerance); AssertEx.EqualTolerance(1, Length.FromAstronomicalUnits(meter.AstronomicalUnits).Meters, AstronomicalUnitsTolerance); AssertEx.EqualTolerance(1, Length.FromCentimeters(meter.Centimeters).Meters, CentimetersTolerance); AssertEx.EqualTolerance(1, Length.FromChains(meter.Chains).Meters, ChainsTolerance); @@ -742,6 +753,7 @@ public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() var prevCulture = Thread.CurrentThread.CurrentUICulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); try { + Assert.Equal("1 Å", new Length(1, LengthUnit.Angstrom).ToString()); Assert.Equal("1 au", new Length(1, LengthUnit.AstronomicalUnit).ToString()); Assert.Equal("1 cm", new Length(1, LengthUnit.Centimeter).ToString()); Assert.Equal("1 ch", new Length(1, LengthUnit.Chain).ToString()); @@ -789,6 +801,7 @@ public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCulture // Chose this culture, because we don't currently have any abbreviations mapped for that culture and we expect the en-US to be used as fallback. var swedishCulture = CultureInfo.GetCultureInfo("sv-SE"); + Assert.Equal("1 Å", new Length(1, LengthUnit.Angstrom).ToString(swedishCulture)); Assert.Equal("1 au", new Length(1, LengthUnit.AstronomicalUnit).ToString(swedishCulture)); Assert.Equal("1 cm", new Length(1, LengthUnit.Centimeter).ToString(swedishCulture)); Assert.Equal("1 ch", new Length(1, LengthUnit.Chain).ToString(swedishCulture)); diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Length.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Length.g.cs index be1a8ae763..7e0647d1ac 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Length.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Length.g.cs @@ -163,6 +163,11 @@ private Length(double value, LengthUnit unit) #region Conversion Properties + /// + /// Gets a value of this quantity converted into + /// + public double Angstroms => As(LengthUnit.Angstrom); + /// /// Gets a value of this quantity converted into /// @@ -339,6 +344,7 @@ private Length(double value, LengthUnit unit) internal static void MapGeneratedLocalizations(UnitAbbreviationsCache unitAbbreviationsCache) { + unitAbbreviationsCache.PerformAbbreviationMapping(LengthUnit.Angstrom, new CultureInfo("en-US"), false, true, new string[]{"Å", "A"}); unitAbbreviationsCache.PerformAbbreviationMapping(LengthUnit.AstronomicalUnit, new CultureInfo("en-US"), false, true, new string[]{"au", "ua"}); unitAbbreviationsCache.PerformAbbreviationMapping(LengthUnit.Centimeter, new CultureInfo("en-US"), false, true, new string[]{"cm"}); unitAbbreviationsCache.PerformAbbreviationMapping(LengthUnit.Centimeter, new CultureInfo("ru-RU"), false, true, new string[]{"см"}); @@ -433,6 +439,16 @@ public static string GetAbbreviation(LengthUnit unit, [CanBeNull] string culture #region Static Factory Methods + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Length FromAngstroms(double angstroms) + { + double value = (double) angstroms; + return new Length(value, LengthUnit.Angstrom); + } /// /// Creates a from . /// @@ -1064,6 +1080,7 @@ private double AsBaseUnit() { switch(Unit) { + case LengthUnit.Angstrom: return _value * 1e-10; case LengthUnit.AstronomicalUnit: return _value * 1.4959787070e11; case LengthUnit.Centimeter: return (_value) * 1e-2d; case LengthUnit.Chain: return _value*20.1168; @@ -1112,6 +1129,7 @@ private double AsBaseNumericType(LengthUnit unit) switch(unit) { + case LengthUnit.Angstrom: return baseUnitValue / 1e-10; case LengthUnit.AstronomicalUnit: return baseUnitValue / 1.4959787070e11; case LengthUnit.Centimeter: return (baseUnitValue) / 1e-2d; case LengthUnit.Chain: return baseUnitValue/20.1168; diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/LengthUnit.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/LengthUnit.g.cs index 65527fba2d..2fe61e739a 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/LengthUnit.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/LengthUnit.g.cs @@ -27,6 +27,12 @@ public enum LengthUnit { Undefined = 0, + /// + /// Angstrom is a metric unit of length equal to 1e-10 meter + /// + /// https://en.wikipedia.org/wiki/Angstrom + Angstrom, + /// /// One Astronomical Unit is the distance from the solar system Star, the sun, to planet Earth. /// diff --git a/UnitsNet/GeneratedCode/Quantities/Length.g.cs b/UnitsNet/GeneratedCode/Quantities/Length.g.cs index 4aac6867ce..27345454f7 100644 --- a/UnitsNet/GeneratedCode/Quantities/Length.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Length.g.cs @@ -62,6 +62,7 @@ static Length() Info = new QuantityInfo("Length", new UnitInfo[] { + new UnitInfo(LengthUnit.Angstrom, "Angstroms", BaseUnits.Undefined), new UnitInfo(LengthUnit.AstronomicalUnit, "AstronomicalUnits", BaseUnits.Undefined), new UnitInfo(LengthUnit.Centimeter, "Centimeters", BaseUnits.Undefined), new UnitInfo(LengthUnit.Chain, "Chains", new BaseUnits(length: LengthUnit.Chain)), @@ -221,6 +222,11 @@ public Length(double value, UnitSystem unitSystem) #region Conversion Properties + /// + /// Gets a value of this quantity converted into + /// + public double Angstroms => As(LengthUnit.Angstrom); + /// /// Gets a value of this quantity converted into /// @@ -402,6 +408,7 @@ public Length(double value, UnitSystem unitSystem) internal static void RegisterDefaultConversions(UnitConverter unitConverter) { // Register in unit converter: BaseUnit -> LengthUnit + unitConverter.SetConversionFunction(LengthUnit.Meter, LengthUnit.Angstrom, quantity => new Length(quantity.Value / 1e-10, LengthUnit.Angstrom)); unitConverter.SetConversionFunction(LengthUnit.Meter, LengthUnit.AstronomicalUnit, quantity => new Length(quantity.Value / 1.4959787070e11, LengthUnit.AstronomicalUnit)); unitConverter.SetConversionFunction(LengthUnit.Meter, LengthUnit.Centimeter, quantity => new Length((quantity.Value) / 1e-2d, LengthUnit.Centimeter)); unitConverter.SetConversionFunction(LengthUnit.Meter, LengthUnit.Chain, quantity => new Length(quantity.Value/20.1168, LengthUnit.Chain)); @@ -439,6 +446,7 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(LengthUnit.Meter, LengthUnit.Meter, quantity => quantity); // Register in unit converter: LengthUnit -> BaseUnit + unitConverter.SetConversionFunction(LengthUnit.Angstrom, LengthUnit.Meter, quantity => new Length(quantity.Value * 1e-10, LengthUnit.Meter)); unitConverter.SetConversionFunction(LengthUnit.AstronomicalUnit, LengthUnit.Meter, quantity => new Length(quantity.Value * 1.4959787070e11, LengthUnit.Meter)); unitConverter.SetConversionFunction(LengthUnit.Centimeter, LengthUnit.Meter, quantity => new Length((quantity.Value) * 1e-2d, LengthUnit.Meter)); unitConverter.SetConversionFunction(LengthUnit.Chain, LengthUnit.Meter, quantity => new Length(quantity.Value*20.1168, LengthUnit.Meter)); @@ -476,6 +484,7 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) internal static void MapGeneratedLocalizations(UnitAbbreviationsCache unitAbbreviationsCache) { + unitAbbreviationsCache.PerformAbbreviationMapping(LengthUnit.Angstrom, new CultureInfo("en-US"), false, true, new string[]{"Å", "A"}); unitAbbreviationsCache.PerformAbbreviationMapping(LengthUnit.AstronomicalUnit, new CultureInfo("en-US"), false, true, new string[]{"au", "ua"}); unitAbbreviationsCache.PerformAbbreviationMapping(LengthUnit.Centimeter, new CultureInfo("en-US"), false, true, new string[]{"cm"}); unitAbbreviationsCache.PerformAbbreviationMapping(LengthUnit.Centimeter, new CultureInfo("ru-RU"), false, true, new string[]{"см"}); @@ -569,6 +578,15 @@ public static string GetAbbreviation(LengthUnit unit, IFormatProvider? provider) #region Static Factory Methods + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Length FromAngstroms(QuantityValue angstroms) + { + double value = (double) angstroms; + return new Length(value, LengthUnit.Angstrom); + } /// /// Creates a from . /// diff --git a/UnitsNet/GeneratedCode/Units/LengthUnit.g.cs b/UnitsNet/GeneratedCode/Units/LengthUnit.g.cs index 65527fba2d..2fe61e739a 100644 --- a/UnitsNet/GeneratedCode/Units/LengthUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/LengthUnit.g.cs @@ -27,6 +27,12 @@ public enum LengthUnit { Undefined = 0, + /// + /// Angstrom is a metric unit of length equal to 1e-10 meter + /// + /// https://en.wikipedia.org/wiki/Angstrom + Angstrom, + /// /// One Astronomical Unit is the distance from the solar system Star, the sun, to planet Earth. ///