Table of Contents

Struct Length

Namespace
EncDotNet.S100.Quantities
Assembly
EncDotNet.S100.Core.dll

A unit-independent linear distance, stored canonically in metres.

public readonly record struct Length : IComparable<Length>, IEquatable<Length>
Implements
Inherited Members

Remarks

Length models a real-world physical distance without committing callers to a particular unit at the API boundary. Values are created through explicit factory methods (FromMetres(double), FromFeet(double), …) and read back through explicit conversion properties (TotalMetres, TotalFeet, …), so the unit is always visible in the calling code rather than buried in a comment or parameter-name suffix.

The design mirrors TimeSpan: a lightweight readonly record struct with value semantics, arithmetic operators, and ordering. Conversions use the exact international foot (1 ft = 0.3048 m) and fathom (1 fm = 1.8288 m).

Because the backing store is a double, equality (==) is exact floating-point equality and is therefore subject to the usual rounding caveats. Prefer CompareTo(Length) with a tolerance when comparing computed values.

Fields

MetresPerFathom

Metres per fathom (exact; 1 fathom = 6 international feet).

public const double MetresPerFathom = 1.8288

Field Value

double

MetresPerFoot

Metres per international foot (exact).

public const double MetresPerFoot = 0.3048

Field Value

double

MetresPerKilometre

Metres per kilometre.

public const double MetresPerKilometre = 1000

Field Value

double

MetresPerNauticalMile

Metres per nautical mile (exact).

public const double MetresPerNauticalMile = 1852

Field Value

double

Properties

TotalFathoms

The length expressed in fathoms.

public double TotalFathoms { get; }

Property Value

double

TotalFeet

The length expressed in international feet.

public double TotalFeet { get; }

Property Value

double

TotalKilometres

The length expressed in kilometres.

public double TotalKilometres { get; }

Property Value

double

TotalMetres

The length expressed in metres (the canonical unit).

public double TotalMetres { get; }

Property Value

double

TotalNauticalMiles

The length expressed in nautical miles.

public double TotalNauticalMiles { get; }

Property Value

double

Zero

A zero-length value. Equal to default(Length).

public static Length Zero { get; }

Property Value

Length

Methods

Abs()

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

public Length Abs()

Returns

Length

CompareTo(Length)

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(Length other)

Parameters

other Length

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.

FromFathoms(double)

Creates a length from a value in fathoms.

public static Length FromFathoms(double fathoms)

Parameters

fathoms double

Returns

Length

FromFeet(double)

Creates a length from a value in international feet.

public static Length FromFeet(double feet)

Parameters

feet double

Returns

Length

FromKilometres(double)

Creates a length from a value in kilometres.

public static Length FromKilometres(double kilometres)

Parameters

kilometres double

Returns

Length

FromMetres(double)

Creates a length from a value in metres.

public static Length FromMetres(double metres)

Parameters

metres double

Returns

Length

FromNauticalMiles(double)

Creates a length from a value in nautical miles.

public static Length FromNauticalMiles(double nauticalMiles)

Parameters

nauticalMiles double

Returns

Length

ToString()

Returns an invariant-culture string of the form "12.5 m" for diagnostic purposes. User-facing presentation should go through a dedicated formatter.

public override string ToString()

Returns

string

Operators

operator +(Length, Length)

Adds two lengths.

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

Parameters

a Length
b Length

Returns

Length

operator /(Length, Length)

Divides two lengths, yielding their dimensionless ratio.

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

Parameters

a Length
b Length

Returns

double

operator /(Length, double)

Divides a length by a dimensionless divisor.

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

Parameters

a Length
divisor double

Returns

Length

operator >(Length, Length)

Indicates whether one length is longer than another.

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

Parameters

a Length
b Length

Returns

bool

operator >=(Length, Length)

Indicates whether one length is longer than or equal to another.

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

Parameters

a Length
b Length

Returns

bool

operator <(Length, Length)

Indicates whether one length is shorter than another.

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

Parameters

a Length
b Length

Returns

bool

operator <=(Length, Length)

Indicates whether one length is shorter than or equal to another.

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

Parameters

a Length
b Length

Returns

bool

operator *(Length, double)

Scales a length by a dimensionless factor.

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

Parameters

a Length
factor double

Returns

Length

operator *(double, Length)

Scales a length by a dimensionless factor.

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

Parameters

factor double
a Length

Returns

Length

operator -(Length, Length)

Subtracts one length from another.

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

Parameters

a Length
b Length

Returns

Length

operator -(Length)

Negates a length.

public static Length operator -(Length a)

Parameters

a Length

Returns

Length