Enroute Flight Navigation
A navigation app for VFR pilots
Units::Distance Class Reference

Convenience class for distance computations. More...

#include <Distance.h>

Public Types

enum  DistanceUnit : quint8
 Units of measurement for distances.
 

Public Member Functions

Q_INVOKABLE Units::Distanceoperator+= (Units::Distance other)
 Add distance to this distance.
 
Q_INVOKABLE bool isFinite () const
 Checks if the distance is valid.
 
Q_INVOKABLE bool isNegative () const
 Checks if the distance is negative.
 
Q_INVOKABLE Units::Distance operator+ (Units::Distance rhs) const
 Addition.
 
Q_INVOKABLE Units::Distance operator- (Units::Distance rhs) const
 Subtraction.
 
Q_INVOKABLE Units::Distance subtract (Units::Distance rhs) const
 Subtraction.
 
Q_INVOKABLE Units::Distance operator* (double factor) const
 Scaling.
 
Q_INVOKABLE std::partial_ordering operator<=> (const Units::Distance &rhs) const =default
 Comparison.
 
Q_INVOKABLE double toFeet () const
 Convert to feet.
 
Q_INVOKABLE double toKM () const
 Convert to meters.
 
Q_INVOKABLE double toM () const
 Convert to meters.
 
Q_INVOKABLE double toMIL () const
 Convert to international miles.
 
Q_INVOKABLE double toNM () const
 Convert to nautical miles.
 
Q_INVOKABLE QString toString (Units::Distance::DistanceUnit units, bool roundBigNumbers=false, bool forceSign=false) const
 Convert to string.
 

Static Public Member Functions

static Q_INVOKABLE constexpr Units::Distance fromM (double distanceInM)
 Constructs a distance.
 
static Q_INVOKABLE constexpr Units::Distance fromKM (double distanceInKM)
 Constructs a distance.
 
static Q_INVOKABLE constexpr Units::Distance fromNM (double distanceInNM)
 Constructs a distance.
 
static Q_INVOKABLE constexpr Units::Distance fromMIL (double distanceInMIL)
 Constructs a distance.
 
static Q_INVOKABLE constexpr Units::Distance fromFT (double distanceInFT)
 Constructs a distance.
 
static Q_INVOKABLE constexpr Units::Distance nan ()
 Constructs an invalid distance.
 

Detailed Description

Convenience class for distance computations.

This extremely simple class allows computation with distances, without the need to worry about units. On construction, the distance is set to NaN.

Definition at line 35 of file Distance.h.

Member Function Documentation

◆ fromFT()

static Q_INVOKABLE constexpr Units::Distance Units::Distance::fromFT ( double distanceInFT)
inlinestaticconstexpr

Constructs a distance.

Parameters
distanceInFTdistance in feet
Returns
distance

Definition at line 108 of file Distance.h.

◆ fromKM()

static Q_INVOKABLE constexpr Units::Distance Units::Distance::fromKM ( double distanceInKM)
inlinestaticconstexpr

Constructs a distance.

Parameters
distanceInKMdistance in kilometers
Returns
distance

Definition at line 69 of file Distance.h.

◆ fromM()

static Q_INVOKABLE constexpr Units::Distance Units::Distance::fromM ( double distanceInM)
inlinestaticconstexpr

Constructs a distance.

Parameters
distanceInMdistance in meters
Returns
distance

Definition at line 56 of file Distance.h.

◆ fromMIL()

static Q_INVOKABLE constexpr Units::Distance Units::Distance::fromMIL ( double distanceInMIL)
inlinestaticconstexpr

Constructs a distance.

Parameters
distanceInMILdistance in international miles
Returns
distance

Definition at line 95 of file Distance.h.

◆ fromNM()

static Q_INVOKABLE constexpr Units::Distance Units::Distance::fromNM ( double distanceInNM)
inlinestaticconstexpr

Constructs a distance.

Parameters
distanceInNMdistance in nautical miles
Returns
distance

Definition at line 82 of file Distance.h.

