37 QML_VALUE_TYPE(distance)
59 result.m_distanceInM = distanceInM;
72 result.m_distanceInM = 1000.0*distanceInKM;
85 result.m_distanceInM = distanceInNM*MetersPerNauticalMile;
98 result.m_distanceInM = distanceInMIL*MetersPerMile;
111 result.m_distanceInM = distanceInFT * MetersPerFeet;
132 m_distanceInM += other.m_distanceInM;
142 return std::isfinite(m_distanceInM);
151 return m_distanceInM < 0.0;
162 return fromM(m_distanceInM + rhs.m_distanceInM);
173 return fromM(m_distanceInM - rhs.m_distanceInM);
184 return fromM(m_distanceInM - rhs.m_distanceInM);
195 return fromM(m_distanceInM*factor);
210 [[nodiscard]] Q_INVOKABLE
double toFeet()
const
212 return m_distanceInM / MetersPerFeet;
219 [[nodiscard]] Q_INVOKABLE
double toKM()
const
221 return m_distanceInM / 1000.;
228 [[nodiscard]] Q_INVOKABLE
double toM()
const
230 return m_distanceInM;
237 [[nodiscard]] Q_INVOKABLE
double toMIL()
const
239 return m_distanceInM / MetersPerMile;
246 [[nodiscard]] Q_INVOKABLE
double toNM()
const
248 return m_distanceInM / MetersPerNauticalMile;
269 static constexpr double MetersPerFeet = 0.3048;
270 static constexpr double MetersPerNauticalMile = 1852;
271 static constexpr double MetersPerMile = 1609.344;
274 double m_distanceInM{ NAN };
280QDataStream& operator<<(QDataStream& stream,
const Units::Distance& distance);
283QDataStream& operator>>(QDataStream& stream,
Units::Distance& distance);
Convenience class for distance computations.
static Q_INVOKABLE constexpr Units::Distance fromNM(double distanceInNM)
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.
Q_INVOKABLE double toFeet() const
Convert to feet.
static Q_INVOKABLE constexpr Units::Distance fromM(double distanceInM)
Constructs a distance.
DistanceUnit
Units of measurement for distances.
Q_INVOKABLE Units::Distance subtract(Units::Distance rhs) const
Subtraction.
Q_INVOKABLE Units::Distance operator+(Units::Distance rhs) const
Addition.
Q_INVOKABLE Units::Distance operator*(double factor) const
Scaling.
Q_INVOKABLE double toM() const
Convert to meters.
static Q_INVOKABLE constexpr Units::Distance fromKM(double distanceInKM)
Constructs a distance.
Q_INVOKABLE Units::Distance & operator+=(Units::Distance other)
Add distance to this distance.
Q_INVOKABLE QString toString(Units::Distance::DistanceUnit units, bool roundBigNumbers=false, bool forceSign=false) const
Convert to string.
Q_INVOKABLE Units::Distance operator-(Units::Distance rhs) const
Subtraction.
Q_INVOKABLE bool isNegative() const
Checks if the distance is negative.
Q_INVOKABLE double toKM() const
Convert to meters.
Q_INVOKABLE std::partial_ordering operator<=>(const Units::Distance &rhs) const =default
Comparison.
static Q_INVOKABLE constexpr Units::Distance fromMIL(double distanceInMIL)
Constructs a distance.
Q_INVOKABLE bool isFinite() const
Checks if the distance is valid.
Q_INVOKABLE double toNM() const
Convert to nautical miles.
Q_INVOKABLE double toMIL() const
Convert to international miles.
Conversion between units used in aviation.