Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

tiles_for_area: vector instead of set #437

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/backend/apidb/quad_tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
*/

#include "cgimap/backend/apidb/quad_tile.hpp"
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>

using std::set;

/* following functions liberally nicked from TomH's quad_tile
* library.
Expand All @@ -24,13 +23,18 @@ std::vector<tile_id_t> tiles_for_area(double minlat, double minlon, double maxla
const unsigned int maxx = lon2x(maxlon);
const unsigned int miny = lat2y(minlat);
const unsigned int maxy = lat2y(maxlat);
set<tile_id_t> tiles;

std::vector<tile_id_t> tiles;
tiles.reserve((1ULL + maxx - minx) * (1ULL + maxy - miny));

for (tile_id_t x = minx; x <= maxx; x++) {
for (tile_id_t y = miny; y <= maxy; y++) {
tiles.insert(xy2tile(x, y));
tiles.emplace_back(xy2tile(x, y));
}
}

return {tiles.begin(), tiles.end()};
std::sort(tiles.begin(), tiles.end());
tiles.erase(std::unique(tiles.begin(), tiles.end()), tiles.end());

return tiles;
}