KOSMIndoorMap

ztile.cpp
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "ztile.h"
8#include "datatypes.h"
9
10using namespace OSM;
11
12OSM::BoundingBox ZTile::boundingBox() const
13{
14 const OSM::Coordinate min(z << (2 * depth));
15 const OSM::Coordinate max(min.latitude + size(), min.longitude + size());
16 return OSM::BoundingBox(min, max);
17}
18
19bool ZTile::intersects(OSM::BoundingBox bbox) const
20{
21 return OSM::intersects(boundingBox(), bbox);
22}
23
24bool ZTile::intersects(ZTile other) const
25{
26 const auto commonDepth = std::max(depth, other.depth);
27 const auto z1 = z >> (2 * (commonDepth - depth));
28 const auto z2 = other.z >> (2 * (commonDepth - other.depth));
29 return z1 == z2;
30}
31
33{
34 return ZTile{z >> 2, (uint8_t)(depth + 1)};
35}
36
37std::array<ZTile, 4> ZTile::quadSplit() const
38{
39 if (depth == 0) {
40 return {};
41 }
42
43 const uint8_t subDepth = depth - 1;
44 const uint64_t subZ = z << 2;
45
46 return { ZTile{ subZ, subDepth }, ZTile{ subZ + 1, subDepth }, ZTile{ subZ + 2, subDepth }, ZTile { subZ + 3, subDepth } };
47}
48
50{
51 uint64_t zMin = bbox.min.z();
52 uint64_t zMax = bbox.max.z();
53
54 ZTile tile;
55
56 while (zMin != zMax) {
57 zMin >>= 2;
58 zMax >>= 2;
59 ++tile.depth;
60 }
61 tile.z = zMin;
62 return tile;
63}
Bounding box, ie.
Definition datatypes.h:95
Coordinate, stored as 1e7 * degree to avoid floating point precision issues, and offset to unsigned v...
Definition datatypes.h:37
constexpr uint64_t z() const
Z-order curve value for this coordinate.
Definition datatypes.h:70
Tile in a quad tree made up out of z-order curve positions.
Definition ztile.h:18
std::array< ZTile, 4 > quadSplit() const
Split into four sub-tiles on one level below.
Definition ztile.cpp:37
ZTile parent() const
The parent tile in a quad tree.
Definition ztile.cpp:32
constexpr uint32_t size() const
tile size in 1e7-th degrees
Definition ztile.h:36
Low-level types and functions to work with raw OSM data as efficiently as possible.
ZTile ztileFromBoundingBox(BoundingBox bbox)
The smallest tile entirely containing the given bounding box.
Definition ztile.cpp:49
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:46:39 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.