Skip to content

Commit 1b87682

Browse files
trb5016Travis Bement
and
Travis Bement
authored
Add operators for ReciprocalLength/-Area (#1382)
Added additional operators that result in `ReciprocalLength` (Length/Area, Area/Volume) and `ReciprocalArea` (Length/Volume) Co-authored-by: Travis Bement <[email protected]>
1 parent 6c4faa9 commit 1b87682

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

UnitsNet.Tests/CustomCode/AreaTests.cs

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ public void AreaDividedByLengthEqualsLength()
4545
Assert.Equal(length, Length.FromMeters(10));
4646
}
4747

48+
[Fact]
49+
public void AreaDividedByVolumeEqualsReciprocalLength()
50+
{
51+
ReciprocalLength reciprocalLength = Area.FromSquareMeters(50) / Volume.FromCubicMeters(5);
52+
Assert.Equal(reciprocalLength, ReciprocalLength.FromInverseMeters(10));
53+
}
54+
4855
[Fact]
4956
public void AreaTimesMassFluxEqualsMassFlow()
5057
{

UnitsNet.Tests/CustomCode/LengthTests.cs

+14
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,20 @@ public void LengthDividedBySpeedEqualsDuration()
134134
Assert.Equal(Duration.FromSeconds(10), duration);
135135
}
136136

137+
[Fact]
138+
public void LengthDividedByAreaEqualsReciprocalLength()
139+
{
140+
ReciprocalLength reciprocalLength = Length.FromMeters(20) / Area.FromSquareMeters(2);
141+
Assert.Equal(ReciprocalLength.FromInverseMeters(10), reciprocalLength);
142+
}
143+
144+
[Fact]
145+
public void LengthDividedByVolumeEqualsReciprocalArea()
146+
{
147+
ReciprocalArea reciprocalArea = Length.FromMeters(20) / Volume.FromCubicMeters(2);
148+
Assert.Equal(ReciprocalArea.FromInverseSquareMeters(10), reciprocalArea);
149+
}
150+
137151
[Fact]
138152
public void LengthTimesSpeedEqualsKinematicViscosity()
139153
{

UnitsNet/CustomCode/Quantities/Area.extra.cs

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ public ReciprocalArea Inverse()
4242
return Length.FromMeters(area.SquareMeters / length.Meters);
4343
}
4444

45+
/// <summary>Get <see cref="ReciprocalLength"/> from <see cref="Area"/> divided by <see cref="Volume"/>.</summary>
46+
public static ReciprocalLength operator /(Area area, Volume volume)
47+
{
48+
return ReciprocalLength.FromInverseMeters(area.SquareMeters / volume.CubicMeters);
49+
}
50+
4551
/// <summary>Get <see cref="MassFlow"/> from <see cref="Area"/> times <see cref="MassFlux"/>.</summary>
4652
public static MassFlow operator *(Area area, MassFlux massFlux)
4753
{

UnitsNet/CustomCode/Quantities/Length.extra.cs

+12
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ public static bool TryParseFeetInches(string? str, out Length result, IFormatPro
141141
return Duration.FromSeconds(length.Meters/speed.MetersPerSecond);
142142
}
143143

144+
/// <summary>Get <see cref="ReciprocalLength"/> from <see cref="Length"/> divided by <see cref="Area"/>.</summary>
145+
public static ReciprocalLength operator /(Length length, Area area)
146+
{
147+
return ReciprocalLength.FromInverseMeters(length.Meters / area.SquareMeters);
148+
}
149+
150+
/// <summary>Get <see cref="ReciprocalArea"/> from <see cref="Length"/> divided by <see cref="Volume"/>.</summary>
151+
public static ReciprocalArea operator /(Length length, Volume volume)
152+
{
153+
return ReciprocalArea.FromInverseSquareMeters(length.Meters / volume.CubicMeters);
154+
}
155+
144156
/// <summary>Get <see cref="Area"/> from <see cref="Length"/> times <see cref="Length"/>.</summary>
145157
public static Area operator *(Length length1, Length length2)
146158
{

0 commit comments

Comments
 (0)