Rationalizing the use of scan_radius and making it accessible
This commit is contained in:
@@ -160,10 +160,13 @@ int PlaneMap::total_cells() const {
|
||||
return total;
|
||||
}
|
||||
|
||||
PlaneMap::IdVector PlaneMap::scan_radius(const std::string &plane, float x, float y, float radius, int64_t prepend) const {
|
||||
PlaneMap::IdVector PlaneMap::scan_radius_unsorted(const std::string &plane, float x, float y, float radius, bool exclude_nowhere, int64_t special, bool omit) const {
|
||||
PlaneMap::IdVector result;
|
||||
if (prepend != 0) {
|
||||
result.push_back(prepend);
|
||||
if ((special != 0)&&(!omit)) {
|
||||
result.push_back(special);
|
||||
}
|
||||
if (exclude_nowhere && (plane == "nowhere")) {
|
||||
return result;
|
||||
}
|
||||
auto piter = planes_.find(plane);
|
||||
if (piter != planes_.end()) {
|
||||
@@ -176,7 +179,7 @@ PlaneMap::IdVector PlaneMap::scan_radius(const std::string &plane, float x, floa
|
||||
if (liter != p.end()) {
|
||||
for (PlaneItem *client : liter->second) {
|
||||
if (util::distance_squared(client->x(), client->y(), x, y) <= radsq) {
|
||||
if (client->id() != prepend) {
|
||||
if (client->id() != special) {
|
||||
result.push_back(client->id());
|
||||
}
|
||||
}
|
||||
@@ -188,6 +191,16 @@ PlaneMap::IdVector PlaneMap::scan_radius(const std::string &plane, float x, floa
|
||||
return result;
|
||||
}
|
||||
|
||||
PlaneMap::IdVector PlaneMap::scan_radius(const std::string &plane, float x, float y, float radius, bool exclude_nowhere, int64_t special, bool omit) const {
|
||||
PlaneMap::IdVector result = scan_radius_unsorted(plane, x, y, radius, exclude_nowhere, special, omit);
|
||||
if ((special != 0)&&(!omit)) {
|
||||
std::sort(result.begin() + 1, result.end());
|
||||
} else {
|
||||
std::sort(result.begin(), result.end());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
LuaDefine(unittests_planemap, "c") {
|
||||
float SC = CELL_SCALE;
|
||||
float E = CELL_SCALE * 0.4;
|
||||
@@ -287,13 +300,13 @@ LuaDefine(unittests_planemap, "c") {
|
||||
pia.set_id(123);
|
||||
pib.set_id(456);
|
||||
pib.set_pos("bar", 1100.0, 1000.0, 0.0);
|
||||
ids = pm.scan_radius("bar", 1000.0, 1000.0, 1.0, 0);
|
||||
ids = pm.scan_radius("bar", 1000.0, 1000.0, 1.0, false, 0, false);
|
||||
LuaAssert(L, ids.size() == 1);
|
||||
LuaAssert(L, ids[0] == 123);
|
||||
ids = pm.scan_radius("bar", 1000.0, 1000.0, 99.9, 0);
|
||||
ids = pm.scan_radius("bar", 1000.0, 1000.0, 99.9, false, 0, false);
|
||||
LuaAssert(L, ids.size() == 1);
|
||||
LuaAssert(L, ids[0] == 123);
|
||||
ids = pm.scan_radius("bar", 1000.0, 1000.0, 100.0, 0);
|
||||
ids = pm.scan_radius("bar", 1000.0, 1000.0, 100.0, false, 0, false);
|
||||
LuaAssert(L, ids.size() == 2);
|
||||
LuaAssert(L, ids[0] == 123);
|
||||
LuaAssert(L, ids[1] == 456);
|
||||
|
||||
Reference in New Issue
Block a user