26#include <olp/core/CoreApi.h>
27#include <olp/core/porting/optional.h>
65 enum { LevelCount = 32 };
66 enum { MaxLevel = LevelCount - 1 };
77 constexpr TileKey() : row_(0), column_(0), level_(LevelCount) {}
87 return level_ < LevelCount && row_ < (1u << level_) &&
88 column_ < (1u << level_);
97 return level_ == other.level_ && row_ == other.row_ &&
98 column_ == other.column_;
107 return !operator==(other);
118 return level_ != other.level_
119 ? level_ < other.level_
120 : row_ != other.row_ ? row_ < other.row_
121 : column_ < other.column_;
189 std::uint32_t level);
196 constexpr std::uint32_t
Level()
const {
return level_; }
205 constexpr std::uint32_t
Row()
const {
return row_; }
214 constexpr std::uint32_t
RowCount()
const {
return 1 << level_; }
224 constexpr std::uint32_t
Column()
const {
return column_; }
233 constexpr std::uint32_t
ColumnCount()
const {
return 1 << level_; }
328 constexpr bool HasNextRow()
const {
return row_ < (1u << level_) - 1; }
343 constexpr bool HasNextColumn()
const {
return column_ < (1u << level_) - 1; }
409 std::uint32_t row_{0};
410 std::uint32_t column_{0};
411 std::uint32_t level_{LevelCount};
482 static inline constexpr std::uint32_t
RowsAtLevel(std::uint32_t level) {
496 return 1u << (level << 1u);
500 std::uint64_t key{0};
503using TileKeyLevels = std::bitset<TileKey::LevelCount>;
512CORE_API porting::optional<std::uint32_t> GetMinTileKeyLevel(
513 const TileKeyLevels& levels);
522CORE_API porting::optional<std::uint32_t> GetMaxTileKeyLevel(
523 const TileKeyLevels& levels);
534CORE_API porting::optional<std::uint32_t> GetNearestAvailableTileKeyLevel(
535 const TileKeyLevels& levels,
const std::uint32_t reference_level);
540CORE_API std::ostream& operator<<(std::ostream& out,
550struct hash<
olp::geo::TileKey> {
557 return std::hash<std::uint64_t>()(tile_key.
ToQuadKey64());
Addresses a tile in a quadtree.
Definition TileKey.h:63
TileKey NextColumn() const
Gets the key of the tile that has the same level and row numbers but belongs to the next column.
static TileKey FromRowColumnLevel(std::uint32_t row, std::uint32_t column, std::uint32_t level)
Creates a tile key.
static TileKey FromQuadKey(const std::string &quad_key)
Creates a tile key from a quad string.
constexpr bool HasPreviousColumn() const
Checks whether there is the previous column at this level.
Definition TileKey.h:373
bool IsParentOf(const TileKey &tile_key) const
Checks whether the current tile is a parent of another tile.
std::string ToQuadKey() const
Creates a quad string from a tile key to later use it in REST API calls.
TileKey AddedSubHereTile(const std::string &sub_here_tile) const
Gets the absolute quadkey that is constructed from its HERE child tile key.
TileKey Parent() const
Gets the key of the parent tile.
TileKey ChangedLevelTo(std::uint32_t level) const
Gets a new tile key at the requested level.
constexpr std::uint32_t Column() const
Gets the tile column.
Definition TileKey.h:224
constexpr bool operator==(const TileKey &other) const
Checks whether the tile keys are equal.
Definition TileKey.h:96
constexpr std::uint32_t RowCount() const
Gets the number of available rows at the tile level.
Definition TileKey.h:214
constexpr bool operator!=(const TileKey &other) const
Checks whether the tile keys are not equal.
Definition TileKey.h:106
constexpr bool HasNextColumn() const
Checks whether there is the next column at this level.
Definition TileKey.h:343
constexpr bool HasNextRow() const
Checks whether there is the next row at this level.
Definition TileKey.h:328
constexpr bool IsValid() const
Checks whether the tile key is valid.
Definition TileKey.h:86
constexpr std::uint32_t Row() const
Gets the tile row.
Definition TileKey.h:205
std::uint64_t GetSubkey64(int delta) const
Gets a subquadkey that is a relative of its parent.
bool IsChildOf(const TileKey &tile_key) const
Checks whether the current tile is a child of another tile.
TileKey GetChild(TileKeyQuadrant direction) const
Gets the child of the current tile using a direction.
constexpr std::uint32_t ColumnCount() const
Gets the number of available columns at the tile level.
Definition TileKey.h:233
std::string ToHereTile() const
Creates a HERE tile code string from a tile key to later use it in REST API calls.
TileKey GetChild(std::uint8_t index) const
Gets the child of the current tile by its index.
constexpr bool operator<(const TileKey &other) const
Implements the following order on tile keys so they can be used in maps: first level,...
Definition TileKey.h:117
static TileKey FromHereTile(const std::string &key)
Creates a tile key from a HERE tile code string.
TileKey ChangedLevelBy(int delta) const
Gets a new tile key at a level that differs from this tile level by delta.
static TileKey FromQuadKey64(std::uint64_t quad_key)
Creates a tile key from a 64-bit Morton code.
constexpr std::uint32_t Level() const
Gets the tile level.
Definition TileKey.h:196
TileKey NextRow() const
Gets the key of the tile that has the same level and column numbers but belongs to the next row.
TileKey & operator=(const TileKey &)=default
The default copy operator.
TileKey PreviousColumn() const
Gets the key of the tile that has the same level and row numbers but belongs to the previous column.
TileKey AddedSubkey(const std::string &sub_quad_key) const
Gets the absolute quadkey that is constructed from its subquadkey.
constexpr TileKey(const TileKey &)=default
The default copy constructor.
std::uint64_t ToQuadKey64() const
Creates a 64-bit Morton code from a tile key.
constexpr TileKey()
Creates an invalid tile key.
Definition TileKey.h:77
TileKey PreviousRow() const
Gets the key of the tile that has the same level and column numbers but belongs to the previous row.
constexpr bool HasPreviousRow() const
Checks whether there is the previous row at this level.
Definition TileKey.h:358
TileKey AddedSubkey64(std::uint64_t sub_quad_key) const
Gets the absolute quadkey that is constructed from its subquadkey.
TileKeyQuadrant RelationshipToParent() const
Computes the direction of the relationship to the parent.
TileKeyQuadrant
The main direction used to find a child node or the relationship to the parent.
Definition TileKey.h:74
Rules all the other namespaces.
Definition AppleSignInProperties.h:24
A helper structure for basic operations on 64-bit Morton quadkeys.
Definition TileKey.h:420
constexpr QuadKey64Helper Parent() const
Gets the quadkey of the parent.
Definition TileKey.h:431
static constexpr std::uint32_t ChildrenAtLevel(std::uint32_t level)
Gets the number of children at a level.
Definition TileKey.h:495
QuadKey64Helper AddedSubkey(QuadKey64Helper sub_key) const
Gets the absolute quadkey that is constructed from its subquadkey.
QuadKey64Helper GetSubkey(int delta) const
Gets a subquadkey that is a relative of its parent.
static constexpr std::uint32_t RowsAtLevel(std::uint32_t level)
Gets the number of rows at a given level.
Definition TileKey.h:482
constexpr QuadKey64Helper Child() const
Gets the quadkey representing the first child of this quad.
Definition TileKey.h:438
constexpr QuadKey64Helper(std::uint64_t key)
The default constructor.
Definition TileKey.h:424
std::size_t operator()(const olp::geo::TileKey &tile_key) const
The hash function for tile keys.
Definition TileKey.h:556