◆ isFinite()

Q_INVOKABLE bool Units::Distance::isFinite ( ) const
inlinenodiscard

Checks if the distance is valid.

Returns
True is the distance is a finite number

Definition at line 140 of file Distance.h.

◆ isNegative()

Q_INVOKABLE bool Units::Distance::isNegative ( ) const
inlinenodiscard

Checks if the distance is negative.

Returns
True is the distance is negative

Definition at line 149 of file Distance.h.

◆ nan()

static Q_INVOKABLE constexpr Units::Distance Units::Distance::nan ( )
inlinestaticconstexpr

Constructs an invalid distance.

Returns
Invalid distance

Definition at line 119 of file Distance.h.

◆ operator*()

Q_INVOKABLE Units::Distance Units::Distance::operator* ( double factor) const
inlinenodiscard

Scaling.

Parameters
factorFactor of scaling
Returns
Result of the scaling

Definition at line 193 of file Distance.h.

◆ operator+()

Q_INVOKABLE Units::Distance Units::Distance::operator+ ( Units::Distance rhs) const
inlinenodiscard

Addition.

Parameters
rhsRight hand side of the addition
Returns
Result of the addition

Definition at line 160 of file Distance.h.

◆ operator+=()

Q_INVOKABLE Units::Distance & Units::Distance::operator+= ( Units::Distance other)
inline

Add distance to this distance.

Parameters
otherdistance to be added
Returns
reference to this distance

Definition at line 130 of file Distance.h.

◆ operator-()

Q_INVOKABLE Units::Distance Units::Distance::operator- ( Units::Distance rhs) const
inlinenodiscard

Subtraction.

Parameters
rhsRight hand side of the subtraction
Returns
Result of the subtraction

Definition at line 171 of file Distance.h.

◆ operator<=>()

Q_INVOKABLE std::partial_ordering Units::Distance::operator<=> ( const Units::Distance & rhs) const
nodiscarddefault

Comparison.

Parameters
rhsRight hand side of the comparison
Returns
Result of the comparison

◆ subtract()

Q_INVOKABLE Units::Distance Units::Distance::subtract ( Units::Distance rhs) const
inlinenodiscard

Subtraction.

Parameters
rhsRight hand side of the subtraction
Returns
Result of the subtraction

Definition at line 182 of file Distance.h.

◆ toFeet()

Q_INVOKABLE double Units::Distance::toFeet ( ) const
inlinenodiscard

Convert to feet.

Returns
distance in feet

Definition at line 210 of file Distance.h.

◆ toKM()

Q_INVOKABLE double Units::Distance::toKM ( ) const
inlinenodiscard

Convert to meters.

Returns
distance in meters

Definition at line 219 of file Distance.h.

◆ toM()

Q_INVOKABLE double Units::Distance::toM ( ) const
inlinenodiscard

Convert to meters.

Returns
distance in meters

Definition at line 228 of file Distance.h.

◆ toMIL()

Q_INVOKABLE double Units::Distance::toMIL ( ) const
inlinenodiscard

Convert to international miles.

Returns
distance in international miles

Definition at line 237 of file Distance.h.

◆ toNM()

Q_INVOKABLE double Units::Distance::toNM ( ) const
inlinenodiscard

Convert to nautical miles.

Returns
distance in nautical miles

Definition at line 246 of file Distance.h.

◆ toString()

Q_INVOKABLE QString Units::Distance::toString ( Units::Distance::DistanceUnit units,
bool roundBigNumbers = false,
bool forceSign = false ) const
nodiscard

Convert to string.

This method converts the distance to string that is fit for human consumption, of the form "10.9 nm", "130 ft" or "3500 m". The distance is rounded to reasonable precision.

Parameters
unitsDetermines the units that are used.
roundBigNumbersIf true, then round "1234" to "1200" and "117" to "120"
forceSignIf 'true', then positive distances are prepended by a "+" sign.
Returns
A string that describes the distance, or an empty string if no reasonable distance is set.

The documentation for this class was generated from the following file: