Runway Contains

Logbook Flags
This commit is contained in:
2022-09-25 01:10:01 +02:00
parent e677a345e0
commit f344ffb727
2 changed files with 42 additions and 11 deletions
+32 -1
View File
@@ -8,6 +8,7 @@
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include "geodata.hpp"
#include "helpers.hpp"
@@ -73,7 +74,37 @@ namespace file
inline bool containsPoint(const geodata::point point) const
{
return false;
size_t j = 3;
bool c = false;
std::vector<geodata::point> poly{this->bounds.topLeft,
this->bounds.topRight,
this->bounds.bottomRight,
this->bounds.bottomLeft};
for (size_t i = 0; i < poly.size(); i++) {
if ((point.latitude == poly[i].latitude) &&
(point.longitude == poly[i].longitude)) {
// point is a corner
return true;
}
if (((poly[i].longitude > point.longitude) !=
(poly[j].longitude > point.longitude))) {
double slope = (point.latitude - poly[i].latitude) *
(poly[j].longitude - poly[i].longitude) -
(poly[j].latitude - poly[i].latitude) *
(point.longitude - poly[i].longitude);
if (slope == 0) {
// point is on boundary
return true;
}
if ((slope < 0) != (poly[j].longitude < poly[i].longitude)) {
c = !c;
}
}
j = i;
}
return c;
}
inline void toFile(std::ofstream &out) const