示例#1
0
static TaskPointFactoryType
GetRandomType(const LegalPointSet &l)
{
    StaticArray<TaskPointFactoryType, LegalPointSet::N> types;
    l.CopyTo(std::back_inserter(types));
    return types[(rand() % types.size())];
}
示例#2
0
  virtual void
  EndFan()
  {
    if (fans.full())
      return;

    // remove unnecessary inclusion of origin if next and last points are identical
    unsigned start = 0;
    const size_t gsize = g.size();
    if (gsize > 2 && g[gsize - 1] == g[1])
      start = 1;

    if (gsize < start + 3)
      return;

    // Perform clipping on the GeoPointVector (Result: clipped)
    unsigned size = clip.ClipPolygon(clipped, g.raw() + start, gsize - start);
    // With less than three points we can't draw a polygon
    if (size < 3)
      return;

    // Work directly on the RasterPoints in the fans vector
    fans.Append(size);

    // Convert GeoPoints to RasterPoints
    for (unsigned i = 0; i < size; ++i)
      fans.Append(proj.GeoToScreen(clipped[i]));
  }
示例#3
0
void StaticArrayTest::convertPointer() {
    StaticArray a;
    int* b = a;
    CORRADE_COMPARE(b, a.begin());

    const StaticArray c;
    const int* d = c;
    CORRADE_COMPARE(d, c.begin());

    /* Pointer arithmetic */
    const StaticArray e;
    const int* f = e + 2;
    CORRADE_COMPARE(f, &e[2]);

    /* Verify that we can't convert rvalues */
    CORRADE_VERIFY((std::is_convertible<StaticArray&, int*>::value));
    CORRADE_VERIFY((std::is_convertible<const StaticArray&, const int*>::value));
    {
        #ifdef CORRADE_GCC47_COMPATIBILITY
        CORRADE_EXPECT_FAIL("Rvalue references for *this are not supported in GCC < 4.8.1.");
        #endif
        CORRADE_VERIFY(!(std::is_convertible<StaticArray, int*>::value));
        CORRADE_VERIFY(!(std::is_convertible<StaticArray&&, int*>::value));
    }

    /* Deleting const&& overload and leaving only const& one will not, in fact,
       disable conversion of const Array&& to pointer, but rather make the
       conversion ambiguous, which is not what we want, as it breaks e.g.
       rvalueArrayAccess() test. */
    {
        CORRADE_EXPECT_FAIL("I don't know how to properly disable conversion of const Array&& to pointer.");
        CORRADE_VERIFY(!(std::is_convertible<const StaticArray, const int*>::value));
        CORRADE_VERIFY(!(std::is_convertible<const StaticArray&&, const int*>::value));
    }
}
示例#4
0
  void Show(const PixelRect &rc) override {
    const Layout layout(rc, *waypoint);

    if (task_manager != nullptr)
      goto_button.MoveAndShow(layout.goto_button);

    if (!images.empty()) {
      magnify_button.MoveAndShow(layout.magnify_button);
      shrink_button.MoveAndShow(layout.shrink_button);
    }

    previous_button.MoveAndShow(layout.previous_button);
    next_button.MoveAndShow(layout.next_button);

    close_button.MoveAndShow(layout.close_button);

    info_dock.Move(layout.main);
    details_panel.Move(layout.main);
    details_text.Move(layout.details_text);
#ifdef HAVE_RUN_FILE
    if (!waypoint->files_external.empty())
      file_list.Move(layout.file_list);
#endif

    commands_dock.Move(layout.main);

    if (!images.empty())
      image_window.Move(layout.main);

    UpdatePage();
  }
示例#5
0
  void Move(const PixelRect &rc) override {
    const Layout layout(rc, waypoint);

    if (allow_navigation)
      goto_button.Move(layout.goto_button);

    if (!images.empty()) {
      magnify_button.Move(layout.magnify_button);
      shrink_button.Move(layout.shrink_button);
    }

    if (allow_navigation) {
      previous_button.Move(layout.previous_button);
      next_button.Move(layout.next_button);
    }

    close_button.Move(layout.close_button);

    info_dock.Move(layout.main);
    details_panel.Move(layout.main);
    details_text.Move(layout.details_text);
#ifdef HAVE_RUN_FILE
    if (!waypoint.files_external.empty())
      file_list.Move(layout.file_list);
#endif
    commands_dock.Move(layout.main);

    if (!images.empty())
      image_window.Move(layout.main);
  }
