More work on diff xmit, not finished yet
This commit is contained in:
@@ -160,8 +160,8 @@ int PlaneMap::total_cells() const {
|
||||
return total;
|
||||
}
|
||||
|
||||
PlaneMap::IdVec PlaneMap::scan_radius(const std::string &plane, double x, double y, double radius, int64_t prepend) const {
|
||||
PlaneMap::IdVec result;
|
||||
PlaneMap::IdVector PlaneMap::scan_radius(const std::string &plane, double x, double y, double radius, int64_t prepend) const {
|
||||
PlaneMap::IdVector result;
|
||||
if (prepend != 0) {
|
||||
result.push_back(prepend);
|
||||
}
|
||||
@@ -188,6 +188,24 @@ PlaneMap::IdVec PlaneMap::scan_radius(const std::string &plane, double x, double
|
||||
return result;
|
||||
}
|
||||
|
||||
util::IdVector PlaneMap::sort_union_id_vectors(const IdVector &v1, const IdVector &v2) {
|
||||
IdVector result(v1.size() + v2.size());
|
||||
int next = 0;
|
||||
for (int64_t id : v1) result[next++] = id;
|
||||
for (int64_t id : v2) result[next++] = id;
|
||||
std::sort(result.begin(), result.end());
|
||||
int64_t prev = -1;
|
||||
int64_t count = 0;
|
||||
for (int64_t id : result) {
|
||||
if (id != prev) {
|
||||
prev = id;
|
||||
result[count++] = id;
|
||||
}
|
||||
}
|
||||
result.resize(count);
|
||||
return result;
|
||||
}
|
||||
|
||||
LuaDefine(unittests_planemap, "c") {
|
||||
double SC = CELL_SCALE;
|
||||
double E = CELL_SCALE * 0.4;
|
||||
@@ -196,7 +214,7 @@ LuaDefine(unittests_planemap, "c") {
|
||||
PlaneMap pm;
|
||||
PlaneItem pia, pib;
|
||||
PlaneMap::EltVec elts;
|
||||
PlaneMap::IdVec ids;
|
||||
PlaneMap::IdVector ids;
|
||||
|
||||
// Simple test.
|
||||
LuaAssert(L, rect_cell_range(-7*SC, -15*SC, 87*SC, 21*SC).equal(-7, -15, 87, 21));
|
||||
@@ -298,5 +316,20 @@ LuaDefine(unittests_planemap, "c") {
|
||||
LuaAssert(L, ids[0] == 123);
|
||||
LuaAssert(L, ids[1] == 456);
|
||||
|
||||
// Test the unioning of ID vectors.
|
||||
PlaneMap::IdVector idv1,idv2;
|
||||
idv1.push_back(1);
|
||||
idv1.push_back(6);
|
||||
idv1.push_back(4);
|
||||
idv2.push_back(1);
|
||||
idv2.push_back(5);
|
||||
idv2.push_back(6);
|
||||
PlaneMap::IdVector joined = PlaneMap::sort_union_id_vectors(idv1, idv2);
|
||||
LuaAssert(L, joined.size() == 4);
|
||||
LuaAssert(L, joined[0] == 1);
|
||||
LuaAssert(L, joined[1] == 4);
|
||||
LuaAssert(L, joined[2] == 5);
|
||||
LuaAssert(L, joined[3] == 6);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user