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