diff --git a/src/MissionManager/SurveyMissionItemTest.cc b/src/MissionManager/SurveyMissionItemTest.cc index f8715946b7cc41cac7e5b17704f0d987e8eb501a..5fa0e4e339c377013deab9c7637f0e762ddc1f9e 100644 --- a/src/MissionManager/SurveyMissionItemTest.cc +++ b/src/MissionManager/SurveyMissionItemTest.cc @@ -178,3 +178,74 @@ void SurveyMissionItemTest::_testCameraTrigger(void) QCOMPARE(_multiSpy->pullIntFromSignalIndex(lastSequenceNumberChangedIndex), lastSeq); #endif } + +// Clamp expected grid angle from 0<->180. We don't care about opposite angles like 90/270 +double SurveyMissionItemTest::_clampGridAngle180(double gridAngle) +{ + if (gridAngle >= 0.0) { + if (gridAngle == 360.0) { + gridAngle = 0.0; + } else if (gridAngle >= 180.0) { + gridAngle -= 180.0; + } + } else { + if (gridAngle < -180.0) { + gridAngle += 360.0; + } else { + gridAngle += 180.0; + } + } + return gridAngle; +} + +void SurveyMissionItemTest::_testGridAngle(void) +{ + QGCMapPolygon* mapPolygon = _surveyItem->mapPolygon(); + + for (int i=0; i<_polyPoints.count(); i++) { + QGeoCoordinate& vertex = _polyPoints[i]; + mapPolygon->appendVertex(vertex); + } + + for (double gridAngle=-360.0; gridAngle<=360.0; gridAngle++) { + _surveyItem->gridAngle()->setRawValue(gridAngle); + + QVariantList gridPoints = _surveyItem->gridPoints(); + QGeoCoordinate firstTransectEntry = gridPoints[0].value(); + QGeoCoordinate firstTransectExit = gridPoints[1].value(); + double azimuth = firstTransectEntry.azimuthTo(firstTransectExit); + //qDebug() << gridAngle << azimuth << _clampGridAngle180(gridAngle) << _clampGridAngle180(azimuth); + QCOMPARE((int)_clampGridAngle180(gridAngle), (int)_clampGridAngle180(azimuth)); + } +} + +void SurveyMissionItemTest::_testEntryLocation(void) +{ + QGCMapPolygon* mapPolygon = _surveyItem->mapPolygon(); + + for (int i=0; i<_polyPoints.count(); i++) { + QGeoCoordinate& vertex = _polyPoints[i]; + mapPolygon->appendVertex(vertex); + } + + for (double gridAngle=-360.0; gridAngle<=360.0; gridAngle++) { + _surveyItem->gridAngle()->setRawValue(gridAngle); + + QList rgSeenEntryCoords; + QList rgEntryLocation; + rgEntryLocation << SurveyMissionItem::EntryLocationTopLeft + << SurveyMissionItem::EntryLocationTopRight + << SurveyMissionItem::EntryLocationBottomLeft + << SurveyMissionItem::EntryLocationBottomRight; + + // Validate that each entry location is unique + for (int i=0; igridEntryLocation()->setRawValue(entryLocation); + QVERIFY(!rgSeenEntryCoords.contains(_surveyItem->coordinate())); + rgSeenEntryCoords << _surveyItem->coordinate(); + } + rgSeenEntryCoords.clear(); + } +} diff --git a/src/MissionManager/SurveyMissionItemTest.h b/src/MissionManager/SurveyMissionItemTest.h index 78c9bef7632dcc118b3a1ea0ca36ef86f3aa1683..db5969207fbe20a9e7aa557d9334e597706e5bd4 100644 --- a/src/MissionManager/SurveyMissionItemTest.h +++ b/src/MissionManager/SurveyMissionItemTest.h @@ -34,8 +34,12 @@ private slots: void _testDirty(void); void _testCameraValueChanged(void); void _testCameraTrigger(void); + void _testGridAngle(void); + void _testEntryLocation(void); private: + double _clampGridAngle180(double gridAngle); + enum { gridPointsChangedIndex = 0, cameraShotsChangedIndex,