From 64eaf6fe03443d375448888022542735552bc65e Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 26 Mar 2019 22:50:46 +0100 Subject: [PATCH] Fix for route-path when leg 0 is not a runway MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid doing turn-computation for the first waypoint, even if it’s not a runway. Add a unit-test to cover this case. Reported by Josh Davidson --- src/Main/fg_io.cxx | 3 +++ src/Navaids/routePath.cxx | 6 ++++- .../unit_tests/Navaids/test_flightplan.cxx | 25 +++++++++++++++++++ .../unit_tests/Navaids/test_flightplan.hxx | 4 ++- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Main/fg_io.cxx b/src/Main/fg_io.cxx index 205de4fd6..480ba0e7f 100644 --- a/src/Main/fg_io.cxx +++ b/src/Main/fg_io.cxx @@ -442,6 +442,9 @@ bool FGIO::isMultiplayerRequested() // is easier than checking the raw Options arguments, but works before // this subsytem is actuallyt created. auto channels = globals->get_channel_options_list(); + if (!channels) + return false; // happens running tests + auto it = std::find_if(channels->begin(), channels->end(), [](const std::string& channelOption) { return (channelOption.find("multiplay") == 0); }); diff --git a/src/Navaids/routePath.cxx b/src/Navaids/routePath.cxx index e4c1e6b52..0a68da87a 100644 --- a/src/Navaids/routePath.cxx +++ b/src/Navaids/routePath.cxx @@ -405,8 +405,12 @@ public: legCourseTrue = rwy->headingDeg(); flyOver = true; } else { - // don't set legCourseValid + legCourseValid = true; + legCourseTrue = next.legCourseTrue; turnExitAngle = 0.0; + turnExitPos = pos; + flyOver = true; + return; } } diff --git a/test_suite/unit_tests/Navaids/test_flightplan.cxx b/test_suite/unit_tests/Navaids/test_flightplan.cxx index 00feb3dfd..70ae082dc 100644 --- a/test_suite/unit_tests/Navaids/test_flightplan.cxx +++ b/test_suite/unit_tests/Navaids/test_flightplan.cxx @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -149,6 +150,30 @@ void FlightplanTests::testRoutePathTrivialFlightPlan() CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, fp1->totalDistanceNm(), 1e-9); } +void FlightplanTests::testRoutPathWpt0Midflight() +{ + // test behaviour of RoutePath when WP0 is not a runway + // happens for the Airbus ND which removes past wpts when sequencing + + FlightPlanRef fp1 = makeTestFP("KNUQ", "14L", "PHNL", "22R", + "ROKME WOVAB"); + RoutePath rtepath(fp1); + + SGGeodVec vec = rtepath.pathForIndex(0); + + FGAirportRef ksfo = FGAirport::findByIdent("KSFO"); + FGFixRef rokme = fgpositioned_cast(FGPositioned::findClosestWithIdent("ROKME", ksfo->geod())); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(rokme->geod().getLongitudeDeg(), vec.front().getLongitudeDeg(), 0.01); + CPPUNIT_ASSERT_DOUBLES_EQUAL(rokme->geod().getLatitudeDeg(), vec.front().getLatitudeDeg(), 0.01); + + SGGeodVec vec2 = rtepath.pathForIndex(1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(rokme->geod().getLongitudeDeg(), vec2.front().getLongitudeDeg(), 0.01); + CPPUNIT_ASSERT_DOUBLES_EQUAL(rokme->geod().getLatitudeDeg(), vec2.front().getLatitudeDeg(), 0.01); + + //CPPUNIT_ASSERT(vec.front() +} + void FlightplanTests::testBasicAirways() { Airway* awy = Airway::findByIdent("J547", Airway::HighLevel); diff --git a/test_suite/unit_tests/Navaids/test_flightplan.hxx b/test_suite/unit_tests/Navaids/test_flightplan.hxx index 6d849012e..80153a749 100644 --- a/test_suite/unit_tests/Navaids/test_flightplan.hxx +++ b/test_suite/unit_tests/Navaids/test_flightplan.hxx @@ -38,7 +38,8 @@ class FlightplanTests : public CppUnit::TestFixture CPPUNIT_TEST(testBasicAirways); CPPUNIT_TEST(testAirwayNetworkRoute); CPPUNIT_TEST(testBug1814); - + CPPUNIT_TEST(testRoutPathWpt0Midflight); + // CPPUNIT_TEST(testParseICAORoute); // CPPUNIT_TEST(testParseICANLowLevelRoute); CPPUNIT_TEST_SUITE_END(); @@ -60,6 +61,7 @@ public: void testParseICAORoute(); void testParseICANLowLevelRoute(); void testBug1814(); + void testRoutPathWpt0Midflight(); }; #endif // FG_FLIGHTPLAN_UNIT_TESTS_HXX