From 29a10bab56c7af03e8e5d5a8d4f60e18f65fc446 Mon Sep 17 00:00:00 2001 From: Valentin Platzgummer Date: Wed, 29 May 2019 12:43:03 +0200 Subject: [PATCH] join poly edited --- src/Wima/WimaArea.cc | 41 ++++++++++++++++++++++++++++++----------- src/Wima/WimaArea.h | 12 +++++++----- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/Wima/WimaArea.cc b/src/Wima/WimaArea.cc index a2a34c3f68..9757cb93f9 100644 --- a/src/Wima/WimaArea.cc +++ b/src/Wima/WimaArea.cc @@ -129,23 +129,38 @@ WimaArea *WimaArea::joinPolygons(WimaArea *poly1, WimaArea *poly2) // continue to walk towards higher indices QGCMapPolyline lineSegment; // segment of walkerPoly, containing only two coordinates int currentPolyIndex = 0; + QGeoCoordinate currentVertex = walkerPoly->vertexCoordinate(currentPolyIndex); + // possible nextVertex (if no intersection between currentVertex and protoVertex with crossPoly) + QGeoCoordinate protoNextVertex = walkerPoly->vertexCoordinate(walkerPoly->nextVertexIndex(currentPolyIndex)); do { - QGeoCoordinate currentVertex = walkerPoly->vertexCoordinate(currentPolyIndex);// change req. - QGeoCoordinate nextVertex = walkerPoly->vertexCoordinate(walkerPoly->nextVertexIndex(currentPolyIndex)); joinedPolygon->appendVertex(currentVertex); QGCMapPolyline walkerPolySegment; walkerPolySegment.appendVertex(currentVertex); - walkerPolySegment.appendVertex(nextVertex); + walkerPolySegment.appendVertex(protoNextVertex); - QList* intersectionList = intersects(&walkerPolySegment, crossPoly); + QList* intersectionList = intersects(&walkerPolySegment, crossPoly); if (intersectionList != nullptr) { - // todo + if (intersectionList->size() > 1*3) { + + } else if ( intersectionList->size() == 1*3) { + // intersectionList->takeAt(0); intersection pt. + // intersectionList->takeAt(1); neighbour of intersec. pt. inside crossPoly, lower index + // intersectionList->takeAt(2); neighbour of intersec. pt. inside crossPoly, higher index + currentVertex = intersectionList->takeAt(0); + protoNextVertex = intersectionList->takeAt(2); + + //currentPolyIndex = crossPoly-> + + } else { + currentPolyIndex++; + currentVertex = walkerPoly->vertexCoordinate(currentPolyIndex);// change req. + protoNextVertex = walkerPoly->vertexCoordinate(walkerPoly->nextVertexIndex(currentPolyIndex)); + } } else { return nullptr; } - } while (currentPolyIndex != 0 || walkerPoly != poly1); return joinedPolygon; @@ -264,9 +279,9 @@ QGeoCoordinate* WimaArea::intersects(QGCMapPolyline *geoLine1, QGCMapPolyline *g } } -QList* WimaArea::intersects(QGCMapPolyline *line, WimaArea *poly) +QList* WimaArea::intersects(QGCMapPolyline *line, WimaArea *poly) { - QList* intersectionList = new QList(); + QList* intersectionList = new QList(); if (line != nullptr && poly != nullptr) { if (line->count() == 2 && poly->count() >= 3) { QVariantList polyPath = poly->path(); @@ -274,13 +289,17 @@ QList* WimaArea::intersects(QGCMapPolyline *line, WimaArea *po QGeoCoordinate pt2; for (int i = 0; i < poly->count(); i++) { QGCMapPolyline polySegment; - polySegment.appendVertex(polyPath.takeAt(i).value()); - polySegment.appendVertex(polyPath.takeAt(poly->nextVertexIndex(i)).value()); + QGeoCoordinate currentVertex = polyPath.takeAt(i).value(); + QGeoCoordinate nextVertex = polyPath.takeAt(poly->nextVertexIndex(i)).value(); + polySegment.appendVertex(currentVertex); + polySegment.appendVertex(nextVertex); QGeoCoordinate* intersectionPoint = intersects(line, &polySegment); if (intersectionPoint != nullptr){ - intersectionList->append(intersectionPoint); + intersectionList->append(*intersectionPoint); + intersectionList->append(currentVertex); + intersectionList->append(nextVertex); } } return intersectionList; diff --git a/src/Wima/WimaArea.h b/src/Wima/WimaArea.h index 8ea2d78b8e..b96fa2d3b9 100644 --- a/src/Wima/WimaArea.h +++ b/src/Wima/WimaArea.h @@ -29,8 +29,8 @@ public: double maxAltitude (void) const { return _maxAltitude;} WimaVehicle* vehicle (void) const { return _wimaVehicle;} - QString mapVisualQML (void) const { return "WimaAreaMapVisual.qml";} - QString editorQML (void) const { return "WimaAreaEditor.qml";} + virtual QString mapVisualQML (void) const { return "WimaAreaMapVisual.qml";} + virtual QString editorQML (void) const { return "WimaAreaEditor.qml";} //Property setters void setMaxAltitude (double alt); @@ -63,11 +63,13 @@ public: /// @param line1 line containing two coordinates, height not taken into account /// @param line2 line containing two coordinates, height not taken into account /// @return the intersection point if line1 intersects line2, nullptr else - QGeoCoordinate* intersects(QGCMapPolyline* line1, QGCMapPolyline* line2); + QGeoCoordinate* intersects(QGCMapPolyline* line1, QGCMapPolyline* line2); /// checks if line1 and poly intersect with each other, takes latitude and longitute into account only (height neglected) /// @param line line containing two coordinates, height not taken into account - /// @return a list of intersection points if line intersects poly, or an empty list else - QList* intersects(QGCMapPolyline* line, WimaArea* poly); + /// @return a list of intersection points and the two neares neighbours of poly to the intersection point if line intersects poly, or an empty list else. + /// The first entry is the first intersec. pt. (if existing). The second and third entries are the nearest neighbours of the first intersec. pt. in poly + /// The fourth entry is the second intersec. pt. (if existing). The fifth and sixth entries are the nearest neighbours of the second intersec. pt. in poly + QList* intersects(QGCMapPolyline* line, WimaArea* poly); // Accurracy used to compute isDisjunct static const double numericalAccuracy; -- GitLab