Exemplo n.º 1
0
bool
AirspaceFilterData::Match(const GeoPoint &location,
                          const FlatProjection &projection,
                          const AbstractAirspace &as) const
{
  if (cls != AirspaceClass::AIRSPACECLASSCOUNT && as.GetType() != cls)
    return false;

  if (name_prefix != nullptr && !as.MatchNamePrefix(name_prefix))
    return false;

  if (!direction.IsNegative()) {
    const auto closest = as.ClosestPoint(location, projection);
    const auto bearing = location.Bearing(closest);
    auto direction_error = (bearing - direction).AsDelta().AbsoluteDegrees();
    if (direction_error > fixed(18))
      return false;
  }

  if (!negative(distance)) {
    const auto closest = as.ClosestPoint(location, projection);
    const auto distance = location.Distance(closest);
    if (distance > distance)
      return false;
  }

  return true;
}
Exemplo n.º 2
0
 void
 AddCircle(Airspaces &airspace_database)
 {
   AbstractAirspace *as = new AirspaceCircle(Center, Radius);
   as->set_properties(Name, Type, Base, Top);
   airspace_database.insert(as);
 }
Exemplo n.º 3
0
  /**
   * Check whether this intersection should be added to, or updated in, the warning manager
   *
   * @param airspace Airspace corresponding to current intersection
   */
  void Intersection(const AbstractAirspace& airspace) {
    if (!airspace.IsActive())
      return; // ignore inactive airspaces completely

    if (!warning_manager.GetConfig().IsClassEnabled(airspace.GetType()) ||
        ExcludeAltitude(airspace))
      return;

    AirspaceWarning *warning = warning_manager.GetWarningPtr(airspace);
    if (warning == NULL || warning->IsStateAccepted(warning_state)) {

      AirspaceInterceptSolution solution;

      if (mode_inside) {
        airspace.Intercept(state, perf, solution, state.location, state.location);
      } else {
        solution = Intercept(airspace, state, perf);
      }
      if (!solution.IsValid())
        return;
      if (solution.elapsed_time > max_time)
        return;

      if (warning == NULL)
        warning = warning_manager.GetNewWarningPtr(airspace);

      warning->UpdateSolution(warning_state, solution);
      found = true;
    }
  }
Exemplo n.º 4
0
bool
AirspacePredicateHeightRangeExcludeTwo::operator()(const AbstractAirspace& t) const
{
  if (!check_height(t))
    return false;
  return !t.inside(p1) && !t.inside(p2);
}
Exemplo n.º 5
0
 void
 AddPolygon(Airspaces &airspace_database)
 {
   AbstractAirspace *as = new AirspacePolygon(points);
   as->set_properties(Name, Type, Base, Top);
   airspace_database.insert(as);
 }
bool
AirspacePredicateHeightRangeExcludeTwo::condition(const AbstractAirspace& t) const
{
  if (!check_height(t))
    return false;

  return !t.Inside(p1) && !t.Inside(p2);
}
Exemplo n.º 7
0
 virtual bool operator()(const AbstractAirspace &airspace) const {
   return CheckAirspace(airspace) &&
     /* skip airspaces that we already entered */
     !airspace.Inside(location) &&
     /* check altitude; hard-coded margin of 50m (for now) */
     (!altitude_available ||
      (airspace.GetBase().IsBelow(altitude, fixed(50)) &&
       airspace.GetTop().IsAbove(altitude, fixed(50))));
 }
Exemplo n.º 8
0
  virtual void visit_general(const AbstractAirspace& as) {
    if (do_report) {
#ifdef DO_PRINT
      *fout << "# Name: " << as.get_name_text() 
            << " " << as.get_vertical_text() 
            << "\n";
#endif
    }
  }
Exemplo n.º 9
0
 void
 AddPolygon(Airspaces &airspace_database)
 {
   AbstractAirspace *as = new AirspacePolygon(points);
   as->set_properties(Name, Type, Base, Top);
   as->set_radio(Radio);
   as->set_days(days_of_operation);
   airspace_database.insert(as);
 }