示例#6
0
void StaticArrayTest::convertStaticView() {
    StaticArray a;
    const StaticArray ca;

    const StaticArrayView b = a;
    const ConstStaticArrayView cb = ca;
    CORRADE_VERIFY(b.begin() == a.begin());
    CORRADE_VERIFY(cb.begin() == ca.begin());
}
示例#7
0
int main()
{
  // print my name and this assignment's title
  cout << "Lab 3b, The \"Write A Static Array Class Template\" Program \n";
  cout << "Programmer: Licong Wang\n";
  cout << "Editor(s) used: Visual studio 2013\n";
  cout << "Compiler(s) used:  Microsoft c++ complier\n";
  cout << "File: " << __FILE__ << endl;
  cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;

  StaticArray<int, 100> a;
  string buf;
  int key;
  int value;

    while (true)
    {
      cout << "Input an index and a value [Q to quit]: ";
    
      cin >> buf;
      if (buf == "Q" || buf == "q")
        break;
      key = atoi(buf.c_str());

      cin >> buf;
      value = atoi(buf.c_str());
      a[key] = value;
    }

  cout << "\nI stored this many values : " << a.size() << endl;
  cout << "These values are:" << endl;

  vector<int> keys = a.keys();
  for (int i = 0; i < keys.size(); i++)
    cout << keys[i] << " " << a[keys[i]] << endl;

  while (true)
  {
    cout << "Input an index for me to look up [Q to quit]: ";
    cin >> buf;

    if (buf == "Q" || buf == "q")
      break;
    else
    {
      key = atoi(buf.c_str());
      if (a.containsKey(key))
        cout << "Found it -- the value stored at " << key << " is " << a[key] << endl;
      else
        cout << "I didn't find it" << endl;
    }
  }
  
  cout << "\nPress ENTER to continue.\n";
  cin.ignore();  // prevent cin.get() from getting a new line from previous cin
  cin.get();
}
    void assignArray(const StaticArray<T>& array) {
      _size = 0;

      if (_data) {
        delete[] _data;
        _data = 0;
      }

      initWithData(array.cArray(), array.size());
    }
示例#9
0
void StaticArrayTest::access() {
    StaticArray a;
    for(std::size_t i = 0; i != 5; ++i)
        a[i] = i;

    CORRADE_COMPARE(a.data(), static_cast<int*>(a));
    CORRADE_COMPARE(*(a.begin()+2), 2);
    CORRADE_COMPARE(a[4], 4);
    CORRADE_COMPARE(a.end()-a.begin(), 5);
}
示例#10
0
  /**
   * Calculate average from samples
   *
   * @return Average value in buffer
   */
  gcc_pure
  fixed Average() const {
    assert(!x.empty());

    fixed y = fixed_zero;
    for (unsigned i = 0; i < x.size(); i++)
      y += x[i];

    return y / x.size();
  }
示例#11
0
  void CalculateRoute(const ProtectedRoutePlanner &route_planner) {
    const ProtectedRoutePlanner::Lease lease(route_planner);

    for (auto it = waypoints.begin(), end = waypoints.end(); it != end; ++it) {
      VisibleWaypoint &vwp = *it;
      const Waypoint &way_point = *vwp.waypoint;

      if (way_point.IsLandable() || way_point.flags.watched)
        vwp.CalculateReachability(lease, task_behaviour);
    }
  }
示例#12
0
void StaticArrayTest::convertView() {
    StaticArray a;
    const StaticArray ca;

    const ArrayView b = a;
    const ConstArrayView cb = ca;
    CORRADE_VERIFY(b.begin() == a.begin());
    CORRADE_VERIFY(cb.begin() == ca.begin());
    CORRADE_COMPARE(b.size(), 5);
    CORRADE_COMPARE(cb.size(), 5);
}
示例#13
0
  void Visit(const AirspaceWarning& as) {
    if (as.GetWarningState() == AirspaceWarning::WARNING_INSIDE) {
      ids_inside.checked_append(&as.GetAirspace());
    } else if (as.GetWarningState() > AirspaceWarning::WARNING_CLEAR) {
      ids_warning.checked_append(&as.GetAirspace());
      locations.checked_append(as.GetSolution().location);
    }

    if (!as.IsAckExpired())
      ids_acked.checked_append(&as.GetAirspace());
  }
