Struct Speed
- Namespace
- EncDotNet.S100.Quantities
- Assembly
- EncDotNet.S100.Core.dll
A linear speed, stored canonically in metres per second.
public readonly record struct Speed : IComparable<Speed>, IEquatable<Speed>
- Implements
- Inherited Members
Remarks
Speed models how fast something moves without committing callers to a unit at the API boundary. It is particularly useful where a single concept arrives in different units from different feeds — AIS reports speed over ground in knots, while own-ship simulators often work in metres per second. Both become a Speed and are read back in whichever unit the consumer needs.
The type follows the same readonly record struct design as
Length: value semantics, arithmetic operators, and ordering.
Because the backing store is a double, equality (==)
is exact floating-point equality. Prefer CompareTo(Speed)
with a tolerance when comparing computed values.
Fields
MetresPerSecondPerKilometrePerHour
Metres per second in one kilometre per hour.
public const double MetresPerSecondPerKilometrePerHour = 0.2777777777777778
Field Value
MetresPerSecondPerKnot
Metres per second in one knot (1 NM/h = 1852 m / 3600 s).
public const double MetresPerSecondPerKnot = 0.5144444444444445
Field Value
Properties
TotalKilometresPerHour
The speed expressed in kilometres per hour.
public double TotalKilometresPerHour { get; }
Property Value
TotalKnots
The speed expressed in knots.
public double TotalKnots { get; }
Property Value
TotalMetresPerSecond
The speed expressed in metres per second (the canonical unit).
public double TotalMetresPerSecond { get; }
Property Value
Zero
A zero speed. Equal to default(Speed).
public static Speed Zero { get; }
Property Value
Methods
Abs()
Returns the absolute (non-negative) magnitude of this speed.
public Speed Abs()
Returns
CompareTo(Speed)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
public int CompareTo(Speed other)
Parameters
otherSpeedAn object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes otherin the sort order.Zero This instance occurs in the same position in the sort order as other.Greater than zero This instance follows otherin the sort order.
DistanceOver(TimeSpan)
The distance travelled at this speed over the supplied duration.
public Length DistanceOver(TimeSpan duration)
Parameters
durationTimeSpan
Returns
FromKilometresPerHour(double)
Creates a speed from a value in kilometres per hour.
public static Speed FromKilometresPerHour(double kilometresPerHour)
Parameters
kilometresPerHourdouble
Returns
FromKnots(double)
Creates a speed from a value in knots.
public static Speed FromKnots(double knots)
Parameters
knotsdouble
Returns
FromMetresPerSecond(double)
Creates a speed from a value in metres per second.
public static Speed FromMetresPerSecond(double metresPerSecond)
Parameters
metresPerSeconddouble
Returns
ToString()
Returns an invariant-culture string of the form "5 m/s" for
diagnostic purposes. User-facing presentation should go through a
dedicated formatter.
public override string ToString()
Returns
Operators
operator +(Speed, Speed)
Adds two speeds.
public static Speed operator +(Speed a, Speed b)
Parameters
Returns
operator /(Speed, Speed)
Divides two speeds, yielding their dimensionless ratio.
public static double operator /(Speed a, Speed b)
Parameters
Returns
operator /(Speed, double)
Divides a speed by a dimensionless divisor.
public static Speed operator /(Speed a, double divisor)
Parameters
Returns
operator >(Speed, Speed)
Indicates whether one speed is faster than another.
public static bool operator >(Speed a, Speed b)
Parameters
Returns
operator >=(Speed, Speed)
Indicates whether one speed is faster than or equal to another.
public static bool operator >=(Speed a, Speed b)
Parameters
Returns
operator <(Speed, Speed)
Indicates whether one speed is slower than another.
public static bool operator <(Speed a, Speed b)
Parameters
Returns
operator <=(Speed, Speed)
Indicates whether one speed is slower than or equal to another.
public static bool operator <=(Speed a, Speed b)
Parameters
Returns
operator *(Speed, double)
Scales a speed by a dimensionless factor.
public static Speed operator *(Speed a, double factor)
Parameters
Returns
operator *(double, Speed)
Scales a speed by a dimensionless factor.
public static Speed operator *(double factor, Speed a)
Parameters
Returns
operator -(Speed, Speed)
Subtracts one speed from another.
public static Speed operator -(Speed a, Speed b)
Parameters
Returns
operator -(Speed)
Negates a speed.
public static Speed operator -(Speed a)
Parameters
aSpeed