7#include "data/spatial_index_data.cpp"
8#include "data/spatial_index_parameters_p.h"
9#include "data/spatial_index_properties.cpp"
10#include "spatial_index_p.h"
15constexpr const float XEnd = XStart + XRange;
16constexpr const float YEnd = YStart + YRange;
19static_assert(spatial_index_properties[0].m_tz == Tz::Undefined);
20static_assert(spatial_index_properties[0].m_subdiv == 0);
23constexpr uint32_t latlonToZ(
float lat,
float lon)
25 const uint32_t x = ((lon - XStart) / XRange) * (1 << ZDepth);
26 const uint32_t y = ((lat - YStart) / YRange) * (1 << ZDepth);
28 for (
int i = ZDepth - 1; i >= 0; --i) {
30 z += (y & (1 << i)) ? 1 : 0;
32 z += (x & (1 << i)) ? 1 : 0;
38static_assert(latlonToZ(YStart, XStart) == 0);
39static_assert(latlonToZ(YEnd - 1.0f / (1 << ZDepth), XEnd - 1.0f / (1 << ZDepth)) == (1 << (2 * ZDepth)) - 1);
40static_assert(latlonToZ(YStart + YRange / 2.0f, 0.0f) == ((1 << (2 * ZDepth - 1)) | (1 << (2 * ZDepth - 2))));
42SpatialIndexProperty SpatialIndex::lookup(
float lat,
float lon)
44 if (std::isnan(lat) || std::isnan(lon) || lon < XStart || lon >= XEnd || lat < YStart || lat >= YEnd) {
45 return spatial_index_properties[0];
48 const auto z = latlonToZ(lat, lon);
49 const auto it = std::upper_bound(std::begin(spatial_index), std::end(spatial_index), z);
50 if (it == std::begin(spatial_index)) {
51 return spatial_index_properties[0];
54 return spatial_index_properties[(*std::prev(it)).propertyIndex()];
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:08:21 by
doxygen 1.12.0 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.