mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 10:15:38 +08:00
Ref T429, functions for angle, heading and situation
* normalize angle -180/+180 when set on situation * clamp vector function
This commit is contained in:
@@ -49,7 +49,7 @@ namespace BlackMisc
|
||||
|
||||
CAircraftSituation::CAircraftSituation(const CCoordinateGeodetic &position, const CHeading &heading, const CAngle &pitch, const CAngle &bank, const CSpeed &gs, const CElevationPlane &groundElevation)
|
||||
: m_position(position), m_groundElevationPlane(groundElevation),
|
||||
m_heading(heading), m_pitch(pitch), m_bank(bank),
|
||||
m_heading(heading.normalizedToPlusMinus180Degrees()), m_pitch(pitch.normalizedToPlusMinus180Degrees()), m_bank(bank.normalizedToPlusMinus180Degrees()),
|
||||
m_groundSpeed(gs)
|
||||
{
|
||||
m_pressureAltitude = position.geodeticHeight().toPressureAltitude(CPressure(1013.25, CPressureUnit::mbar()));
|
||||
@@ -58,7 +58,7 @@ namespace BlackMisc
|
||||
CAircraftSituation::CAircraftSituation(const CCallsign &correspondingCallsign, const CCoordinateGeodetic &position, const CHeading &heading, const CAngle &pitch, const CAngle &bank, const CSpeed &gs, const CElevationPlane &groundElevation)
|
||||
: m_correspondingCallsign(correspondingCallsign),
|
||||
m_position(position), m_groundElevationPlane(groundElevation),
|
||||
m_heading(heading), m_pitch(pitch), m_bank(bank),
|
||||
m_heading(heading.normalizedToPlusMinus180Degrees()), m_pitch(pitch.normalizedToPlusMinus180Degrees()), m_bank(bank.normalizedToPlusMinus180Degrees()),
|
||||
m_groundSpeed(gs)
|
||||
{
|
||||
m_correspondingCallsign.setTypeHint(CCallsign::Aircraft);
|
||||
@@ -889,6 +889,11 @@ namespace BlackMisc
|
||||
return ag;
|
||||
}
|
||||
|
||||
void CAircraftSituation::setHeading(const CHeading &heading)
|
||||
{
|
||||
m_heading = heading.normalizedToPlusMinus180Degrees();
|
||||
}
|
||||
|
||||
const CLengthUnit &CAircraftSituation::getAltitudeOrDefaultUnit() const
|
||||
{
|
||||
if (this->getAltitude().isNull()) { return CAltitude::defaultUnit(); }
|
||||
@@ -989,6 +994,16 @@ namespace BlackMisc
|
||||
m_pressureAltitude = altitude;
|
||||
}
|
||||
|
||||
void CAircraftSituation::setPitch(const CAngle &pitch)
|
||||
{
|
||||
m_pitch = pitch.normalizedToPlusMinus180Degrees();
|
||||
}
|
||||
|
||||
void CAircraftSituation::setBank(const CAngle &bank)
|
||||
{
|
||||
m_bank = bank.normalizedToPlusMinus180Degrees();
|
||||
}
|
||||
|
||||
void CAircraftSituation::setZeroPBH()
|
||||
{
|
||||
static const CAngle za(0, CAngleUnit::deg());
|
||||
|
||||
@@ -362,7 +362,7 @@ namespace BlackMisc
|
||||
const CHeading &getHeading() const { return m_heading; }
|
||||
|
||||
//! Set heading
|
||||
void setHeading(const CHeading &heading) { m_heading = heading; }
|
||||
void setHeading(const CHeading &heading);
|
||||
|
||||
//! Get altitude
|
||||
const CAltitude &getAltitude() const { return m_position.geodeticHeight(); }
|
||||
@@ -405,13 +405,13 @@ namespace BlackMisc
|
||||
const PhysicalQuantities::CAngle &getPitch() const { return m_pitch; }
|
||||
|
||||
//! Set pitch
|
||||
void setPitch(const PhysicalQuantities::CAngle &pitch) { m_pitch = pitch; }
|
||||
void setPitch(const PhysicalQuantities::CAngle &pitch);
|
||||
|
||||
//! Get bank (angle)
|
||||
const PhysicalQuantities::CAngle &getBank() const { return m_bank; }
|
||||
|
||||
//! Set bank (angle)
|
||||
void setBank(const PhysicalQuantities::CAngle &bank) { m_bank = bank; }
|
||||
void setBank(const PhysicalQuantities::CAngle &bank);
|
||||
|
||||
//! Set PBH values to 0 (zero)
|
||||
void setZeroPBH();
|
||||
|
||||
@@ -21,18 +21,28 @@ namespace BlackMisc
|
||||
QString CHeading::convertToQString(bool i18n) const
|
||||
{
|
||||
static const QString s("%1 %2");
|
||||
if (i18n)
|
||||
{
|
||||
return s.arg(CAngle::convertToQString(i18n),
|
||||
this->isMagneticHeading() ?
|
||||
QCoreApplication::translate("Aviation", "magnetic") :
|
||||
QCoreApplication::translate("Aviation", "true"));
|
||||
}
|
||||
else
|
||||
{
|
||||
return s.arg(CAngle::convertToQString(i18n),
|
||||
this->isMagneticHeading() ? "magnetic" : "true");
|
||||
}
|
||||
return i18n ?
|
||||
s.arg(CAngle::convertToQString(i18n),
|
||||
this->isMagneticHeading() ?
|
||||
QCoreApplication::translate("Aviation", "magnetic") :
|
||||
QCoreApplication::translate("Aviation", "true")) :
|
||||
s.arg(CAngle::convertToQString(i18n),
|
||||
this->isMagneticHeading() ? "magnetic" : "true");
|
||||
}
|
||||
|
||||
void CHeading::normalizeToPlusMinus180Degrees()
|
||||
{
|
||||
const double v = normalizeDegrees180(this->value(CAngleUnit::deg()));
|
||||
const CAngleUnit u = this->getUnit();
|
||||
*this = CHeading(v, this->getReferenceNorth(), CAngleUnit::deg());
|
||||
this->switchUnit(u);
|
||||
}
|
||||
|
||||
CHeading CHeading::normalizedToPlusMinus180Degrees() const
|
||||
{
|
||||
CHeading copy(*this);
|
||||
copy.normalizeToPlusMinus180Degrees();
|
||||
return copy;
|
||||
}
|
||||
|
||||
void CHeading::registerMetadata()
|
||||
|
||||
@@ -87,6 +87,12 @@ namespace BlackMisc
|
||||
//! Get reference north (magnetic or true)
|
||||
ReferenceNorth getReferenceNorth() const { return m_north; }
|
||||
|
||||
//! Normalize to +- 180deg, [-179.99, 180.0]
|
||||
void normalizeToPlusMinus180Degrees();
|
||||
|
||||
//! As [-179.99, 180.0] normalized heading
|
||||
CHeading normalizedToPlusMinus180Degrees() const;
|
||||
|
||||
//! Register metadata
|
||||
static void registerMetadata();
|
||||
|
||||
|
||||
@@ -223,17 +223,23 @@ namespace BlackMisc
|
||||
v[0] >= -l && v[1] >= -l && v[2] >= -l;
|
||||
}
|
||||
|
||||
int CCoordinateGeodetic::clampVector()
|
||||
{
|
||||
int c = 0;
|
||||
// *INDENT-OFF*
|
||||
if (m_x < -1.0) { m_x = -1.0; c++; } else if (m_x > 1.0) { m_x = 1.0; c++; }
|
||||
if (m_y < -1.0) { m_y = -1.0; c++; } else if (m_y > 1.0) { m_y = 1.0; c++; }
|
||||
if (m_z < -1.0) { m_z = -1.0; c++; } else if (m_z > 1.0) { m_z = 1.0; c++; }
|
||||
// *INDENT-ON*
|
||||
return c;
|
||||
}
|
||||
|
||||
CVariant CCoordinateGeodetic::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
if (ICoordinateGeodetic::canHandleIndex(index))
|
||||
{
|
||||
return ICoordinateGeodetic::propertyByIndex(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
return (ICoordinateGeodetic::canHandleIndex(index)) ?
|
||||
ICoordinateGeodetic::propertyByIndex(index) :
|
||||
CValueObject::propertyByIndex(index);
|
||||
}
|
||||
|
||||
void CCoordinateGeodetic::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
@@ -255,14 +261,9 @@ namespace BlackMisc
|
||||
|
||||
int CCoordinateGeodetic::comparePropertyByIndex(const CPropertyIndex &index, const CCoordinateGeodetic &compareValue) const
|
||||
{
|
||||
if (ICoordinateGeodetic::canHandleIndex(index))
|
||||
{
|
||||
return ICoordinateGeodetic::comparePropertyByIndex(index, compareValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
return CValueObject::comparePropertyByIndex(index, compareValue);
|
||||
}
|
||||
return ICoordinateGeodetic::canHandleIndex(index) ?
|
||||
ICoordinateGeodetic::comparePropertyByIndex(index, compareValue) :
|
||||
CValueObject::comparePropertyByIndex(index, compareValue);
|
||||
}
|
||||
|
||||
CCoordinateGeodetic::CCoordinateGeodetic(const std::array<double, 3> &normalVector)
|
||||
|
||||
@@ -299,6 +299,9 @@ namespace BlackMisc
|
||||
//! Set normal vector
|
||||
void setNormalVector(const std::array<double, 3> &normalVector);
|
||||
|
||||
//! Clamp vector values if out [-1, 1]
|
||||
int clampVector();
|
||||
|
||||
//! Set to null
|
||||
void setNull()
|
||||
{
|
||||
|
||||
@@ -109,6 +109,21 @@ namespace BlackMisc
|
||||
return std::tan(this->value(CAngleUnit::rad()));
|
||||
}
|
||||
|
||||
void CAngle::normalizeToPlusMinus180Degrees()
|
||||
{
|
||||
const double v = normalizeDegrees180(this->value(CAngleUnit::deg()));
|
||||
const CAngleUnit u = this->getUnit();
|
||||
*this = CAngle(v, CAngleUnit::deg());
|
||||
this->switchUnit(u);
|
||||
}
|
||||
|
||||
CAngle CAngle::normalizedToPlusMinus180Degrees() const
|
||||
{
|
||||
CAngle copy(*this);
|
||||
copy.normalizeToPlusMinus180Degrees();
|
||||
return copy;
|
||||
}
|
||||
|
||||
double CAngle::normalizeDegrees180(double degrees, int roundDigits)
|
||||
{
|
||||
double d = CMathUtils::normalizeDegrees360(degrees + 180.0) - 180.0;
|
||||
|
||||
@@ -97,6 +97,12 @@ namespace BlackMisc
|
||||
//! Tangent of angle
|
||||
double tan() const;
|
||||
|
||||
//! Normalize to +- 180deg, [-179.99, 180.0]
|
||||
void normalizeToPlusMinus180Degrees();
|
||||
|
||||
//! As [-179.99, 180.0] normalized heading
|
||||
CAngle normalizedToPlusMinus180Degrees() const;
|
||||
|
||||
//! Normalize: -180< degrees ≤180
|
||||
static double normalizeDegrees180(double degrees, int roundDigits = -1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user