Struct Angle
- Namespace
- EncDotNet.S100.Quantities
- Assembly
- EncDotNet.S100.Core.dll
A planar angle, stored canonically in degrees.
public readonly record struct Angle : IComparable<Angle>, IEquatable<Angle>
- Implements
- Inherited Members
Remarks
Angle models directions and rotations — most commonly marine bearings measured clockwise from true north — without committing callers to degrees or radians at the API boundary. Values are created through FromDegrees(double)/FromRadians(double) and read back through TotalDegrees/TotalRadians.
The type follows the same readonly record struct design as
Length: value semantics, arithmetic operators, and ordering.
Stored angles are not implicitly normalized; call Normalized()
to fold a value into the [0, 360) degree range used for bearings.
Because the backing store is a double, equality (==)
is exact floating-point equality. Prefer CompareTo(Angle)
with a tolerance when comparing computed values.
Fields
DegreesPerRadian
Degrees per radian (180 / π).
public const double DegreesPerRadian = 57.29577951308232
Field Value
DegreesPerTurn
Degrees in a full turn.
public const double DegreesPerTurn = 360
Field Value
Properties
TotalDegrees
The angle expressed in degrees (the canonical unit).
public double TotalDegrees { get; }
Property Value
TotalRadians
The angle expressed in radians.
public double TotalRadians { get; }
Property Value
Zero
A zero angle. Equal to default(Angle).
public static Angle Zero { get; }
Property Value
Methods
CompareTo(Angle)
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(Angle other)
Parameters
otherAngleAn 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.
FromDegrees(double)
Creates an angle from a value in degrees.
public static Angle FromDegrees(double degrees)
Parameters
degreesdouble
Returns
FromRadians(double)
Creates an angle from a value in radians.
public static Angle FromRadians(double radians)
Parameters
radiansdouble
Returns
Normalized()
Returns an equivalent angle folded into the [0, 360) degree
range (the convention for compass bearings).
public Angle Normalized()
Returns
ToString()
Returns an invariant-culture string of the form "90°" for
diagnostic purposes. User-facing presentation should go through a
dedicated formatter.
public override string ToString()
Returns
Operators
operator +(Angle, Angle)
Adds two angles.
public static Angle operator +(Angle a, Angle b)
Parameters
Returns
operator /(Angle, double)
Divides an angle by a dimensionless divisor.
public static Angle operator /(Angle a, double divisor)
Parameters
Returns
operator >(Angle, Angle)
Indicates whether one angle is greater than another.
public static bool operator >(Angle a, Angle b)
Parameters
Returns
operator >=(Angle, Angle)
Indicates whether one angle is greater than or equal to another.
public static bool operator >=(Angle a, Angle b)
Parameters
Returns
operator <(Angle, Angle)
Indicates whether one angle is less than another.
public static bool operator <(Angle a, Angle b)
Parameters
Returns
operator <=(Angle, Angle)
Indicates whether one angle is less than or equal to another.
public static bool operator <=(Angle a, Angle b)
Parameters
Returns
operator *(Angle, double)
Scales an angle by a dimensionless factor.
public static Angle operator *(Angle a, double factor)
Parameters
Returns
operator *(double, Angle)
Scales an angle by a dimensionless factor.
public static Angle operator *(double factor, Angle a)
Parameters
Returns
operator -(Angle, Angle)
Subtracts one angle from another.
public static Angle operator -(Angle a, Angle b)
Parameters
Returns
operator -(Angle)
Negates an angle.
public static Angle operator -(Angle a)
Parameters
aAngle