AP_OAVisGraph.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. #include "AP_OAVisGraph.h"
  14. // constructor initialises expanding array to use 20 elements per chunk
  15. AP_OAVisGraph::AP_OAVisGraph() :
  16. _items(20)
  17. {
  18. }
  19. // add item to visiblity graph, returns true on success, false if graph is full
  20. bool AP_OAVisGraph::add_item(const OAItemID &id1, const OAItemID &id2, float distance_cm)
  21. {
  22. // ensure there is space in the array
  23. if (!_items.expand_to_hold(_num_items+1)) {
  24. return false;
  25. }
  26. // add item
  27. _items[_num_items] = {id1, id2, distance_cm};
  28. _num_items++;
  29. return true;
  30. }