Exemplo n.º 10
0
 void
 AddPolygon(Airspaces &airspace_database)
 {
   AbstractAirspace *as = new AirspacePolygon(points);
   as->SetProperties(name, type, base, top);
   as->SetRadio(radio);
   as->SetDays(days_of_operation);
   airspace_database.Add(as);
 }
Exemplo n.º 11
0
 void Visit(const AbstractAirspace &as) {
     if (do_report) {
         *fout << as;
         *fout << "# Name: " << as.GetName()
               << "Base: " << as.GetBase()
               << " Top: " << as.GetTop()
               << "\n";
     }
 }
Exemplo n.º 12
0
 void
 AddCircle(Airspaces &airspace_database)
 {
   AbstractAirspace *as = new AirspaceCircle(center, radius);
   as->SetProperties(std::move(name), type, base, top);
   as->SetRadio(radio);
   as->SetDays(days_of_operation);
   airspace_database.Add(as);
 }
Exemplo n.º 13
0
void write_border (const AbstractAirspace& as)
{
  const SearchPointVector& spv = as.GetPoints();
  for (auto v = spv.begin(); v != spv.end(); ++v)
    write_point(*v, v->get_flatLocation(), "polygon");

  printf("polygon\n");
  write_spv(as.GetClearance());
  fflush(stdout);
}
Exemplo n.º 14
0
  void
  AddPolygon(Airspaces &airspace_database)
  {
    if (points.size() < 3)
      return;

    AbstractAirspace *as = new AirspacePolygon(points);
    as->SetProperties(std::move(name), type, base, top);
    as->SetRadio(radio);
    as->SetDays(days_of_operation);
    airspace_database.Add(as);
  }
Exemplo n.º 15
0
AirspaceInterceptSolution
AirspaceNearestSort::solve_intercept(const AbstractAirspace &a) const
{
  if (a.Inside(m_location)) {
    return AirspaceInterceptSolution::Invalid();
  } else {
    AirspaceInterceptSolution sol;
    sol.location = a.ClosestPoint(m_location);
    sol.distance = sol.location.Distance(m_location);
    return sol;
  }
}
Exemplo n.º 16
0
  /**
   * Renders the AbstractAirspace on the canvas
   * @param as AbstractAirspace to render
   */
  void
  Render(const AbstractAirspace& as)
  {
    int type = as.get_type();
    if (type <= 0)
      return;

    // No intersections for this airspace
    if (m_intersections.empty())
      return;

    // Select pens and brushes
#ifdef ENABLE_SDL
    Color color =
      Graphics::GetAirspaceColour(settings.colours[type]);
#ifdef ENABLE_OPENGL
    color = color.with_alpha(48);
#endif
    Brush brush(color);
#else
    const Brush &brush = Graphics::GetAirspaceBrushByClass(type, settings);
    canvas.set_text_color(light_color(Graphics::GetAirspaceColourByClass(type, settings)));
#endif

    PixelRect rcd;
    // Calculate top and bottom coordinate
    rcd.top = chart.screenY(as.get_top_altitude(state));
    if (as.is_base_terrain())
      rcd.bottom = chart.screenY(fixed_zero);
    else
      rcd.bottom = chart.screenY(as.get_base_altitude(state));

    // Iterate through the intersections
    for (AirspaceIntersectionVector::const_iterator it = m_intersections.begin();
         it != m_intersections.end(); ++it) {
      const GeoPoint p_start = it->first;
      const GeoPoint p_end = it->second;
      const fixed distance_start = start.distance(p_start);
      const fixed distance_end = start.distance(p_end);

      // Determine left and right coordinate
      rcd.left = chart.screenX(distance_start);
      rcd.right = chart.screenX(distance_end);

      // only one edge found, next edge must be beyond screen
      if ((rcd.left == rcd.right) && (p_start == p_end)) {
        rcd.right = chart.screenX(chart.getXmax());
      }

      // Draw the airspace
      RenderBox(rcd, brush, settings.black_outline, type);
    }
  }
