From baa0ac147e70020d4933bb0a4a8f7b4a5e7caa40 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Wed, 14 Aug 2013 03:29:03 +0100 Subject: [PATCH] remove integer quantities --- src/blackmisc/pqacceleration.h | 7 --- src/blackmisc/pqangle.h | 7 --- src/blackmisc/pqfrequency.h | 7 --- src/blackmisc/pqlength.h | 7 --- src/blackmisc/pqmass.h | 7 --- src/blackmisc/pqphysicalquantity.cpp | 65 +++------------------- src/blackmisc/pqphysicalquantity.h | 40 ------------- src/blackmisc/pqpressure.h | 7 --- src/blackmisc/pqspeed.h | 7 --- src/blackmisc/pqtemperature.h | 7 --- src/blackmisc/pqtime.h | 7 --- tests/blackmisc/testphysicalquantities.cpp | 7 +-- 12 files changed, 10 insertions(+), 165 deletions(-) diff --git a/src/blackmisc/pqacceleration.h b/src/blackmisc/pqacceleration.h index 449c2aec9..0461f8b3f 100644 --- a/src/blackmisc/pqacceleration.h +++ b/src/blackmisc/pqacceleration.h @@ -23,13 +23,6 @@ public: */ CAcceleration() : CPhysicalQuantity(0, CAccelerationUnit::m_s2(), CAccelerationUnit::m_s2()) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CAcceleration(qint32 value, const CAccelerationUnit &unit) : CPhysicalQuantity(value, unit, CAccelerationUnit::m_s2()) {} - /*! * \brief Init by double value * \param value diff --git a/src/blackmisc/pqangle.h b/src/blackmisc/pqangle.h index de0bd6517..1dc37a270 100644 --- a/src/blackmisc/pqangle.h +++ b/src/blackmisc/pqangle.h @@ -29,13 +29,6 @@ public: */ CAngle(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CAngle(qint32 value, const CAngleUnit &unit): CPhysicalQuantity(value, unit, CAngleUnit::rad()) {} - /*! * \brief Init by double value * \param value diff --git a/src/blackmisc/pqfrequency.h b/src/blackmisc/pqfrequency.h index 4501a7461..7d106204a 100644 --- a/src/blackmisc/pqfrequency.h +++ b/src/blackmisc/pqfrequency.h @@ -29,13 +29,6 @@ public: */ CFrequency(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CFrequency(qint32 value, const CFrequencyUnit &unit) : CPhysicalQuantity(value, unit, CFrequencyUnit::Hz()) {} - /*! * \brief Init by double value * \param value diff --git a/src/blackmisc/pqlength.h b/src/blackmisc/pqlength.h index 6cc339203..fe24480b0 100644 --- a/src/blackmisc/pqlength.h +++ b/src/blackmisc/pqlength.h @@ -29,13 +29,6 @@ public: */ CLength(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CLength(qint32 value, const CLengthUnit &unit) : CPhysicalQuantity(value, unit, CLengthUnit::m()) {} - /*! *\brief Init by double value * \param value diff --git a/src/blackmisc/pqmass.h b/src/blackmisc/pqmass.h index 76cc070a0..266b54929 100644 --- a/src/blackmisc/pqmass.h +++ b/src/blackmisc/pqmass.h @@ -23,13 +23,6 @@ public: */ CMass() : CPhysicalQuantity(0, CMassUnit::kg(), CMassUnit::kg()) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CMass(qint32 value, const CMassUnit &unit) : CPhysicalQuantity(value, unit, CMassUnit::kg()) {} - /*! * \brief Init by double value * \param value diff --git a/src/blackmisc/pqphysicalquantity.cpp b/src/blackmisc/pqphysicalquantity.cpp index 581cc9025..63b7ba8b3 100644 --- a/src/blackmisc/pqphysicalquantity.cpp +++ b/src/blackmisc/pqphysicalquantity.cpp @@ -10,15 +10,6 @@ namespace BlackMisc namespace PhysicalQuantities { -/* - * Constructor by integer - */ -template CPhysicalQuantity::CPhysicalQuantity(qint32 baseValue, const MU &unit, const MU &siConversionUnit) : - m_unit(unit), m_conversionSiUnit(siConversionUnit) -{ - this->setUnitValue(baseValue); -} - /* * Constructor by double */ @@ -32,8 +23,8 @@ template CPhysicalQuantity::CPhysicalQuantity(doubl * Copy constructor */ template CPhysicalQuantity::CPhysicalQuantity(const CPhysicalQuantity &other) : - m_unitValueD(other.m_unitValueD), m_unitValueI(other.m_unitValueI), m_convertedSiUnitValueD(other.m_convertedSiUnitValueD), - m_isIntegerBaseValue(other.m_isIntegerBaseValue), m_unit(other.m_unit), m_conversionSiUnit(other.m_conversionSiUnit) + m_unitValueD(other.m_unitValueD), m_convertedSiUnitValueD(other.m_convertedSiUnitValueD), + m_unit(other.m_unit), m_conversionSiUnit(other.m_conversionSiUnit) { } @@ -58,18 +49,9 @@ template bool CPhysicalQuantity::operator ==(const bool eq = false; if (this->m_unit == other.m_unit) { - // same unit - if (this->m_isIntegerBaseValue && other.m_isIntegerBaseValue) - { - // pure integer comparison, no rounding issues - eq = this->m_unitValueI == other.m_unitValueI; - } - else - { - // same unit, comparison based on double - diff = qAbs(this->m_unitValueD - other.m_unitValueD); - eq = diff <= (lenient * this->m_unit.getEpsilon()); - } + // same unit, comparison based on double + diff = qAbs(this->m_unitValueD - other.m_unitValueD); + eq = diff <= (lenient * this->m_unit.getEpsilon()); } else { @@ -95,10 +77,8 @@ template CPhysicalQuantity& CPhysicalQuantitym_unitValueI = other.m_unitValueI; this->m_unitValueD = other.m_unitValueD; this->m_convertedSiUnitValueD = other.m_convertedSiUnitValueD; - this->m_isIntegerBaseValue = other.m_isIntegerBaseValue; this->m_unit = other.m_unit; this->m_conversionSiUnit = other.m_conversionSiUnit; return *this; @@ -111,16 +91,7 @@ template CPhysicalQuantity &CPhysicalQuantitym_unit == other.m_unit) { - // same unit - if (this->m_isIntegerBaseValue && other.m_isIntegerBaseValue) - { - // pure integer, no rounding issues - this->setUnitValue(other.m_unitValueI + this->m_unitValueI); - } - else - { - this->setUnitValue(other.m_unitValueD + this->m_unitValueD); - } + this->setUnitValue(other.m_unitValueD + this->m_unitValueD); } else { @@ -163,16 +134,7 @@ template CPhysicalQuantity &CPhysicalQuantitym_unit == other.m_unit) { - // same unit - if (this->m_isIntegerBaseValue && other.m_isIntegerBaseValue) - { - // pure integer, no rounding issues - this->setUnitValue(other.m_unitValueI - this->m_unitValueI); - } - else - { - this->setUnitValue(other.m_unitValueD - this->m_unitValueD); - } + this->setUnitValue(other.m_unitValueD - this->m_unitValueD); } else { @@ -283,25 +245,12 @@ template PQ &CPhysicalQuantity::switchUnit(const MU return *derived(); } -/* - * Init by integer - */ -template void CPhysicalQuantity::setUnitValue(qint32 baseValue) -{ - this->m_unitValueI = baseValue; - this->m_unitValueD = double(baseValue); - this->m_isIntegerBaseValue = true; - this->setConversionSiUnitValue(); -} - /* * Init by double */ template void CPhysicalQuantity::setUnitValue(double baseValue) { this->m_unitValueD = baseValue; - this->m_unitValueI = qRound(baseValue); - this->m_isIntegerBaseValue = false; this->setConversionSiUnitValue(); } diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index 18fa3c275..586755265 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -28,9 +28,7 @@ template class CPhysicalQuantity : public BlackMisc::CBaseS { private: double m_unitValueD; //!< value backed by double - qint32 m_unitValueI; //!< value backed by integer, allows sole integer arithmetic double m_convertedSiUnitValueD; //!< SI unit value - bool m_isIntegerBaseValue; //!< flag integer? / double? /*! * \brief Easy access to derived class (CRTP template parameter) @@ -54,14 +52,6 @@ protected: MU m_unit; //!< unit MU m_conversionSiUnit; //!< corresponding SI base unit - /*! - * \brief Constructor by integer - * \param baseValue - * \param unit - * \param siConversionUnit - */ - CPhysicalQuantity(qint32 baseValue, const MU &unit, const MU &siConversionUnit); - /*! * \brief Constructor with double * \param baseValue @@ -80,12 +70,6 @@ protected: return this->unitValueRoundedWithUnit(-1, i18n); } - /*! - * \brief Init by integer - * \param baseValue - */ - void setUnitValue(qint32 baseValue); - /*! * \brief Init by double * \param baseValue @@ -186,15 +170,6 @@ public: */ QString valueRoundedWithUnit(const MU &unit, int digits = -1, bool i18n = false) const; - /*! - * \brief Value as int - * \return - */ - qint32 unitValueToInteger() const - { - return this->m_unitValueI; - } - /*! * \brief Value as double * \return @@ -235,16 +210,6 @@ public: return this->m_convertedSiUnitValueD; } - /*! - * \brief SI value as integer - * \return - */ - qint32 convertedSiValueToInteger() const - { - return static_cast( - BlackMisc::Math::CMath::round(this->m_convertedSiUnitValueD, 0)); - } - /*! * \brief Rounded SI value by n digits * \param digits @@ -403,7 +368,6 @@ public: */ bool isZeroEpsilon() const { - if (this->m_isIntegerBaseValue) return this->m_unitValueI == 0; return this->m_unit.isEpsilon(this->m_unitValueD); } @@ -432,9 +396,7 @@ public: virtual void marshallToDbus(QDBusArgument &argument) const { argument << this->m_unitValueD; - argument << this->m_unitValueI; argument << this->m_convertedSiUnitValueD; - argument << this->m_isIntegerBaseValue; argument << this->m_unit; argument << this->m_conversionSiUnit; } @@ -446,9 +408,7 @@ public: virtual void unmarshallFromDbus(const QDBusArgument &argument) { argument >> this->m_unitValueD; - argument >> this->m_unitValueI; argument >> this->m_convertedSiUnitValueD; - argument >> this->m_isIntegerBaseValue; argument >> this->m_unit; argument >> this->m_conversionSiUnit; } diff --git a/src/blackmisc/pqpressure.h b/src/blackmisc/pqpressure.h index 660f1451a..80d57f96c 100644 --- a/src/blackmisc/pqpressure.h +++ b/src/blackmisc/pqpressure.h @@ -30,13 +30,6 @@ public: */ CPressure(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CPressure(qint32 value, const CPressureUnit &unit) : CPhysicalQuantity(value, unit, CPressureUnit::Pa()) {} - /*! *\brief Init by double value * \param value diff --git a/src/blackmisc/pqspeed.h b/src/blackmisc/pqspeed.h index 737b2f0d4..f5ecf2e72 100644 --- a/src/blackmisc/pqspeed.h +++ b/src/blackmisc/pqspeed.h @@ -30,13 +30,6 @@ public: */ CSpeed(const CPhysicalQuantity &base): CPhysicalQuantity(base) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CSpeed(qint32 value, const CSpeedUnit &unit) : CPhysicalQuantity(value, unit, CSpeedUnit::m_s()) {} - /*! *\brief Init by double value * \param value diff --git a/src/blackmisc/pqtemperature.h b/src/blackmisc/pqtemperature.h index 896b313d4..4553493fd 100644 --- a/src/blackmisc/pqtemperature.h +++ b/src/blackmisc/pqtemperature.h @@ -29,13 +29,6 @@ public: */ CTemperature(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CTemperature(qint32 value, const CTemperatureUnit &unit): CPhysicalQuantity(value, unit, CTemperatureUnit::K()) {} - /*! * \brief Init by double value * \param value diff --git a/src/blackmisc/pqtime.h b/src/blackmisc/pqtime.h index 62e78f115..16bbf9fe4 100644 --- a/src/blackmisc/pqtime.h +++ b/src/blackmisc/pqtime.h @@ -30,13 +30,6 @@ public: */ CTime(const CPhysicalQuantity &base): CPhysicalQuantity(base) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CTime(qint32 value, const CTimeUnit &unit) : CPhysicalQuantity(value, unit, CTimeUnit::s()) {} - /*! *\brief Init by double value * \param value diff --git a/tests/blackmisc/testphysicalquantities.cpp b/tests/blackmisc/testphysicalquantities.cpp index 6dabc06cb..9b9202b3e 100644 --- a/tests/blackmisc/testphysicalquantities.cpp +++ b/tests/blackmisc/testphysicalquantities.cpp @@ -97,7 +97,6 @@ void CTestPhysicalQuantities::angleTests() CAngle a2(1.5 * CAngle::PI(), CAngleUnit::rad()); 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()))); QVERIFY2(a3.valueRounded(CAngleUnit::deg()) == 35.73, "Expecting 35.73"); } @@ -108,9 +107,9 @@ void CTestPhysicalQuantities::angleTests() void CTestPhysicalQuantities::massTests() { CMass w1(1000, CMassUnit::kg()); - CMass w2(w1.unitValueToInteger(), CMassUnit::kg()); + CMass w2(w1.unitValueToDouble(), CMassUnit::kg()); w2.switchUnit(CMassUnit::t()); - QVERIFY2(w2.unitValueToInteger() == 1, "1tonne shall be 1000kg"); + QVERIFY2(w2.unitValueToDouble() == 1, "1tonne shall be 1000kg"); w2.switchUnit(CMassUnit::lb()); QVERIFY2(w2.unitValueToDoubleRounded(2) == 2204.62, "1tonne shall be 2204pounds"); QVERIFY2(w1 == w2, "Masses shall be equal"); @@ -154,7 +153,7 @@ void CTestPhysicalQuantities::temperatureTests() void CTestPhysicalQuantities::timeTests() { CTime t1(1, CTimeUnit::h()); - QVERIFY2(t1.convertedSiValueToInteger() == 3600, "1hour shall be 3600s"); + QVERIFY2(t1.convertedSiValueToDouble() == 3600, "1hour shall be 3600s"); } /*