From a3b8d776a077c1257b2aa4f24597011066a561d6 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 3 Jun 2018 00:29:40 +0200 Subject: [PATCH] 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 ... --- src/blackmisc/aviation/aircraftparts.cpp | 7 +++++ src/blackmisc/aviation/aircraftparts.h | 3 ++ src/blackmisc/aviation/aircraftsituation.cpp | 30 ++++++++++++++++++++ src/blackmisc/aviation/aircraftsituation.h | 24 ++++++++++++++-- src/blackmisc/geo/coordinategeodetic.cpp | 5 ++++ src/blackmisc/geo/coordinategeodetic.h | 5 +++- 6 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/blackmisc/aviation/aircraftparts.cpp b/src/blackmisc/aviation/aircraftparts.cpp index 009661107..5de0b23e1 100644 --- a/src/blackmisc/aviation/aircraftparts.cpp +++ b/src/blackmisc/aviation/aircraftparts.cpp @@ -68,6 +68,13 @@ namespace BlackMisc 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() { static const CAircraftParts null(-1); diff --git a/src/blackmisc/aviation/aircraftparts.h b/src/blackmisc/aviation/aircraftparts.h index 347e333f7..9093fb574 100644 --- a/src/blackmisc/aviation/aircraftparts.h +++ b/src/blackmisc/aviation/aircraftparts.h @@ -169,6 +169,9 @@ namespace BlackMisc //! NULL parts object? bool isNull() const; + //! Equal values, but not comparing timestamp etc. + bool equalValues(const CAircraftParts &other) const; + //! NULL parts object static const CAircraftParts &null(); diff --git a/src/blackmisc/aviation/aircraftsituation.cpp b/src/blackmisc/aviation/aircraftsituation.cpp index 2dc38d579..71e841a39 100644 --- a/src/blackmisc/aviation/aircraftsituation.cpp +++ b/src/blackmisc/aviation/aircraftsituation.cpp @@ -234,6 +234,16 @@ namespace BlackMisc 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() { m_position.setNull(); @@ -482,6 +492,21 @@ namespace BlackMisc 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 { return this->isOnGroundByElevation(m_cg); @@ -548,6 +573,11 @@ namespace BlackMisc return false; } + void CAircraftSituation::resetGroundElevation() + { + m_groundElevationPlane = CElevationPlane::null(); + } + const CLength &CAircraftSituation::getGroundElevationRadius() const { if (!this->hasGroundElevation()) { return CLength::null(); } diff --git a/src/blackmisc/aviation/aircraftsituation.h b/src/blackmisc/aviation/aircraftsituation.h index 63a6c005e..4323f32db 100644 --- a/src/blackmisc/aviation/aircraftsituation.h +++ b/src/blackmisc/aviation/aircraftsituation.h @@ -154,6 +154,14 @@ namespace BlackMisc //! Null situation 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 void setNull(); @@ -244,6 +252,12 @@ namespace BlackMisc //! Elevation of the ground directly beneath 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 //! @{ IsOnGround isOnGroundByElevation() const; @@ -266,6 +280,9 @@ namespace BlackMisc //! \remark override if better bool setGroundElevationChecked(const Geo::CElevationPlane &elevationPlane); + //! Reset ground elevation + void resetGroundElevation(); + //! Distance of ground elevation const PhysicalQuantities::CLength &getGroundElevationRadius() const; @@ -345,6 +362,9 @@ namespace BlackMisc //! Corresponding callsign const CCallsign &getCallsign() const { return m_correspondingCallsign; } + //! Has corresponding callsign + bool hasCallsign() const { return !this->getCallsign().isEmpty(); } + //! Corresponding callsign void setCallsign(const CCallsign &callsign); @@ -408,13 +428,13 @@ namespace BlackMisc return isDoubleEpsilonEqual(0.0, oldGroundFactor) && isDoubleEpsilonEqual(0.0, newGroundFactor); } - //! Plane is starting + //! Aircraft is starting static bool isGfStarting(double oldGroundFactor, double newGroundFactor) { return isDoubleEpsilonEqual(0.0, oldGroundFactor) && isDoubleEpsilonEqual(1.0, newGroundFactor); } - //! Plane is landing + //! Aircraft is landing static bool isGfLanding(double oldGroundFactor, double newGroundFactor) { return isDoubleEpsilonEqual(1.0, oldGroundFactor) && isDoubleEpsilonEqual(0.0, newGroundFactor); diff --git a/src/blackmisc/geo/coordinategeodetic.cpp b/src/blackmisc/geo/coordinategeodetic.cpp index 3e9c4818b..4b4934f77 100644 --- a/src/blackmisc/geo/coordinategeodetic.cpp +++ b/src/blackmisc/geo/coordinategeodetic.cpp @@ -81,6 +81,11 @@ namespace BlackMisc return true; } + bool ICoordinateGeodetic::equalNormalVectorDouble(const ICoordinateGeodetic &otherCoordinate) const + { + return this->equalNormalVectorDouble(otherCoordinate.normalVectorDouble()); + } + CLength ICoordinateGeodetic::calculateGreatCircleDistance(const ICoordinateGeodetic &otherCoordinate) const { return Geo::calculateGreatCircleDistance((*this), otherCoordinate); diff --git a/src/blackmisc/geo/coordinategeodetic.h b/src/blackmisc/geo/coordinategeodetic.h index 0cf09fd99..1734ac631 100644 --- a/src/blackmisc/geo/coordinategeodetic.h +++ b/src/blackmisc/geo/coordinategeodetic.h @@ -83,9 +83,12 @@ namespace BlackMisc //! Normal vector with double precision virtual std::array normalVectorDouble() const = 0; - //! Is equal, epsilon considered + //! Is equal, epsilon considered? bool equalNormalVectorDouble(const std::array &otherVector) const; + //! Is equal, epsilon considered? + bool equalNormalVectorDouble(const ICoordinateGeodetic &otherCoordinate) const; + //! Latitude as string QString latitudeAsString() const { return this->latitude().toQString(true); }