From 3f71f26b53bca0023bd9c755f0dfa6354997e22d Mon Sep 17 00:00:00 2001 From: Travis Bement Date: Thu, 4 Apr 2024 12:38:00 -0400 Subject: [PATCH] Add operators for ReciprocalLength/-Area (v6) (#1385) Added additional operators that result in ReciprocalLength (Length/Area, Area/Volume) and ReciprocalArea (Length/Volume) (Mirrors functionality of v5 PR #1382) --------- Co-authored-by: Travis Bement Co-authored-by: Andreas Gullberg Larsen --- Common/UnitRelations.json | 3 ++ UnitsNet/GeneratedCode/Quantities/Area.g.cs | 21 ++++++++++++++ UnitsNet/GeneratedCode/Quantities/Length.g.cs | 28 +++++++++++++++++++ .../Quantities/ReciprocalArea.g.cs | 7 +++++ .../Quantities/ReciprocalLength.g.cs | 14 ++++++++++ UnitsNet/GeneratedCode/Quantities/Volume.g.cs | 14 ++++++++++ 6 files changed, 87 insertions(+) diff --git a/Common/UnitRelations.json b/Common/UnitRelations.json index b6e6cc2ad3..afd0ab65b6 100644 --- a/Common/UnitRelations.json +++ b/Common/UnitRelations.json @@ -8,6 +8,7 @@ "Angle.Radian = RotationalSpeed.RadianPerSecond * Duration.Second", "Area.SquareMeter = KinematicViscosity.SquareMeterPerSecond * Duration.Second", "Area.SquareMeter = Length.Meter * Length.Meter", + "Area.SquareMeter = Volume.CubicMeter * ReciprocalLength.InverseMeter", "AreaMomentOfInertia.MeterToTheFourth = Volume.CubicMeter * Length.Meter", "double = Density.KilogramPerCubicMeter * SpecificVolume.CubicMeterPerKilogram", "double = SpecificEnergy.JoulePerKilogram * BrakeSpecificFuelConsumption.KilogramPerJoule", @@ -30,7 +31,9 @@ "ForcePerLength.NewtonPerMeter = Pressure.NewtonPerSquareMeter * Length.Meter", "ForcePerLength.NewtonPerMeter = SpecificWeight.NewtonPerCubicMeter * Area.SquareMeter", "KinematicViscosity.SquareMeterPerSecond = Length.Meter * Speed.MeterPerSecond", + "Length.Meter = Area.SquareMeter * ReciprocalLength.InverseMeter", "Length.Meter = Speed.MeterPerSecond * Duration.Second", + "Length.Meter = Volume.CubicMeter * ReciprocalArea.InverseSquareMeter", "LinearDensity.KilogramPerMeter = Area.SquareMeter * Density.KilogramPerCubicMeter", "LuminousIntensity.Candela = Luminance.CandelaPerSquareMeter * Area.SquareMeter", "Mass.Gram = AmountOfSubstance.Mole * MolarMass.GramPerMole", diff --git a/UnitsNet/GeneratedCode/Quantities/Area.g.cs b/UnitsNet/GeneratedCode/Quantities/Area.g.cs index 4dbb6648d8..682a6e052c 100644 --- a/UnitsNet/GeneratedCode/Quantities/Area.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Area.g.cs @@ -46,6 +46,7 @@ namespace UnitsNet IMultiplyOperators, IMultiplyOperators, IDivisionOperators, + IMultiplyOperators, IDivisionOperators, IMultiplyOperators, IMultiplyOperators, @@ -53,8 +54,10 @@ namespace UnitsNet IMultiplyOperators, IMultiplyOperators, IMultiplyOperators, + IDivisionOperators, IMultiplyOperators, IMultiplyOperators, + IDivisionOperators, IMultiplyOperators, #endif IComparable, @@ -687,6 +690,12 @@ public ReciprocalArea Inverse() return KinematicViscosity.FromSquareMetersPerSecond(area.SquareMeters / duration.Seconds); } + /// Get from * . + public static Length operator *(Area area, ReciprocalLength reciprocalLength) + { + return Length.FromMeters(area.SquareMeters * reciprocalLength.InverseMeters); + } + /// Get from / . public static Length operator /(Area area, Length length) { @@ -729,6 +738,12 @@ public ReciprocalArea Inverse() return Ratio.FromDecimalFractions(area.SquareMeters * reciprocalArea.InverseSquareMeters); } + /// Get from / . + public static ReciprocalLength operator /(Area area, Volume volume) + { + return ReciprocalLength.FromInverseMeters(area.SquareMeters / volume.CubicMeters); + } + /// Get from * . public static Torque operator *(Area area, ForcePerLength forcePerLength) { @@ -741,6 +756,12 @@ public ReciprocalArea Inverse() return Volume.FromCubicMeters(area.SquareMeters * length.Meters); } + /// Get from / . + public static Volume operator /(Area area, ReciprocalLength reciprocalLength) + { + return Volume.FromCubicMeters(area.SquareMeters / reciprocalLength.InverseMeters); + } + /// Get from * . public static VolumeFlow operator *(Area area, Speed speed) { diff --git a/UnitsNet/GeneratedCode/Quantities/Length.g.cs b/UnitsNet/GeneratedCode/Quantities/Length.g.cs index 6e4ae98f80..3ccc3ee605 100644 --- a/UnitsNet/GeneratedCode/Quantities/Length.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Length.g.cs @@ -43,6 +43,7 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IMultiplyOperators, + IDivisionOperators, IMultiplyOperators, IDivisionOperators, IMultiplyOperators, @@ -50,12 +51,15 @@ namespace UnitsNet IMultiplyOperators, IMultiplyOperators, IMultiplyOperators, + IDivisionOperators, IMultiplyOperators, + IDivisionOperators, IMultiplyOperators, IDivisionOperators, IMultiplyOperators, IMultiplyOperators, IMultiplyOperators, + IDivisionOperators, #endif IComparable, IComparable, @@ -1117,6 +1121,12 @@ public ReciprocalLength Inverse() return Area.FromSquareMeters(left.Meters * right.Meters); } + /// Get from / . + public static Area operator /(Length length, ReciprocalLength reciprocalLength) + { + return Area.FromSquareMeters(length.Meters / reciprocalLength.InverseMeters); + } + /// Get from * . public static AreaMomentOfInertia operator *(Length length, Volume volume) { @@ -1159,12 +1169,24 @@ public ReciprocalLength Inverse() return Pressure.FromPascals(length.Meters * specificWeight.NewtonsPerCubicMeter); } + /// Get from / . + public static ReciprocalArea operator /(Length length, Volume volume) + { + return ReciprocalArea.FromInverseSquareMeters(length.Meters / volume.CubicMeters); + } + /// Get from * . public static ReciprocalLength operator *(Length length, ReciprocalArea reciprocalArea) { return ReciprocalLength.FromInverseMeters(length.Meters * reciprocalArea.InverseSquareMeters); } + /// Get from / . + public static ReciprocalLength operator /(Length length, Area area) + { + return ReciprocalLength.FromInverseMeters(length.Meters / area.SquareMeters); + } + /// Get from * . public static RotationalStiffness operator *(Length length, RotationalStiffnessPerLength rotationalStiffnessPerLength) { @@ -1195,6 +1217,12 @@ public ReciprocalLength Inverse() return Volume.FromCubicMeters(length.Meters * area.SquareMeters); } + /// Get from / . + public static Volume operator /(Length length, ReciprocalArea reciprocalArea) + { + return Volume.FromCubicMeters(length.Meters / reciprocalArea.InverseSquareMeters); + } + #endregion #region Equality / IComparable diff --git a/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs b/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs index 8bf4af8a24..248d5d7006 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs @@ -45,6 +45,7 @@ namespace UnitsNet public readonly partial struct ReciprocalArea : IArithmeticQuantity, #if NET7_0_OR_GREATER + IMultiplyOperators, IMultiplyOperators, IMultiplyOperators, IMultiplyOperators, @@ -608,6 +609,12 @@ public Area Inverse() return InverseSquareMeters == 0.0 ? Area.Zero : Area.FromSquareMeters(1 / InverseSquareMeters); } + /// Get from * . + public static Length operator *(ReciprocalArea reciprocalArea, Volume volume) + { + return Length.FromMeters(reciprocalArea.InverseSquareMeters * volume.CubicMeters); + } + /// Get from * . public static Pressure operator *(ReciprocalArea reciprocalArea, Force force) { diff --git a/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs b/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs index 8fa5f8bcd3..64a152158b 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs @@ -45,7 +45,9 @@ namespace UnitsNet public readonly partial struct ReciprocalLength : IArithmeticQuantity, #if NET7_0_OR_GREATER + IMultiplyOperators, IMultiplyOperators, + IMultiplyOperators, IDivisionOperators, IMultiplyOperators, IMultiplyOperators, @@ -593,12 +595,24 @@ public Length Inverse() return InverseMeters == 0.0 ? Length.Zero : Length.FromMeters(1 / InverseMeters); } + /// Get from * . + public static Area operator *(ReciprocalLength reciprocalLength, Volume volume) + { + return Area.FromSquareMeters(reciprocalLength.InverseMeters * volume.CubicMeters); + } + /// Get from * . public static ForcePerLength operator *(ReciprocalLength reciprocalLength, Force force) { return ForcePerLength.FromNewtonsPerMeter(reciprocalLength.InverseMeters * force.Newtons); } + /// Get from * . + public static Length operator *(ReciprocalLength reciprocalLength, Area area) + { + return Length.FromMeters(reciprocalLength.InverseMeters * area.SquareMeters); + } + /// Get from / . public static Length operator /(ReciprocalLength reciprocalLength, ReciprocalArea reciprocalArea) { diff --git a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs index 880acbe456..60c61dba93 100644 --- a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs @@ -43,10 +43,12 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IMultiplyOperators, + IMultiplyOperators, IDivisionOperators, IMultiplyOperators, IDivisionOperators, IMultiplyOperators, + IMultiplyOperators, IDivisionOperators, IMultiplyOperators, IMultiplyOperators, @@ -1299,6 +1301,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum return AmountOfSubstance.FromMoles(volume.CubicMeters * molarity.MolesPerCubicMeter); } + /// Get from * . + public static Area operator *(Volume volume, ReciprocalLength reciprocalLength) + { + return Area.FromSquareMeters(volume.CubicMeters * reciprocalLength.InverseMeters); + } + /// Get from / . public static Area operator /(Volume volume, Length length) { @@ -1323,6 +1331,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum return Energy.FromJoules(volume.CubicMeters * energyDensity.JoulesPerCubicMeter); } + /// Get from * . + public static Length operator *(Volume volume, ReciprocalArea reciprocalArea) + { + return Length.FromMeters(volume.CubicMeters * reciprocalArea.InverseSquareMeters); + } + /// Get from / . public static Length operator /(Volume volume, Area area) {