From 3112498cca7e5d992eabed064664a61aab897ecb Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Mon, 25 Jul 2016 18:08:20 -0700 Subject: [PATCH] Adjust grid line direction after polygon clip --- src/MissionManager/ComplexMissionItem.cc | 35 +++++++++++++++++++++--- src/MissionManager/ComplexMissionItem.h | 1 + 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/MissionManager/ComplexMissionItem.cc b/src/MissionManager/ComplexMissionItem.cc index 687c6a485..567b96223 100644 --- a/src/MissionManager/ComplexMissionItem.cc +++ b/src/MissionManager/ComplexMissionItem.cc @@ -396,6 +396,24 @@ void ComplexMissionItem::_intersectLinesWithPolygon(const QList& lineLis } } +/// Adjust the line segments such that they are all going the same direction with respect to going from P1->P2 +void ComplexMissionItem::_adjustLineDirection(const QList& lineList, QList& resultLines) +{ + for (int i=0; i 180.0) { + adjustedLine.setP1(line.p2()); + adjustedLine.setP2(line.p1()); + } else { + adjustedLine = line; + } + + resultLines += adjustedLine; + } +} + void ComplexMissionItem::_gridGenerator(const QList& polygonPoints, QList& gridPoints) { double gridAngle = _gridAngleFact.rawValue().toDouble(); @@ -435,15 +453,24 @@ void ComplexMissionItem::_gridGenerator(const QList& polygonPoints, QL float yBottom = largeBoundRect.bottomRight().y() + 100.0; lineList += QLineF(_rotatePoint(QPointF(x, yTop), center, gridAngle), _rotatePoint(QPointF(x, yBottom), center, gridAngle)); - qCDebug(ComplexMissionItemLog) << "line" << lineList.last().x1() << lineList.last().y1() << lineList.last().x2() << lineList.last().y2(); + qCDebug(ComplexMissionItemLog) << "line(" << lineList.last().x1() << ", " << lineList.last().y1() << ")-(" << lineList.last().x2() <<", " << lineList.last().y2() << ")"; x += gridSpacing; } - // Now intesect the lines with the smaller bounding rect + // Now intersect the lines with the polygon + QList intersectLines; +#if 1 + _intersectLinesWithPolygon(lineList, polygon, intersectLines); +#else + // This is handy for debugging grid problems, not for release + intersectLines = lineList; +#endif + + // Make sure all lines are going to same direction. Polygon intersection leads to line which + // can be in varied directions depending on the order of the intesecting sides. QList resultLines; - //_intersectLinesWithRect(lineList, smallBoundRect, resultLines); - _intersectLinesWithPolygon(lineList, polygon, resultLines); + _adjustLineDirection(intersectLines, resultLines); // Turn into a path for (int i=0; i& lineList, const QRectF& boundRect, QList& resultLines); void _intersectLinesWithPolygon(const QList& lineList, const QPolygonF& polygon, QList& resultLines); + void _adjustLineDirection(const QList& lineList, QList& resultLines); int _sequenceNumber; bool _dirty; -- 2.22.0