125 lines
4.3 KiB
C++

#ifndef GERMANAIRLINESVA_FILE_SIMDATA_RUNWAY_H
#define GERMANAIRLINESVA_FILE_SIMDATA_RUNWAY_H
#include <fstream>
#include <iomanip>
#include <iostream>
#include <regex>
#include <sstream>
#include <string>
#include <utility>
#include "FSUIPC/FsGeoData.h"
#include "geodata.hpp"
#include "helpers.hpp"
#include "util.hpp"
namespace germanairlinesva
{
namespace file
{
namespace simdata
{
/*
* Representation of one runway with supplementary information
* Heading in degrees true
* Threshold center in lat/lon degrees
* Width and length in feet
*
* UINT8 | CHAR[] | POINT | UINT8 | UINT16 | DOUBLE
* -------+------------+--------+-------+--------+-------
* STRLEN | DESIGNATOR | CENTER | WIDTH | LENGTH | TRUHDG
*/
class Runway
{
private:
std::string designator;
struct geodata::point center;
std::uint8_t width;
std::uint16_t length;
double trueHeading;
// QUAD TEST
FSUIPC::FsLatLonQuadrilateral quad;
public:
// From X-Plane or MakeRwys
inline Runway(std::string designator,
double latitudeStart,
double longitudeStart,
double latitudeEnd,
double longitudeEnd,
double width)
{
this->designator = designator;
this->width = width * 33.280839895;
this->length = geodata::distanceEarthD(latitudeStart,
longitudeStart,
latitudeEnd,
longitudeEnd) *
3.280839895;
this->trueHeading = geodata::bearingDD(latitudeStart,
longitudeStart,
latitudeEnd,
longitudeEnd);
this->center = {latitudeStart, longitudeStart};
FSUIPC::FsLatLonPoint threshold(latitudeStart, longitudeStart);
quad = FSUIPC::FsLatLonQuadrilateral::ForRunway(threshold,
this->trueHeading,
this->width,
this->length);
}
// From database
inline Runway(std::string designator,
struct geodata::point center,
std::uint8_t width,
std::uint16_t length,
double trueHeading)
{
this->designator = designator;
this->center = center;
this->width = width;
this->length = length;
this->trueHeading = trueHeading;
FSUIPC::FsLatLonPoint threshold(center.latitude, center.longitude);
quad = FSUIPC::FsLatLonQuadrilateral::ForRunway(threshold,
trueHeading,
width,
length);
}
inline void toFile(std::ofstream &out) const
{
writeString(out, this->designator);
write<decltype(this->center)>(out, this->center);
write<decltype(this->width)>(out, this->width);
write<decltype(this->length)>(out, this->length);
write<decltype(this->trueHeading)>(out, this->trueHeading);
}
inline const std::string to_string() const
{
std::ostringstream str;
str << "Runway " << this->designator << " with threshold center "
<< this->center.latitude << "N " << this->center.longitude
<< "E, Width " << (int)this->width << "ft, Length "
<< this->length << "ft, True Heading " << this->trueHeading
<< "°, Quad " << quad.to_string(true, ' ');
return str.str();
}
friend inline std::ostream &operator<<(std::ostream &os,
const Runway &runway)
{
return os << runway.to_string();
}
};
} // namespace simdata
} // namespace file
} // namespace germanairlinesva
#endif