From 535a16f63890b8e8e15ea8ea6ddc631a07cecad9 Mon Sep 17 00:00:00 2001 From: Russell Jahn Date: Thu, 21 Feb 2019 16:13:36 -0800 Subject: [PATCH] Added BeatPerMinute (unit used for measuring heart rate) as a frequency. --- Common/UnitDefinitions/Frequency.json | 12 ++++++++++++ UnitsNet.Tests/CustomCode/FrequencyTests.cs | 2 ++ .../Quantities/Frequency.NetFramework.g.cs | 16 ++++++++++++++++ .../GeneratedCode/UnitAbbreviationsCache.g.cs | 1 + UnitsNet/GeneratedCode/Units/FrequencyUnit.g.cs | 1 + 5 files changed, 32 insertions(+) diff --git a/Common/UnitDefinitions/Frequency.json b/Common/UnitDefinitions/Frequency.json index c82946ecbc..9d60cdd35e 100644 --- a/Common/UnitDefinitions/Frequency.json +++ b/Common/UnitDefinitions/Frequency.json @@ -55,6 +55,18 @@ "Abbreviations": [ "cph" ] } ] + }, + { + "SingularName": "BeatPerMinute", + "PluralName": "BeatsPerMinute", + "FromUnitToBaseFunc": "x/60", + "FromBaseToUnitFunc": "x*60", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "bpm" ] + } + ] } ] } diff --git a/UnitsNet.Tests/CustomCode/FrequencyTests.cs b/UnitsNet.Tests/CustomCode/FrequencyTests.cs index 3a38d0830b..b32012b2d9 100644 --- a/UnitsNet.Tests/CustomCode/FrequencyTests.cs +++ b/UnitsNet.Tests/CustomCode/FrequencyTests.cs @@ -40,5 +40,7 @@ public class FrequencyTests : FrequencyTestsBase protected override double CyclesPerMinuteInOneHertz => 60; protected override double RadiansPerSecondInOneHertz => 2*Math.PI; + + protected override double BeatsPerMinuteInOneHertz => 60; } } diff --git a/UnitsNet/GeneratedCode/Quantities/Frequency.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Frequency.NetFramework.g.cs index 2a9033426b..a901e3d7b9 100644 --- a/UnitsNet/GeneratedCode/Quantities/Frequency.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Frequency.NetFramework.g.cs @@ -158,6 +158,11 @@ public Frequency(double numericValue, FrequencyUnit unit) #region Conversion Properties + /// + /// Get Frequency in BeatsPerMinute. + /// + public double BeatsPerMinute => As(FrequencyUnit.BeatPerMinute); + /// /// Get Frequency in CyclesPerHour. /// @@ -227,6 +232,15 @@ public static string GetAbbreviation(FrequencyUnit unit, [CanBeNull] IFormatProv #region Static Factory Methods + /// + /// Get Frequency from BeatsPerMinute. + /// + /// If value is NaN or Infinity. + public static Frequency FromBeatsPerMinute(QuantityValue beatsperminute) + { + double value = (double) beatsperminute; + return new Frequency(value, FrequencyUnit.BeatPerMinute); + } /// /// Get Frequency from CyclesPerHour. /// @@ -657,6 +671,7 @@ private double AsBaseUnit() { switch(Unit) { + case FrequencyUnit.BeatPerMinute: return _value/60; case FrequencyUnit.CyclePerHour: return _value/3600; case FrequencyUnit.CyclePerMinute: return _value/60; case FrequencyUnit.Gigahertz: return (_value) * 1e9d; @@ -679,6 +694,7 @@ private double AsBaseNumericType(FrequencyUnit unit) switch(unit) { + case FrequencyUnit.BeatPerMinute: return baseUnitValue*60; case FrequencyUnit.CyclePerHour: return baseUnitValue*3600; case FrequencyUnit.CyclePerMinute: return baseUnitValue*60; case FrequencyUnit.Gigahertz: return (baseUnitValue) / 1e9d; diff --git a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs index 6bf7d0e29a..9b90ce19fd 100644 --- a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -400,6 +400,7 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(ForcePerLengthUnit), (int)ForcePerLengthUnit.MillinewtonPerMeter, new string[]{"mN/m"}), ("en-US", typeof(ForcePerLengthUnit), (int)ForcePerLengthUnit.NanonewtonPerMeter, new string[]{"nN/m"}), ("en-US", typeof(ForcePerLengthUnit), (int)ForcePerLengthUnit.NewtonPerMeter, new string[]{"N/m"}), + ("en-US", typeof(FrequencyUnit), (int)FrequencyUnit.BeatPerMinute, new string[]{"bpm"}), ("en-US", typeof(FrequencyUnit), (int)FrequencyUnit.CyclePerHour, new string[]{"cph"}), ("en-US", typeof(FrequencyUnit), (int)FrequencyUnit.CyclePerMinute, new string[]{"cpm"}), ("en-US", typeof(FrequencyUnit), (int)FrequencyUnit.Gigahertz, new string[]{"GHz"}), diff --git a/UnitsNet/GeneratedCode/Units/FrequencyUnit.g.cs b/UnitsNet/GeneratedCode/Units/FrequencyUnit.g.cs index 98d4d43584..255d655289 100644 --- a/UnitsNet/GeneratedCode/Units/FrequencyUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/FrequencyUnit.g.cs @@ -44,6 +44,7 @@ namespace UnitsNet.Units public enum FrequencyUnit { Undefined = 0, + BeatPerMinute, CyclePerHour, CyclePerMinute, Gigahertz,