+ return cleanGeneratedPath(aFrom, aTo, aPath, exactTo, exactFrom);
+}
+
+bool Airway::Network::cleanGeneratedPath(WayptRef aFrom, WayptRef aTo, WayptVec& aPath,
+ bool exactTo, bool exactFrom)
+{
+ // path cleaning phase : various cases to handle here.
+ // if either the TO or FROM waypoints were 'exact', i.e part of the enroute
+ // structure, we don't want to duplicate them. This happens frequently with
+ // published SIDs and STARs.
+ // secondly, if the waypoints are NOT on the enroute structure, the course to
+ // them may be a significant dog-leg. Check how the leg course deviates
+ // from the direct course FROM->TO, and delete the first/last leg if it's more
+ // than 90 degrees out.
+ // note we delete a maximum of one leg, and no more. This is a heuristic - we
+ // could check the next (previous) legs, but at some point we'll end up
+ // deleting too much.
+
+ const double MAX_DOG_LEG = 90.0;
+ double enrouteCourse = SGGeodesy::courseDeg(aFrom->position(), aTo->position()),
+ finalLegCourse = SGGeodesy::courseDeg(aPath.back()->position(), aTo->position());
+
+ bool isDogLeg = fabs(headingDiffDeg(enrouteCourse, finalLegCourse)) > MAX_DOG_LEG;
+ if (exactTo || isDogLeg) {