refs #742, allow to search by colors

* color distance in livery
* and in container
This commit is contained in:
Klaus Basan
2016-08-25 00:20:41 +02:00
committed by Mathew Sutcliffe
parent 940137b921
commit 74740991a3
4 changed files with 62 additions and 0 deletions

View File

@@ -103,6 +103,11 @@ namespace BlackMisc
return c == this->m_combinedCode;
}
bool CLivery::matchesColors(const CRgbColor &fuselage, const CRgbColor &tail) const
{
return this->getColorFuselage() == fuselage && this->getColorTail() == tail;
}
QString CLivery::convertToQString(bool i18n) const
{
QString s(i18n ? QCoreApplication::translate("Aviation", "Livery") : "Livery");
@@ -178,6 +183,23 @@ namespace BlackMisc
return m_combinedCode.startsWith(colorLiveryMarker());
}
double CLivery::getColorDistance(const CRgbColor &fuselage, const CRgbColor &tail) const
{
if (!fuselage.isValid() || !tail.isValid()) { return 1.0; }
if (this->getColorFuselage().isValid() && this->getColorTail().isValid())
{
if (this->matchesColors(fuselage, tail)) { return 0.0; } // avoid rounding
const double xDist = this->getColorFuselage().colorDistance(fuselage);
const double yDist = this->getColorTail().colorDistance(tail);
const double d = xDist * xDist + yDist * yDist;
return d / 2.0; // normalize to 0..1
}
else
{
return 1.0;
}
}
CLivery CLivery::fromDatabaseJson(const QJsonObject &json, const QString &prefix)
{
if (!existsKey(json, prefix))