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

@@ -74,6 +74,34 @@ namespace BlackMisc
return this->findStdLiveryByAirlineIcaoVDesignator(icao.getVDesignator());
}
CLivery CLiveryList::findColorLiveryOrDefault(const CRgbColor &fuselage, const CRgbColor &tail) const
{
if (!fuselage.isValid() || !tail.isValid()) { return CLivery(); }
return this->findFirstByOrDefault([&](const CLivery & livery)
{
if (!livery.isColorLivery()) { return false; }
return livery.matchesColors(fuselage, tail);
});
}
CLivery CLiveryList::findClosestColorLiveryOrDefault(const CRgbColor &fuselage, const CRgbColor &tail) const
{
if (!fuselage.isValid() || !tail.isValid()) { return CLivery(); }
CLivery bestMatch;
double bestDistance = 1.0;
for (const CLivery &livery : *this)
{
double d = livery.getColorDistance(fuselage, tail);
if (d == 0.0) { return livery; } // exact match
if (d < bestDistance)
{
bestMatch = livery;
bestDistance = d;
}
}
return bestMatch;
}
CLivery CLiveryList::findByCombinedCode(const QString &combinedCode) const
{
if (!CLivery::isValidCombinedCode(combinedCode)) { return CLivery(); }