2019-05-10 02:59:31 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2024-03-08 22:35:25 -04:00
|
|
|
#include "AC_Avoidance_config.h"
|
|
|
|
|
|
|
|
#if AP_OAPATHPLANNER_ENABLED
|
|
|
|
|
2019-05-10 02:59:31 -03:00
|
|
|
#include "AP_OAVisGraph.h"
|
|
|
|
|
2019-06-17 01:29:10 -03:00
|
|
|
// constructor initialises expanding array to use 20 elements per chunk
|
|
|
|
AP_OAVisGraph::AP_OAVisGraph() :
|
|
|
|
_items(20)
|
2019-05-10 02:59:31 -03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// add item to visiblity graph, returns true on success, false if graph is full
|
|
|
|
bool AP_OAVisGraph::add_item(const OAItemID &id1, const OAItemID &id2, float distance_cm)
|
|
|
|
{
|
2019-07-15 01:11:25 -03:00
|
|
|
// no more than 65k items
|
|
|
|
if (_num_items == UINT16_MAX) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-06-17 01:29:10 -03:00
|
|
|
// ensure there is space in the array
|
|
|
|
if (!_items.expand_to_hold(_num_items+1)) {
|
|
|
|
return false;
|
2019-05-10 02:59:31 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// add item
|
|
|
|
_items[_num_items] = {id1, id2, distance_cm};
|
|
|
|
_num_items++;
|
|
|
|
return true;
|
|
|
|
}
|
2024-03-08 22:35:25 -04:00
|
|
|
|
|
|
|
#endif // AP_OAPATHPLANNER_ENABLED
|