Skip to content

Commit

Permalink
rip out more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
cldellow committed Oct 5, 2024
1 parent c13ce48 commit 1dfa034
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 101 deletions.
29 changes: 1 addition & 28 deletions include/coordinates.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

#include <cstdint>
#include <utility>
#include <vector>
#include <deque>
#include <unordered_set>

// A 36-bit integer can store all OSM node IDs; we represent this as 16 collections
// of 32-bit integers.
Expand All @@ -21,9 +18,6 @@ typedef uint64_t NodeID;
typedef uint64_t WayID;
typedef uint64_t RelationID;

typedef std::vector<WayID> WayVec;


// Supports up to z22
typedef uint32_t TileCoordinate;

Expand Down Expand Up @@ -60,32 +54,14 @@ struct TileCoordinatesCompare {
return a.y < b.y;
}
};

typedef class TileCoordinates_ TileCoordinates;
namespace std {
template<> struct hash<TileCoordinates> {
size_t operator()(const TileCoordinates & obj) const {
return 16384 * hash<TileCoordinate>()(obj.x) + hash<TileCoordinate>()(obj.y);
}
};
}

struct LatpLon {
int32_t latp;
int32_t lon;
};
inline bool operator==(const LatpLon &a, const LatpLon &b) { return a.latp==b.latp && a.lon==b.lon; }
namespace std {
/// Hashing function so we can use an unordered_set
template<>
struct hash<LatpLon> {
size_t operator()(const LatpLon &ll) const {
return std::hash<int32_t>()(ll.latp) ^ std::hash<int32_t>()(ll.lon);
}
};
}

typedef std::vector<LatpLon> LatpLonVec;
typedef std::deque<LatpLon> LatpLonDeque;

double deg2rad(double deg);
double rad2deg(double rad);
Expand Down Expand Up @@ -123,8 +99,5 @@ double degp2meter(double degp, double latp);

double meter2degp(double meter, double latp);

// the range between smallest y and largest y is filled, for each x
void fillCoveredTiles(std::unordered_set<TileCoordinates> &tileSet);

#endif //_COORDINATES_H

37 changes: 6 additions & 31 deletions include/tile_coordinates_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <cstddef>
#include "coordinates.h"
#include <vector>

struct Bbox {
size_t minX;
Expand All @@ -11,44 +12,18 @@ struct Bbox {
size_t maxY;
};

// Interface representing a bitmap of tiles of interest at a given zoom.
class TileCoordinatesSet {
public:
virtual bool test(TileCoordinate x, TileCoordinate y) const = 0;
virtual void set(TileCoordinate x, TileCoordinate y) = 0;
virtual size_t size() const = 0;
virtual size_t zoom() const = 0;
};

// Read-write implementation for precise sets; maximum zoom is
// generally expected to be z14.
class PreciseTileCoordinatesSet : public TileCoordinatesSet {
class PreciseTileCoordinatesSet {
public:
PreciseTileCoordinatesSet(unsigned int zoom);
bool test(TileCoordinate x, TileCoordinate y) const override;
size_t size() const override;
size_t zoom() const override;
void set(TileCoordinate x, TileCoordinate y) override;
bool test(TileCoordinate x, TileCoordinate y) const;
size_t size() const;
size_t zoom() const;
void set(TileCoordinate x, TileCoordinate y);

private:
unsigned int zoom_;
std::vector<bool> tiles;
};

// Read-only implementation for a lossy set. Used when zoom is
// z15 or higher, extrapolates a result based on a set for a lower zoom.
class LossyTileCoordinatesSet : public TileCoordinatesSet {
public:
LossyTileCoordinatesSet(unsigned int zoom, const TileCoordinatesSet& precise);
bool test(TileCoordinate x, TileCoordinate y) const override;
size_t size() const override;
size_t zoom() const override;
void set(TileCoordinate x, TileCoordinate y) override;

private:
unsigned int zoom_;
const TileCoordinatesSet& tiles;
unsigned int scale;
};

#endif
18 changes: 0 additions & 18 deletions src/coordinates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,3 @@ double degp2meter(double degp, double latp) {
double meter2degp(double meter, double latp) {
return rad2deg((1/RadiusMeter) * (meter / cos(deg2rad(latp2lat(latp)))));
}

// the range between smallest y and largest y is filled, for each x
void fillCoveredTiles(std::unordered_set<TileCoordinates>& tileSet) {
std::vector<TileCoordinates> tileList(tileSet.begin(), tileSet.end());
std::sort(tileList.begin(), tileList.end(), TileCoordinatesCompare());

TileCoordinate prevX = 0, prevY = static_cast<TileCoordinate>(-2);
for (TileCoordinates index: tileList) {
TileCoordinate tileX = index.x, tileY = index.y;
if (tileX == prevX) {
// this loop has no effect at the first iteration
for (TileCoordinate fillY = prevY+1; fillY < tileY; fillY++) {
tileSet.insert(TileCoordinates(tileX, fillY));
}
}
prevX = tileX, prevY = tileY;
}
}
20 changes: 0 additions & 20 deletions src/tile_coordinates_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,4 @@ void PreciseTileCoordinatesSet::set(TileCoordinate x, TileCoordinate y) {
tiles[loc] = true;
}

LossyTileCoordinatesSet::LossyTileCoordinatesSet(unsigned int zoom, const TileCoordinatesSet& underlying) : zoom_(zoom), tiles(underlying), scale(1 << (zoom - underlying.zoom())) {
if (zoom <= underlying.zoom())
throw std::out_of_range("LossyTileCoordinatesSet: zoom (" + std::to_string(zoom_) + ") must be greater than underlying set's zoom (" + std::to_string(underlying.zoom()) + ")");
}

bool LossyTileCoordinatesSet::test(TileCoordinate x, TileCoordinate y) const {
return tiles.test(x / scale, y / scale);
}

size_t LossyTileCoordinatesSet::size() const {
return tiles.size() * scale * scale;
}

size_t LossyTileCoordinatesSet::zoom() const {
return zoom_;
}

void LossyTileCoordinatesSet::set(TileCoordinate x, TileCoordinate y) {
throw std::logic_error("LossyTileCoordinatesSet::set() is not implemented; LossyTileCoordinatesSet is read-only");
}

5 changes: 1 addition & 4 deletions src/tilemaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
#include <iostream>
#include <vector>
#include <cstdint>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <stdexcept>
#include <thread>
#include <mutex>
#include <chrono>
#include <deque>
#include <map>

// Tilemaker code
Expand Down

0 comments on commit 1dfa034

Please sign in to comment.