Newer
Older
const double WimaArea::numericalAccuracy = 1e-3; // meters
WimaArea::WimaArea(QObject *parent) :
WimaArea (nullptr, parent)
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
//qWarning() << "WimaPolygon:: polygon count" << _polygon->count();
}
WimaArea::WimaArea(WimaArea *other, QObject *parent):
QGCMapPolygon (parent)
,_maxAltitude (30)
,_wimaVehicle (new WimaVehicle(this))
{
if (other != nullptr) {
_maxAltitude = other->maxAltitude();
_wimaVehicle = other->vehicle();
setPath (other->path());
setCenter (other->center());
setCenterDrag (other->centerDrag());
setInteractive (other->interactive());
}
}
WimaArea::~WimaArea()
{
}
void WimaArea::setMaxAltitude(double alt)
{
if(alt > 0 && alt != _maxAltitude){
_maxAltitude = alt;
emit maxAltitudeChanged();
}
}
void WimaArea::setVehicle(WimaVehicle *vehicle)
{
if(_wimaVehicle != vehicle){
_wimaVehicle->deleteLater();
_wimaVehicle = vehicle;
emit vehicleChanged();
}
}
/*QList<WimaArea *>* WimaArea::splitArea<T>(WimaArea *polygonToSplitt, int numberOfFractions)
{
if(numberOfFractions > 0 && polygonToSplitt != nullptr){
WimaArea* poly;
if(p)
= new WimaArea(polygonToSplitt, this);
QList<WimaArea*>* list = new QList<WimaArea*>();
list->append(poly);
return list;
}
return nullptr;
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
89
90
91
92
93
94
95
96
QList<QGCMapPolygon*>* WimaArea::splitArea(int numberOfFractions)
{
return splitPolygonArea(this, numberOfFractions);
}*/
int WimaArea::getClosestVertexIndex(QGeoCoordinate coordinate)
{
if (this->count() == 0) {
qWarning("Polygon count == 0!");
return -1;
}else if (this->count() == 1) {
return 0;
}else {
int index = 0;
double min_dist = coordinate.distanceTo(this->vertexCoordinate(index));
for(int i = 1; i < this->count(); i++){
double dist = coordinate.distanceTo(this->vertexCoordinate(i));
if (dist < min_dist){
min_dist = dist;
index = i;
}
}
return index;
}
}
QGeoCoordinate WimaArea::getClosestVertex(QGeoCoordinate coordinate)
{
return this->vertexCoordinate(getClosestVertexIndex(coordinate));
}
QGCMapPolygon* WimaArea::toQGCPolygon(WimaArea *poly)
{
if (poly != nullptr) {
QGCMapPolygon* qgcPoly = new QGCMapPolygon(this);
qgcPoly->setPath(poly->path());
qgcPoly->setCenter(poly->center());
qgcPoly->setCenterDrag(poly->centerDrag());
qgcPoly->setInteractive(poly->interactive());
return qgcPoly;
} else {
qWarning("WimaArea::toQGCPolygon(): poly == nullptr");
return nullptr;
}
}
QGCMapPolygon *WimaArea::joinPolygons(QList<QGCMapPolygon *>* polyList)
{
return new QGCMapPolygon(this);
}
QGCMapPolygon *WimaArea::joinPolygons(QGCMapPolygon *poly1, QGCMapPolygon *poly2)
return new QGCMapPolygon(this);
}
bool WimaArea::isDisjunct(QList<QGCMapPolygon *>* polyList)
{
// needs improvement
if (polyList != nullptr){
for (int i = 0;i < polyList->size()-1; i++) {
QGCMapPolygon* currPoly = polyList->takeAt(i);
for (int j = i+1; i < polyList->size(); j++) {
if (isDisjunct(currPoly, polyList->takeAt(j))) {
return false;
}
}
}
return true;
} else {
qWarning("WimaArea::isDisjunct(polyList): polyList == nullptr!");
return false;
}
}
bool WimaArea::isDisjunct(QGCMapPolygon *poly1, QGCMapPolygon *poly2)
{
if (poly1 != nullptr && poly2 != nullptr) {
QGCMapPolygon* poly1Copy = new QGCMapPolygon(this);
poly1Copy->setPath(poly1->path());
poly1Copy->offset(numericalAccuracy);// take numerical errors in account
for(int i = 0; i < poly2->count(); i++){
if (poly1Copy->containsCoordinate(poly2->vertexCoordinate(i))){
return false;
}
}
return true;
} else {
qWarning("WimaArea::isDisjunct(poly1, poly2): poly1 == nullptr || poly2 == nullptr!");
return false;
}