-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patharea.cpp
More file actions
88 lines (77 loc) · 2.22 KB
/
area.cpp
File metadata and controls
88 lines (77 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "pch.h"
#include "area.h"
#include "messageHandler.h"
#include "utils.h"
#include <algorithm>
#include <stdexcept>
vsid::Area::Area(std::vector<std::pair<std::string, std::string>> &coords, bool isActive, bool arrAsDep)
{
for (std::pair<std::string, std::string>& coord : coords)
{
if(coord.first.empty() || coord.second.empty())
{
messageHandler->writeMessage("WARNING", "Empty coordinate string found (first: \"" + coord.first +
"\" / second: \"" + coord.second + "\"! Skipping coordinate.");
continue;
}
this->points.push_back(toPoint(coord));
}
for (auto it = this->points.begin(); it != this->points.end();)
{
Point p1 = *it;
Point p2;
++it;
if (it != this->points.end())
{
p2 = *it;
}
else
{
p2 = *this->points.begin();
}
this->lines.push_back({ p1, p2 });
}
this->isActive = isActive;
this->arrAsDep = arrAsDep;
}
void vsid::Area::showline()
{
for (auto& line : this->lines)
{
messageHandler->writeMessage("DEBUG", "line: " + std::to_string(line.first.lon) + ":" + std::to_string(line.first.lat) + " - " +
std::to_string(line.second.lon) + "." + std::to_string(line.second.lat));
}
}
vsid::Area::Point vsid::Area::toPoint(std::pair<std::string, std::string> &pos)
{
/*double lat = toDeg(pos.first);
double lon = toDeg(pos.second);*/
double lat = vsid::utils::toDeg(pos.first);
double lon = vsid::utils::toDeg(pos.second);
return {lat, lon};
}
bool vsid::Area::inside(const EuroScopePlugIn::CPosition& fplnPos)
{
std::pair<Point, Point> l5 = { {fplnPos.m_Latitude, fplnPos.m_Longitude}, {fplnPos.m_Latitude + 0.05, fplnPos.m_Longitude + 0.05} };
bool inside = false;
for (auto &line : this->lines)
{
if (fplnPos.m_Latitude > std::min<double>(line.first.lat, line.second.lat))
{
if (fplnPos.m_Latitude <= std::max<double>(line.first.lat, line.second.lat))
{
if (fplnPos.m_Longitude <= std::max<double>(line.first.lon, line.second.lon))
{
double x_inter = (fplnPos.m_Latitude - line.first.lat) *
(line.second.lon - line.first.lon) /
(line.second.lat - line.first.lat) + line.first.lon;
if (line.first.lon == line.second.lon || fplnPos.m_Longitude <= x_inter)
{
inside = !inside;
}
}
}
}
}
return inside;
}