示例#14
0
void
QuickMenu::Prepare(ContainerWindow &parent, const PixelRect &rc)
{
  WindowStyle grid_view_style;
  grid_view_style.ControlParent();
  grid_view_style.Hide();

  const auto &dialog_look = UIGlobals::GetDialogLook();

  const auto &font = *dialog_look.button.font;
  const unsigned column_width = Layout::Scale(78u);
  const unsigned row_height =
    std::max(2 * (Layout::GetTextPadding() + font.GetHeight()),
             Layout::GetMaximumControlHeight());

  grid_view.Create(parent, dialog_look, rc, grid_view_style,
                   column_width, row_height);
  SetWindow(&grid_view);

  WindowStyle buttonStyle;
  buttonStyle.TabStop();

  for (unsigned i = 0; i < menu.MAX_ITEMS; ++i) {
    if (buttons.full())
      continue;

    const auto &menuItem = menu[i];
    if (!menuItem.IsDefined())
      continue;

    TCHAR buffer[100];
    const auto expanded =
      ButtonLabel::Expand(menuItem.label, buffer, ARRAY_SIZE(buffer));
    if (!expanded.visible)
      continue;

    PixelRect button_rc;
    button_rc.left = 0;
    button_rc.top = 0;
    button_rc.right = 80;
    button_rc.bottom = 30;
    auto *button = new Button(grid_view, button_rc, buttonStyle,
                              new QuickMenuButtonRenderer(dialog_look,
                                                          expanded.text),
                              *this, menuItem.event);
    button->SetEnabled(expanded.enabled);

    buttons.append(button);
    grid_view.AddItem(*button);
  }

  grid_view.RefreshLayout();
  UpdateCaption();
}
示例#15
0
文件: State.hpp 项目: macsux/XCSoar
  void Refresh(fixed Time) {
    available.Expire(Time, fixed(10));
    if (!available)
      traffic.clear();

    for (unsigned i = traffic.size(); i-- > 0;)
      if (!traffic[i].Refresh(Time))
        traffic.quick_remove(i);

    NewTraffic = false;
  }
示例#16
0
  void AddWaypoint(const WaypointPtr &way_point, bool in_task) {
    if (waypoints.full())
      return;

    if (!projection.WaypointInScaleFilter(*way_point) && !in_task)
      return;

    PixelPoint sc;
    if (!projection.GeoToScreenIfVisible(way_point->location, sc))
      return;

    VisibleWaypoint &vwp = waypoints.append();
    vwp.Set(way_point, sc, in_task);
  }
示例#17
0
StaticArray<uint8_t,5> readRegister(Spi& pSpi, FiveByteRegister pRegister)
{
    StaticArray<uint8_t,5> value;
    uint8_t cmd = CMD_R_REGISTER | (pRegister & MASK_REGISTER_CMD);

    pSpi.chipSelect(true);
    pSpi.transfer(cmd);
    for (size_t i = 0 ; i < value.size()  ; ++i) {
        value[i] = pSpi.transfer(CMD_NOP);
    }
    pSpi.chipSelect(false);

    return value;
}
void
FlarmDetails::LoadSecondary()
{
  LogStartUp(_T("OpenFLARMDetails"));

  // if (FLARM Details already there) delete them;
  if (!FLARM_Names.empty())
    FLARM_Names.clear();

  TLineReader *reader = OpenDataTextFile(_T("xcsoar-flarm.txt"));
  if (reader != NULL) {
    LoadSecondaryFile(*reader);
    delete reader;
  }
}
示例#19
0
文件: State.hpp 项目: macsux/XCSoar
  /**
   * Looks up an item in the traffic list.
   *
   * @param id FLARM id
   * @return the FLARM_TRAFFIC pointer, NULL if not found
   */
  FLARM_TRAFFIC *FindTraffic(FlarmId id) {
    for (unsigned i = 0; i < traffic.size(); i++)
      if (traffic[i].id == id)
        return &traffic[i];

    return NULL;
  }
示例#20
0
文件: State.hpp 项目: macsux/XCSoar
  /**
   * Looks up an item in the traffic list.
   *
   * @param name the name or call sign
   * @return the FLARM_TRAFFIC pointer, NULL if not found
   */
  const FLARM_TRAFFIC *FindTraffic(const TCHAR *name) const {
    for (unsigned i = 0; i < traffic.size(); i++)
      if (traffic[i].name.equals(name))
        return &traffic[i];

    return NULL;
  }
