Ref T273, high level functions to compare "equal" situations

Remark: "==" compares a lot of attributes, those will only compare values to determine equal PBH/vector ...
This commit is contained in:
Klaus Basan
2018-06-03 00:29:40 +02:00
parent 6f8d980d2c
commit a3b8d776a0
6 changed files with 71 additions and 3 deletions

View File

@@ -68,6 +68,13 @@ namespace BlackMisc
return this->getPartsDetails() == NotSet && m_flapsPercentage < 0; return this->getPartsDetails() == NotSet && m_flapsPercentage < 0;
} }
bool CAircraftParts::equalValues(const CAircraftParts &other) const
{
// currently same as some values are diabled for comparison
// but that could change in future
return other == *this;
}
const CAircraftParts &CAircraftParts::null() const CAircraftParts &CAircraftParts::null()
{ {
static const CAircraftParts null(-1); static const CAircraftParts null(-1);

View File

@@ -169,6 +169,9 @@ namespace BlackMisc
//! NULL parts object? //! NULL parts object?
bool isNull() const; bool isNull() const;
//! Equal values, but not comparing timestamp etc.
bool equalValues(const CAircraftParts &other) const;
//! NULL parts object //! NULL parts object
static const CAircraftParts &null(); static const CAircraftParts &null();

View File

@@ -234,6 +234,16 @@ namespace BlackMisc
return this->isPositionNull(); return this->isPositionNull();
} }
bool CAircraftSituation::equalPbh(const CAircraftSituation &other) const
{
return this->getPitch() == other.getPitch() && this->getBank() == other.getBank() && this->getHeading() == other.getHeading();
}
bool CAircraftSituation::equalPbhAndVector(const CAircraftSituation &other) const
{
return this->equalNormalVectorDouble(other.normalVectorDouble()) && this->equalPbh(other);
}
void CAircraftSituation::setNull() void CAircraftSituation::setNull()
{ {
m_position.setNull(); m_position.setNull();
@@ -482,6 +492,21 @@ namespace BlackMisc
return this->onGroundAsString() % QLatin1Char(' ') % this->getOnDetailsAsString(); return this->onGroundAsString() % QLatin1Char(' ') % this->getOnDetailsAsString();
} }
bool CAircraftSituation::canTransferGroundElevation(const CAircraftSituation &otherSituation, const CLength &radius) const
{
if (!this->hasGroundElevation()) { return false; }
const CLength distance = this->getGroundElevationPlane().calculateGreatCircleDistance(otherSituation);
const bool transferable = distance <= radius;
return transferable;
}
bool CAircraftSituation::transferGroundElevation(CAircraftSituation &otherSituation, const CLength &radius) const
{
if (!this->canTransferGroundElevation(otherSituation, radius)) { return false; }
otherSituation.setGroundElevation(this->getGroundElevationPlane());
return true;
}
CAircraftSituation::IsOnGround CAircraftSituation::isOnGroundByElevation() const CAircraftSituation::IsOnGround CAircraftSituation::isOnGroundByElevation() const
{ {
return this->isOnGroundByElevation(m_cg); return this->isOnGroundByElevation(m_cg);
@@ -548,6 +573,11 @@ namespace BlackMisc
return false; return false;
} }
void CAircraftSituation::resetGroundElevation()
{
m_groundElevationPlane = CElevationPlane::null();
}
const CLength &CAircraftSituation::getGroundElevationRadius() const const CLength &CAircraftSituation::getGroundElevationRadius() const
{ {
if (!this->hasGroundElevation()) { return CLength::null(); } if (!this->hasGroundElevation()) { return CLength::null(); }

View File

@@ -154,6 +154,14 @@ namespace BlackMisc
//! Null situation //! Null situation
virtual bool isNull() const override; virtual bool isNull() const override;
//! Equal pitch, bank heading
//! \sa Geo::ICoordinateGeodetic::equalNormalVectorDouble
bool equalPbh(const CAircraftSituation &other) const;
//! Equal PBH and vector
//! \sa Geo::ICoordinateGeodetic::equalNormalVectorDouble
bool equalPbhAndVector(const CAircraftSituation &other) const;
//! Set to null //! Set to null
void setNull(); void setNull();
@@ -244,6 +252,12 @@ namespace BlackMisc
//! Elevation of the ground directly beneath //! Elevation of the ground directly beneath
const Geo::CElevationPlane &getGroundElevationPlane() const { return m_groundElevationPlane; } const Geo::CElevationPlane &getGroundElevationPlane() const { return m_groundElevationPlane; }
//! Can the elevation be transferred to another situation?
bool canTransferGroundElevation(const CAircraftSituation &otherSituation, const PhysicalQuantities::CLength &radius = Geo::CElevationPlane::singlePointRadius()) const;
//! Transfer from "this" situation to \c otherSituation
bool transferGroundElevation(CAircraftSituation &otherSituation, const PhysicalQuantities::CLength &radius = Geo::CElevationPlane::singlePointRadius()) const;
//! Is on ground by elevation data, requires elevation and CG //! Is on ground by elevation data, requires elevation and CG
//! @{ //! @{
IsOnGround isOnGroundByElevation() const; IsOnGround isOnGroundByElevation() const;
@@ -266,6 +280,9 @@ namespace BlackMisc
//! \remark override if better //! \remark override if better
bool setGroundElevationChecked(const Geo::CElevationPlane &elevationPlane); bool setGroundElevationChecked(const Geo::CElevationPlane &elevationPlane);
//! Reset ground elevation
void resetGroundElevation();
//! Distance of ground elevation //! Distance of ground elevation
const PhysicalQuantities::CLength &getGroundElevationRadius() const; const PhysicalQuantities::CLength &getGroundElevationRadius() const;
@@ -345,6 +362,9 @@ namespace BlackMisc
//! Corresponding callsign //! Corresponding callsign
const CCallsign &getCallsign() const { return m_correspondingCallsign; } const CCallsign &getCallsign() const { return m_correspondingCallsign; }
//! Has corresponding callsign
bool hasCallsign() const { return !this->getCallsign().isEmpty(); }
//! Corresponding callsign //! Corresponding callsign
void setCallsign(const CCallsign &callsign); void setCallsign(const CCallsign &callsign);
@@ -408,13 +428,13 @@ namespace BlackMisc
return isDoubleEpsilonEqual(0.0, oldGroundFactor) && isDoubleEpsilonEqual(0.0, newGroundFactor); return isDoubleEpsilonEqual(0.0, oldGroundFactor) && isDoubleEpsilonEqual(0.0, newGroundFactor);
} }
//! Plane is starting //! Aircraft is starting
static bool isGfStarting(double oldGroundFactor, double newGroundFactor) static bool isGfStarting(double oldGroundFactor, double newGroundFactor)
{ {
return isDoubleEpsilonEqual(0.0, oldGroundFactor) && isDoubleEpsilonEqual(1.0, newGroundFactor); return isDoubleEpsilonEqual(0.0, oldGroundFactor) && isDoubleEpsilonEqual(1.0, newGroundFactor);
} }
//! Plane is landing //! Aircraft is landing
static bool isGfLanding(double oldGroundFactor, double newGroundFactor) static bool isGfLanding(double oldGroundFactor, double newGroundFactor)
{ {
return isDoubleEpsilonEqual(1.0, oldGroundFactor) && isDoubleEpsilonEqual(0.0, newGroundFactor); return isDoubleEpsilonEqual(1.0, oldGroundFactor) && isDoubleEpsilonEqual(0.0, newGroundFactor);

View File

@@ -81,6 +81,11 @@ namespace BlackMisc
return true; return true;
} }
bool ICoordinateGeodetic::equalNormalVectorDouble(const ICoordinateGeodetic &otherCoordinate) const
{
return this->equalNormalVectorDouble(otherCoordinate.normalVectorDouble());
}
CLength ICoordinateGeodetic::calculateGreatCircleDistance(const ICoordinateGeodetic &otherCoordinate) const CLength ICoordinateGeodetic::calculateGreatCircleDistance(const ICoordinateGeodetic &otherCoordinate) const
{ {
return Geo::calculateGreatCircleDistance((*this), otherCoordinate); return Geo::calculateGreatCircleDistance((*this), otherCoordinate);

View File

@@ -83,9 +83,12 @@ namespace BlackMisc
//! Normal vector with double precision //! Normal vector with double precision
virtual std::array<double, 3> normalVectorDouble() const = 0; virtual std::array<double, 3> normalVectorDouble() const = 0;
//! Is equal, epsilon considered //! Is equal, epsilon considered?
bool equalNormalVectorDouble(const std::array<double, 3> &otherVector) const; bool equalNormalVectorDouble(const std::array<double, 3> &otherVector) const;
//! Is equal, epsilon considered?
bool equalNormalVectorDouble(const ICoordinateGeodetic &otherCoordinate) const;
//! Latitude as string //! Latitude as string
QString latitudeAsString() const { return this->latitude().toQString(true); } QString latitudeAsString() const { return this->latitude().toQString(true); }