diff --git a/samples/blackmiscquantities/sample_quantities_avionics.pro b/samples/blackmiscquantities/sample_quantities_avionics.pro index a69afcd41..59cf6ab98 100644 --- a/samples/blackmiscquantities/sample_quantities_avionics.pro +++ b/samples/blackmiscquantities/sample_quantities_avionics.pro @@ -10,10 +10,6 @@ CONFIG -= app_bundle DEPENDPATH += . ../../src/blackmisc INCLUDEPATH += . ../../src -SOURCES += main.cpp \ - samplesphysicalquantities.cpp \ - samplesaviation.cpp - win32-msvc* { PRE_TARGETDEPS += ../../lib/blackmisc.lib LIBS += ../../lib/blackmisc.lib @@ -26,6 +22,5 @@ win32-msvc* { DESTDIR = ../../bin -HEADERS += \ - samplesphysicalquantities.h \ - samplesaviation.h +HEADERS += *.h +SOURCES += *.cpp diff --git a/samples/blackmiscquantities/samplesphysicalquantities.cpp b/samples/blackmiscquantities/samplesphysicalquantities.cpp index 6594cc157..0a88b6be5 100644 --- a/samples/blackmiscquantities/samplesphysicalquantities.cpp +++ b/samples/blackmiscquantities/samplesphysicalquantities.cpp @@ -110,6 +110,9 @@ int CSamplesPhysicalQuantities::samples() ti2.switchUnit(CTimeUnit::ms()); qDebug() << ti1 << ti2; + CAcceleration ac1(10, CAccelerationUnit::m_s2()); + qDebug() << ac1; + // bye qDebug() << "-----------------------------------------------"; return 0; diff --git a/samples/blackmiscvectorgeo/samplesvectormatrix.h b/samples/blackmiscvectorgeo/samplesvectormatrix.h index 5e2495375..2af44df54 100644 --- a/samples/blackmiscvectorgeo/samplesvectormatrix.h +++ b/samples/blackmiscvectorgeo/samplesvectormatrix.h @@ -26,4 +26,4 @@ private: }; } // namespace -#endif +#endif // guard diff --git a/src/blackmisc/blackmisc.pro b/src/blackmisc/blackmisc.pro index f2be19eb4..ffa483da8 100644 --- a/src/blackmisc/blackmisc.pro +++ b/src/blackmisc/blackmisc.pro @@ -5,19 +5,16 @@ TEMPLATE = lib CONFIG += staticlib INCLUDEPATH += .. - # DEPENDPATH += . .. // BlackMisc should be independent -# PRECOMPILED_HEADER = stdpch.h +# PRECOMPILED_HEADER = stdpch.h precompile_header:!isEmpty(PRECOMPILED_HEADER) { DEFINES += USING_PCH } DEFINES += LOG_IN_FILE -HEADERS += *.h \ - pqacceleration.h - +HEADERS += *.h SOURCES += *.cpp DESTDIR = ../../lib diff --git a/src/blackmisc/mathmatrix3x3.h b/src/blackmisc/mathmatrix3x3.h index 970c09d8c..4291d5265 100644 --- a/src/blackmisc/mathmatrix3x3.h +++ b/src/blackmisc/mathmatrix3x3.h @@ -166,10 +166,10 @@ public: /*! * \brief Get row - * \param column + * \param row * \return */ - CMatrix1x3 getRow(int column) const; + CMatrix1x3 getRow(int row) const; }; diff --git a/src/blackmisc/mathvector3dbase.h b/src/blackmisc/mathvector3dbase.h index b0a421550..1dfd1f6ba 100644 --- a/src/blackmisc/mathvector3dbase.h +++ b/src/blackmisc/mathvector3dbase.h @@ -375,7 +375,7 @@ public: */ double length()const { - return this->m_i * this->m_j + this->m_k; + return this->m_i + this->m_j + this->m_k; } /*! diff --git a/src/blackmisc/pqallquantities.h b/src/blackmisc/pqallquantities.h index a56d9844d..0381c0b60 100644 --- a/src/blackmisc/pqallquantities.h +++ b/src/blackmisc/pqallquantities.h @@ -1,5 +1,10 @@ -#ifndef PQUNITSALL_H -#define PQUNITSALL_H +/* 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 BLACKMISC_PQUNITSALL_H +#define BLACKMISC_PQUNITSALL_H // All units / quantities, required for the instantiations of the template // especially as CRTP is used. @@ -14,5 +19,6 @@ #include "blackmisc/pqtemperature.h" #include "blackmisc/pqangle.h" #include "blackmisc/pqtime.h" +#include "blackmisc/pqacceleration.h" -#endif // PQUNITSALL_H +#endif // guard diff --git a/src/blackmisc/pqconstants.h b/src/blackmisc/pqconstants.h index 035cc8072..4a022ea88 100644 --- a/src/blackmisc/pqconstants.h +++ b/src/blackmisc/pqconstants.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 VATSIM Community +/* 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/. */ diff --git a/src/blackmisc/pqphysicalquantity.cpp b/src/blackmisc/pqphysicalquantity.cpp index 1ac0219cf..40aefdd20 100644 --- a/src/blackmisc/pqphysicalquantity.cpp +++ b/src/blackmisc/pqphysicalquantity.cpp @@ -276,13 +276,15 @@ template bool CPhysicalQuantity::operator <=(const /* * Switch to another unit */ -template CPhysicalQuantity &CPhysicalQuantity::switchUnit(const MU &newUnit) +template PQ &CPhysicalQuantity::switchUnit(const MU &newUnit) { - if (this->m_unit == newUnit) return *this; - double cf = this->m_unit.conversionToUnit(this->m_unitValueD, newUnit); - this->m_unit = newUnit; - this->setUnitValue(cf); - return *this; + if (this->m_unit != newUnit) + { + double cf = this->m_unit.conversionToUnit(this->m_unitValueD, newUnit); + this->m_unit = newUnit; + this->setUnitValue(cf); + } + return static_cast(*this); } /* @@ -407,6 +409,7 @@ template class CPhysicalQuantity; template class CPhysicalQuantity; template class CPhysicalQuantity; template class CPhysicalQuantity; +template class CPhysicalQuantity; } // namespace } // namespace diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index 5415325ea..6db60b34c 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -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/. */ @@ -108,11 +108,11 @@ public: } /*! - * \brief Switch unit, e.g. feet meter + * \brief Switch unit, e.g. feet to meter * \param newUnit * \return */ - CPhysicalQuantity &switchUnit(const MU &newUnit); + PQ &switchUnit(const MU &newUnit); /*! * \brief Value in SI base unit? Meter is an SI base unit, hertz not! diff --git a/src/blackmisc/pqunits.cpp b/src/blackmisc/pqunits.cpp index 3676f36ec..396f05332 100644 --- a/src/blackmisc/pqunits.cpp +++ b/src/blackmisc/pqunits.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 VATSIM Community +/* 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/. */ @@ -69,7 +69,8 @@ double CAngleUnit::conversionSexagesimalToSi(const CMeasurementUnit &, double va QString CAngleUnit::toQStringRounded(double value, int digits) const { QString s; - if ((*this) == CAngleUnit::sexagesimalDeg()) { + if ((*this) == CAngleUnit::sexagesimalDeg()) + { // special formatting for sexagesimal degrees double de = floor(value); double mi = floor((value - de) * 100.0); @@ -77,7 +78,9 @@ QString CAngleUnit::toQStringRounded(double value, int digits) const QString ses = QLocale::system().toString(se, 'f', 2); s = QString::number(de).append(this->getUnitName()).append(QString::number(mi)) .append("'").append(ses).append("\""); - } else { + } + else + { s = CMeasurementUnit::toQStringRounded(value, digits); } return s; diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index 5c7529a02..e3c5d6d10 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -731,7 +731,7 @@ public: */ static const CAccelerationUnit &m_s2() { - static CAccelerationUnit ms2("meter/second^2", "m/s^2", true, false, 1, CMeasurementPrefix::None(), 1); + static CAccelerationUnit ms2("meter/second²", "m/s²", true, false, 1, CMeasurementPrefix::None(), 1); return ms2; } @@ -741,13 +741,11 @@ public: */ static const CAccelerationUnit &ft_s2() { - static CAccelerationUnit fts2("feet/seconds^s", "ft/s^2", true, false, 3.28084, CMeasurementPrefix::m(), 0); + static CAccelerationUnit fts2("feet/seconds²", "ft/s²", true, false, 3.28084, CMeasurementPrefix::m(), 0); return fts2; } }; - - } // namespace } // namespace #endif // guard diff --git a/tests/blackmisc/test_blackmisc.pro b/tests/blackmisc/test_blackmisc.pro index 8a5299da1..68427a185 100644 --- a/tests/blackmisc/test_blackmisc.pro +++ b/tests/blackmisc/test_blackmisc.pro @@ -8,18 +8,9 @@ CONFIG -= app_bundle DEPENDPATH += . ../../src/blackmisc INCLUDEPATH += . ../../src -SOURCES += main.cpp testmain.cpp \ - testphysicalquantities.cpp \ - testvectormatrix.cpp \ - testaviation.cpp \ - testgeo.cpp -HEADERS += testmain.h \ - blackmisctest.h \ - testphysicalquantities.h \ - testvectormatrix.h \ - testaviation.h \ - testgeo.h +HEADERS += *.h +SOURCES += *.cpp win32-msvc* { PRE_TARGETDEPS += ../../lib/blackmisc.lib diff --git a/tests/blackmisc/testphysicalquantities.cpp b/tests/blackmisc/testphysicalquantities.cpp index 267de0b65..2fd7b0ba6 100644 --- a/tests/blackmisc/testphysicalquantities.cpp +++ b/tests/blackmisc/testphysicalquantities.cpp @@ -10,14 +10,6 @@ using namespace BlackMisc::PhysicalQuantities; namespace BlackMiscTest { -/* - * Constructor - */ -CTestPhysicalQuantities::CTestPhysicalQuantities(QObject *parent) : QObject(parent) -{ - // void -} - /* * Basic unit tests for physical units */ @@ -163,6 +155,22 @@ void CTestPhysicalQuantities::timeTests() QVERIFY2(t1.convertedSiValueToInteger() == 3600, "1hour shall be 3600s"); } +/* + * Test acceleration + */ +void CTestPhysicalQuantities::accelerationTests() +{ + CLength oneMeter(1, CLengthUnit::m()); + double ftFactor = oneMeter.switchUnit(CLengthUnit::ft()).unitValueToDouble(); + + CAcceleration a1(10.0, CAccelerationUnit::m_s2()); + CAcceleration a2(a1); + a1.switchUnit(CAccelerationUnit::ft_s2()); + QVERIFY2(a1 == a2, "Accelerations should be similar"); + QVERIFY2(BlackMisc::Math::CMath::round(a1.unitValueToDouble() * ftFactor, 6) == a2.unitValueToDoubleRounded(6), + "Numerical values should be equal"); +} + /* * Just testing obvious memory create / destruct flaws */ @@ -182,7 +190,7 @@ void CTestPhysicalQuantities::memoryTests() } /* - * @brief Just testing obvious memory create / destruct flaws + * Some very basic arithmetic tests on the PQs */ void CTestPhysicalQuantities::basicArithmetic() { @@ -195,5 +203,7 @@ void CTestPhysicalQuantities::basicArithmetic() QVERIFY2(p3 == p1, "Pressure needs to be the same (1time)"); p3 = p3 - p3; QVERIFY2(p3.unitValueToDouble() == 0, "Value needs to be zero"); + p3 = CPressure(1013, CPressureUnit::hPa()); + QVERIFY2(p3 * 1.5 == 1.5 * p3, "Basic commutative test on PQ failed"); } } // namespace diff --git a/tests/blackmisc/testphysicalquantities.h b/tests/blackmisc/testphysicalquantities.h index 9a8f6c123..8f159b1df 100644 --- a/tests/blackmisc/testphysicalquantities.h +++ b/tests/blackmisc/testphysicalquantities.h @@ -24,49 +24,64 @@ public: * \brief Standard test case constructor * \param parent */ - explicit CTestPhysicalQuantities(QObject *parent = 0); + explicit CTestPhysicalQuantities(QObject *parent = 0) : QObject(parent) {} private slots: /*! * \brief Basic unit tests for physical units */ void unitsBasics(); + /*! * \brief Basic tests around length */ void lengthBasics(); + /*! * \brief Basic tests about speed */ void speedBasics(); + /*! * \brief Frequency tests */ void frequencyTests(); + /*! * \brief Testing angles (degrees / radians) */ void angleTests(); + /*! * \brief Testing angles */ void massTests(); + /*! * \brief Testing pressure */ void pressureTests(); + /*! * \brief Testing temperature */ void temperatureTests(); + /*! * \brief Testing time */ void timeTests(); + + /*! + * \brief Testing acceleration + */ + void accelerationTests(); + /*! * \brief Testing construction / destruction in memory */ void memoryTests(); + /*! * \brief Basic arithmetic such as +/- */ diff --git a/tests/blackmisc/testvectormatrix.cpp b/tests/blackmisc/testvectormatrix.cpp index 9cd78ad88..2a9b5616d 100644 --- a/tests/blackmisc/testvectormatrix.cpp +++ b/tests/blackmisc/testvectormatrix.cpp @@ -28,6 +28,9 @@ void CTestVectorMatrix::vectorBasics() CVector3D v7(3, 4, 5); QVERIFY2(v6.crossProduct(v7) == CVector3D(-2, 4, -2), "Cross product is wrong"); QVERIFY2(v6.dotProduct(v7) == 26, "Dot product is wrong, 26 expected"); + QVERIFY2(v6.length() == (1 + 2 + 3), "Wrong vector length"); + QVERIFY2(v6.lengthSquared() == (1 + 4 + 9), "Wrong squared vector length"); + QVERIFY2(v6.magnitude() == sqrt(1.0 + 4.0 + 9.0), "Wrong vector magnitude"); } /* @@ -68,8 +71,13 @@ void CTestVectorMatrix::matrixBasics() QVERIFY2(m1(0, 0) == 1 && m1(1, 0) == 2 && m1(0, 2) == 3, "Index error"); CMatrix3x3 mi = m1.inverse(invertible); CMatrix3x3 mid = m1 * mi; - mid.round(); - QVERIFY2(mid.isIdentity(), qPrintable(QString("Multiply with inverse should be identity: %1").arg(mid.toQString()))); + QVERIFY2(mid.isIdentityEpsilon(), qPrintable(QString("Multiply with inverse should be identity: %1").arg(mid.toQString()))); + + m1.setToIdentity(); + CMatrix3x1 mc1 = m1.getColumn(0); + CMatrix1x3 mr2 = m1.getRow(1); + QVERIFY2(mc1 == CMatrix3x1(1, 0, 0), "Wrong column 0"); + QVERIFY2(mr2 == CMatrix1x3(0, 1, 0), "Wrong row 1"); } } // namespace