133 lines
3.8 KiB
C++

#ifndef GERMANAIRLINESVA_FILE_FSUIPC_FSLONGITUDEIMPL_H
#define GERMANAIRLINESVA_FILE_FSUIPC_FSLONGITUDEIMPL_H
#include "FsLongitude.h"
namespace germanairlinesva
{
namespace file
{
namespace FSUIPC
{
inline FsLongitude::FsLongitude() = default;
inline FsLongitude::FsLongitude(double DecimalDegrees)
{
this->pos = DecimalDegrees;
while (this->pos < -180.0 || this->pos > 180.0) {
if (this->pos > 180.0)
this->pos -= 360.0;
if (this->pos < -180.0)
this->pos += 360.0;
}
}
inline FsLongitude::FsLongitude(std::int64_t FSUnits)
: FsLongitude(FSUnits * 360.0 / 1.8446744073709552E+19)
{
}
inline FsLongitude::FsLongitude(std::int32_t FSUnits)
: FsLongitude(FSUnits * 360.0 / 4294967296.0)
{
}
inline FsLongitude::FsLongitude(std::int32_t Degrees, double DecimalMinutes)
: FsLongitude(Degrees + DecimalMinutes / 60.0)
{
}
inline FsLongitude::FsLongitude(std::int32_t Degrees,
std::int32_t Minutes,
double DecimalSeconds)
: FsLongitude(Degrees + Minutes / 60.0 + DecimalSeconds / 3600.0)
{
}
inline long FsLongitude::ToFSUnits8() const
{
return this->pos * 1.8446744073709552E+19 / 360.0;
}
inline std::int32_t FsLongitude::ToFSUnits4() const
{
return this->pos * 4294967296.0 / 360.0;
}
inline double FsLongitude::DecimalDegrees() const { return this->pos; }
inline double FsLongitude::DecimalMinutes() const
{
return (this->pos - trunc(this->pos)) * 60.0;
}
inline double FsLongitude::DecimalSeconds() const
{
double decimalMinutes = this->DecimalMinutes();
return (decimalMinutes - trunc(decimalMinutes)) * 60.0;
}
inline std::int32_t FsLongitude::Degree() const
{
return trunc(this->DecimalDegrees());
}
inline std::int32_t FsLongitude::Minute() const
{
return trunc(this->DecimalMinutes());
}
inline std::int32_t FsLongitude::Second() const
{
return trunc(this->DecimalSeconds());
}
inline double FsLongitude::UDegrees() const { return this->pos + 180.0; }
inline const std::string FsLongitude::to_string(bool HemisphereAsText,
char DetailLevel) const
{
std::ostringstream str;
if (!HemisphereAsText) {
str << (this->pos < 0.0 ? "-" : "");
} else {
str << (this->pos < 0.0 ? "W" : "E");
}
switch (DetailLevel) {
case 'm':
str << this->Degree() << "° " << this->DecimalMinutes() << "'";
break;
case 's':
str << this->Degree() << "° " << this->Minute() << "' "
<< this->DecimalSeconds() << "\"";
break;
default:
str << this->pos << "*";
break;
}
return str.str();
}
inline const std::string FsLongitude::to_string() const
{
return this->to_string(true, 'm');
}
inline FsLongitude FsLongitude::Add(const FsLongitudeSpan &Distance) const
{
return FsLongitude(this->pos + Distance.DecimalDegrees());
}
inline FsLongitude
FsLongitude::Subtract(const FsLongitudeSpan &Distance) const
{
return FsLongitude(this->pos - Distance.DecimalDegrees());
}
inline FsLongitude FsLongitude::AddDegrees(double Degrees) const
{
return FsLongitude(this->pos + Degrees);
}
inline FsLongitude FsLongitude::AddMinutes(double Minutes) const
{
return FsLongitude(this->pos + Minutes / 60.0);
}
inline FsLongitude FsLongitude::AddSeconds(double Seconds) const
{
return FsLongitude(this->pos + Seconds / 3600.0);
}
} // namespace FSUIPC
} // namespace file
} // namespace germanairlinesva
#endif