Ejemplo n.º 1
0
gcc_pure
NearestAirspace
NearestAirspace::FindHorizontal(const MoreData &basic,
                                const ProtectedAirspaceWarningManager &airspace_warnings,
                                const Airspaces &airspace_database)
{
  if (!basic.location_available)
    /* can't check for airspaces without a GPS fix */
    return NearestAirspace();

  /* find the nearest airspace */
  //consider only active airspaces
  const WrapAirspacePredicate<ActiveAirspacePredicate> active_predicate(&airspace_warnings);
  const WrapAirspacePredicate<OutsideAirspacePredicate> outside_predicate(AGeoPoint(basic.location, RoughAltitude(0)));
  const AndAirspacePredicate outside_and_active_predicate(active_predicate, outside_predicate);
  const Airspace *airspace;

  //if altitude is available, filter airspaces in same height as airplane
  if (basic.NavAltitudeAvailable()) {
    /* check altitude; hard-coded margin of 50m (for now) */
    WrapAirspacePredicate<AirspacePredicateHeightRange> height_range_predicate(RoughAltitude(basic.nav_altitude-fixed(50)),
                                                                               RoughAltitude(basic.nav_altitude+fixed(50)));
     AndAirspacePredicate and_predicate(outside_and_active_predicate, height_range_predicate);
     airspace = airspace_database.FindNearest(basic.location, and_predicate);
  } else //only filter outside and active
    airspace = airspace_database.FindNearest(basic.location, outside_and_active_predicate);

  if (airspace == nullptr)
    return NearestAirspace();

  const AbstractAirspace &as = airspace->GetAirspace();

  /* calculate distance to the nearest point */
  const GeoPoint closest = as.ClosestPoint(basic.location,
                                           airspace_database.GetProjection());
  return NearestAirspace(as, basic.location.Distance(closest));
}
Ejemplo n.º 2
0
void scan_airspaces(const AircraftState state,
                    const Airspaces& airspaces,
                    const AirspaceAircraftPerformance& perf,
                    bool do_report,
                    const GeoPoint &target)
{
    const fixed range(20000.0);

    Directory::Create(_T("output/results"));
    AirspaceVisitorPrint pvn("output/results/res-bb-nearest.txt",
                             do_report);
    const Airspace *nearest = airspaces.FindNearest(state.location);
    if (nearest != nullptr) {
        AirspaceVisitor &v = pvn;
        v.Visit(*nearest);
    }

    {
        AirspaceVisitorPrint pvisitor("output/results/res-bb-range.txt",
                                      do_report);
        airspaces.VisitWithinRange(state.location, range, pvisitor);
    }

    {
        AirspaceVisitorClosest pvisitor("output/results/res-bb-closest.txt",
                                        airspaces.GetProjection(), state, perf);
        airspaces.VisitWithinRange(state.location, range, pvisitor);
    }

    {
        const std::vector<Airspace> vi = airspaces.FindInside(state);
        AirspaceVisitorPrint pvi("output/results/res-bb-inside.txt",
                                 do_report);
        std::for_each(vi.begin(), vi.end(), CallVisitor<AirspaceVisitor>(pvi));
    }

    {
        AirspaceIntersectionVisitorPrint ivisitor("output/results/res-bb-intersects.txt",
                "output/results/res-bb-intersected.txt",
                "output/results/res-bb-intercepts.txt",
                do_report,
                state, perf);
        airspaces.VisitIntersecting(state.location, target, ivisitor);
    }

    {
        AirspaceNearestSort ans(state.location);
        const AbstractAirspace* as = ans.find_nearest(airspaces, range);
        if (do_report) {
            std::ofstream fout("output/results/res-bb-sortednearest.txt");
            if (as) {
                fout << *as << "\n";
            } else {
                fout << "# no nearest found\n";
            }
        }
    }

    {
        AirspaceSoonestSort ans(state, perf);
        const AbstractAirspace* as = ans.find_nearest(airspaces);
        if (do_report) {
            std::ofstream fout("output/results/res-bb-sortedsoonest.txt");
            if (as) {
                fout << *as << "\n";
            } else {
                fout << "# no soonest found\n";
            }
        }
    }
}