Skip to content

Commit 694d786

Browse files
authored
Add ForceChangeRate arithmetic operators (#992)
1 parent ebc6a49 commit 694d786

File tree

6 files changed

+56
-6
lines changed

6 files changed

+56
-6
lines changed

UnitsNet.Tests/CustomCode/DurationTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,5 +199,12 @@ public void DurationTimesAcceleration()
199199
Speed speed = Duration.FromSeconds(10) * Acceleration.FromMetersPerSecondSquared(10);
200200
Assert.Equal(Speed.FromMetersPerSecond(100), speed);
201201
}
202+
203+
[Fact]
204+
public void DurationTimesForceChangeRate()
205+
{
206+
Force force = Duration.FromSeconds(10) * ForceChangeRate.FromNewtonsPerSecond(100);
207+
Assert.Equal(Force.FromNewtons(1000), force);
208+
}
202209
}
203210
}

UnitsNet.Tests/CustomCode/ForceChangeRateTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Licensed under MIT No Attribution, see LICENSE file at the root.
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

4+
using Xunit;
5+
46
namespace UnitsNet.Tests.CustomCode
57
{
68
public class ForceChangeRateTests : ForceChangeRateTestsBase
@@ -21,5 +23,12 @@ public class ForceChangeRateTests : ForceChangeRateTestsBase
2123
protected override double MillinewtonsPerSecondInOneNewtonPerSecond => 1E3;
2224
protected override double MicronewtonsPerSecondInOneNewtonPerSecond => 1E6;
2325
protected override double NanonewtonsPerSecondInOneNewtonPerSecond => 1E9;
26+
27+
[Fact]
28+
public void DurationTimesForceChangeRate()
29+
{
30+
Force force = ForceChangeRate.FromNewtonsPerSecond(100) * Duration.FromSeconds(10);
31+
Assert.Equal(Force.FromNewtons(1000), force);
32+
}
2433
}
2534
}

UnitsNet.Tests/CustomCode/ForceTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,12 @@ public void ForceTimesReciprocalAreaEqualsPressure()
9797
Pressure pressure = Force.FromNewtons(2) * ReciprocalArea.FromInverseSquareMeters(25);
9898
Assert.Equal(pressure, Pressure.FromNewtonsPerSquareMeter(50));
9999
}
100+
101+
[Fact]
102+
public void ForceDividedByForceChangeRateEqualsDuration()
103+
{
104+
Duration duration = Force.FromNewtons(200) / ForceChangeRate.FromNewtonsPerSecond(50);
105+
Assert.Equal(duration, Duration.FromSeconds(4));
106+
}
100107
}
101108
}

UnitsNet/CustomCode/Quantities/Duration.extra.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

44
using System;
5+
using UnitsNet.Units;
56

67
namespace UnitsNet
78
{
@@ -92,24 +93,28 @@ public static explicit operator Duration(TimeSpan duration)
9293
return timeSpan.TotalSeconds >= duration.Seconds;
9394
}
9495

95-
/// <summary>Get <see cref="Volume"/> from <see cref="Duration"/> times <see cref="VolumeFlow"/>.</summary>
96+
/// <summary>Get <see cref="Volume"/> from <see cref="Duration"/> multiplied by <see cref="VolumeFlow"/>.</summary>
9697
public static Volume operator *(Duration duration, VolumeFlow volumeFlow)
9798
{
9899
return Volume.FromCubicMeters(volumeFlow.CubicMetersPerSecond * duration.Seconds);
99100
}
100101

101-
/// <summary>Calculate <see cref="ElectricCharge"/> from <see cref="Duration"/> multiplied by <see cref="ElectricCurrent"/>.</summary>
102+
/// <summary>Get <see cref="ElectricCharge"/> from <see cref="Duration"/> multiplied by <see cref="ElectricCurrent"/>.</summary>
102103
public static ElectricCharge operator *(Duration time, ElectricCurrent current)
103104
{
104105
return ElectricCharge.FromAmpereHours(current.Amperes * time.Hours);
105106
}
106107

107-
/// <summary>
108-
/// Multiply <see cref="Duration"/> and <see cref="Acceleration"/> to get <see cref="Speed"/>.
109-
/// </summary>
108+
/// <summary>Get <see cref="Speed"/> from <see cref="Duration"/> multiplied by <see cref="Acceleration"/>.</summary>
110109
public static Speed operator *(Duration duration, Acceleration acceleration)
111110
{
112-
return new Speed(acceleration.MetersPerSecondSquared * duration.Seconds, UnitsNet.Units.SpeedUnit.MeterPerSecond);
111+
return new Speed(acceleration.MetersPerSecondSquared * duration.Seconds, SpeedUnit.MeterPerSecond);
112+
}
113+
114+
/// <summary>Get <see cref="Force"/> from <see cref="Duration"/> multiplied by <see cref="ForceChangeRate"/>.</summary>
115+
public static Force operator *(Duration duration, ForceChangeRate forceChangeRate)
116+
{
117+
return new Force(forceChangeRate.NewtonsPerSecond * duration.Seconds, ForceUnit.Newton);
113118
}
114119
}
115120
}

UnitsNet/CustomCode/Quantities/Force.extra.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,11 @@ public static Force FromMassByAcceleration(Mass mass, Acceleration acceleration)
6767
{
6868
return ForcePerLength.FromNewtonsPerMeter(force.Newtons / length.Meters);
6969
}
70+
71+
/// <summary>Get <see cref="Duration"/> from <see cref="Force"/> divided by <see cref="ForceChangeRate"/>.</summary>
72+
public static Duration operator /(Force force, ForceChangeRate forceChangeRate)
73+
{
74+
return new Duration(force.Newtons / forceChangeRate.NewtonsPerSecond, DurationUnit.Second);
75+
}
7076
}
7177
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed under MIT No Attribution, see LICENSE file at the root.
2+
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
3+
4+
using UnitsNet.Units;
5+
6+
namespace UnitsNet
7+
{
8+
public partial struct ForceChangeRate
9+
{
10+
/// <summary>Get <see cref="Force"/> from <see cref="ForcePerLength"/> multiplied by <see cref="Length"/>.</summary>
11+
public static Force operator *(ForceChangeRate forceChangeRate, Duration duration)
12+
{
13+
return new Force(forceChangeRate.NewtonsPerSecond * duration.Seconds, ForceUnit.Newton);
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)