Overpass API regression suite coverage (Saxony) / overpass_api/core/index_computations.h

overpass_api/core/index_computations.h

636 of 1064 instrumented lines run by the suite (59.8%) at 8edf11b0419c (this file on GitHub).

runnever runcolumns: line, executions, queries (click for the queries that run the line)

1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.
2 *
3 * This file is part of Overpass_API.
4 *
5 * Overpass_API is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * Overpass_API is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.
17 */
19#ifndef DE__OSM3S___OVERPASS_API__CORE__INDEX_COMPUTATIONS_H
20#define DE__OSM3S___OVERPASS_API__CORE__INDEX_COMPUTATIONS_H
22#include "../../template_db/ranges.h"
23#include "basic_types.h"
25#include <algorithm>
26#include <set>
27#include <vector>
30inline uint32 ll_upper(uint32 ilat, uint32 ilon);
31inline uint32 ll_upper_(uint32 ilat, int32 ilon);
32inline uint32 upper_ilat(uint32 quadtile);
33inline uint32 upper_ilon(uint32 quadtile);
34inline uint32 ilat(uint32 ll_upper, uint32 ll_lower);
35inline int32 ilon(uint32 ll_upper, uint32 ll_lower);
37inline uint32 calc_index(const std::vector< uint32 >& node_idxs);
38inline std::pair< Uint32_Index, Uint32_Index > calc_bbox_bounds(Uint31_Index way_rel_idx);
39inline std::vector< Uint32_Index > calc_node_children(const std::vector< uint32 >& way_rel_idxs);
40inline std::vector< Uint31_Index > calc_children(const std::vector< uint32 >& way_rel_idxs);
41inline std::vector< uint32 > calc_parents(const std::vector< uint32 >& node_idxs);
43inline Ranges< Uint32_Index > calc_ranges(double south, double north, double west, double east);
45inline void recursively_calc_ranges
46 (uint32 south, uint32 north, int32 west, int32 east,
47 uint32 bitlevel, Ranges< Uint32_Index >& ranges);
49/** ------------------------------------------------------------------------ */
51struct Uint31_Compare
53 bool operator()(uint32 a, uint32 b) const
5426943652103 q {
5526943652103 q return (a & 0x7fffffff) < (b & 0x7fffffff);
5626943652103 q }
57};
59inline uint32 ll_upper(uint32 ilat, uint32 ilon)
6026850564449 q{
6126850564449 q ilat &= 0xffff0000;
6226850564449 q ilat |= (ilat>>8);
6326850564449 q ilat &= 0xff00ff00;
6426850564449 q ilat |= (ilat>>4);
6526850564449 q ilat &= 0xf0f0f0f0;
6626850564449 q ilat |= (ilat>>2);
6726850564449 q ilat &= 0xcccccccc;
6826850564449 q ilat |= (ilat>>1);
6926850564449 q ilat &= 0xaaaaaaaa;
7126850564449 q ilon &= 0xffff0000;
7226850564449 q ilon |= (ilon>>8);
7326850564449 q ilon &= 0xff00ff00;
7426850564449 q ilon |= (ilon>>4);
7526850564449 q ilon &= 0xf0f0f0f0;
7626850564449 q ilon |= (ilon>>2);
7726850564449 q ilon &= 0xcccccccc;
7826850564449 q ilon |= (ilon>>1);
7926850564449 q ilon &= 0xaaaaaaaa;
8126850564449 q return ilat | (ilon>>1);
8226850564449 q}
84inline uint32 ll_upper_(uint32 ilat, int32 ilon)
859503379366 q{
869503379366 q return (ll_upper(ilat, ilon) ^ 0x40000000);
879503379366 q}
89inline uint32 upper_ilat(uint32 quadtile)
9024910461456 q{
9124910461456 q uint32 result = (quadtile & 0xaaaaaaaa)>>1;
9224910461456 q result |= (result>>1);
9324910461456 q result &= 0x33333333;
9424910461456 q result |= (result>>2);
9524910461456 q result &= 0x0f0f0f0f;
9624910461456 q result |= (result>>4);
9724910461456 q result &= 0x00ff00ff;
9824910461456 q result |= (result>>8);
10024910461456 q return result & 0xffff;
10124910461456 q}
103inline uint32 upper_ilon(uint32 quadtile)
10424910461456 q{
10524910461456 q uint32 result = (quadtile & 0x55555555);
10624910461456 q result |= (result>>1);
10724910461456 q result &= 0x33333333;
10824910461456 q result |= (result>>2);
10924910461456 q result &= 0x0f0f0f0f;
11024910461456 q result |= (result>>4);
11124910461456 q result &= 0x00ff00ff;
11224910461456 q result |= (result>>8);
11424910461456 q return result & 0xffff;
11524910461456 q}
117inline uint32 calc_index(const std::vector< uint32 >& node_idxs)
11824287653225 q{
11924287653225 q if (node_idxs.empty())
1200 return 0xfe;
122 // Calculate the bounding box of the appearing indices.
12424287653225 q std::vector< uint32 >::const_iterator it = node_idxs.begin();
12524287653225 q uint32 lat_min = *it & 0x2aaaaaaa;
12624287653225 q uint32 lat_max = lat_min;
12724287653225 q uint32 lon_min = *it & 0x55555555;
12824287653225 q uint32 lon_max = lon_min;
13024287653225 q if (*it & 0x80000000)
1310 {
1320 if (*it & 0x00000001)
1330 {
1340 lat_min = *it & 0x2aaaaaa8;
1350 lon_min = *it & 0x55555554;
1360 lat_max = ll_upper((upper_ilat(lat_min) + 3)<<16, 0);
1370 lon_max = ll_upper(0, (upper_ilon(lon_min) + 3)<<16);
1380 }
1390 else if (*it & 0x00000002)
1400 {
1410 lat_min = *it & 0x2aaaaa80;
1420 lon_min = *it & 0x55555540;
1430 lat_max = ll_upper((upper_ilat(lat_min) + 0xf)<<16, 0);
1440 lon_max = ll_upper(0, (upper_ilon(lon_min) + 0xf)<<16);
1450 }
1460 else if (*it & 0x00000004)
1470 {
1480 lat_min = *it & 0x2aaaa800;
1490 lon_min = *it & 0x55555400;
1500 lat_max = ll_upper((upper_ilat(lat_min) + 0x3f)<<16, 0);
1510 lon_max = ll_upper(0, (upper_ilon(lon_min) + 0x3f)<<16);
1520 }
1530 else if (*it & 0x00000008)
1540 {
1550 lat_min = *it & 0x2aaa8000;
1560 lon_min = *it & 0x55554000;
1570 lat_max = ll_upper((upper_ilat(lat_min) + 0xff)<<16, 0);
1580 lon_max = ll_upper(0, (upper_ilon(lon_min) + 0xff)<<16);
1590 }
1600 else if (*it & 0x00000010)
1610 {
1620 lat_min = *it & 0x2aa80000;
1630 lon_min = *it & 0x55540000;
1640 lat_max = ll_upper((upper_ilat(lat_min) + 0x3ff)<<16, 0);
1650 lon_max = ll_upper(0, (upper_ilon(lon_min) + 0x3ff)<<16);
1660 }
1670 else if (*it & 0x00000020)
1680 {
1690 lat_min = *it & 0x2a800000;
1700 lon_min = *it & 0x55400000;
1710 lat_max = ll_upper((upper_ilat(lat_min) + 0xfff)<<16, 0);
1720 lon_max = ll_upper(0, (upper_ilon(lon_min) + 0xfff)<<16);
1730 }
1740 else if (*it & 0x00000040)
1750 {
1760 lat_min = *it & 0x28000000;
1770 lon_min = *it & 0x54000000;
1780 lat_max = ll_upper((upper_ilat(lat_min) + 0x3fff)<<16, 0);
1790 lon_max = ll_upper(0, (upper_ilon(lon_min) + 0x3fff)<<16);
1800 }
1810 else // *it == 0x80000080
1820 return 0x80000080;
1830 }
18548575318225 q for (++it; it != node_idxs.end(); ++it)
18624287665225 q {
18724287665225 q if (*it & 0x80000000)
1880 {
1890 uint32 lat = 0;
1900 uint32 lon = 0;
1910 uint32 lat_u = 0;
1920 uint32 lon_u = 0;
1940 if (*it & 0x00000001)
1950 {
1960 lat = *it & 0x2aaaaaa8;
1970 lon = *it & 0x55555554;
1980 lat_u = ll_upper((upper_ilat(lat) + 3)<<16, 0);
1990 lon_u = ll_upper(0, (upper_ilon(lon) + 3)<<16);
2000 }
2010 else if (*it & 0x00000002)
2020 {
2030 lat = *it & 0x2aaaaa80;
2040 lon = *it & 0x55555540;
2050 lat_u = ll_upper((upper_ilat(lat) + 0xf)<<16, 0);
2060 lon_u = ll_upper(0, (upper_ilon(lon) + 0xf)<<16);
2070 }
2080 else if (*it & 0x00000004)
2090 {
2100 lat = *it & 0x2aaaa800;
2110 lon = *it & 0x55555400;
2120 lat_u = ll_upper((upper_ilat(lat) + 0x3f)<<16, 0);
2130 lon_u = ll_upper(0, (upper_ilon(lon) + 0x3f)<<16);
2140 }
2150 else if (*it & 0x00000008)
2160 {
2170 lat = *it & 0x2aaa8000;
2180 lon = *it & 0x55554000;
2190 lat_u = ll_upper((upper_ilat(lat) + 0xff)<<16, 0);
2200 lon_u = ll_upper(0, (upper_ilon(lon) + 0xff)<<16);
2210 }
2220 else if (*it & 0x00000010)
2230 {
2240 lat = *it & 0x2aa80000;
2250 lon = *it & 0x55540000;
2260 lat_u = ll_upper((upper_ilat(lat) + 0x3ff)<<16, 0);
2270 lon_u = ll_upper(0, (upper_ilon(lon) + 0x3ff)<<16);
2280 }
2290 else if (*it & 0x00000020)
2300 {
2310 lat = *it & 0x2a800000;
2320 lon = *it & 0x55400000;
2330 lat_u = ll_upper((upper_ilat(lat) + 0xfff)<<16, 0);
2340 lon_u = ll_upper(0, (upper_ilon(lon) + 0xfff)<<16);
2350 }
2360 else if (*it & 0x00000040)
2370 {
2380 lat = *it & 0x28000000;
2390 lon = *it & 0x54000000;
2400 lat_u = ll_upper((upper_ilat(lat) + 0x3fff)<<16, 0);
2410 lon_u = ll_upper(0, (upper_ilon(lon) + 0x3fff)<<16);
2420 }
2430 else // *it == 0x80000080
2440 return 0x80000080;
2460 if (lat < lat_min)
2470 lat_min = lat;
2480 if (lat_u > lat_max)
2490 lat_max = lat_u;
2500 if (lon < lon_min)
2510 lon_min = lon;
2520 if (lon_u > lon_max)
2530 lon_max = lon_u;
2540 }
25524287665225 q else
25624287665225 q {
25724287665225 q uint32 lat = *it & 0x2aaaaaaa;
25824287665225 q uint32 lon = *it & 0x55555555;
26024287665225 q if (lat < lat_min)
2613875592222 q lat_min = lat;
26220412073224 q else if (lat > lat_max)
2634092505222 q lat_max = lat;
26424287665225 q if (lon < lon_min)
2654444461223 q lon_min = lon;
26619843204224 q else if (lon > lon_max)
2674324812220 q lon_max = lon;
26824287665225 q }
26924287665225 q }
272 // Evaluate the bounding box.
27424287653225 q if ((lat_max == lat_min) && (lon_max == lon_min))
27514652586219 q return node_idxs.front();
2779635067224 q uint32 ilat_min = upper_ilat(lat_min);
2789635067224 q uint32 ilat_max = upper_ilat(lat_max);
2799635067224 q uint32 ilon_min = upper_ilon(lon_min);
2809635067224 q uint32 ilon_max = upper_ilon(lon_max);
2829635067224 q if (((ilat_max & 0xfffe) - (ilat_min & 0xfffe) < 4) &&
2839635067224 q ((ilon_max & 0xfffe) - (ilon_min & 0xfffe) < 4))
2842873519214 q return (((lon_min | lat_min) & 0xfffffffc) | 0x80000001);
2866761548213 q if (((ilat_max & 0xfff8) - (ilat_min & 0xfff8) < 0x10) &&
2876761548213 q ((ilon_max & 0xfff8) - (ilon_min & 0xfff8) < 0x10))
288141711206 q return (((lon_min | lat_min) & 0xffffffc0) | 0x80000002);
2906619837213 q if (((ilat_max & 0xffe0) - (ilat_min & 0xffe0) < 0x40) &&
2916619837213 q ((ilon_max & 0xffe0) - (ilon_min & 0xffe0) < 0x40))
29238633206 q return (((lon_min | lat_min) & 0xfffffc00) | 0x80000004);
294658120497 q if (((ilat_max & 0xff80) - (ilat_min & 0xff80) < 0x100) &&
295658120497 q ((ilon_max & 0xff80) - (ilon_min & 0xff80) < 0x100))
2962210683 q return (((lon_min | lat_min) & 0xffffc000) | 0x80000008);
298655909897 q if (((ilat_max & 0xfe00) - (ilat_min & 0xfe00) < 0x400) &&
299655909897 q ((ilon_max & 0xfe00) - (ilon_min & 0xfe00) < 0x400))
30014372093 q return (((lon_min | lat_min) & 0xfffc0000) | 0x80000010);
302641537895 q if (((ilat_max & 0xf800) - (ilat_min & 0xf800) < 0x1000) &&
303641537895 q ((ilon_max & 0xf800) - (ilon_min & 0xf800) < 0x1000))
30480836891 q return (((lon_min | lat_min) & 0xffc00000) | 0x80000020);
306560701095 q if (((ilat_max & 0xe000) - (ilat_min & 0xe000) < 0x4000) &&
307560701095 q ((ilon_max & 0xe000) - (ilon_min & 0xe000) < 0x4000))
308250321486 q return (((lon_min | lat_min) & 0xfc000000) | 0x80000040);
310310379695 q return 0x80000080;
311560701095 q}
314inline std::pair< Uint32_Index, Uint32_Index > calc_bbox_bounds(Uint31_Index way_rel_idx)
3150{
3160 if (way_rel_idx.val() & 0x80000000)
3170 {
3180 uint32 lat = 0;
3190 uint32 lon = 0;
3200 uint32 offset = 0;
3220 if (way_rel_idx.val() & 0x00000001)
3230 {
3240 lat = upper_ilat(way_rel_idx.val() & 0x2aaaaaa8);
3250 lon = upper_ilon(way_rel_idx.val() & 0x55555554);
3260 offset = 2;
3270 }
3280 else if (way_rel_idx.val() & 0x00000002)
3290 {
3300 lat = upper_ilat(way_rel_idx.val() & 0x2aaaaa80);
3310 lon = upper_ilon(way_rel_idx.val() & 0x55555540);
3320 offset = 8;
3330 }
3340 else if (way_rel_idx.val() & 0x00000004)
3350 {
3360 lat = upper_ilat(way_rel_idx.val() & 0x2aaaa800);
3370 lon = upper_ilon(way_rel_idx.val() & 0x55555400);
3380 offset = 0x20;
3390 }
3400 else if (way_rel_idx.val() & 0x00000008)
3410 {
3420 lat = upper_ilat(way_rel_idx.val() & 0x2aaa8000);
3430 lon = upper_ilon(way_rel_idx.val() & 0x55554000);
3440 offset = 0x80;
3450 }
3460 else if (way_rel_idx.val() & 0x00000010)
3470 {
3480 lat = upper_ilat(way_rel_idx.val() & 0x2aa80000);
3490 lon = upper_ilon(way_rel_idx.val() & 0x55540000);
3500 offset = 0x200;
3510 }
3520 else if (way_rel_idx.val() & 0x00000020)
3530 {
3540 lat = upper_ilat(way_rel_idx.val() & 0x2a800000);
3550 lon = upper_ilon(way_rel_idx.val() & 0x55400000);
3560 offset = 0x800;
3570 }
3580 else if (way_rel_idx.val() & 0x00000040)
3590 {
3600 lat = upper_ilat(way_rel_idx.val() & 0x28000000);
3610 lon = upper_ilon(way_rel_idx.val() & 0x54000000);
3620 offset = 0x2000;
3630 }
3640 else // way_rel_idx.val() == 0x80000080
3650 {
3660 lat = 0;
3670 lon = 0;
3680 offset = 0x8000;
3690 }
3710 return std::make_pair(ll_upper(lat<<16, lon<<16),
3720 ll_upper((lat+2*offset-1)<<16, (lon+2*offset-1)<<16)+1);
3730 }
3740 else if (way_rel_idx.val() > 0xff)
3750 return std::make_pair(way_rel_idx.val(), way_rel_idx.val() + 1);
3760 else
3770 return std::make_pair(0u, 1u);
3780}
381inline std::vector< Uint32_Index > calc_node_children(const std::vector< uint32 >& way_rel_idxs)
3820{
3830 std::vector< Uint32_Index > result;
3850 std::vector< std::pair< uint32, uint32 > > ranges;
3870 for (std::vector< uint32 >::const_iterator it = way_rel_idxs.begin();
3880 it != way_rel_idxs.end(); ++it)
3890 {
3900 if (*it & 0x80000000)
3910 {
3920 uint32 lat = 0;
3930 uint32 lon = 0;
3940 uint32 lat_u = 0;
3950 uint32 lon_u = 0;
3960 uint32 offset = 0;
3980 if (*it & 0x00000001)
3990 {
4000 lat = upper_ilat(*it & 0x2aaaaaa8);
4010 lon = upper_ilon(*it & 0x55555554);
4020 offset = 2;
4030 }
4040 else if (*it & 0x00000002)
4050 {
4060 lat = upper_ilat(*it & 0x2aaaaa80);
4070 lon = upper_ilon(*it & 0x55555540);
4080 offset = 8;
4090 }
4100 else if (*it & 0x00000004)
4110 {
4120 lat = upper_ilat(*it & 0x2aaaa800);
4130 lon = upper_ilon(*it & 0x55555400);
4140 offset = 0x20;
4150 }
4160 else if (*it & 0x00000008)
4170 {
4180 lat = upper_ilat(*it & 0x2aaa8000);
4190 lon = upper_ilon(*it & 0x55554000);
4200 offset = 0x80;
4210 }
4220 else if (*it & 0x00000010)
4230 {
4240 lat = upper_ilat(*it & 0x2aa80000);
4250 lon = upper_ilon(*it & 0x55540000);
4260 offset = 0x200;
4270 }
4280 else if (*it & 0x00000020)
4290 {
4300 lat = upper_ilat(*it & 0x2a800000);
4310 lon = upper_ilon(*it & 0x55400000);
4320 offset = 0x800;
4330 }
4340 else if (*it & 0x00000040)
4350 {
4360 lat = upper_ilat(*it & 0x28000000);
4370 lon = upper_ilon(*it & 0x54000000);
4380 offset = 0x2000;
4390 }
4400 else // *it == 0x80000080
4410 {
4420 lat = 0;
4430 lon = 0;
4440 offset = 0x8000;
4450 }
4470 ranges.push_back(std::make_pair(ll_upper(lat<<16, lon<<16),
4480 ll_upper((lat+offset-1)<<16, (lon+offset-1)<<16)+1));
4490 ranges.push_back(std::make_pair(ll_upper(lat<<16, (lon+offset)<<16),
4500 ll_upper((lat+offset-1)<<16, (lon+2*offset-1)<<16)+1));
4510 ranges.push_back(std::make_pair(ll_upper((lat+offset)<<16, lon<<16),
4520 ll_upper((lat+2*offset-1)<<16, (lon+offset-1)<<16)+1));
4530 ranges.push_back(std::make_pair(ll_upper((lat+offset)<<16, (lon+offset)<<16),
4540 ll_upper((lat+2*offset-1)<<16, (lon+2*offset-1)<<16)+1));
4550 for (uint32 i = lat; i <= lat_u; ++i)
4560 {
4570 for (uint32 j = lon; j <= lon_u; ++j)
4580 result.push_back(ll_upper(i<<16, j<<16));
4590 }
4600 }
4610 else
4620 ranges.push_back(std::make_pair(*it, (*it) + 1));
4630 }
4650 sort(ranges.begin(), ranges.end());
4660 uint32 pos = 0;
4670 for (std::vector< std::pair< uint32, uint32 > >::const_iterator it = ranges.begin();
4680 it != ranges.end(); ++it)
4690 {
4700 if (pos < it->first)
4710 pos = it->first;
4720 for (; pos < it->second; ++pos)
4730 result.push_back(pos);
4740 }
4750 return result;
4760}
479struct Idx_Bbox
481 Idx_Bbox(uint32 ll_upper)
48280335163 q {
48380335163 q if (ll_upper & 0x80000000)
48438310154 q {
48538310154 q if (ll_upper & 0x00000001)
48626430142 q {
48726430142 q lat = upper_ilat(ll_upper & 0x2aaaaaa8);
48826430142 q lon = upper_ilon(ll_upper & 0x55555554);
48926430142 q lat_u = lat + 3;
49026430142 q lon_u = lon + 3;
49126430142 q }
49211880139 q else if (ll_upper & 0x00000002)
49311880139 q {
49411880139 q lat = upper_ilat(ll_upper & 0x2aaaaa80);
49511880139 q lon = upper_ilon(ll_upper & 0x55555540);
49611880139 q lat_u = lat + 0xf;
49711880139 q lon_u = lon + 0xf;
49811880139 q }
4990 else if (ll_upper & 0x00000004)
5000 {
5010 lat = upper_ilat(ll_upper & 0x2aaaa800);
5020 lon = upper_ilon(ll_upper & 0x55555400);
5030 lat_u = lat + 0x3f;
5040 lon_u = lon + 0x3f;
5050 }
5060 else if (ll_upper & 0x00000008)
5070 {
5080 lat = upper_ilat(ll_upper & 0x2aaa8000);
5090 lon = upper_ilon(ll_upper & 0x55554000);
5100 lat_u = lat + 0xff;
5110 lon_u = lon + 0xff;
5120 }
5130 else if (ll_upper & 0x00000010)
5140 {
5150 lat = upper_ilat(ll_upper & 0x2aa80000);
5160 lon = upper_ilon(ll_upper & 0x55540000);
5170 lat_u = lat + 0x3ff;
5180 lon_u = lon + 0x3ff;
5190 }
5200 else if (ll_upper & 0x00000020)
5210 {
5220 lat = upper_ilat(ll_upper & 0x2a800000);
5230 lon = upper_ilon(ll_upper & 0x55400000);
5240 lat_u = lat + 0xfff;
5250 lon_u = lon + 0xfff;
5260 }
5270 else if (ll_upper & 0x00000040)
5280 {
5290 lat = upper_ilat(ll_upper & 0x28000000);
5300 lon = upper_ilon(ll_upper & 0x54000000);
5310 lat_u = lat + 0x3fff;
5320 lon_u = lon + 0x3fff;
5330 }
5340 else // ll_upper == 0x80000080
5350 {
5360 lat = 0;
5370 lon = 0;
5380 lat_u = 0x7fff;
5390 lon_u = 0xffff;
5400 }
54138310154 q }
54242025142 q else
54342025142 q {
54442025142 q lat = upper_ilat(ll_upper);
54542025142 q lon = upper_ilon(ll_upper);
54642025142 q lat_u = lat;
54742025142 q lon_u = lon;
54842025142 q }
54980335163 q }
551 int compare(const Idx_Bbox& rhs)
55273165150 q {
55373165150 q bool lhs_bigger = (lat < rhs.lat || lon < rhs.lon || lat_u > rhs.lat_u || lon_u > rhs.lon_u);
55473165150 q bool rhs_bigger = (lat > rhs.lat || lon > rhs.lon || lat_u < rhs.lat_u || lon_u < rhs.lon_u);
55573165150 q return (lhs_bigger<<1) | rhs_bigger;
55673165150 q }
558 int32 lat;
559 int32 lon;
560 int32 lat_u;
561 int32 lon_u;
562};
565inline std::vector< Uint31_Index > calc_children(const std::vector< uint32 >& way_rel_idxs)
5660{
5670 std::vector< Uint31_Index > result;
5690 for (std::vector< uint32 >::const_iterator it = way_rel_idxs.begin();
5700 it != way_rel_idxs.end(); ++it)
5710 {
5720 if (*it & 0x80000000)
5730 {
5740 Idx_Bbox bbox(*it);
5760 if (!(*it & 0x0000007f))
5770 result.push_back(0x80000080);
5780 for (int32 i = bbox.lat; i <= (bbox.lat_u - 0x3fff); i += 0x2000)
5790 {
5800 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0x3fff); j += 0x2000)
5810 result.push_back((ll_upper(i<<16, j<<16) & 0xfc000000) | 0x80000040);
5820 }
5830 for (int32 i = bbox.lat; i <= (bbox.lat_u - 0xfff); i += 0x800)
5840 {
5850 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0xfff); j += 0x800)
5860 result.push_back((ll_upper(i<<16, j<<16) & 0xffc00000) | 0x80000020);
5870 }
5880 for (int32 i = bbox.lat; i <= (bbox.lat_u - 0x3ff); i += 0x200)
5890 {
5900 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0x3ff); j += 0x200)
5910 result.push_back((ll_upper(i<<16, j<<16) & 0xfffc0000) | 0x80000010);
5920 }
5930 for (int32 i = bbox.lat; i <= (bbox.lat_u - 0xff); i += 0x80)
5940 {
5950 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0xff); j += 0x80)
5960 result.push_back((ll_upper(i<<16, j<<16) & 0xffffc000) | 0x80000008);
5970 }
5980 for (int32 i = bbox.lat; i <= (bbox.lat_u - 0x3f); i += 0x20)
5990 {
6000 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0x3f); j += 0x20)
6010 result.push_back((ll_upper(i<<16, j<<16) & 0xfffffc00) | 0x80000004);
6020 }
6030 for (int32 i = bbox.lat; i <= (bbox.lat_u - 0xf); i += 8)
6040 {
6050 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0xf); j += 8)
6060 result.push_back((ll_upper(i<<16, j<<16) & 0xffffffc0) | 0x80000002);
6070 }
6080 for (int32 i = bbox.lat; i <= (bbox.lat_u - 3); i += 2)
6090 {
6100 for (int32 j = bbox.lon; j <= (bbox.lon_u - 3); j += 2)
6110 result.push_back((ll_upper(i<<16, j<<16) & 0xfffffffc) | 0x80000001);
6120 }
6130 for (int32 i = bbox.lat; i <= bbox.lat_u; ++i)
6140 {
6150 for (int32 j = bbox.lon; j <= bbox.lon_u; ++j)
6160 result.push_back(ll_upper(i<<16, j<<16));
6170 }
6180 }
6190 else
6200 result.push_back(*it);
6210 }
6230 sort(result.begin(), result.end());
6240 result.erase(unique(result.begin(), result.end()), result.end());
6250 return result;
6260}
629inline Ranges< Uint31_Index > calc_children(std::vector< Uint31_Index >&& parents)
63028110477 q{
63128110477 q Ranges< Uint31_Index > result;
63328110477 q if (parents.empty())
63427646353 q return result;
635464163 q std::sort(parents.begin(), parents.end());
636464163 q auto i_src = parents.begin()+1;
637464163 q auto i_target = parents.begin();
638464163 q Idx_Bbox bbox_target(i_target->val());
63973629163 q while (i_src != parents.end())
64073165150 q {
64173165150 q Idx_Bbox bbox_src(i_src->val());
64273165150 q uint comp = bbox_target.compare(bbox_src);
64373165150 q if (comp == 3)
6447577148 q ++i_target;
64573165150 q if (comp == 1 || comp == 3)
6468907149 q {
6478907149 q *i_target = *i_src;
6488907149 q bbox_target = bbox_src;
6498907149 q }
65073165150 q ++i_src;
65173165150 q }
652464163 q parents.erase(i_target+1, parents.end());
654464163 q for (auto i : parents)
6558041163 q {
6568041163 q if (i.val() & 0x80000000)
6576706154 q {
6586706154 q Idx_Bbox bbox(i.val());
6606706154 q if (!(i.val() & 0x0000007f))
6610 result.push_back(0x80000080, 0x81);
6626706154 q for (int32 i = bbox.lat; i <= (bbox.lat_u - 0x3fff); i += 0x2000)
6630 {
6640 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0x3fff); j += 0x2000)
6650 {
6660 Uint31_Index idx((ll_upper(i<<16, j<<16) & 0xfc000000) | 0x80000040);
6670 result.push_back(idx, inc(idx));
6680 }
6690 }
6706706154 q for (int32 i = bbox.lat; i <= (bbox.lat_u - 0xfff); i += 0x800)
6710 {
6720 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0xfff); j += 0x800)
6730 {
6740 Uint31_Index idx((ll_upper(i<<16, j<<16) & 0xffc00000) | 0x80000020);
6750 result.push_back(idx, inc(idx));
6760 }
6770 }
6786706154 q for (int32 i = bbox.lat; i <= (bbox.lat_u - 0x3ff); i += 0x200)
6790 {
6800 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0x3ff); j += 0x200)
6810 {
6820 Uint31_Index idx((ll_upper(i<<16, j<<16) & 0xfffc0000) | 0x80000010);
6830 result.push_back(idx, inc(idx));
6840 }
6850 }
68655752154 q for (int32 i = bbox.lat; i <= bbox.lat_u; i += 2)
68749046154 q {
688432210154 q for (int32 j = bbox.lon; j <= bbox.lon_u; j += 2)
689383164154 q {
690383164154 q uint32 idx = ll_upper(i<<16, j<<16);
691383164154 q uint32 lower = idx;
692383164154 q if (((idx & 0xf) == 0x0 && ((idx & 0x3ffff) == 0x10 || (idx & 0x3fffff) == 0x20
69395791154 q || (idx & 0x3ffffff) == 0x40 || (idx & 0x3fffffff) == 0x80))
694383164154 q || ((idx & 0x3ff) == 0x4 && (i > (bbox.lat_u - 0x3f) || j > (bbox.lon_u - 0x3d)))
695383164154 q || ((idx & 0x3fff) == 0x8 && (i > (bbox.lat_u - 0xfd) || j > (bbox.lon_u - 0xff))))
6961613105 q {
6971613105 q result.push_back(Uint31_Index(idx), Uint31_Index(idx | 0x80000000));
6981613105 q lower = idx+1;
6991613105 q }
700383164154 q if (i > (bbox.lat_u - 3) || j > (bbox.lon_u - 3))
70191386154 q {
70291386154 q result.push_back(Uint31_Index(lower), Uint31_Index((idx+1) | 0x80000000));
70391386154 q lower = idx+2;
70491386154 q }
705383164154 q if ((idx & 0x3f) == 0x2 && (i > (bbox.lat_u - 0xf) || j > (bbox.lon_u - 0xf)))
7060 {
7070 result.push_back(Uint31_Index(lower), Uint31_Index((idx+2) | 0x80000000));
7080 lower = idx+3;
7090 }
710383164154 q result.push_back(Uint31_Index(lower), Uint31_Index(idx+4));
711383164154 q }
71249046154 q }
7136706154 q }
714133565 q else
715133565 q result.push_back(i, inc(i));
7168041163 q }
718464163 q result.sort();
719464163 q return result;
72028110477 q}
723inline Ranges< Uint31_Index > calc_children_(const std::vector< Uint31_Index >& parents)
72428110477 q{
72528110477 q auto copy = parents;
72628110477 q return calc_children(std::move(copy));
72728110477 q}
730inline Ranges< Uint32_Index > calc_children(const Ranges< Uint31_Index >& way_rel_idxs)
73219836 q Ranges< Uint32_Index > ranges;
73415992336 q for (auto it = way_rel_idxs.begin(); it != way_rel_idxs.end(); ++it)
73515972520 q {
73636919220 q for (Uint31_Index idx = it.lower_bound(); idx < it.upper_bound(); idx = inc(idx))
73720946720 q {
73820946720 q if (idx.val() & 0x80000000)
7398972816 q {
7408972816 q uint32 lat = 0;
7418972816 q uint32 lon = 0;
7428972816 q uint32 offset = 0;
7448972816 q if (idx.val() & 0x00000001)
7457672715 q {
7467672715 q lat = upper_ilat(idx.val() & 0x2aaaaaa8);
7477672715 q lon = upper_ilon(idx.val() & 0x55555554);
7487672715 q offset = 2;
7497672715 q }
750130019 q else if (idx.val() & 0x00000002)
751112918 q {
752112918 q lat = upper_ilat(idx.val() & 0x2aaaaa80);
753112918 q lon = upper_ilon(idx.val() & 0x55555540);
754112918 q offset = 8;
755112918 q }
75617107 q else if (idx.val() & 0x00000004)
75711976 q {
75811976 q lat = upper_ilat(idx.val() & 0x2aaaa800);
75911976 q lon = upper_ilon(idx.val() & 0x55555400);
76011976 q offset = 0x20;
76111976 q }
7625134 q else if (idx.val() & 0x00000008)
7631994 q {
7641994 q lat = upper_ilat(idx.val() & 0x2aaa8000);
7651994 q lon = upper_ilon(idx.val() & 0x55554000);
7661994 q offset = 0x80;
7671994 q }
7683143 q else if (idx.val() & 0x00000010)
769943 q {
770943 q lat = upper_ilat(idx.val() & 0x2aa80000);
771943 q lon = upper_ilon(idx.val() & 0x55540000);
772943 q offset = 0x200;
773943 q }
7742201 q else if (idx.val() & 0x00000020)
7751201 q {
7761201 q lat = upper_ilat(idx.val() & 0x2a800000);
7771201 q lon = upper_ilon(idx.val() & 0x55400000);
7781201 q offset = 0x800;
7791201 q }
7801001 q else if (idx.val() & 0x00000040)
781901 q {
782901 q lat = upper_ilat(idx.val() & 0x28000000);
783901 q lon = upper_ilon(idx.val() & 0x54000000);
784901 q offset = 0x2000;
785901 q }
786101 q else // idx.val() == 0x80000080
787101 q {
788101 q lat = 0;
789101 q lon = 0;
790101 q offset = 0x8000;
791101 q }
7938972816 q ranges.push_back(
7948972816 q ll_upper(lat<<16, lon<<16),
7958972816 q ll_upper((lat+offset-1)<<16, (lon+offset-1)<<16)+1);
7968972816 q ranges.push_back(
7978972816 q ll_upper(lat<<16, (lon+offset)<<16),
7988972816 q ll_upper((lat+offset-1)<<16, (lon+2*offset-1)<<16)+1);
7998972816 q ranges.push_back(
8008972816 q ll_upper((lat+offset)<<16, lon<<16),
8018972816 q ll_upper((lat+2*offset-1)<<16, (lon+offset-1)<<16)+1);
8028972816 q ranges.push_back(
8038972816 q ll_upper((lat+offset)<<16, (lon+offset)<<16),
8048972816 q ll_upper((lat+2*offset-1)<<16, (lon+2*offset-1)<<16)+1);
8058972816 q }
80611973918 q else
80711973918 q ranges.push_back(idx.val(), idx.val() + 1);
80820946720 q }
80915972520 q }
81019836 q ranges.sort();
81219836 q return ranges;
816inline std::set< Uint31_Index > calc_parents(const std::set< Uint31_Index >& node_idxs)
8185350 q std::set< Uint31_Index > result;
8195350 q result.insert(0x80000080);
8215350 q for (std::set< Uint31_Index >::const_iterator it = node_idxs.begin();
822185550 q it != node_idxs.end(); ++it)
823180241 q {
824180241 q result.insert(*it);
826180241 q uint32 lat = upper_ilat(it->val() & 0x2aaaaaa8) & 0xfffe;
827180241 q uint32 lon = upper_ilon(it->val() & 0x55555554) & 0xfffe;
828180241 q result.insert(ll_upper((lat - 2)<<16, (lon - 2)<<16) | 0x80000001);
829180241 q result.insert(ll_upper(lat<<16, (lon - 2)<<16) | 0x80000001);
830180241 q result.insert(ll_upper((lat - 2)<<16, lon<<16) | 0x80000001);
831180241 q result.insert(ll_upper(lat<<16, lon<<16) | 0x80000001);
833180241 q lat = lat & 0xfff8;
834180241 q lon = lon & 0xfff8;
835180241 q result.insert(ll_upper((lat - 8)<<16, (lon - 8)<<16) | 0x80000002);
836180241 q result.insert(ll_upper(lat<<16, (lon - 8)<<16) | 0x80000002);
837180241 q result.insert(ll_upper((lat - 8)<<16, lon<<16) | 0x80000002);
838180241 q result.insert(ll_upper(lat<<16, lon<<16) | 0x80000002);
840180241 q lat = lat & 0xffe0;
841180241 q lon = lon & 0xffe0;
842180241 q result.insert(ll_upper((lat - 0x20)<<16, (lon - 0x20)<<16) | 0x80000004);
843180241 q result.insert(ll_upper(lat<<16, (lon - 0x20)<<16) | 0x80000004);
844180241 q result.insert(ll_upper((lat - 0x20)<<16, lon<<16) | 0x80000004);
845180241 q result.insert(ll_upper(lat<<16, lon<<16) | 0x80000004);
847180241 q lat = lat & 0xff80;
848180241 q lon = lon & 0xff80;
849180241 q result.insert(ll_upper((lat - 0x80)<<16, (lon - 0x80)<<16) | 0x80000008);
850180241 q result.insert(ll_upper(lat<<16, (lon - 0x80)<<16) | 0x80000008);
851180241 q result.insert(ll_upper((lat - 0x80)<<16, lon<<16) | 0x80000008);
852180241 q result.insert(ll_upper(lat<<16, lon<<16) | 0x80000008);
854180241 q lat = lat & 0xfe00;
855180241 q lon = lon & 0xfe00;
856180241 q result.insert(ll_upper((lat - 0x200)<<16, (lon - 0x200)<<16) | 0x80000010);
857180241 q result.insert(ll_upper(lat<<16, (lon - 0x200)<<16) | 0x80000010);
858180241 q result.insert(ll_upper((lat - 0x200)<<16, lon<<16) | 0x80000010);
859180241 q result.insert(ll_upper(lat<<16, lon<<16) | 0x80000010);
861180241 q lat = lat & 0xf800;
862180241 q lon = lon & 0xf800;
863180241 q result.insert(ll_upper((lat - 0x800)<<16, (lon - 0x800)<<16) | 0x80000020);
864180241 q result.insert(ll_upper(lat<<16, (lon - 0x800)<<16) | 0x80000020);
865180241 q result.insert(ll_upper((lat - 0x800)<<16, lon<<16) | 0x80000020);
866180241 q result.insert(ll_upper(lat<<16, lon<<16) | 0x80000020);
868180241 q lat = lat & 0xe000;
869180241 q lon = lon & 0xe000;
870180241 q result.insert(ll_upper((lat - 0x2000)<<16, (lon - 0x2000)<<16) | 0x80000040);
871180241 q result.insert(ll_upper(lat<<16, (lon - 0x2000)<<16) | 0x80000040);
872180241 q result.insert(ll_upper((lat - 0x2000)<<16, lon<<16) | 0x80000040);
873180241 q result.insert(ll_upper(lat<<16, lon<<16) | 0x80000040);
874180241 q }
8765350 q return result;
880inline std::vector< uint32 > calc_parents(const std::vector< uint32 >& node_idxs)
882573144 q std::vector< uint32 > result;
883573144 q result.push_back(0x80000080);
885573144 q for (std::vector< uint32 >::const_iterator it = node_idxs.begin();
88657798144 q it != node_idxs.end(); ++it)
88757225103 q {
88857225103 q result.push_back(*it);
89057225103 q uint32 lat = upper_ilat(*it & 0x2aaaaaa8) & 0xfffe;
89157225103 q uint32 lon = upper_ilon(*it & 0x55555554) & 0xfffe;
89257225103 q result.push_back(ll_upper((lat - 2)<<16, (lon - 2)<<16) | 0x80000001);
89357225103 q result.push_back(ll_upper(lat<<16, (lon - 2)<<16) | 0x80000001);
89457225103 q result.push_back(ll_upper((lat - 2)<<16, lon<<16) | 0x80000001);
89557225103 q result.push_back(ll_upper(lat<<16, lon<<16) | 0x80000001);
89757225103 q lat = lat & 0xfff8;
89857225103 q lon = lon & 0xfff8;
89957225103 q result.push_back(ll_upper((lat - 8)<<16, (lon - 8)<<16) | 0x80000002);
90057225103 q result.push_back(ll_upper(lat<<16, (lon - 8)<<16) | 0x80000002);
90157225103 q result.push_back(ll_upper((lat - 8)<<16, lon<<16) | 0x80000002);
90257225103 q result.push_back(ll_upper(lat<<16, lon<<16) | 0x80000002);
90457225103 q lat = lat & 0xffe0;
90557225103 q lon = lon & 0xffe0;
90657225103 q result.push_back(ll_upper((lat - 0x20)<<16, (lon - 0x20)<<16) | 0x80000004);
90757225103 q result.push_back(ll_upper(lat<<16, (lon - 0x20)<<16) | 0x80000004);
90857225103 q result.push_back(ll_upper((lat - 0x20)<<16, lon<<16) | 0x80000004);
90957225103 q result.push_back(ll_upper(lat<<16, lon<<16) | 0x80000004);
91157225103 q lat = lat & 0xff80;
91257225103 q lon = lon & 0xff80;
91357225103 q result.push_back(ll_upper((lat - 0x80)<<16, (lon - 0x80)<<16) | 0x80000008);
91457225103 q result.push_back(ll_upper(lat<<16, (lon - 0x80)<<16) | 0x80000008);
91557225103 q result.push_back(ll_upper((lat - 0x80)<<16, lon<<16) | 0x80000008);
91657225103 q result.push_back(ll_upper(lat<<16, lon<<16) | 0x80000008);
91857225103 q lat = lat & 0xfe00;
91957225103 q lon = lon & 0xfe00;
92057225103 q result.push_back(ll_upper((lat - 0x200)<<16, (lon - 0x200)<<16) | 0x80000010);
92157225103 q result.push_back(ll_upper(lat<<16, (lon - 0x200)<<16) | 0x80000010);
92257225103 q result.push_back(ll_upper((lat - 0x200)<<16, lon<<16) | 0x80000010);
92357225103 q result.push_back(ll_upper(lat<<16, lon<<16) | 0x80000010);
92557225103 q lat = lat & 0xf800;
92657225103 q lon = lon & 0xf800;
92757225103 q result.push_back(ll_upper((lat - 0x800)<<16, (lon - 0x800)<<16) | 0x80000020);
92857225103 q result.push_back(ll_upper(lat<<16, (lon - 0x800)<<16) | 0x80000020);
92957225103 q result.push_back(ll_upper((lat - 0x800)<<16, lon<<16) | 0x80000020);
93057225103 q result.push_back(ll_upper(lat<<16, lon<<16) | 0x80000020);
93257225103 q lat = lat & 0xe000;
93357225103 q lon = lon & 0xe000;
93457225103 q result.push_back(ll_upper((lat - 0x2000)<<16, (lon - 0x2000)<<16) | 0x80000040);
93557225103 q result.push_back(ll_upper(lat<<16, (lon - 0x2000)<<16) | 0x80000040);
93657225103 q result.push_back(ll_upper((lat - 0x2000)<<16, lon<<16) | 0x80000040);
93757225103 q result.push_back(ll_upper(lat<<16, lon<<16) | 0x80000040);
93857225103 q }
940573144 q sort(result.begin(), result.end(), Uint31_Compare());
941573144 q result.erase(unique(result.begin(), result.end()), result.end());
943573144 q return result;
947inline void push_back_interval(Ranges< Uint31_Index >& ranges, uint32 idx)
9488892990385 q{
9498892990385 q ranges.push_back(Uint31_Index(idx), Uint31_Index((idx + 1) & 0x7fffffff));
9508892990385 q}
953inline void blur_index(
954 uint32 distance, uint32 bitmask, uint32 lower_idx, uint32 upper_idx, Ranges< Uint31_Index >& result)
9552639140385 q{
9562639140385 q uint32 source_bitmask = 0x10000 - distance;
9572639140385 q uint32 min_lat = upper_ilat(lower_idx) & source_bitmask;
9582639140385 q uint32 min_lon = upper_ilon(lower_idx) & source_bitmask;
9592639140385 q uint32 max_lat = upper_ilat(upper_idx) & source_bitmask;
9602639140385 q uint32 max_lon = upper_ilon(upper_idx) & source_bitmask;
9615545744385 q for (uint32 lat = min_lat - distance; lat <= max_lat; lat += distance)
9622906604385 q push_back_interval(result, ll_upper(lat<<16, (min_lon - distance)<<16) | bitmask);
9635986386385 q for (uint32 lon = min_lon; lon <= max_lon; lon += distance)
9643347246385 q push_back_interval(result, ll_upper((min_lat - distance)<<16, lon<<16) | bitmask);
9652639140385 q push_back_interval(result, ll_upper(max_lat<<16, max_lon<<16) | bitmask);
9662639140385 q}
969inline void add_decomp_range(const std::pair< Uint32_Index, Uint32_Index >& range,
970 std::vector< std::pair< Uint32_Index, Uint32_Index > >& node_decomp)
971199582385 q{
972199582385 q uint32 lower = range.first.val();
973576602385 q while (lower < range.second.val())
974377020385 q {
975377020385 q uint32 upper = 0;
976377020385 q if ((lower & 0x3) != 0 || lower + 4 > range.second.val())
977252400311 q upper = lower + 1;
978124620361 q else if ((lower & 0xf) != 0 || lower + 0x10 > range.second.val())
979107765290 q upper = lower + 4;
98016855234 q else if ((lower & 0x3f) != 0 || lower + 0x40 > range.second.val())
9812911146 q upper = lower + 0x10;
98213944163 q else if ((lower & 0xff) != 0 || lower + 0x100 > range.second.val())
983171977 q upper = lower + 0x40;
98412225122 q else if ((lower & 0x3ff) != 0 || lower + 0x400 > range.second.val())
98510253114 q upper = lower + 0x100;
986197232 q else if ((lower & 0xfff) != 0 || lower + 0x1000 > range.second.val())
987123126 q upper = lower + 0x400;
98874124 q else if ((lower & 0x3fff) != 0 || lower + 0x4000 > range.second.val())
98941717 q upper = lower + 0x1000;
99032417 q else if ((lower & 0xffff) != 0 || lower + 0x10000 > range.second.val())
9911258 q upper = lower + 0x4000;
99219912 q else if ((lower & 0x3ffff) != 0 || lower + 0x40000 > range.second.val())
993323 q upper = lower + 0x10000;
9941679 q else if ((lower & 0xfffff) != 0 || lower + 0x100000 > range.second.val())
995645 q upper = lower + 0x40000;
9961034 q else if ((lower & 0x3fffff) != 0 || lower + 0x400000 > range.second.val())
9970 upper = lower + 0x100000;
9981034 q else if ((lower & 0xffffff) != 0 || lower + 0x1000000 > range.second.val())
9990 upper = lower + 0x400000;
10001034 q else if ((lower & 0x3ffffff) != 0 || lower + 0x4000000 > range.second.val())
100173 q upper = lower + 0x1000000;
1002961 q else if ((lower & 0xfffffff) != 0 || lower + 0x10000000 > range.second.val())
1003961 q upper = lower + 0x4000000;
10040 else if ((lower & 0x3fffffff) != 0 || lower + 0x40000000 > range.second.val())
10050 upper = lower + 0x10000000;
10060 else
10070 upper = lower + 0x40000000;
1008377020385 q node_decomp.push_back(std::make_pair(lower, upper));
1009377020385 q lower = upper;
1010377020385 q }
1011199582385 q}
1014inline void add_decomp_range(const Ranges< Uint32_Index >::Iterator& range,
1015 std::vector< std::pair< Uint32_Index, Uint32_Index > >& node_decomp)
10170 add_decomp_range(std::pair< Uint32_Index, Uint32_Index >{ range.lower_bound(), range.upper_bound() }, node_decomp);
1021template< typename Container >
1022Ranges< Uint31_Index > calc_parents(const Container& node_idxs)
10241006399 q std::vector< std::pair< Uint32_Index, Uint32_Index > > node_decomp;
1025200588399 q for (auto it = node_idxs.begin(); it != node_idxs.end(); ++it)
1026199582385 q add_decomp_range(*it, node_decomp);
10281006399 q Ranges< Uint31_Index > result;
10291006399 q result.push_back(0x80000080, 0x80000081);
10311006399 q for (std::vector< std::pair< Uint32_Index, Uint32_Index > >::const_iterator
1032378026399 q it = node_decomp.begin(); it != node_decomp.end(); ++it)
1033377020385 q {
1034377020385 q result.push_back(it->first.val(), it->second.val());
1036377020385 q uint32 lower_idx = it->first.val() & 0x7ffffffc;
1037377020385 q uint32 upper_idx = (it->second.val() - 1) & 0x7ffffffc;
1038377020385 q blur_index(2, 0x80000001, lower_idx, upper_idx, result);
1040377020385 q lower_idx = it->first.val() & 0x7fffffc0;
1041377020385 q upper_idx = (it->second.val() - 1) & 0x7fffffc0;
1042377020385 q blur_index(8, 0x80000002, lower_idx, upper_idx, result);
1044377020385 q lower_idx = it->first.val() & 0x7ffffc00;
1045377020385 q upper_idx = (it->second.val() - 1) & 0x7ffffc00;
1046377020385 q blur_index(0x20, 0x80000004, lower_idx, upper_idx, result);
1048377020385 q lower_idx = it->first.val() & 0x7fffc000;
1049377020385 q upper_idx = (it->second.val() - 1) & 0x7fffc000;
1050377020385 q blur_index(0x80, 0x80000008, lower_idx, upper_idx, result);
1052377020385 q lower_idx = it->first.val() & 0x7ffc0000;
1053377020385 q upper_idx = (it->second.val() - 1) & 0x7ffc0000;
1054377020385 q blur_index(0x200, 0x80000010, lower_idx, upper_idx, result);
1056377020385 q lower_idx = it->first.val() & 0x7fc00000;
1057377020385 q upper_idx = (it->second.val() - 1) & 0x7fc00000;
1058377020385 q blur_index(0x800, 0x80000020, lower_idx, upper_idx, result);
1060377020385 q lower_idx = it->first.val() & 0x7c000000;
1061377020385 q upper_idx = (it->second.val() - 1) & 0x7c000000;
1062377020385 q blur_index(0x2000, 0x80000040, lower_idx, upper_idx, result);
1063377020385 q }
10641006399 q result.sort();
10661006399 q return result;
1070/**--------------------------------------------------------------------------*/
1072// Calculates the ranges touched by the given bbox.
1073// This function implicitly depends on the chosen coordinate encoding.
1074inline Ranges< Uint32_Index > calc_ranges(double south, double north, double west, double east)
1075274676317 q{
1076274676317 q Ranges< Uint32_Index > ranges;
1078274676317 q uint32 isouth((south + 91.0)*10000000+0.5);
1079274676317 q uint32 inorth((north + 91.0)*10000000+0.5);
1080274676317 q int32 iwest(west*10000000 + (west > 0 ? 0.5 : -0.5));
1081274676317 q int32 ieast(east*10000000 + (east > 0 ? 0.5 : -0.5));
1083274676317 q if (west <= east)
1084274671317 q {
1085274671317 q if ((west < 0) && (east >= 0))
108711 q recursively_calc_ranges
108811 q (isouth & 0xffff0000, inorth & 0xffff0000,
108911 q 0, ieast & 0xffff0000, 1, ranges);
109011 q recursively_calc_ranges
109111 q (isouth & 0xffff0000, inorth & 0xffff0000,
109211 q iwest & 0xffff0000, 0xffff0000, 1, ranges);
1094274670316 q else
1095274670316 q recursively_calc_ranges
1096274670316 q (isouth & 0xffff0000, inorth & 0xffff0000,
1097274670316 q iwest & 0xffff0000, ieast & 0xffff0000, 1, ranges);
1098274671317 q }
109951 q else
110151 q if (west < 0)
110351 q recursively_calc_ranges
110451 q (isouth & 0xffff0000, inorth & 0xffff0000,
110551 q iwest & 0xffff0000, 0xffff0000, 1, ranges);
110651 q recursively_calc_ranges
110751 q (isouth & 0xffff0000, inorth & 0xffff0000,
110851 q 0, int32(180.0*10000000 + 0.5) & 0xffff0000, 1, ranges);
11100 else
11110 recursively_calc_ranges
11120 (isouth & 0xffff0000, inorth & 0xffff0000,
11130 iwest & 0xffff0000, int32(180.0*10000000 + 0.5) & 0xffff0000, 1, ranges);
111551 q if (east > 0)
11160 {
11170 recursively_calc_ranges
11180 (isouth & 0xffff0000, inorth & 0xffff0000,
11190 int32(-180.0*10000000 - 0.5) & 0xffff0000, 0xffff0000, 1, ranges);
11200 recursively_calc_ranges
11210 (isouth & 0xffff0000, inorth & 0xffff0000,
11220 0, ieast & 0xffff0000, 1, ranges);
11230 }
112451 q else
112551 q recursively_calc_ranges
112651 q (isouth & 0xffff0000, inorth & 0xffff0000,
112751 q int32(-180.0*10000000 - 0.5) & 0xffff0000, ieast & 0xffff0000, 1, ranges);
1129274676317 q ranges.sort();
1131274676317 q return ranges;
1132274676317 q}
1135inline Ranges< Uint32_Index > get_ranges_32(double south, double north, double west, double east)
1137254222 q return ::calc_ranges(south, north, west, east);
1141// Adds recursively the ranges based on the given products of
1142// closed intervals.
1143// The expected assertion for the recursion is that the indices are equal
1144// on the first bitlevel bits. Also, indexes must have the last 16 bit set to zero.
1145inline void recursively_calc_ranges
1146 (uint32 south, uint32 north, int32 west, int32 east,
1147 uint32 bitlevel, Ranges< Uint32_Index >& ranges)
11487474051317 q{
11497474051317 q int32 dist = ((0xffff0000u>>bitlevel)&0xffff0000);
1151 // If the difference is exactly dist, the indices fill the whole square
1152 // and we can add this square to the ranges.
11537474051317 q if ((south + dist == north) && (west + dist == east))
11541814365317 q {
11551814365317 q ranges.push_back(ll_upper_(south, west), ll_upper_(north, east) + 1);
11561814365317 q return;
11571814365317 q }
1159 // Shift dist to obtain a proper recursion.
11605659686317 q dist = ((dist>>1)&0xffff0000);
11625659686317 q if ((north | dist) != (south | dist))
1163106541305 q {
1164 // We need to split between northern and southern part.
1165106541305 q if ((east | dist) != (west | dist))
116624203239 q {
1167 // We also need to split between western and eastern part.
116824203239 q recursively_calc_ranges
116924203239 q (south, south | dist, west, west | dist,
117024203239 q bitlevel + 1, ranges);
117124203239 q recursively_calc_ranges
117224203239 q (south, south | dist, (west | dist) + 0x10000, east,
117324203239 q bitlevel + 1, ranges);
117424203239 q recursively_calc_ranges
117524203239 q ((south | dist) + 0x10000, north, west, west | dist,
117624203239 q bitlevel + 1, ranges);
117724203239 q recursively_calc_ranges
117824203239 q ((south | dist) + 0x10000, north, (west | dist) + 0x10000, east,
117924203239 q bitlevel + 1, ranges);
118024203239 q }
118182338302 q else
118282338302 q {
1183 // We don't need to split because east and west lie in the
1184 // same half of the current square.
118582338302 q recursively_calc_ranges
118682338302 q (south, south | dist, west, east,
118782338302 q bitlevel + 1, ranges);
118882338302 q recursively_calc_ranges
118982338302 q ((south | dist) + 0x10000, north, west, east,
119082338302 q bitlevel + 1, ranges);
119182338302 q }
1192106541305 q }
11935553145317 q else
11945553145317 q {
1195 // We don't need to split because north and south lie in the
1196 // same half of the current square.
11975553145317 q if ((east | dist) != (west | dist))
11981384731304 q {
1199 // We only need to split between western and eastern part.
12001384731304 q recursively_calc_ranges
12011384731304 q (south, north, west, west | dist,
12021384731304 q bitlevel + 1, ranges);
12031384731304 q recursively_calc_ranges
12041384731304 q (south, north, (west | dist) + 0x10000, east,
12051384731304 q bitlevel + 1, ranges);
12061384731304 q }
12074168414317 q else
1208 // We need no split at all.
12094168414317 q recursively_calc_ranges
12104168414317 q (south, north, west, east, bitlevel + 1, ranges);
12115553145317 q }
12125659686317 q}
1215/*---------------------------------------------------------------------------*/
1218inline uint32 ilat_(double lat)
12194344716419 q{
12204344716419 q return ((lat + 91.0)*10000000+0.5);
12214344716419 q}
1224inline int32 ilon_(double lon)
12254344716419 q{
12264344716419 q return (lon*10000000 + (lon > 0 ? 0.5 : -0.5));
12274344716419 q}
1230inline uint32 ll_upper_(double lat, double lon)
12314273505140 q{
12324273505140 q uint32 temp = ll_upper(ilat_(lat), ilon_(lon));
12334273505140 q return (temp ^ 0x40000000);
12344273505140 q}
1237inline uint32 ll_lower(uint32 ilat, int32 ilon)
123842663795 q{
123942663795 q uint32 result(0);
1241725282995 q for (uint32 i(0); i < 16; ++i)
1242682619295 q {
1243682619295 q result |= ((0x1<<i)&ilat)<<(i+1);
1244682619295 q result |= ((0x1<<i)&(uint32)ilon)<<i;
1245682619295 q }
124742663795 q return result;
124842663795 q}
1251inline uint32 ll_lower(double lat, double lon)
12526318730 q{
12536318730 q return ll_lower(ilat_(lat), ilon_(lon));
12546318730 q}
1257inline uint32 ilat(double lat)
12581573175109 q{
12591573175109 q return (lat + 91.0)*10000000+0.5;
12601573175109 q}
1263inline int32 ilon(double lon)
126499531050 q{
126599531050 q return lon*10000000 + (lon > 0 ? 0.5 : -0.5);
126699531050 q}
1269// convert interleaved coordinates to plain integers
1270inline uint32 ilat(uint32 ll_upper, uint32 ll_lower)
12714180144546487 q{
12724180144546487 q uint32 upper = ll_upper & 0xaaaaaaaa;
12734180144546487 q upper = (upper | (upper<<1)) & 0xcccccccc;
12744180144546487 q upper = (upper | (upper<<2)) & 0xf0f0f0f0;
12754180144546487 q upper = (upper | (upper<<4)) & 0xff00ff00;
12764180144546487 q upper = (upper | (upper<<8)) & 0xffff0000;
12784180144546487 q uint32 lower = ll_lower & 0xaaaaaaaa;
12794180144546487 q lower = (lower | (lower>>1)) & 0x99999999;
12804180144546487 q lower = (lower | (lower>>2)) & 0x87878787;
12814180144546487 q lower = (lower | (lower>>4)) & 0x807f807f;
12824180144546487 q lower = (lower | (lower>>8)) & 0x80007fff;
12834180144546487 q lower = (lower | (lower>>16)) & 0x0000ffff;
12854180144546487 q return (upper | lower);
12864180144546487 q}
1289inline double lat(uint32 ll_upper, uint32 ll_lower)
129054528135465 q{
129154528135465 q return ((double)ilat(ll_upper, ll_lower))/10000000 - 91.0;
129254528135465 q}
1294inline double lat(uint32 ilat)
12951221567 q{
12961221567 q return ((double)ilat)/10000000 - 91.0;
12971221567 q}
1300// convert interleaved coordinates to plain integers
1301inline int32 ilon(uint32 ll_upper, uint32 ll_lower)
13024189002595489 q{
13034189002595489 q uint32 upper = (ll_upper ^ 0x40000000) & 0x55555555;
13044189002595489 q upper = (upper | (upper<<1)) & 0x99999999;
13054189002595489 q upper = (upper | (upper<<2)) & 0xe1e1e1e1;
13064189002595489 q upper = (upper | (upper<<4)) & 0xfe01fe01;
13074189002595489 q upper = (upper | (upper<<8)) & 0xfffe0001;
13084189002595489 q upper = (upper | (upper<<16)) & 0xffff0000;
13104189002595489 q uint32 lower = ll_lower & 0x55555555;
13114189002595489 q lower = (lower | (lower>>1)) & 0x33333333;
13124189002595489 q lower = (lower | (lower>>2)) & 0x0f0f0f0f;
13134189002595489 q lower = (lower | (lower>>4)) & 0x00ff00ff;
13144189002595489 q lower = (lower | (lower>>8)) & 0x0000ffff;
13164189002595489 q return (upper | lower);
13174189002595489 q}
1320inline double lon(uint32 ll_upper, uint32 ll_lower)
132163374509465 q{
132263374509465 q return ((double)ilon(ll_upper, ll_lower))/10000000;
132363374509465 q}
1325inline double lon(int32 ilon)
132675922369 q{
132775922369 q return ((double)ilon)/10000000;
132875922369 q}
1331inline bool is_compound_idx(Uint31_Index idx)
13324724870 q{
13334724870 q return idx.val() & 0x80000000u;
13344724870 q}
1337#endif