From 86efb38e036fe9039ad8e622264a94352ada33eb Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Tue, 17 Oct 2017 15:31:37 -0700 Subject: [PATCH] Add ::offset and :: nedPolygon support --- src/MissionManager/QGCMapPolygon.cc | 80 ++++++++++++++++++++++++++++- src/MissionManager/QGCMapPolygon.h | 6 +++ 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/src/MissionManager/QGCMapPolygon.cc b/src/MissionManager/QGCMapPolygon.cc index fddd166a5..460c7c0a5 100644 --- a/src/MissionManager/QGCMapPolygon.cc +++ b/src/MissionManager/QGCMapPolygon.cc @@ -15,6 +15,7 @@ #include #include #include +#include const char* QGCMapPolygon::jsonPolygonKey = "polygon"; @@ -290,7 +291,7 @@ void QGCMapPolygon::_updateCenter(void) if (!_ignoreCenterUpdates) { QGeoCoordinate center; - if (_polygonPath.count() > 2) { + if (_polygonPath.count() > 2) { QPointF centroid(0, 0); QPolygonF polygonF = _toPolygonF(); for (int i=0; i QGCMapPolygon::nedPolygon(void) +{ + QList nedPolygon; + + if (count() > 0) { + QGeoCoordinate tangentOrigin = vertexCoordinate(0); + + for (int i=0; i<_polygonModel.count(); i++) { + double y, x, down; + QGeoCoordinate vertex = vertexCoordinate(i); + if (i == 0) { + // This avoids a nan calculation that comes out of convertGeoToNed + x = y = 0; + } else { + convertGeoToNed(vertex, tangentOrigin, &y, &x, &down); + } + nedPolygon += QPointF(x, y); + } + } + + return nedPolygon; +} + + +void QGCMapPolygon::offset(double distance) +{ + QList rgNewPolygon; + + // I'm sure there is some beautiful famous algorithm to do this, but here is a brute force method + + if (count() > 2) { + // Convert the polygon to NED + QList rgNedVertices = nedPolygon(); + + // Walk the edges, offsetting by the specified distance + QList rgOffsetEdges; + for (int i=0; i coordinateList(void) const; @@ -69,6 +72,9 @@ public: /// @return true: success, false: failure (errorString set) bool loadFromJson(const QJsonObject& json, bool required, QString& errorString); + /// Convert polygon to NED and return (D is ignored) + QList nedPolygon(void); + // Property methods int count (void) const { return _polygonPath.count(); } -- 2.22.0