Exemplo n.º 17
0
AirspaceInterceptSolution
AirspaceNearestSort::solve_intercept(const AbstractAirspace &a) const
{
  if (a.inside(m_location)) {
    AirspaceInterceptSolution null_sol;
    return null_sol;
  } else {
    AirspaceInterceptSolution sol;
    sol.location = a.closest_point(m_location);
    sol.distance = sol.location.distance(m_location);
    return sol;
  }
}
Exemplo n.º 18
0
  /**
   * Renders the AbstractAirspace on the canvas
   * @param as AbstractAirspace to render
   */
  void
  Render(const AbstractAirspace& as)
  {
    int type = as.GetType();
    if (type <= 0)
      return;

    // No intersections for this airspace
    if (m_intersections.empty())
      return;

    // Select pens and brushes
#ifndef USE_GDI
    Color color = airspace_look.colors[settings.colours[type]];
#ifdef ENABLE_OPENGL
    color = color.WithAlpha(48);
#endif
    Brush brush(color);
#else
    const Brush &brush = airspace_look.brushes[settings.brushes[type]];
    canvas.SetTextColor(LightColor(airspace_look.colors[settings.colours[type]]));
#endif

    PixelRect rcd;
    // Calculate top and bottom coordinate
    rcd.top = chart.screenY(as.GetTopAltitude(state));
    if (as.IsBaseTerrain())
      rcd.bottom = chart.screenY(fixed_zero);
    else
      rcd.bottom = chart.screenY(as.GetBaseAltitude(state));

    // Iterate through the intersections
    for (auto it = m_intersections.begin(); it != m_intersections.end(); ++it) {
      const GeoPoint p_start = it->first;
      const GeoPoint p_end = it->second;
      const fixed distance_start = start.Distance(p_start);
      const fixed distance_end = start.Distance(p_end);

      // Determine left and right coordinate
      rcd.left = chart.screenX(distance_start);
      rcd.right = chart.screenX(distance_end);

      // only one edge found, next edge must be beyond screen
      if ((rcd.left == rcd.right) && (p_start == p_end)) {
        rcd.right = chart.screenX(chart.getXmax());
      }

      // Draw the airspace
      RenderBox(rcd, brush, settings.black_outline, type);
    }
  }
Exemplo n.º 19
0
Airspace::Airspace(AbstractAirspace& airspace,
                   const TaskProjection& tp):
  FlatBoundingBox(airspace.GetBoundingBox(tp)),
  pimpl_airspace(&airspace)
{
  pimpl_airspace->SetTaskProjection(tp);
}
Exemplo n.º 20
0
 void setup_outline(const AbstractAirspace &airspace) {
   if (settings.black_outline)
     canvas.SelectBlackPen();
   else
     canvas.Select(airspace_look.pens[airspace.GetType()]);
   canvas.SelectHollowBrush();
 }
Exemplo n.º 21
0
AirspaceInterceptSolution 
AirspaceSoonestSort::solve_intercept(const AbstractAirspace &a) const
{
  const GeoPoint loc = a.closest_point(m_state.Location);

  AirspaceInterceptSolution sol;
  bool valid = a.intercept(m_state, m_perf, sol, loc, loc);

  if (sol.elapsed_time > m_max_time) {
    valid = false;
  }
  if (!valid) {
    sol.elapsed_time = -fixed_one;
  }
  return sol;
}
Exemplo n.º 22
0
 void closest(const AbstractAirspace &as) {
   GeoPoint c = as.ClosestPoint(state.location, projection);
   if (fout) {
     *fout << "# closest point\n";
     *fout << c.longitude << " " << c.latitude << " " << "\n";
     *fout << state.location.longitude << " " << state.location.latitude << " " << "\n\n";
   }
   AirspaceInterceptSolution solution;
   GeoVector vec(state.location, c);
   vec.distance = fixed(20000); // set big distance (for testing)
   if (as.Intercept(state, vec.EndPoint(state.location), projection, m_perf, solution)) {
     if (fout) {
       *fout << "# intercept in " << solution.elapsed_time << " h " << solution.altitude << "\n";
     }
   }
 }
