mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +08:00
Some interesting results: * Minor simplification of PQ converters and unit ctors; may not seem like much, but I think it enables possible future simplifications of a similar kind. * CMeasurementPrefix is gone, no longer needed. Now prefixes are applied at the template stage. * Apart from that, PQs public API is unchanged. * Discovered that ft/s^2 conversion factor was wrong: fixed.
79 lines
2.0 KiB
C++
79 lines
2.0 KiB
C++
/* 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/. */
|
|
|
|
#include "blackmisc/pqbase.h"
|
|
#include "blackmisc/mathematics.h"
|
|
|
|
using namespace BlackMisc::Math;
|
|
|
|
namespace BlackMisc
|
|
{
|
|
namespace PhysicalQuantities
|
|
{
|
|
|
|
// -----------------------------------------------------------------------
|
|
// --- Measurement unit --------------------------------------------------
|
|
// -----------------------------------------------------------------------
|
|
|
|
/*
|
|
* Equal operator
|
|
*/
|
|
bool CMeasurementUnit::operator ==(const CMeasurementUnit &other) const
|
|
{
|
|
if (this == &other) return true;
|
|
return this->m_name == other.m_name;
|
|
}
|
|
|
|
/*
|
|
* Unequal operator
|
|
*/
|
|
bool CMeasurementUnit::operator !=(const CMeasurementUnit &other) const
|
|
{
|
|
return !(other == *this);
|
|
}
|
|
|
|
/*
|
|
* Conversion
|
|
*/
|
|
double CMeasurementUnit::convertFrom(double value, const CMeasurementUnit &unit) const
|
|
{
|
|
Q_ASSERT(this->m_converter);
|
|
Q_ASSERT(unit.m_converter);
|
|
if (this->m_converter == unit.m_converter) return value;
|
|
return this->m_converter->fromDefault(unit.m_converter->toDefault(value));
|
|
}
|
|
|
|
/*
|
|
* Value to QString with unit, e.g. "5.00m"
|
|
* @return
|
|
*/
|
|
QString CMeasurementUnit::makeRoundedQStringWithUnit(double value, int digits, bool i18n) const
|
|
{
|
|
return this->makeRoundedQString(value, digits).append(this->getSymbol(i18n));
|
|
}
|
|
|
|
/*
|
|
* Value rounded
|
|
*/
|
|
double CMeasurementUnit::roundValue(double value, int digits) const
|
|
{
|
|
if (digits < 0) digits = this->m_displayDigits;
|
|
return CMath::round(value, digits);
|
|
}
|
|
|
|
/*
|
|
* Rounded to QString
|
|
*/
|
|
QString CMeasurementUnit::makeRoundedQString(double value, int digits, bool /* i18n */) const
|
|
{
|
|
if (digits < 0) digits = this->m_displayDigits;
|
|
double v = CMath::round(value, digits);
|
|
QString s = QLocale::system().toString(v, 'f', digits);
|
|
return s;
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace
|