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
MetresPerFoot
Metres per international foot (exact).
public const double MetresPerFoot = 0.3048
Field Value
MetresPerKilometre
Metres per kilometre.
public const double MetresPerKilometre = 1000
Field Value
MetresPerNauticalMile
Metres per nautical mile (exact).
public const double MetresPerNauticalMile = 1852
Field Value
Properties
TotalFathoms
The length expressed in fathoms.
public double TotalFathoms { get; }
Property Value
TotalFeet
The length expressed in international feet.
public double TotalFeet { get; }
Property Value
TotalKilometres
The length expressed in kilometres.
public double TotalKilometres { get; }
Property Value
TotalMetres
The length expressed in metres (the canonical unit).
public double TotalMetres { get; }
Property Value
TotalNauticalMiles
The length expressed in nautical miles.
public double TotalNauticalMiles { get; }
Property Value
Zero
A zero-length value. Equal to default(Length).
public static Length Zero { get; }
Property Value
Methods
Abs()
Returns the absolute (non-negative) magnitude of this length.
public Length Abs()
Returns
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
otherLengthAn 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.
FromFathoms(double)
Creates a length from a value in fathoms.
public static Length FromFathoms(double fathoms)
Parameters
fathomsdouble
Returns
FromFeet(double)
Creates a length from a value in international feet.
public static Length FromFeet(double feet)
Parameters
feetdouble
Returns
FromKilometres(double)
Creates a length from a value in kilometres.
public static Length FromKilometres(double kilometres)
Parameters
kilometresdouble
Returns
FromMetres(double)
Creates a length from a value in metres.
public static Length FromMetres(double metres)
Parameters
metresdouble
Returns
FromNauticalMiles(double)
Creates a length from a value in nautical miles.
public static Length FromNauticalMiles(double nauticalMiles)
Parameters
nauticalMilesdouble
Returns
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
Operators
operator +(Length, Length)
Adds two lengths.
public static Length operator +(Length a, Length b)
Parameters
Returns
operator /(Length, Length)
Divides two lengths, yielding their dimensionless ratio.
public static double operator /(Length a, Length b)
Parameters
Returns
operator /(Length, double)
Divides a length by a dimensionless divisor.
public static Length operator /(Length a, double divisor)
Parameters
Returns
operator >(Length, Length)
Indicates whether one length is longer than another.
public static bool operator >(Length a, Length b)
Parameters
Returns
operator >=(Length, Length)
Indicates whether one length is longer than or equal to another.
public static bool operator >=(Length a, Length b)
Parameters
Returns
operator <(Length, Length)
Indicates whether one length is shorter than another.
public static bool operator <(Length a, Length b)
Parameters
Returns
operator <=(Length, Length)
Indicates whether one length is shorter than or equal to another.
public static bool operator <=(Length a, Length b)
Parameters
Returns
operator *(Length, double)
Scales a length by a dimensionless factor.
public static Length operator *(Length a, double factor)
Parameters
Returns
operator *(double, Length)
Scales a length by a dimensionless factor.
public static Length operator *(double factor, Length a)
Parameters
Returns
operator -(Length, Length)
Subtracts one length from another.
public static Length operator -(Length a, Length b)
Parameters
Returns
operator -(Length)
Negates a length.
public static Length operator -(Length a)
Parameters
aLength