Skip to content

Commit

Permalink
Merge pull request #1369 from rammba/features/knot-and-nautical-mile
Browse files Browse the repository at this point in the history
Add Knot and NauticalMile
  • Loading branch information
louthy authored Sep 20, 2024
2 parents fbdba70 + b6fc85a commit 826005a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
36 changes: 23 additions & 13 deletions LanguageExt.Core/Units of Measure/Length.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,20 @@ public Length Min(Length rhs) =>
public Length Max(Length rhs) =>
new (Math.Max(Value, rhs.Value));

public double Miles => Value * 6.2137119223484848484848484848485e-4;
public double Yards => Value * 1.0936132983333333333333333333333;
public double Feet => Value * 3.280839895;
public double Inches => Value * 39.37007874;
public double Kilometres => Value / 1000.0;
public double Hectometres => Value / 100.0;
public double Decametres => Value / 10.0;
public double Metres => Value;
public double Centimetres => Value * 100.0;
public double Millimetres => Value * 1000.0;
public double Micrometres => Value * 1000000.0;
public double Nanometres => Value * 1000000000.0;
public double Angstroms => Value * 10000000000.0;
public double Miles => Value * 6.2137119223484848484848484848485e-4;
public double NauticalMiles => Value * 1852.0;
public double Yards => Value * 1.0936132983333333333333333333333;
public double Feet => Value * 3.280839895;
public double Inches => Value * 39.37007874;
public double Kilometres => Value / 1000.0;
public double Hectometres => Value / 100.0;
public double Decametres => Value / 10.0;
public double Metres => Value;
public double Centimetres => Value * 100.0;
public double Millimetres => Value * 1000.0;
public double Micrometres => Value * 1000000.0;
public double Nanometres => Value * 1000000000.0;
public double Angstroms => Value * 10000000000.0;

static Fin<Length> DomainType<Length, double>.From(double repr) =>
new Length(repr);
Expand All @@ -164,6 +165,15 @@ public static Length Miles(this float self) =>
public static Length Miles(this double self) =>
new (1609.344000006437376000025749504 * self);

public static Length NauticalMiles(this int self) =>
new (self / 1852.0);

public static Length NauticalMiles(this float self) =>
new (self / 1852.0);

public static Length NauticalMiles(this double self) =>
new (self / 1852.0);

public static Length Yards(this int self) =>
new (0.9144000000036576000000146304 * self);

Expand Down
20 changes: 14 additions & 6 deletions LanguageExt.Core/Units of Measure/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public class UnitsOfMeasure
/// Inch
/// </summary>
/// <example>
/// Length x = 7*inch;
/// Length x = 7*inches;
/// </example>
public static readonly Length inches = 1.Inches();

Expand All @@ -189,15 +189,15 @@ public class UnitsOfMeasure
/// Feet
/// </summary>
/// <example>
/// Length x = 7*ft;
/// Length x = 7*foot;
/// </example>
public static readonly Length foot = 1.Feet();

/// <summary>
/// Feet
/// </summary>
/// <example>
/// Length x = 7*ft;
/// Length x = 7*feet;
/// </example>
public static readonly Length feet = 1.Feet();

Expand All @@ -213,15 +213,15 @@ public class UnitsOfMeasure
/// Yard
/// </summary>
/// <example>
/// Length x = 7*yd;
/// Length x = 7*yard;
/// </example>
public static readonly Length yard = 1.Yards();

/// <summary>
/// Yard
/// </summary>
/// <example>
/// Length x = 7*yd;
/// Length x = 7*yards;
/// </example>
public static readonly Length yards = 1.Yards();

Expand All @@ -237,10 +237,18 @@ public class UnitsOfMeasure
/// Mile
/// </summary>
/// <example>
/// Length x = 7*mile;
/// Length x = 7*miles;
/// </example>
public static readonly Length miles = 1.Miles();

/// <summary>
/// NauticalMile
/// </summary>
/// <example>
/// Length x = 7*nauticalMile;
/// </example>
public static readonly Length nauticalMile = 1.NauticalMiles();

/// <summary>
/// Millimetre squared
/// </summary>
Expand Down
12 changes: 11 additions & 1 deletion LanguageExt.Core/Units of Measure/Velocity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Velocity Divide(double rhs) =>
public static VelocitySq operator *(Velocity lhs, Velocity rhs) =>
new (lhs.Value * rhs.Value);

public static VelocitySq operator^(Velocity lhs, int power) =>
public static VelocitySq operator ^(Velocity lhs, int power) =>
power == 2
? new VelocitySq(lhs.Value * lhs.Value)
: raise<VelocitySq>(new NotSupportedException("Velocity can only be raised to the power of 2"));
Expand Down Expand Up @@ -133,6 +133,7 @@ public Velocity Max(Velocity rhs) =>
public double KilometresPerHour => Value / 1000.0 * 3600.0;
public double MilesPerSecond => Value / 1609.344000006437376000025749504;
public double MilesPerHour => Value / 1609.344000006437376000025749504 * 3600.0;
public double Knots => Value / 0.51444444444444;
}

public static class UnitsVelocityExtensions
Expand Down Expand Up @@ -181,4 +182,13 @@ public static Velocity MilesPerHour(this float self) =>

public static Velocity MilesPerHour(this double self) =>
new (self * 1609.344000006437376000025749504 / 3600.0);

public static Velocity Knots(this int self) =>
new (self * 0.51444444444444);

public static Velocity Knots(this float self) =>
new(self * 0.51444444444444);

public static Velocity Knots(this double self) =>
new(self * 0.51444444444444);
}

0 comments on commit 826005a

Please sign in to comment.