Table of Contents

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

double

MetresPerSecondPerKnot

Metres per second in one knot (1 NM/h = 1852 m / 3600 s).

public const double MetresPerSecondPerKnot = 0.5144444444444445

Field Value

double

Properties

TotalKilometresPerHour

The speed expressed in kilometres per hour.

public double TotalKilometresPerHour { get; }

Property Value

double

TotalKnots

The speed expressed in knots.

public double TotalKnots { get; }

Property Value

double

TotalMetresPerSecond

The speed expressed in metres per second (the canonical unit).

public double TotalMetresPerSecond { get; }

Property Value

double

Zero

A zero speed. Equal to default(Speed).

public static Speed Zero { get; }

Property Value

Speed

Methods

Abs()

Returns the absolute (non-negative) magnitude of this speed.

public Speed Abs()

Returns

Speed

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

other Speed

An 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 other in the sort order.
Zero This instance occurs in the same position in the sort order as other.
Greater than zero This instance follows other in the sort order.

DistanceOver(TimeSpan)

The distance travelled at this speed over the supplied duration.

public Length DistanceOver(TimeSpan duration)

Parameters

duration TimeSpan

Returns

Length

FromKilometresPerHour(double)

Creates a speed from a value in kilometres per hour.

public static Speed FromKilometresPerHour(double kilometresPerHour)

Parameters

kilometresPerHour double

Returns

Speed

FromKnots(double)

Creates a speed from a value in knots.

public static Speed FromKnots(double knots)

Parameters

knots double

Returns

Speed

FromMetresPerSecond(double)

Creates a speed from a value in metres per second.

public static Speed FromMetresPerSecond(double metresPerSecond)

Parameters

metresPerSecond double

Returns

Speed

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

string

Operators

operator +(Speed, Speed)

Adds two speeds.

public static Speed operator +(Speed a, Speed b)

Parameters

a Speed
b Speed

Returns

Speed

operator /(Speed, Speed)

Divides two speeds, yielding their dimensionless ratio.

public static double operator /(Speed a, Speed b)

Parameters

a Speed
b Speed

Returns

double

operator /(Speed, double)

Divides a speed by a dimensionless divisor.

public static Speed operator /(Speed a, double divisor)

Parameters

a Speed
divisor double

Returns

Speed

operator >(Speed, Speed)

Indicates whether one speed is faster than another.

public static bool operator >(Speed a, Speed b)

Parameters

a Speed
b Speed

Returns

bool

operator >=(Speed, Speed)

Indicates whether one speed is faster than or equal to another.

public static bool operator >=(Speed a, Speed b)

Parameters

a Speed
b Speed

Returns

bool

operator <(Speed, Speed)

Indicates whether one speed is slower than another.

public static bool operator <(Speed a, Speed b)

Parameters

a Speed
b Speed

Returns

bool

operator <=(Speed, Speed)

Indicates whether one speed is slower than or equal to another.

public static bool operator <=(Speed a, Speed b)

Parameters

a Speed
b Speed

Returns

bool

operator *(Speed, double)

Scales a speed by a dimensionless factor.

public static Speed operator *(Speed a, double factor)

Parameters

a Speed
factor double

Returns

Speed

operator *(double, Speed)

Scales a speed by a dimensionless factor.

public static Speed operator *(double factor, Speed a)

Parameters

factor double
a Speed

Returns

Speed

operator -(Speed, Speed)

Subtracts one speed from another.

public static Speed operator -(Speed a, Speed b)

Parameters

a Speed
b Speed

Returns

Speed

operator -(Speed)

Negates a speed.

public static Speed operator -(Speed a)

Parameters

a Speed

Returns

Speed