mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Completed transformation class and created samples for this class
This commit is contained in:
@@ -26,8 +26,18 @@ int CSamplesGeo::samples()
|
||||
// lat3 = lon1; //must not work
|
||||
// CGeoLongitude lonx(lat2); // must notwork
|
||||
|
||||
CCoordinateGeodetic gc(10.0, 20.0, 1000);
|
||||
qDebug() << gc;
|
||||
CCoordinateGeodetic cg(10.0, 20.0, 1000);
|
||||
CCoordinateEcef ce = CCoordinateTransformation::toEcef(cg);
|
||||
CCoordinateGeodetic cg2 = CCoordinateTransformation::toGeodetic(ce);
|
||||
cg2.switchUnit(CAngleUnit::deg());
|
||||
qDebug() << cg << ce << cg2;
|
||||
|
||||
CCoordinateNed cned = CCoordinateTransformation::toNed(ce, cg);
|
||||
CCoordinateEcef ce2 = CCoordinateTransformation::toEcef(cned);
|
||||
qDebug() << ce << cned << ce2;
|
||||
qDebug() << (cned + cned) << (ce + ce);
|
||||
|
||||
// cned += ce2; // must not work
|
||||
|
||||
// bye
|
||||
qDebug() << "-----------------------------------------------";
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / authors
|
||||
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef BLACKMISCTEST_SAMPLESGEO_H
|
||||
#define BLACKMISCTEST_SAMPLESGEO_H
|
||||
#include "blackmisc/coordinategeodetic.h"
|
||||
#include "blackmisc/coordinatetransformation.h"
|
||||
|
||||
namespace BlackMiscTest
|
||||
{
|
||||
|
||||
@@ -96,8 +96,20 @@ public:
|
||||
*/
|
||||
BlackMisc::Math::CVector3D toMathVector() const
|
||||
{
|
||||
return BlackMisc::Math::CVector3D(this->z(), this->y(), this->x());
|
||||
return BlackMisc::Math::CVector3D(this->x(), this->y(), this->z());
|
||||
}
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* \brief String for converter
|
||||
* \return
|
||||
*/
|
||||
virtual QString stringForConverter() const
|
||||
{
|
||||
QString s = "ECEF: {x %1, y %2, z %3}";
|
||||
return s.arg(this->x()).arg(this->y()).arg(this->z());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / authors
|
||||
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
@@ -33,8 +33,8 @@ protected:
|
||||
*/
|
||||
virtual QString stringForConverter() const
|
||||
{
|
||||
QString s = "{%1, %2, %3}";
|
||||
return s.arg(this->m_latitude).arg(this->m_longitude).arg(this->height());
|
||||
QString s = "Geodetic: {%1, %2, %3}";
|
||||
return s.arg(this->m_latitude.unitValueRoundedWithUnit()).arg(this->m_longitude.unitValueRoundedWithUnit()).arg(this->m_height.unitValueRoundedWithUnit());
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -67,7 +67,6 @@ public:
|
||||
CCoordinateGeodetic(qreal latitudeDegrees, qreal longitudeDegrees, qreal heightMeters) :
|
||||
m_latitude(latitudeDegrees, BlackMisc::PhysicalQuantities::CAngleUnit::deg()), m_longitude(longitudeDegrees, BlackMisc::PhysicalQuantities::CAngleUnit::deg()), m_height(heightMeters, BlackMisc::PhysicalQuantities::CLengthUnit::m()) {}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Latitude
|
||||
* \return
|
||||
@@ -95,6 +94,25 @@ public:
|
||||
return this->m_height;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Switch unit of latitude / longitude
|
||||
* \param unit
|
||||
*/
|
||||
void switchUnit(const BlackMisc::PhysicalQuantities::CAngleUnit &unit)
|
||||
{
|
||||
this->m_latitude.switchUnit(unit);
|
||||
this->m_longitude.switchUnit(unit);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Switch unit of height
|
||||
* \param unit
|
||||
*/
|
||||
void switchUnit(const BlackMisc::PhysicalQuantities::CLengthUnit &unit)
|
||||
{
|
||||
this->m_height.switchUnit(unit);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Set latitude
|
||||
* \param latitude
|
||||
|
||||
@@ -23,6 +23,17 @@ private:
|
||||
CCoordinateGeodetic m_referencePosition; //!< geodetic reference position
|
||||
bool m_hasReferencePosition; //!< valid reference position?
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* \brief String for converter
|
||||
* \return
|
||||
*/
|
||||
virtual QString stringForConverter() const
|
||||
{
|
||||
QString s = "NED: {N %1, E %2, D %3}";
|
||||
return s.arg(this->north()).arg(this->east()).arg(this->down());
|
||||
}
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief Default constructor
|
||||
|
||||
@@ -60,13 +60,49 @@ CCoordinateEcef CCoordinateTransformation::toEcef(const CCoordinateNed &ned)
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert to NED
|
||||
* Geodetic to ECEF
|
||||
*/
|
||||
CCoordinateNed toNed(const CCoordinateEcef &ecef, const CCoordinateGeodetic &geo)
|
||||
CCoordinateEcef CCoordinateTransformation::toEcef(const CCoordinateGeodetic &geo)
|
||||
{
|
||||
// TODO: Clarify the comparions with fixed angles (==90, ==180) -> what happens here
|
||||
|
||||
CLatitude lat = geo.latitude();
|
||||
CLongitude lon = geo.longitude();
|
||||
qreal latDeg = lat.value(CAngleUnit::deg());
|
||||
qreal lonDeg = lon.value(CAngleUnit::deg());
|
||||
|
||||
double phi = lat.value(CAngleUnit::rad());
|
||||
double lambdaRad = lon.value(CAngleUnit::rad());
|
||||
double sphi = sin(phi);
|
||||
double cphi = 0;
|
||||
if (abs(latDeg) != 90) cphi = cos(phi);
|
||||
|
||||
double n = EarthRadiusMeters() / sqrt(1 - e2() * CMath::square(sphi));
|
||||
|
||||
double slambda = 0;
|
||||
if (lonDeg != -180) slambda = sin(lambdaRad);
|
||||
|
||||
double clambda = 0;
|
||||
if (abs(lonDeg) != 90) clambda = cos(lambdaRad);
|
||||
|
||||
double h = geo.height().convertedSiValueToDouble();
|
||||
double X = (n + h) * cphi;
|
||||
double Y = X * slambda;
|
||||
X *= clambda;
|
||||
double Z = (e2m() * n + h) * sphi;
|
||||
|
||||
CCoordinateEcef result(X, Y, Z);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert to NED
|
||||
*/
|
||||
CCoordinateNed CCoordinateTransformation::toNed(const CCoordinateEcef &ecef, const CCoordinateGeodetic &referencePosition)
|
||||
{
|
||||
|
||||
CLatitude lat = referencePosition.latitude();
|
||||
CLongitude lon = referencePosition.longitude();
|
||||
double angleRad = - (lat.value(CAngleUnit::rad())) - BlackMisc::Math::PI / 2;
|
||||
|
||||
CMatrix3x3 dcm1;
|
||||
@@ -91,7 +127,7 @@ CCoordinateNed toNed(const CCoordinateEcef &ecef, const CCoordinateGeodetic &geo
|
||||
dcm = dcm1 * dcm2 * dcm3;
|
||||
|
||||
CVector3D tempResult = dcm * ecef.toMathVector(); // to generic vector
|
||||
CCoordinateNed result(geo, tempResult);
|
||||
CCoordinateNed result(referencePosition, tempResult);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ private:
|
||||
*/
|
||||
static const qreal &Flattening()
|
||||
{
|
||||
static qreal f = 1/298.257223563;
|
||||
static qreal f = 1 / 298.257223563;
|
||||
return f;
|
||||
}
|
||||
|
||||
@@ -105,11 +105,19 @@ public:
|
||||
static CCoordinateEcef toEcef(const CCoordinateNed &ned);
|
||||
|
||||
/*!
|
||||
* \brief ECEF via Geodetic to NED
|
||||
* \brief Geodetic to ECEF
|
||||
* \param geo
|
||||
* \return
|
||||
*/
|
||||
static CCoordinateNed toNed(const CCoordinateEcef &ecef, const CCoordinateGeodetic &geo);
|
||||
static CCoordinateEcef toEcef(const CCoordinateGeodetic &geo);
|
||||
|
||||
/*!
|
||||
* \brief ECEF via Geodetic to NED
|
||||
* \param ecef
|
||||
* \param referencePosition
|
||||
* \return
|
||||
*/
|
||||
static CCoordinateNed toNed(const CCoordinateEcef &ecef, const CCoordinateGeodetic &referencePosition);
|
||||
|
||||
/*!
|
||||
* \brief ECEF to Geodetic
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
return M_PI;
|
||||
}
|
||||
/*!
|
||||
* \brief Value as factor of PI (e.g.0.5PI)
|
||||
* \brief Value as factor of PI (e.g. 0.5PI)
|
||||
* \return
|
||||
*/
|
||||
double piFactor() const {
|
||||
|
||||
@@ -164,7 +164,7 @@ public:
|
||||
QString valueRoundedWithUnit(const MU &unit, int digits = -1) const;
|
||||
|
||||
/*!
|
||||
* \brief Value a int
|
||||
* \brief Value as int
|
||||
* \return
|
||||
*/
|
||||
qint32 unitValueToInteger() const
|
||||
@@ -173,7 +173,7 @@ public:
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Value a double
|
||||
* \brief Value as double
|
||||
* \return
|
||||
*/
|
||||
double unitValueToDouble() const
|
||||
@@ -188,24 +188,6 @@ public:
|
||||
*/
|
||||
QString unitValueRoundedWithUnit(int digits = -1) const;
|
||||
|
||||
/*!
|
||||
* \brief SI value to integer
|
||||
* \return
|
||||
*/
|
||||
qint32 siBaseUnitValueToInteger() const
|
||||
{
|
||||
return CMeasurementUnit::round(this->m_convertedSiUnitValueD, 0);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief SI value to double
|
||||
* \return
|
||||
*/
|
||||
double siBaseUnitValueToDouble() const
|
||||
{
|
||||
return this->m_convertedSiUnitValueD;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Rounded value by n digits
|
||||
* \param digits
|
||||
@@ -221,7 +203,7 @@ public:
|
||||
QString unitValueToQStringRounded(int digits = -1) const;
|
||||
|
||||
/*!
|
||||
* \brief SI value as double
|
||||
* \brief Conversion SI value as double
|
||||
* \return
|
||||
*/
|
||||
double convertedSiValueToDouble() const
|
||||
@@ -391,4 +373,4 @@ public:
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
#endif // BLACKMISC_PQPHYSICALQUANTITY_H
|
||||
#endif // guard
|
||||
|
||||
@@ -27,15 +27,15 @@ private:
|
||||
* \brief Constructor Distance unit
|
||||
* \param name
|
||||
* \param unitName
|
||||
* \param isSIUnit
|
||||
* \param isSiUnit
|
||||
* \param isSIBaseUnit
|
||||
* \param conversionFactorToSI
|
||||
* \param mulitplier
|
||||
* \param displayDigits
|
||||
* \param epsilon
|
||||
*/
|
||||
CLengthUnit(const QString &name, const QString &unitName, bool isSIUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "distance", isSIUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon)
|
||||
CLengthUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "distance", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon)
|
||||
{
|
||||
// void
|
||||
}
|
||||
@@ -111,17 +111,17 @@ private:
|
||||
* \brief Constructor angle units: Radian, degree
|
||||
* \param name
|
||||
* \param unitName
|
||||
* \param isSIUnit
|
||||
* \param isSiUnit
|
||||
* \param conversionFactorToSI
|
||||
* \param mulitplier
|
||||
* \param multiplier
|
||||
* \param displayDigits
|
||||
* \param epsilon
|
||||
*/
|
||||
CAngleUnit(const QString &name, const QString &unitName, bool isSIUnit, double conversionFactorToSI = 1.0,
|
||||
const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2,
|
||||
CAngleUnit(const QString &name, const QString &unitName, bool isSiUnit, double conversionFactorToSI = 1.0,
|
||||
const CMeasurementPrefix &multiplier = CMeasurementPrefix::One(), qint32 displayDigits = 2,
|
||||
double epsilon = 1E-9, UnitConverter converterToSi = nullptr, UnitConverter converterFromSi = nullptr) :
|
||||
CMeasurementUnit(name, unitName, "angle", isSIUnit, false, conversionFactorToSI,
|
||||
mulitplier, displayDigits, epsilon, converterToSi, converterFromSi)
|
||||
CMeasurementUnit(name, unitName, "angle", isSiUnit, false, conversionFactorToSI,
|
||||
multiplier, displayDigits, epsilon, converterToSi, converterFromSi)
|
||||
{
|
||||
// void
|
||||
}
|
||||
@@ -192,14 +192,14 @@ private:
|
||||
* \brief CFrequencyUnit
|
||||
* \param name
|
||||
* \param unitName
|
||||
* \param isSIUnit
|
||||
* \param isSiUnit
|
||||
* \param conversionFactorToSI
|
||||
* \param mulitplier
|
||||
* \param displayDigits
|
||||
* \param epsilon
|
||||
*/
|
||||
CFrequencyUnit(const QString &name, const QString &unitName, bool isSIUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "frequency", isSIUnit, false, conversionFactorToSI, mulitplier, displayDigits, epsilon) {}
|
||||
CFrequencyUnit(const QString &name, const QString &unitName, bool isSiUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "frequency", isSiUnit, false, conversionFactorToSI, mulitplier, displayDigits, epsilon) {}
|
||||
public:
|
||||
/*!
|
||||
* \brief Copy constructor
|
||||
@@ -258,15 +258,15 @@ private:
|
||||
* \brief Constructor mass units
|
||||
* \param name
|
||||
* \param unitName
|
||||
* \param isSIUnit
|
||||
* \param isSiUnit
|
||||
* \param isSIBaseUnit
|
||||
* \param conversionFactorToSI
|
||||
* \param mulitplier
|
||||
* \param displayDigits
|
||||
* \param epsilon
|
||||
*/
|
||||
CMassUnit(const QString &name, const QString &unitName, bool isSIUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "mass", isSIUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {}
|
||||
CMassUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "mass", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {}
|
||||
public:
|
||||
/*!
|
||||
* \brief Copy constructor
|
||||
@@ -326,14 +326,14 @@ private:
|
||||
* \brief Pressure unit
|
||||
* \param name
|
||||
* \param unitName
|
||||
* \param isSIUnit
|
||||
* \param isSiUnit
|
||||
* \param conversionFactorToSI
|
||||
* \param mulitplier
|
||||
* \param displayDigits
|
||||
* \param epsilon
|
||||
*/
|
||||
CPressureUnit(const QString &name, const QString &unitName, bool isSIUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "frequency", isSIUnit, false, conversionFactorToSI, mulitplier, displayDigits, epsilon) {}
|
||||
CPressureUnit(const QString &name, const QString &unitName, bool isSiUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "frequency", isSiUnit, false, conversionFactorToSI, mulitplier, displayDigits, epsilon) {}
|
||||
public:
|
||||
/*!
|
||||
* \brief Copy constructor
|
||||
@@ -421,7 +421,7 @@ private:
|
||||
* Constructor temperature unit
|
||||
* \param name
|
||||
* \param unitName
|
||||
* \param isSIUnit
|
||||
* \param isSiUnit
|
||||
* \param isSIBaseUnit
|
||||
* \param conversionFactorToSI
|
||||
* \param temperatureOffsetToSI
|
||||
@@ -429,8 +429,8 @@ private:
|
||||
* \param displayDigits
|
||||
* \param epsilon
|
||||
*/
|
||||
CTemperatureUnit(const QString &name, const QString &unitName, bool isSIUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, double temperatureOffsetToSI = 0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "temperature", isSIUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon), m_conversionOffsetToSi(temperatureOffsetToSI) {}
|
||||
CTemperatureUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, double temperatureOffsetToSI = 0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "temperature", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon), m_conversionOffsetToSi(temperatureOffsetToSI) {}
|
||||
protected:
|
||||
/*!
|
||||
* \brief Convert to SI conversion unit, specific for temperature
|
||||
@@ -501,15 +501,15 @@ private:
|
||||
* \brief Speed unit constructor
|
||||
* \param name
|
||||
* \param unitName
|
||||
* \param isSIUnit
|
||||
* \param isSiUnit
|
||||
* \param isSIBaseUnit
|
||||
* \param conversionFactorToSI
|
||||
* \param mulitplier
|
||||
* \param displayDigits
|
||||
* \param epsilon
|
||||
*/
|
||||
CSpeedUnit(const QString &name, const QString &unitName, bool isSIUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "speed", isSIUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {}
|
||||
CSpeedUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "speed", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {}
|
||||
public:
|
||||
/*!
|
||||
* Constructor, allows to implement methods in base class
|
||||
@@ -584,15 +584,15 @@ private:
|
||||
* \brief Time unit constructor
|
||||
* \param name
|
||||
* \param unitName
|
||||
* \param isSIUnit
|
||||
* \param isSiUnit
|
||||
* \param isSIBaseUnit
|
||||
* \param conversionFactorToSI
|
||||
* \param mulitplier
|
||||
* \param displayDigits
|
||||
* \param epsilon
|
||||
*/
|
||||
CTimeUnit(const QString &name, const QString &unitName, bool isSIUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "time", isSIUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {}
|
||||
CTimeUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "time", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {}
|
||||
public:
|
||||
/*!
|
||||
* Constructor, allows to implement methods in base class
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / authors
|
||||
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
@@ -7,7 +7,8 @@
|
||||
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackMiscTest {
|
||||
namespace BlackMiscTest
|
||||
{
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
@@ -43,16 +44,16 @@ void CTestPhysicalQuantitiesBase::unitsBasics()
|
||||
*/
|
||||
void CTestPhysicalQuantitiesBase::lengthBasics()
|
||||
{
|
||||
CLength d1(1,CLengthUnit::m()); // 1m
|
||||
CLength d1(1, CLengthUnit::m()); // 1m
|
||||
CLength d2(100, CLengthUnit::cm());
|
||||
CLength d3(1.852 * 1000,CLengthUnit::m()); // 1852m
|
||||
CLength d4(1,CLengthUnit::NM());
|
||||
CLength d3(1.852 * 1000, CLengthUnit::m()); // 1852m
|
||||
CLength d4(1, CLengthUnit::NM());
|
||||
|
||||
QVERIFY2(d1 == d2, "1meter shall be 100cm");
|
||||
QVERIFY2(d3 == d4, "1852meters shall be 1NM");
|
||||
|
||||
d3 *=2; // SI value
|
||||
d4 *=2.0; // SI value !
|
||||
d3 *= 2; // SI value
|
||||
d4 *= 2.0; // SI value !
|
||||
QVERIFY2(d3 == d4, "2*1852meters shall be 2NM");
|
||||
|
||||
// less / greater
|
||||
@@ -76,8 +77,8 @@ void CTestPhysicalQuantitiesBase::speedBasics()
|
||||
{
|
||||
CSpeed s1(100, CSpeedUnit::km_h());
|
||||
CSpeed s2(1000, CSpeedUnit::ft_min());
|
||||
QVERIFY2(s1.valueRounded(CSpeedUnit::NM_h(),0) == 54, qPrintable(QString("100km/h is not %1 NM/h").arg(s1.valueRounded(CSpeedUnit::NM_h(),0))));
|
||||
QVERIFY2(s2.valueRounded(CSpeedUnit::m_s(),1) == 5.1, qPrintable(QString("1000ft/min is not %1 m/s").arg(s2.valueRounded(CSpeedUnit::m_s(),1))));
|
||||
QVERIFY2(s1.valueRounded(CSpeedUnit::NM_h(), 0) == 54, qPrintable(QString("100km/h is not %1 NM/h").arg(s1.valueRounded(CSpeedUnit::NM_h(), 0))));
|
||||
QVERIFY2(s2.valueRounded(CSpeedUnit::m_s(), 1) == 5.1, qPrintable(QString("1000ft/min is not %1 m/s").arg(s2.valueRounded(CSpeedUnit::m_s(), 1))));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -86,10 +87,10 @@ void CTestPhysicalQuantitiesBase::speedBasics()
|
||||
void CTestPhysicalQuantitiesBase::frequencyTests()
|
||||
{
|
||||
CFrequency f1(1, CFrequencyUnit::MHz());
|
||||
QVERIFY2(f1.valueRounded(CFrequencyUnit::kHz(),2) == 1000, "Mega is 1000kHz");
|
||||
QVERIFY2(f1.valueRounded(CFrequencyUnit::kHz(), 2) == 1000, "Mega is 1000kHz");
|
||||
QVERIFY2(f1.unitValueToDouble() == 1 , "1MHz");
|
||||
QVERIFY2(f1.siBaseUnitValueToDouble() == 1000000 , "1E6 Hz");
|
||||
CFrequency f2(CMeasurementPrefix::M(),CFrequencyUnit::Hz()) ; // 1 Megahertz
|
||||
QVERIFY2(f1.convertedSiValueToDouble() == 1000000 , "1E6 Hz");
|
||||
CFrequency f2(CMeasurementPrefix::M(), CFrequencyUnit::Hz()) ; // 1 Megahertz
|
||||
QVERIFY2(f1 == f2 , "MHz is 1E6 Hz");
|
||||
}
|
||||
|
||||
@@ -100,7 +101,7 @@ void CTestPhysicalQuantitiesBase::angleTests()
|
||||
{
|
||||
CAngle a1(180, CAngleUnit::deg());
|
||||
CAngle a2(1.5 * CAngle::pi(), CAngleUnit::rad());
|
||||
CAngle a3(35.4336,CAngleUnit::sexagesimalDeg()); // 35.72666
|
||||
CAngle a3(35.4336, CAngleUnit::sexagesimalDeg()); // 35.72666
|
||||
a2.switchUnit(CAngleUnit::deg());
|
||||
QVERIFY2(a2.unitValueToInteger() == 270, qPrintable(QString("1.5Pi should be 270deg, not %1 deg").arg(a2.unitValueToInteger())));
|
||||
QVERIFY2(a1.piFactor() == 1, qPrintable(QString("Pi should be 1PI, not %1").arg(a1.piFactor())));
|
||||
@@ -127,8 +128,8 @@ void CTestPhysicalQuantitiesBase::massTests()
|
||||
void CTestPhysicalQuantitiesBase::pressureTests()
|
||||
{
|
||||
CPressure p1(1013.25, CPressureUnit::hPa());
|
||||
CPressure p2(29.92,CPressureUnit::inHg());
|
||||
CPressure p3(29.92,CPressureUnit::inHgFL());
|
||||
CPressure p2(29.92, CPressureUnit::inHg());
|
||||
CPressure p3(29.92, CPressureUnit::inHgFL());
|
||||
CPressure p4(p1);
|
||||
p4.switchUnit(CPressureUnit::mbar());
|
||||
|
||||
@@ -159,7 +160,7 @@ void CTestPhysicalQuantitiesBase::temperatureTests()
|
||||
void CTestPhysicalQuantitiesBase::timeTests()
|
||||
{
|
||||
CTime t1(1, CTimeUnit::h());
|
||||
QVERIFY2(t1.siBaseUnitValueToInteger() == 3600, "1hour shall be 3600s");
|
||||
QVERIFY2(t1.convertedSiValueToInteger() == 3600, "1hour shall be 3600s");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -167,13 +168,13 @@ void CTestPhysicalQuantitiesBase::timeTests()
|
||||
*/
|
||||
void CTestPhysicalQuantitiesBase::memoryTests()
|
||||
{
|
||||
CLength* c = new CLength(100, CLengthUnit::m());
|
||||
CLength *c = new CLength(100, CLengthUnit::m());
|
||||
c->switchUnit(CLengthUnit::NM());
|
||||
QVERIFY2(c->getUnit() == CLengthUnit::NM() && c->getConversionSiUnit() == CLengthUnit::m(),
|
||||
"Testing distance units failed");
|
||||
delete c;
|
||||
|
||||
CAngle* a = new CAngle(100, CAngleUnit::rad());
|
||||
CAngle *a = new CAngle(100, CAngleUnit::rad());
|
||||
a->switchUnit(CAngleUnit::deg());
|
||||
QVERIFY2(a->getUnit() == CAngleUnit::deg() && c->getConversionSiUnit() == CAngleUnit::rad(),
|
||||
"Testing angle units failed");
|
||||
|
||||
Reference in New Issue
Block a user