File indexing completed on 2024-12-01 10:29:54
0001 /* 0002 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef OSM_ZTILE_H 0008 #define OSM_ZTILE_H 0009 0010 #include <array> 0011 #include <cstdint> 0012 0013 namespace OSM { 0014 class BoundingBox; 0015 0016 /** Tile in a quad tree made up out of z-order curve positions. */ 0017 class ZTile 0018 { 0019 public: 0020 constexpr ZTile() = default; 0021 constexpr inline ZTile(uint64_t _z, uint8_t _depth) 0022 : z(_z) 0023 , depth(_depth) 0024 {} 0025 0026 constexpr inline bool operator<(ZTile other) const 0027 { 0028 return depth == other.depth ? z < other.z : depth > other.depth; 0029 } 0030 constexpr inline bool operator==(ZTile other) const 0031 { 0032 return depth == other.depth && z == other.z; 0033 } 0034 0035 /** tile size in 1e7-th degrees **/ 0036 constexpr inline uint32_t size() const 0037 { 0038 return (1ull << depth) - 1; 0039 } 0040 0041 BoundingBox boundingBox() const; 0042 bool intersects(BoundingBox bbox) const; 0043 bool intersects(ZTile other) const; 0044 0045 /** The parent tile in a quad tree. */ 0046 ZTile parent() const; 0047 /** Split into four sub-tiles on one level below. */ 0048 std::array<ZTile, 4> quadSplit() const; 0049 0050 0051 uint64_t z = 0; 0052 uint8_t depth = 0; 0053 }; 0054 0055 /** The smallest tile entirely containing the given bounding box. */ 0056 ZTile ztileFromBoundingBox(BoundingBox bbox); 0057 0058 } 0059 0060 #endif // OSM_ZTILE_H