Exemplo n.º 23
0
  bool operator()(const AbstractAirspace& airspace) const {
    // Airspace should be visible or have a warning/inside status
    // and airspace needs to be at specified location

    return (visible_predicate(airspace) || warnings.Contains(airspace)) &&
      airspace.Inside(location);
  }
Exemplo n.º 24
0
  virtual void closest(const AbstractAirspace& as) {
    GeoPoint c = as.closest_point(state.Location);
#ifdef DO_PRINT
    *fout << "# closest point\n";
    *fout << c.Longitude << " " << c.Latitude << " " << "\n";
    *fout << state.Location.Longitude << " " << state.Location.Latitude << " " << "\n\n";
#endif
    AirspaceInterceptSolution solution;
    GeoVector vec(state.Location, c);
    vec.Distance = fixed(20000); // set big distance (for testing)
    if (as.intercept(state, vec, m_perf, solution)) {
#ifdef DO_PRINT
      *fout << "# intercept in " << solution.elapsed_time << " h " << solution.altitude << "\n";
#endif
    }
  }
Exemplo n.º 25
0
static inline SoonestAirspace
CalculateSoonestAirspace(const AircraftState &state,
                         const AirspaceAircraftPerformance &perf,
                         const double max_time,
                         const FlatProjection &projection,
                         const AbstractAirspace &airspace)
{
  const auto closest = airspace.ClosestPoint(state.location, projection);
  assert(closest.IsValid());

  const auto solution = airspace.Intercept(state, perf, closest, closest);
  if (!solution.IsValid() ||
      solution.elapsed_time > max_time)
    return SoonestAirspace();

  return SoonestAirspace(airspace, solution.elapsed_time);
}
Exemplo n.º 26
0
void airspace_random_properties(AbstractAirspace& as) {
  AirspaceClass_t Type = (AirspaceClass_t)(rand()%15);
  AIRSPACE_ALT base;
  AIRSPACE_ALT top;
  base.Altitude = fixed(rand()%2000);
  top.Altitude = base.Altitude+fixed(rand()%3000);
  as.set_properties(_T("hello"), Type, base, top);
}
Exemplo n.º 27
0
gcc_pure
static bool
CheckAirspace(const AbstractAirspace &airspace)
{
  const AirspaceWarningConfig &config =
    CommonInterface::GetComputerSettings().airspace.warnings;

  return config.IsClassEnabled(airspace.GetType()) && !IsAcked(airspace);
}
Exemplo n.º 28
0
AirspaceInterceptSolution
AirspaceSoonestSort::solve_intercept(const AbstractAirspace &a,
                                     const TaskProjection &projection) const
{
  const GeoPoint loc = a.ClosestPoint(m_state.location, projection);

  AirspaceInterceptSolution sol =
    AirspaceInterceptSolution::Invalid();
  bool valid = a.Intercept(m_state, m_perf, sol, loc, loc);

  if (sol.elapsed_time > m_max_time) {
    valid = false;
  }
  if (!valid) {
    sol.elapsed_time = fixed(-1);
  }
  return sol;
}
Exemplo n.º 29
0
  void visit_abstract(const AbstractAirspace &as) {
    assert(!m_intersections.empty());

    GeoPoint point = m_intersections[0].first;

    RouteLink l = rpolar.generate_intermediate(link.first,
                                               RoutePoint(proj.project(point), link.second.altitude),
                                               proj);

    if ((l.second.altitude< (short)as.get_base().Altitude) ||
        (l.second.altitude> (short)as.get_top().Altitude))
      return;

    if (negative(min_distance) || (l.d < min_distance)) {
      min_distance = l.d;
      nearest = std::make_pair(&as, l.second);
    }
  }
Exemplo n.º 30
0
static void
airspace_random_properties(AbstractAirspace& as)
{
    AirspaceClass Type = (AirspaceClass)(rand()%14);
    AirspaceAltitude base;
    AirspaceAltitude top;
    base.altitude = fixed(rand()%4000);
    top.altitude = base.altitude+fixed(rand()%3000);
    as.SetProperties(_T("hello"), Type, base, top);
}