Rationalizing the use of scan_radius and making it accessible

This commit is contained in:
2021-11-23 16:10:48 -05:00
parent c75ba3b3a8
commit 8c871a9f40
10 changed files with 109 additions and 110 deletions

View File

@@ -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);