示例#21
0
  WindowReference(const ContainerWindow &root, Window &_window)
    :window(&_window) {
    const ContainerWindow *parent = window->GetParent();
    while (true) {
      if (parent == &root)
        return;

      if (parent == NULL || parents.full()) {
        window = NULL;
        return;
      }

      parents.append(parent);
      parent = parent->GetParent();
    }
  }
示例#22
0
static void
NextPage(int Step)
{
    assert(waypoint);

    int last_page = 2 + images.size();
    do {
        page += Step;
        if (page < 0)
            page = last_page;
        else if (page > last_page)
            page = 0;
        // skip wDetails frame, if there are no details
    } while (page == 1 &&
#ifdef ANDROID
             waypoint->files_external.empty() &&
#endif
             waypoint->details.empty());

    wInfo->SetVisible(page == 0);
    wDetails->SetVisible(page == 1);
    wCommand->SetVisible(page == 2);
    wImage->SetVisible(page >= 3);
    zoom = 0;
    wMagnify->SetVisible(page >= 3);
    wMagnify->SetEnabled(true);
    wShrink->SetVisible(page >= 3);
    wShrink->SetEnabled(false);
}
示例#23
0
 StaticArray<T>::StaticArray(const StaticArray& sa)
 {
     m_Size = sa.size();
     m_MasPoint = new T[m_Size];
     for (uint32_t i = 0; i < m_Size; i++)
         m_MasPoint[i] = sa[i];
 }
示例#24
0
    /**
     * On devices without a touch screen, enable button selection with
     * KEY_LEFT / KEY_RIGHT.  That allows navigating a ListControl while
     * allowing the user to select an action on a list item.
     */
    void EnableCursorSelection(unsigned _index=0) {
        assert(selected_index < 0);
        assert(_index < buttons.size());

        selected_index = _index;
        buttons[selected_index]->SetSelected(true);
    }
int
FlarmDetails::LookupSecondaryIndex(FlarmId id)
{
  for (unsigned i = 0; i < FLARM_Names.size(); i++)
    if (FLARM_Names[i].ID == id)
      return i;

  return -1;
}
int
FlarmDetails::LookupSecondaryIndex(const TCHAR *cn)
{
  for (unsigned i = 0; i < FLARM_Names.size(); i++)
    if (FLARM_Names[i].Name.equals(cn))
      return i;

  return -1;
}
示例#27
0
void
QuickMenu::UpdateCaption()
{
  StaticString<32> buffer;
  unsigned pageSize = grid_view.GetNumColumns() * grid_view.GetNumRows();
  unsigned lastPage = buttons.size() / pageSize;
  buffer.Format(_T("Quick Menu  %d/%d"),
                grid_view.GetCurrentPage() + 1, lastPage + 1);
  dialog.SetCaption(buffer);
}
示例#28
0
  void CalculateDirect(const PolarSettings &polar_settings,
                       const TaskBehaviour &task_behaviour,
                       const DerivedInfo &calculated) {
    if (!basic.location_available || !basic.NavAltitudeAvailable())
      return;

    const GlidePolar &glide_polar =
      task_behaviour.route_planner.reach_polar_mode == RoutePlannerConfig::Polar::TASK
      ? polar_settings.glide_polar_task
      : calculated.glide_polar_safety;
    const MacCready mac_cready(task_behaviour.glide, glide_polar);

    for (auto it = waypoints.begin(), end = waypoints.end(); it != end; ++it) {
      VisibleWaypoint &vwp = *it;
      const Waypoint &way_point = *vwp.waypoint;

      if (way_point.IsLandable() || way_point.flags.watched)
        vwp.CalculateReachabilityDirect(basic, calculated.GetWindOrZero(),
                                        mac_cready, task_behaviour);
    }
  }
示例#29
0
  void Hide() override {
    if (task_manager != nullptr)
      goto_button.Hide();

    if (!images.empty()) {
      magnify_button.Hide();
      shrink_button.Hide();
    }

    previous_button.Hide();
    next_button.Hide();

    close_button.Hide();

    info_dock.Hide();
    details_panel.Hide();
    commands_dock.Hide();

    if (!images.empty())
      image_window.Hide();
  }
示例#30
0
  void Show(const PixelRect &rc) override {
    const Layout layout(rc, geometry);

    RowFormWidget::Show(layout.form);

    copy_button.MoveAndShow(layout.copy_button);
    paste_button.MoveAndShow(layout.paste_button);
    close_button.MoveAndShow(layout.close_button);

    for (unsigned i = 0; i < previews.size(); ++i)
      previews[i].MoveAndShow(layout.info_boxes.positions[i]);
  }