Overpass API regression suite coverage (Nova Scotia) / overpass_api/data/tilewise_geometry.h

overpass_api/data/tilewise_geometry.h

582 of 785 instrumented lines run by the suite (74.1%) 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__DATA__TILEWISE_GEOMETRY_H
20#define DE__OSM3S___OVERPASS_API__DATA__TILEWISE_GEOMETRY_H
22#include <cctype>
23#include <cmath>
24#include <fstream>
25#include <iostream>
26#include <map>
27#include <set>
28#include <sstream>
29#include <string>
30#include <math.h>
31#include <stdlib.h>
32#include <vector>
34#include "way_geometry_store.h"
37inline Point_Double make_point_double(Quad_Coord arg)
387850457 q{
397850457 q return Point_Double(lat(arg.ll_upper, arg.ll_lower), lon(arg.ll_upper, arg.ll_lower));
407850457 q}
43inline void add_idx_sequence(uint32 lat_lhs, uint32 lat_rhs, int32 lon, std::vector< Uint31_Index >& result)
440{
450 uint32 min_lat = std::min(lat_lhs, lat_rhs);
460 uint32 max_lat = std::max(lat_lhs, lat_rhs);
470 for (uint32 lat = (min_lat & 0xffff0000) + 0x10000; lat + 0x10000 < max_lat; lat += 0x10000)
480 result.push_back(Uint31_Index(ll_upper_(lat, lon)));
490}
52inline std::vector< Uint31_Index > touched_indexes(Quad_Coord lhs, Quad_Coord rhs)
530{
540 uint32 lat_lhs = ilat(lhs.ll_upper, lhs.ll_lower);
550 int32 lon_lhs = ilon(lhs.ll_upper, lhs.ll_lower);
560 uint32 lat_rhs = ilat(rhs.ll_upper, rhs.ll_lower);
570 int32 lon_rhs = ilon(rhs.ll_upper, rhs.ll_lower);
590 if (lat_lhs == lat_rhs && std::abs(lon_rhs - lon_lhs) <= 1)
600 return std::vector< Uint31_Index >();
610 if (lon_lhs == lon_rhs && (lat_rhs - lat_lhs <= 1 || lat_lhs - lat_rhs <= 1))
620 return std::vector< Uint31_Index >();
630 if ((lat_rhs - lat_lhs <= 1 || lat_lhs - lat_rhs <= 1) && std::abs(lon_rhs - lon_lhs) <= 1)
640 {
650 int32 lon_boundary = ((lon_lhs < lon_rhs ? lon_rhs : lon_lhs) & 0xffff0000);
660 uint32 lat_boundary = ((double)lat_rhs - lat_lhs)*(lon_boundary - lon_lhs)/(lon_rhs - lon_lhs) + lat_lhs;
670 return std::vector< Uint31_Index >(1, Uint31_Index(ll_upper_(lat_boundary, lon_boundary)));
680 }
690
700 std::vector< Uint31_Index > result;
710 if ((lon_lhs & 0xffff0000) == (lon_rhs & 0xffff0000))
720 add_idx_sequence(lat_lhs, lat_rhs, lon_lhs, result);
730 else
740 {
750 Great_Circle gc(make_point_double(lhs), make_point_double(rhs));
760 Quad_Coord min = lon_lhs < lon_rhs ? lhs : rhs;
770 Quad_Coord max = lon_lhs < lon_rhs ? rhs : lhs;
780 int32 i_ilon = ilon(min.ll_upper, min.ll_lower);
790 int32 ilon_max = ilon(max.ll_upper, max.ll_lower);
800 if (ilon_max - i_ilon < 1800000000)
810 {
820 uint32 i_ilat = ilat(gc.lat_of(lon((i_ilon & 0xffff0000) + 0x10000)));
830 add_idx_sequence(ilat(min.ll_upper, min.ll_lower), i_ilat, i_ilon, result);
840 for (i_ilon = (i_ilon & 0xffff0000) + 0x10000; i_ilon + 0x10000 < ilon_max; i_ilon += 0x10000)
850 {
860 uint32 last_ilat = i_ilat;
870 uint32 i_ilat = ilat(gc.lat_of(lon(i_ilon + 0x10000)));
880 add_idx_sequence(last_ilat, i_ilat, i_ilon, result);
890 }
900 add_idx_sequence(i_ilat, ilat(max.ll_upper, max.ll_lower), ilon_max, result);
910 }
920 else if (ilon_max - i_ilon == 1800000000)
930 {
940 uint64 ilat_min = ilat(min.ll_upper, min.ll_lower);
950 uint64 ilat_max = ilat(max.ll_upper, max.ll_lower);
960 if (ilat_min + ilat_max > 2*910000000)
970 {
980 add_idx_sequence(ilat_min, 1810000000, i_ilon, result);
990 add_idx_sequence(ilat_max, 1810000000, ilon_max, result);
1000 }
1010 else
1020 {
1030 add_idx_sequence(10000000, ilat_min, i_ilon, result);
1040 add_idx_sequence(10000000, ilat_max, ilon_max, result);
1050 }
1060 }
1070 else
1080 {
1090 //TODO: antimeridian
1100 }
1110 }
1120
1130 return result;
1140}
117inline Uint31_Index touched_index(Quad_Coord lhs, Quad_Coord rhs)
11882669460 q{
11982669460 q uint32 lat_lhs = ilat(lhs.ll_upper, lhs.ll_lower)>>16;
12082669460 q int32 lon_lhs = ilon(lhs.ll_upper, lhs.ll_lower)>>16;
12182669460 q uint32 lat_rhs = ilat(rhs.ll_upper, rhs.ll_lower)>>16;
12282669460 q int32 lon_rhs = ilon(rhs.ll_upper, rhs.ll_lower)>>16;
12482669460 q if (lat_lhs == lat_rhs && std::abs(lon_rhs - lon_lhs) <= 1)
12543606660 q return Uint31_Index(0u);
12639062860 q if (lon_lhs == lon_rhs && (lat_rhs - lat_lhs <= 1 || lat_lhs - lat_rhs <= 1))
12729821060 q return Uint31_Index(0u);
1299241859 q if ((lat_rhs - lat_lhs <= 1 || lat_lhs - lat_rhs <= 1) && std::abs(lon_rhs - lon_lhs) <= 1)
1304564459 q {
1314564459 q lat_lhs = ilat(lhs.ll_upper, lhs.ll_lower);
1324564459 q lon_lhs = ilon(lhs.ll_upper, lhs.ll_lower);
1334564459 q lat_rhs = ilat(rhs.ll_upper, rhs.ll_lower);
1344564459 q lon_rhs = ilon(rhs.ll_upper, rhs.ll_lower);
1354564459 q int32 lon_boundary = (std::max(lon_lhs, lon_rhs) & 0xffff0000);
1364564459 q uint32 lat_boundary = ((double)lat_rhs - lat_lhs)*(lon_boundary - lon_lhs)/(lon_rhs - lon_lhs) + lat_lhs;
1384564459 q int32 missing_lon = lon_lhs;
1394564459 q if (lat_lhs < lat_rhs)
1402106958 q missing_lon = (lat_boundary < (lat_rhs & 0xffff0000) ? lon_rhs : lon_lhs);
1412457559 q else
1422457559 q missing_lon = (lat_boundary < (lat_lhs & 0xffff0000) ? lon_lhs : lon_rhs);
1434564459 q return Uint31_Index(ll_upper_(lat_boundary, missing_lon));
1444564459 q }
1454677457 q return Uint31_Index(0xffu);
1469241859 q}
149struct Segment
151 Segment(uint32 lat_lhs, int32 lon_lhs, uint32 lat_rhs, int32 lon_rhs)
15235905057 q {
15335905057 q populate(lat_lhs, lon_lhs, lat_rhs, lon_rhs);
15435905057 q }
156 Segment(const Quad_Coord& lhs, const Quad_Coord& rhs)
157919827560 q {
158919827560 q populate(
159919827560 q ilat(lhs.ll_upper, lhs.ll_lower), ilon(lhs.ll_upper, lhs.ll_lower),
160919827560 q ilat(rhs.ll_upper, rhs.ll_lower), ilon(rhs.ll_upper, rhs.ll_lower));
161919827560 q }
163 void populate(uint32 ilat_lhs, int32 ilon_lhs, uint32 ilat_rhs, int32 ilon_rhs)
164955732560 q {
165955732560 q if (ilon_lhs < ilon_rhs)
166489238360 q {
167489238360 q ilat_west = ilat_lhs;
168489238360 q ilon_west = ilon_lhs;
169489238360 q ilat_east = ilat_rhs;
170489238360 q ilon_east = ilon_rhs;
171489238360 q }
172466494260 q else
173466494260 q {
174466494260 q ilat_west = ilat_rhs;
175466494260 q ilon_west = ilon_rhs;
176466494260 q ilat_east = ilat_lhs;
177466494260 q ilon_east = ilon_lhs;
178466494260 q }
179955732560 q }
181 uint32 ilat_west;
182 int32 ilon_west;
183 uint32 ilat_east;
184 int32 ilon_east;
185};
188template< typename Segment_Collector >
189void make_entries(const Segment_Collector& collector, const std::vector< Quad_Coord >& geom)
19028216660 q{
19128216660 q if (geom.empty())
19264 q return;
194870164560 q for (uint i = 1; i < geom.size(); ++i)
195841948560 q {
196841948560 q if (geom[i].ll_upper == geom[i-1].ll_upper)
197759279160 q collector.push(geom[i].ll_upper, Segment(geom[i-1], geom[i]));
19882669460 q else
19982669460 q {
20082669460 q Uint31_Index extra_idx = touched_index(geom[i-1], geom[i]);
201// std::cout<<std::dec<<ilat(geom[i-1].ll_upper, geom[i-1].ll_lower)<<' '<<ilon(geom[i-1].ll_upper, geom[i-1].ll_lower)<<' '
202// <<ilat(geom[i].ll_upper, geom[i].ll_lower)<<' '<<ilon(geom[i].ll_upper, geom[i].ll_lower)<<' '
203// <<std::hex<<extra_idx.val()<<'\n';
20482669460 q if (extra_idx.val() == 0xff)
2054677457 q calculate_auxiliary_points(collector, geom[i-1], geom[i]);
20677992060 q else
20777992060 q {
20877992060 q collector.push(geom[i-1].ll_upper, Segment(geom[i-1], geom[i]));
20977992060 q collector.push(geom[i].ll_upper, Segment(geom[i-1], geom[i]));
21077992060 q if (!(extra_idx.val() == 0))
2114564459 q collector.push(extra_idx, Segment(geom[i-1], geom[i]));
21277992060 q }
21382669460 q }
214841948560 q }
21528216060 q}
218template< typename Segment_Collector >
219void calculate_auxiliary_points(const Segment_Collector& collector, Quad_Coord lhs, Quad_Coord rhs)
2204677457 q{
2214677457 q uint32 lat_lhs = ilat(lhs.ll_upper, lhs.ll_lower);
2224677457 q int32 lon_lhs = ilon(lhs.ll_upper, lhs.ll_lower);
2234677457 q uint32 lat_rhs = ilat(rhs.ll_upper, rhs.ll_lower);
2244677457 q int32 lon_rhs = ilon(rhs.ll_upper, rhs.ll_lower);
2264677457 q if ((lon_lhs & 0xffff0000) == (lon_rhs & 0xffff0000))
227752256 q calculate_south_north_sequence(collector, lat_lhs, lon_lhs, lat_rhs, lon_rhs);
2283925257 q else
2293925257 q {
2303925257 q Great_Circle gc(make_point_double(lhs), make_point_double(rhs));
2313925257 q Quad_Coord min = lon_lhs < lon_rhs ? lhs : rhs;
2323925257 q Quad_Coord max = lon_lhs < lon_rhs ? rhs : lhs;
2333925257 q int32 i_ilon = ilon(min.ll_upper, min.ll_lower);
2343925257 q int32 ilon_max = ilon(max.ll_upper, max.ll_lower);
2353925257 q if ((int64)ilon_max - i_ilon < 1800000000)
2363925257 q {
237// std::cout<<"aux_gc "<<ilat(min.ll_upper, min.ll_lower)<<' '<<ilon(min.ll_upper, min.ll_lower)
238// <<' '<<ilat(max.ll_upper, max.ll_lower)<<' '<<ilon(max.ll_upper, max.ll_lower)<<'\n';
2393925257 q uint32 i_ilat = ilat(gc.lat_of(lon((i_ilon & 0xffff0000) + 0x10000)));
2403925257 q calculate_south_north_sequence(
2413925257 q collector, ilat(min.ll_upper, min.ll_lower), i_ilon,
2423925257 q i_ilat, (i_ilon & 0xffff0000) + 0x10000);
24319992557 q for (i_ilon = (i_ilon & 0xffff0000) + 0x10000; i_ilon + 0x10000 < ilon_max;
24416067357 q i_ilon += 0x10000)
24516067357 q {
24616067357 q uint32 last_ilat = i_ilat;
24716067357 q i_ilat = ilat(gc.lat_of(lon(i_ilon + 0x10000)));
24816067357 q calculate_south_north_sequence(
24916067357 q collector, last_ilat, i_ilon, i_ilat, i_ilon + 0x10000);
25016067357 q }
2523925257 q calculate_south_north_sequence(
2533925257 q collector, i_ilat, i_ilon, ilat(max.ll_upper, max.ll_lower), ilon_max);
2543925257 q }
2550 else if (ilon_max - i_ilon == 1800000000)
2560 {
257// std::cout<<"aux_180 "<<ilat(min.ll_upper, min.ll_lower)<<' '<<ilon(min.ll_upper, min.ll_lower)
258// <<' '<<ilat(max.ll_upper, max.ll_lower)<<' '<<ilon(max.ll_upper, max.ll_lower)<<'\n';
2590 uint64 ilat_min = ilat(min.ll_upper, min.ll_lower);
2600 uint64 ilat_max = ilat(max.ll_upper, max.ll_lower);
2610 if (ilat_min + ilat_max > 2*910000000)
2620 {
2630 calculate_south_north_sequence(collector, ilat_min, i_ilon, 1810000000, i_ilon);
2640 calculate_south_north_sequence(collector, ilat_max, ilon_max, 1810000000, ilon_max);
2650 }
2660 else
2670 {
2680 calculate_south_north_sequence(collector, 10000000, i_ilon, ilat_min, i_ilon);
2690 calculate_south_north_sequence(collector, 10000000, ilon_max, ilat_max, ilon_max);
2700 }
2710 }
2720 else
2730 {
274// std::cout<<"aux_anti "<<ilat(min.ll_upper, min.ll_lower)<<' '<<ilon(min.ll_upper, min.ll_lower)
275// <<' '<<ilat(max.ll_upper, max.ll_lower)<<' '<<ilon(max.ll_upper, max.ll_lower)<<'\n';
2760 if ((i_ilon & 0xffff0000) == (-1800000000 & 0xffff0000))
2770 calculate_south_north_sequence(
2780 collector, ilat(gc.lat_of(-180.)), -1800000000, ilat(min.ll_upper, min.ll_lower), i_ilon);
2790 else
2800 {
2810 uint32 i_ilat = ilat(gc.lat_of(-180.));
2820 int32 ilon_max = i_ilon;
2830 i_ilon = -1800000000;
2840 calculate_south_north_sequence(
2850 collector, ilat(min.ll_upper, min.ll_lower), i_ilon,
2860 i_ilat, (i_ilon & 0xffff0000) + 0x10000);
2870 for (i_ilon = (i_ilon & 0xffff0000) + 0x10000; i_ilon + 0x10000 < ilon_max;
2880 i_ilon += 0x10000)
2890 {
2900 uint32 last_ilat = i_ilat;
2910 i_ilat = ilat(gc.lat_of(lon(i_ilon + 0x10000)));
2920 calculate_south_north_sequence(
2930 collector, last_ilat, i_ilon, i_ilat, i_ilon + 0x10000);
2940 }
2960 calculate_south_north_sequence(
2970 collector, i_ilat, i_ilon, ilat(min.ll_upper, min.ll_lower), ilon_max);
2980 }
3000 if ((ilon_max & 0xffff0000) == (1800000000 & 0xffff0000))
3010 {
3020 uint32 anti_lat = ilat(gc.lat_of(180.));
3030 calculate_south_north_sequence(
3040 collector, ilat(max.ll_upper, max.ll_lower), ilon_max, anti_lat, 1800000000);
3050 collector.push(Uint31_Index(ll_upper_(anti_lat, 1800000000)), Segment(anti_lat, 1800000000, anti_lat, 1800000001));
3060 }
3070 else
3080 {
3090 i_ilon = ilon_max;
3100 uint32 i_ilat = ilat(gc.lat_of(lon((i_ilon & 0xffff0000) + 0x10000)));
3110 calculate_south_north_sequence(
3120 collector, ilat(max.ll_upper, max.ll_lower), i_ilon,
3130 i_ilat, (i_ilon & 0xffff0000) + 0x10000);
3140 for (i_ilon = (i_ilon & 0xffff0000) + 0x10000; i_ilon + 0x10000 < 1800000000;
3150 i_ilon += 0x10000)
3160 {
3170 uint32 last_ilat = i_ilat;
3180 i_ilat = ilat(gc.lat_of(lon(i_ilon + 0x10000)));
3190 calculate_south_north_sequence(
3200 collector, last_ilat, i_ilon, i_ilat, i_ilon + 0x10000);
3210 }
3230 uint32 anti_lat = ilat(gc.lat_of(180.));
3240 calculate_south_north_sequence(
3250 collector, i_ilat, i_ilon, anti_lat, 1800000000);
3260 collector.push(Uint31_Index(ll_upper_(anti_lat, 1800000000)), Segment(anti_lat, 1800000000, anti_lat, 1800000001));
3270 }
3280 }
3293925257 q }
3304677457 q}
333template< typename Segment_Collector >
334void calculate_south_north_sequence(
335 const Segment_Collector& collector, uint32 lat_lhs, int32 lon_lhs, uint32 lat_rhs, int32 lon_rhs)
33624669957 q{
337// std::cout<<"sn "<<lat_lhs<<' '<<lon_lhs<<' '<<lat_rhs<<' '<<lon_rhs<<'\n';
33824669957 q if ((lat_lhs & 0xffff0000) == (lat_rhs & 0xffff0000))
33916987957 q {
34016987957 q collector.push(Uint31_Index(ll_upper_(lat_lhs, lon_lhs)), Segment(lat_lhs, lon_lhs, lat_rhs, lon_rhs));
34116987957 q return;
34216987957 q }
3447682056 q if (lat_rhs < lat_lhs)
3453360956 q {
3463360956 q std::swap(lat_lhs, lat_rhs);
3473360956 q std::swap(lon_lhs, lon_rhs);
3483360956 q }
3497682056 q int32 min_lon = std::min(lon_lhs, lon_rhs);
3517682056 q uint32 i_lat = (lat_lhs & 0xffff0000) + 0x10000;
3527682056 q int32 i_lon = lon_lhs + ((double)i_lat - lat_lhs)/((int32)lat_rhs - (int32)lat_lhs)*(lon_rhs - lon_lhs);
353// std::cout<<"DEBUG_B "<<std::hex<<ll_upper_(lat_lhs, min_lon)<<' '
354// <<std::dec<<lat_lhs<<' '<<lon_lhs<<' '<<i_lat<<' '<<i_lon<<'\n';
3557682056 q collector.push(Uint31_Index(ll_upper_(lat_lhs, min_lon)), Segment(lat_lhs, lon_lhs, i_lat, i_lon));
35711235156 q while (i_lat + 0x10000 < lat_rhs)
3583553156 q {
3593553156 q uint32 last_ilat = i_lat;
3603553156 q int32 last_ilon = i_lon;
3613553156 q i_lat += 0x10000;
3623553156 q i_lon = lon_lhs + ((double)i_lat - lat_lhs)/((int32)lat_rhs - (int32)lat_lhs)*(lon_rhs - lon_lhs);
363// std::cout<<"DEBUG_D "<<std::hex<<ll_upper_(last_ilat, min_lon)<<' '
364// <<std::dec<<last_ilat<<' '<<last_ilon<<' '<<i_lat<<' '<<i_lon<<'\n';
3653553156 q collector.push(Uint31_Index(ll_upper_(last_ilat, min_lon)), Segment(last_ilat, last_ilon, i_lat, i_lon));
3663553156 q }
368// std::cout<<"DEBUG_C "<<std::hex<<ll_upper_(i_lat, min_lon)<<' '
369// <<std::dec<<i_lat<<' '<<i_lon<<' '<<lat_rhs<<' '<<lon_rhs<<'\n';
3707682056 q collector.push(Uint31_Index(ll_upper_(i_lat, min_lon)), Segment(i_lat, i_lon, lat_rhs, lon_rhs));
3717682056 q}
374// fwd iterator only
375class Tilewise_Area_Iterator
377public:
378 enum Relative_Position { outside, inside, border };
380 struct Index_Block
381 {
38240832752 q Index_Block() : sw_is_inside(false) {}
384 std::vector< Segment > segments;
385 bool sw_is_inside;
386 };
388 struct Full_Way_Ref
389 {
390 Full_Way_Ref(Uint31_Index idx_, Way_Skeleton* way_, uint64 timestamp_)
3913805635 q : idx(idx_), way(way_), timestamp(timestamp_) {}
393 Uint31_Index idx;
394 Way_Skeleton* way;
395 uint64 timestamp;
397 bool operator<(const Full_Way_Ref& rhs) const
398598141835 q {
399598141835 q return !(idx == rhs.idx) ? idx < rhs.idx
400598141835 q : way < rhs.way;
401598141835 q }
402 };
404 // non-const, but relies to pointers into each vec.
405 // That way, objects can be moved from or marked as done.
406 Tilewise_Area_Iterator(
407 std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways_,
408 std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways_,
409 const Statement& stmt, Resource_Manager& rman)
4104139 q : ways(&ways_), attic_ways(&attic_ways_), cur_it(ways->begin()), attic_it(attic_ways->begin()),
4114139 q cur_geom_store(*ways, stmt, rman), attic_geom_store(*attic_ways, stmt, rman),
4124139 q complete_idx(0u), minlat(0u), maxlat(0x7fff0000)
4144139 q refill();
417 void next()
41819763135 q {
41919763135 q propagate_inside_flag();
42019763135 q queue.erase(queue.begin());
42119763135 q if (queue.empty() || !(queue.begin()->first.val() < complete_idx.val()))
422403535 q refill();
42319763135 q }
42421096336 q bool is_end() const { return queue.empty(); }
42628910035 q const std::map< Full_Way_Ref, Index_Block >& get_obj() const { return queue.begin()->second; }
42757240735 q Uint31_Index get_idx() const { return queue.begin()->first; }
429 Relative_Position rel_position(uint32 ll_upper, uint32 ll_lower, bool accept_border)
4300 {
4310 return rel_pos_ilat_ilon(ilat(ll_upper, ll_lower), ilon(ll_upper, ll_lower), accept_border);
4320 }
434 void move_covering_ways(
435 uint32 ll_upper, uint32 ll_lower,
436 std::map< Uint31_Index, std::vector< Way_Skeleton > >& target_ways,
437 std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& target_attic_ways);
438 void set_limits(uint32 minlat_, uint32 maxlat_)
4404139 q minlat = minlat_;
4414139 q maxlat = maxlat_;
444 Relative_Position rel_position(const std::vector< Segment >& segments, bool accept_border);
446private:
447 std::map< Uint31_Index, std::vector< Way_Skeleton > >* ways;
448 std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >* attic_ways;
449 std::map< Uint31_Index, std::vector< Way_Skeleton > >::iterator cur_it;
450 std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >::iterator attic_it;
451 Way_Geometry_Store cur_geom_store;
452 Way_Geometry_Store attic_geom_store;
453 std::map< Uint31_Index, std::map< Full_Way_Ref, Index_Block > > queue;
454 Uint31_Index complete_idx;
455 uint32 minlat;
456 uint32 maxlat;
458 struct Segment_Collector
459 {
460 Segment_Collector(
461 std::map< Uint31_Index, std::map< Full_Way_Ref, Index_Block > >& queue_, Full_Way_Ref skel_)
4623805635 q : queue(&queue_), skel(skel_) {}
463 void push(Uint31_Index idx, const Segment& segment) const
464204708535 q { (*queue)[idx][skel].segments.push_back(segment); }
466 private:
467 std::map< Uint31_Index, std::map< Full_Way_Ref, Index_Block > >* queue;
468 Full_Way_Ref skel;
469 };
471 void refill()
472407639 q {
473664539 q while (cur_it != ways->end() || attic_it != attic_ways->end())
474657136 q {
475657136 q Uint31_Index idx = (cur_it != ways->end() && (attic_it == attic_ways->end() || cur_it->first < attic_it->first)
476657136 q ? cur_it->first : attic_it->first);
477657136 q if (cur_it != ways->end() && cur_it->first == idx)
478657136 q {
4794374936 q for (std::vector< Way_Skeleton >::iterator it = cur_it->second.begin(); it != cur_it->second.end(); ++it)
4803717835 q {
4813717835 q if (!it->nds.empty() && it->nds.front() == it->nds.back())
4823717835 q make_entries(Segment_Collector(queue, Full_Way_Ref(idx, &*it, NOW)), cur_geom_store.get_geometry(*it));
4833717835 q }
484657136 q ++cur_it;
485657136 q }
486657136 q if (attic_it != attic_ways->end() && attic_it->first == idx)
48763310 q {
48863310 q for (std::vector< Attic< Way_Skeleton > >::iterator it = attic_it->second.begin();
489151110 q it != attic_it->second.end(); ++it)
4908789 q {
4918789 q if (!it->nds.empty() && it->nds.front() == it->nds.back())
4928789 q make_entries(Segment_Collector(queue, Full_Way_Ref(idx, &*it, it->timestamp)), attic_geom_store.get_geometry(*it));
4938789 q }
49463310 q ++attic_it;
49563310 q }
497657136 q complete_idx = Uint31_Index(idx.val() & 0x7fffffff);
498657136 q if (!queue.empty() && is_compound_idx(idx) && (queue.begin()->first.val() & 0x7fffffff) < complete_idx.val())
499400235 q break;
500657136 q }
502// std::cout<<"DEBUG refill ";
503// for (std::map< Uint31_Index, std::map< Full_Way_Ref, Index_Block > >::const_iterator it = queue.begin(); it != queue.end(); ++it)
504// std::cout<<' '<<std::hex<<it->first.val()<<'\n';
505// std::cout<<'\n';
506407639 q }
508 void propagate_inside_flag();
509 Relative_Position rel_pos_ilat_ilon(uint32 lat_p, int32 lon_p, bool accept_border);
510};
513// fwd iterator only
514class Tilewise_Const_Area_Iterator
516public:
517 struct Full_Way_Ref
518 {
519 Full_Way_Ref(Uint31_Index idx_, const Way_Skeleton* way_, uint64 timestamp_)
52045729 q : idx(idx_), way(way_), timestamp(timestamp_) {}
522 Uint31_Index idx;
523 const Way_Skeleton* way;
524 uint64 timestamp;
526 bool operator<(const Full_Way_Ref& rhs) const
52721891829 q {
52821891829 q return !(idx == rhs.idx) ? idx < rhs.idx
52921891829 q : way < rhs.way;
53021891829 q }
531 };
533 // non-const, but relies to pointers into each vec.
534 // That way, objects can be moved from or marked as done.
535 Tilewise_Const_Area_Iterator(
536 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways_,
537 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways_,
538 const Statement& stmt, Resource_Manager& rman)
53922245 q : ways(&ways_), attic_ways(&attic_ways_), cur_it(ways->begin()), attic_it(attic_ways->begin()),
54022245 q cur_geom_store(*ways, stmt, rman), attic_geom_store(*attic_ways, stmt, rman),
54122245 q complete_idx(0u)
54222245 q {
54322245 q refill();
54422245 q }
546 void next()
5473778524 q {
5483778524 q propagate_inside_flag();
5493778524 q queue.erase(queue.begin());
5503778524 q if (queue.empty() || !(queue.begin()->first.val() < complete_idx.val()))
551832024 q refill();
5523778524 q }
55396167538 q bool is_end() const { return queue.empty(); }
55514314424 q const std::map< Full_Way_Ref, Tilewise_Area_Iterator::Index_Block >& get_obj() const { return queue.begin()->second; }
55670810426 q Uint31_Index get_idx() const { return queue.begin()->first; }
558 Tilewise_Area_Iterator::Relative_Position rel_position(uint32 ll_upper, uint32 ll_lower, bool accept_border)
559318246 q {
560318246 q return rel_pos_ilat_ilon(ilat(ll_upper, ll_lower), ilon(ll_upper, ll_lower), accept_border);
561318246 q }
563 void move_covering_ways(
564 uint32 ll_upper, uint32 ll_lower,
565 std::map< Uint31_Index, std::vector< Way_Skeleton > >& target_ways,
566 std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& target_attic_ways);
568 Tilewise_Area_Iterator::Relative_Position rel_position(const std::vector< Segment >& segments, bool accept_border);
570private:
571 const std::map< Uint31_Index, std::vector< Way_Skeleton > >* ways;
572 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >* attic_ways;
573 std::map< Uint31_Index, std::vector< Way_Skeleton > >::const_iterator cur_it;
574 std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >::const_iterator attic_it;
575 Way_Geometry_Store cur_geom_store;
576 Way_Geometry_Store attic_geom_store;
577 std::map< Uint31_Index, std::map< Full_Way_Ref, Tilewise_Area_Iterator::Index_Block > > queue;
578 Uint31_Index complete_idx;
580 struct Segment_Collector
581 {
582 Segment_Collector(
583 std::map< Uint31_Index, std::map< Full_Way_Ref, Tilewise_Area_Iterator::Index_Block > >& queue_,
584 Full_Way_Ref skel_)
58545729 q : queue(&queue_), skel(skel_) {}
586 void push(Uint31_Index idx, const Segment& segment) const
58712350029 q { (*queue)[idx][skel].segments.push_back(segment); }
589 private:
590 std::map< Uint31_Index, std::map< Full_Way_Ref, Tilewise_Area_Iterator::Index_Block > >* queue;
591 Full_Way_Ref skel;
592 };
594 void refill()
595854245 q {
596877045 q while (cur_it != ways->end() || attic_it != attic_ways->end())
59744329 q {
59844329 q Uint31_Index idx = (cur_it != ways->end() && (attic_it == attic_ways->end() || cur_it->first < attic_it->first)
59944329 q ? cur_it->first : attic_it->first);
60044329 q if (cur_it != ways->end() && cur_it->first == idx)
60134221 q {
60269221 q for (std::vector< Way_Skeleton >::const_iterator it = cur_it->second.begin(); it != cur_it->second.end(); ++it)
60335021 q {
60435021 q if (!it->nds.empty() && it->nds.front() == it->nds.back())
60535021 q make_entries(Segment_Collector(queue, Full_Way_Ref(idx, &*it, NOW)), cur_geom_store.get_geometry(*it));
60635021 q }
60734221 q ++cur_it;
60834221 q }
60944329 q if (attic_it != attic_ways->end() && attic_it->first == idx)
61010110 q {
61110110 q for (std::vector< Attic< Way_Skeleton > >::const_iterator it = attic_it->second.begin();
61220810 q it != attic_it->second.end(); ++it)
61310710 q {
61410710 q if (!it->nds.empty() && it->nds.front() == it->nds.back())
61510710 q make_entries(Segment_Collector(queue, Full_Way_Ref(idx, &*it, it->timestamp)), attic_geom_store.get_geometry(*it));
61610710 q }
61710110 q ++attic_it;
61810110 q }
62044329 q complete_idx = Uint31_Index(idx.val() & 0x7fffffff);
62144329 q if (!queue.empty() && is_compound_idx(idx) && (queue.begin()->first.val() & 0x7fffffff) < complete_idx.val())
62221520 q break;
62344329 q }
624854245 q }
626 void propagate_inside_flag();
627 Tilewise_Area_Iterator::Relative_Position rel_pos_ilat_ilon(uint32 lat_p, int32 lon_p, bool accept_border);
628};
631inline bool eastern_sw_is_inside(const Tilewise_Area_Iterator::Index_Block& block, uint32 south, int32 west)
63225883749 q{
63325883749 q bool is_inside = block.sw_is_inside;
635138815249 q for (std::vector< Segment >::const_iterator it = block.segments.begin(); it != block.segments.end(); ++it)
636112931549 q {
637112931549 q if ((it->ilat_west <= south) ^ (it->ilat_east <= south))
6385239347 q {
6395239347 q double isect_lon = it->ilon_west +
6405239347 q ((double)south - it->ilat_west)
6415239347 q *(it->ilon_east - it->ilon_west)/((int32)it->ilat_east - (int32)it->ilat_west);
6425239347 q if (west <= isect_lon && isect_lon < west + 0x10000)
6435056647 q is_inside = !is_inside;
6445239347 q }
645112931549 q }
64725883749 q return is_inside;
64825883749 q}
651inline bool northern_sw_is_inside(const Tilewise_Area_Iterator::Index_Block& block)
6520{
6530 bool is_inside = block.sw_is_inside;
6550 for (std::vector< Segment >::const_iterator it = block.segments.begin(); it != block.segments.end(); ++it)
6560 {
6570 if (it->ilon_west == -1800000000 && it->ilon_east != -1800000000)
6580 is_inside = !is_inside;
6590 }
6610 return is_inside;
6620}
665inline Tilewise_Area_Iterator::Relative_Position rel_pos_ilat_ilon(
666 uint32 lat_p, int32 lon_p, const Tilewise_Area_Iterator::Index_Block& block, uint32 south, int32 west)
66747342046 q{
66847342046 q bool is_inside = block.sw_is_inside;
670451430446 q for (std::vector< Segment >::const_iterator it = block.segments.begin(); it != block.segments.end(); ++it)
671404909546 q {
672404909546 q if (it->ilat_west > south && it->ilat_east > south)
673396723746 q {
674 // northern segment not touching the southern boundary
675396723746 q if (it->ilon_west == lon_p)
676440829 q {
677440829 q if (it->ilat_west == lat_p)
678390826 q return Tilewise_Area_Iterator::border;
67950018 q if (it->ilon_west == it->ilon_east)
6801928 q {
6811928 q if (std::min(it->ilat_west, it->ilat_east) <= lat_p && lat_p <= std::max(it->ilat_west, it->ilat_east))
682797 q return Tilewise_Area_Iterator::border;
6831928 q }
68430817 q else
68530817 q is_inside ^= (it->ilat_west < lat_p);
68650018 q }
687396282946 q else if (it->ilon_east == lon_p)
688370027 q {
689370027 q if (it->ilat_east == lat_p)
690340824 q return Tilewise_Area_Iterator::border;
691370027 q }
692395912946 q else if (it->ilon_west < lon_p && lon_p < it->ilon_east)
69310407143 q {
69410407143 q double isect_lat = it->ilat_west +
69510407143 q ((double)lon_p - it->ilon_west)
69610407143 q *((int32)it->ilat_east - (int32)it->ilat_west)/(it->ilon_east - it->ilon_west);
69710407143 q if (isect_lat - .5 < lat_p)
6984720938 q {
6994720938 q if (lat_p < isect_lat + .5)
70069514 q return Tilewise_Area_Iterator::border;
7014651438 q is_inside = !is_inside;
7024651438 q }
70310407143 q }
704396723746 q }
7058185840 q else if ((it->ilat_west <= south) ^ (it->ilat_east <= south))
7068180840 q {
7078180840 q double isect_lon = it->ilon_west +
7088180840 q ((double)south - it->ilat_west)
7098180840 q *(it->ilon_east - it->ilon_west)/((int32)it->ilat_east - (int32)it->ilat_west);
7108180840 q if (west <= isect_lon && isect_lon < west + 0x10000)
7117946240 q {
7127946240 q if (it->ilat_west <= south)
7134172238 q {
7144172238 q if (it->ilon_east <= lon_p)
7151809037 q {
7161809037 q if (it->ilon_east == lon_p)
717839 q {
718839 q if (it->ilat_east == lat_p)
719399 q return Tilewise_Area_Iterator::border;
720441 q if (it->ilon_west == it->ilon_east && lat_p <= it->ilat_east)
721131 q return Tilewise_Area_Iterator::border;
722441 q }
7231803837 q is_inside = !is_inside;
7241803837 q }
7252363228 q else if (isect_lon < lon_p)
726108318 q {
727108318 q double isect_lat = it->ilat_west +
728108318 q ((double)lon_p - it->ilon_west)
729108318 q *((int32)it->ilat_east - (int32)it->ilat_west)/(it->ilon_east - it->ilon_west);
730108318 q if (lat_p < isect_lat + .5)
731267 q {
732267 q if (isect_lat - .5 < lat_p)
73321 q return Tilewise_Area_Iterator::border;
734246 q is_inside = !is_inside;
735246 q }
736108318 q }
7374172238 q }
7383774034 q else
7393774034 q {
7403774034 q if (isect_lon <= lon_p)
7411710532 q {
7421710532 q if (isect_lon == lon_p)
743272 q {
744272 q if (lat_p == south)
74561 q return Tilewise_Area_Iterator::border;
746212 q if (isect_lon == it->ilon_west && lat_p <= it->ilat_west)
74772 q return Tilewise_Area_Iterator::border;
748212 q }
7491709232 q is_inside = !is_inside;
7501709232 q }
7512063529 q else if (it->ilon_west <= lon_p)
752118920 q {
753118920 q double isect_lat = it->ilat_west +
754118920 q ((double)lon_p - it->ilon_west)
755118920 q *((int32)it->ilat_east - (int32)it->ilat_west)/(it->ilon_east - it->ilon_west);
756118920 q if (isect_lat - .5 < lat_p)
757105918 q {
758105918 q if (lat_p < isect_lat + .5)
759518 q return Tilewise_Area_Iterator::border;
760100817 q is_inside = !is_inside;
761100817 q }
762118920 q }
7633774034 q }
7647946240 q }
765234614 q else
766234614 q {
767 // northern segment similar to above
768234614 q if (it->ilon_west == lon_p)
77022 q if (it->ilat_west == lat_p)
77122 q return Tilewise_Area_Iterator::border;
772 // Here it->ilon_west == lon_p implies south < it->ilat_west
7730 is_inside ^= (it->ilat_west < lat_p);
7740 }
775234414 q else if (it->ilon_east == lon_p)
77711 q if (it->ilat_east == lat_p)
77811 q return Tilewise_Area_Iterator::border;
780234314 q else if (it->ilon_west < lon_p && lon_p < it->ilon_east)
7811478 q {
7821478 q double isect_lat = it->ilat_west +
7831478 q ((double)lon_p - it->ilon_west)
7841478 q *((int32)it->ilat_east - (int32)it->ilat_west)/(it->ilon_east - it->ilon_west);
7851478 q if (isect_lat - .5 < lat_p)
7861388 q {
7871388 q if (lat_p < isect_lat + .5)
7880 return Tilewise_Area_Iterator::border;
7891388 q is_inside = !is_inside;
7901388 q }
7911478 q }
792234614 q }
7938180840 q }
794504 q else if (it->ilat_west == south && it->ilat_east == south)
7950 {
796 // segment on the southern boundary
7970 if (lat_p == south)
7980 {
7990 if (it->ilon_west <= lon_p && lon_p <= it->ilon_east)
8000 return Tilewise_Area_Iterator::border;
8010 }
8030 if (it->ilon_west == -1800000000)
8040 is_inside = !is_inside;
8050 }
806// std::cout<<"DEBUG "<<lat_p<<' '<<lon_p<<' '<<it->ilat_west<<' '<<it->ilon_west<<' '<<it->ilat_east<<' '<<it->ilon_east<<' '<<is_inside<<'\n';
807404909546 q }
80946520946 q return is_inside ? Tilewise_Area_Iterator::inside : Tilewise_Area_Iterator::outside;
81047342046 q}
813inline Tilewise_Area_Iterator::Relative_Position rel_position(
814 Uint31_Index idx, const Segment& segment, const Tilewise_Area_Iterator::Index_Block& block)
8152567715 q{
8162567715 q std::vector< std::pair< uint32, int32 > > touching_coords;
81852844115 q for (std::vector< Segment >::const_iterator ait = block.segments.begin(); ait != block.segments.end(); ++ait)
81950283215 q {
82050283215 q if (ait->ilon_west <= segment.ilon_east && segment.ilon_west <= ait->ilon_east)
8213042614 q {
822 // Compute the scalar products of both endpoints of one segment with the other segment's direction
823 // If they have different signs then we know that the intersection of both lines is within the segment
8243042614 q double scal_ait_west = ((double)ait->ilat_west - segment.ilat_west)*(segment.ilon_east - segment.ilon_west)
8253042614 q - (ait->ilon_west - segment.ilon_west)*((double)segment.ilat_east - segment.ilat_west);
8263042614 q double scal_ait_east = ((double)ait->ilat_east - segment.ilat_west)*(segment.ilon_east - segment.ilon_west)
8273042614 q - (ait->ilon_east - segment.ilon_west)*((double)segment.ilat_east - segment.ilat_west);
8283042614 q if (scal_ait_east * scal_ait_west > 0)
8292620013 q continue;
831422614 q double scal_it_west = ((double)segment.ilat_west - ait->ilat_west)*(ait->ilon_east - ait->ilon_west)
832422614 q - (segment.ilon_west - ait->ilon_west)*((double)ait->ilat_east - ait->ilat_west);
833422614 q double scal_it_east = ((double)segment.ilat_east - ait->ilat_west)*(ait->ilon_east - ait->ilon_west)
834422614 q - (segment.ilon_east - ait->ilon_west)*((double)ait->ilat_east - ait->ilat_west);
835422614 q if (scal_it_east * scal_it_west > 0)
836126713 q continue;
838// std::cout<<"DEBUG "<<bit->first->id.val()
839// <<" "<<segment.ilat_west<<' '<<segment.ilon_west<<" "<<segment.ilat_east<<' '<<segment.ilon_east
840// <<" "<<ait->ilat_west<<' '<<ait->ilon_west<<" "<<ait->ilat_east<<' '<<ait->ilon_east
841// <<" "<<scal_ait_west<<' '<<scal_ait_east<<' '<<scal_it_west<<' '<<scal_it_east<<'\n';
842// std::cout<<"DEBUG "<<((double)ait->ilat_east - segment.ilat_west)<<' '<<(segment.ilon_west - segment.ilon_east)
843// <<' '<<(ait->ilon_east - segment.ilon_west)<<' '<<((double)segment.ilat_east - segment.ilat_west)<<'\n';
845295912 q if (scal_ait_west == 0)
846183212 q {
847183212 q touching_coords.push_back(std::make_pair(ait->ilat_west, ait->ilon_west));
848183212 q if (scal_ait_east == 0)
84987812 q touching_coords.push_back(std::make_pair(ait->ilat_east, ait->ilon_east));
850183212 q }
851112712 q else if (scal_ait_east == 0)
852105612 q touching_coords.push_back(std::make_pair(ait->ilat_east, ait->ilon_east));
853718 q else if (scal_it_west == 0)
85431 q touching_coords.push_back(std::make_pair(segment.ilat_west, segment.ilon_west));
855688 q else if (scal_it_east != 0)
856688 q return Tilewise_Area_Iterator::inside;
857295912 q }
85850283215 q }
8602560915 q if (!touching_coords.empty())
861110512 q {
862110512 q touching_coords.push_back(std::make_pair(segment.ilat_west, segment.ilon_west));
863110512 q touching_coords.push_back(std::make_pair(segment.ilat_east, segment.ilon_east));
864110512 q std::sort(touching_coords.begin(), touching_coords.end());
865110512 q touching_coords.erase(std::unique(touching_coords.begin(), touching_coords.end()), touching_coords.end());
866110512 q uint32 south = ilat(idx.val(), 0u);
867110512 q int32 west = ilon(idx.val(), 0u);
869209412 q for (std::vector< std::pair< uint32, int32 > >::size_type i = 1; i < touching_coords.size(); ++i)
870114712 q {
871114712 q Tilewise_Area_Iterator::Relative_Position status = ::rel_pos_ilat_ilon(
872114712 q ((uint64)touching_coords[i-1].first + touching_coords[i].first)/2,
873114712 q ((int64)touching_coords[i-1].second + touching_coords[i].second)/2, block, south, west);
874114712 q if (status == Tilewise_Area_Iterator::inside)
87515811 q return Tilewise_Area_Iterator::inside;
876114712 q }
877110512 q }
8792545115 q return Tilewise_Area_Iterator::outside;
8802560915 q}
883inline Tilewise_Area_Iterator::Relative_Position Tilewise_Area_Iterator::rel_position(
884 const std::vector< Segment >& segments, bool accept_border)
8850{
8860 for (std::vector< Segment >::const_iterator it = segments.begin(); it != segments.end(); ++it)
8870 {
8880 Relative_Position status = rel_pos_ilat_ilon(it->ilat_west, it->ilon_west, false);
8890 if (status == inside)
8900 return status;
8910 status = rel_pos_ilat_ilon(it->ilat_east, it->ilon_east, false);
8920 if (status == inside)
8930 return status;
8950 const std::map< Full_Way_Ref, Index_Block >& way_blocks = get_obj();
8960 for (std::map< Full_Way_Ref, Index_Block >::const_iterator bit = way_blocks.begin();
8970 bit != way_blocks.end(); ++bit)
8980 {
8990 const Index_Block& block = bit->second;
9000 Relative_Position result = ::rel_position(get_idx(), *it, block);
9010 if (result != outside)
9020 return result;
9030 }
9040 }
9050 return outside;
9060}
909inline Tilewise_Area_Iterator::Relative_Position Tilewise_Const_Area_Iterator::rel_position(
910 const std::vector< Segment >& segments, bool accept_border)
911378215 q{
9122887115 q for (std::vector< Segment >::const_iterator it = segments.begin(); it != segments.end(); ++it)
9132617315 q {
9142617315 q Tilewise_Area_Iterator::Relative_Position status = rel_pos_ilat_ilon(it->ilat_west, it->ilon_west, false);
9152617315 q if (status == Tilewise_Area_Iterator::inside)
91673711 q return status;
9172543615 q status = rel_pos_ilat_ilon(it->ilat_east, it->ilon_east, false);
9182543615 q if (status == Tilewise_Area_Iterator::inside)
9191218 q return status;
9212531515 q const std::map< Full_Way_Ref, Tilewise_Area_Iterator::Index_Block >& way_blocks = get_obj();
9222531515 q for (std::map< Full_Way_Ref, Tilewise_Area_Iterator::Index_Block >::const_iterator bit = way_blocks.begin();
9235076615 q bit != way_blocks.end(); ++bit)
9242567715 q {
9252567715 q const Tilewise_Area_Iterator::Index_Block& block = bit->second;
9262567715 q Tilewise_Area_Iterator::Relative_Position result = ::rel_position(get_idx(), *it, block);
9272567715 q if (result != Tilewise_Area_Iterator::outside)
92822611 q return result;
9292567715 q }
9302531515 q }
931269815 q return Tilewise_Area_Iterator::outside;
932378215 q}
935inline void Tilewise_Area_Iterator::propagate_inside_flag()
93619763135 q{
93719763135 q Uint31_Index idx = get_idx();
93819763135 q uint32 south = ilat(idx.val(), 0u);
93919763135 q int32 west = ilon(idx.val(), 0u);
94019763135 q if (maxlat < south)
941924832 q return;
94218838335 q if (south < minlat && west >= -1800000000)
9434167935 q return;
94514670434 q const std::map< Full_Way_Ref, Index_Block >& way_blocks = get_obj();
94714670434 q for (std::map< Full_Way_Ref, Index_Block >::const_iterator bit = way_blocks.begin();
94835976134 q bit != way_blocks.end(); ++bit)
94921305734 q {
95021305734 q const Index_Block& block = bit->second;
95121305734 q if (eastern_sw_is_inside(block, south, west))
95213459033 q queue[Uint31_Index(ll_upper_(ilat(idx.val(), 0u), ilon(idx.val(), 0u)+0x10000))][bit->first].sw_is_inside = true;
95321305734 q if (west < -1800000000 && northern_sw_is_inside(block))
9540 queue[Uint31_Index(ll_upper_(ilat(idx.val(), 0u)+0x10000, ilon(idx.val(), 0u)))][bit->first].sw_is_inside = true;
95521305734 q }
95614670434 q}
959inline void Tilewise_Const_Area_Iterator::propagate_inside_flag()
9603778524 q{
9613778524 q Uint31_Index idx = get_idx();
9623778524 q uint32 south = ilat(idx.val(), 0u);
9633778524 q int32 west = ilon(idx.val(), 0u);
9643778524 q const std::map< Full_Way_Ref, Tilewise_Area_Iterator::Index_Block >& way_blocks = get_obj();
9663778524 q for (std::map< Full_Way_Ref, Tilewise_Area_Iterator::Index_Block >::const_iterator bit = way_blocks.begin();
9678356524 q bit != way_blocks.end(); ++bit)
9684578024 q {
9694578024 q const Tilewise_Area_Iterator::Index_Block& block = bit->second;
9704578024 q if (eastern_sw_is_inside(block, south, west))
9714268116 q queue[Uint31_Index(ll_upper_(ilat(idx.val(), 0u), ilon(idx.val(), 0u)+0x10000))][bit->first].sw_is_inside = true;
9724578024 q if (west < -1800000000 && northern_sw_is_inside(block))
9730 queue[Uint31_Index(ll_upper_(ilat(idx.val(), 0u)+0x10000, ilon(idx.val(), 0u)))][bit->first].sw_is_inside = true;
9744578024 q }
9753778524 q}
978inline Tilewise_Area_Iterator::Relative_Position Tilewise_Area_Iterator::rel_pos_ilat_ilon(
979 uint32 lat_p, int32 lon_p, bool accept_border)
9800{
9810 Uint31_Index idx = get_idx();
9820 uint32 south = ilat(idx.val(), 0u);
9830 int32 west = ilon(idx.val(), 0u);
9840 if (lat_p < south || lat_p - south > 65535 || lon_p < west || lon_p - west > 65535)
9850 return outside;
9860 const std::map< Full_Way_Ref, Index_Block >& way_blocks = get_obj();
9870
9880 for (std::map< Full_Way_Ref, Index_Block >::const_iterator bit = way_blocks.begin();
9890 bit != way_blocks.end(); ++bit)
9900 {
9910 Relative_Position status = ::rel_pos_ilat_ilon(lat_p, lon_p, bit->second, south, west);
9920 if (status == inside)
9930 return inside;
9940 else if (status == border && accept_border)
9950 return border;
9960 }
9980 return outside;
9990}
1002inline Tilewise_Area_Iterator::Relative_Position Tilewise_Const_Area_Iterator::rel_pos_ilat_ilon(
1003 uint32 lat_p, int32 lon_p, bool accept_border)
10048343315 q{
10058343315 q Uint31_Index idx = get_idx();
10068343315 q uint32 south = ilat(idx.val(), 0u);
10078343315 q int32 west = ilon(idx.val(), 0u);
10088343315 q if (lat_p < south || lat_p - south > 65535 || lon_p < west || lon_p - west > 65535)
1009338915 q return Tilewise_Area_Iterator::outside;
10108004415 q const std::map< Full_Way_Ref, Tilewise_Area_Iterator::Index_Block >& way_blocks = get_obj();
10128004415 q for (std::map< Full_Way_Ref, Tilewise_Area_Iterator::Index_Block >::const_iterator bit = way_blocks.begin();
101314712715 q bit != way_blocks.end(); ++bit)
10148105715 q {
10158105715 q Tilewise_Area_Iterator::Relative_Position status = ::rel_pos_ilat_ilon(lat_p, lon_p, bit->second, south, west);
10168105715 q if (status == Tilewise_Area_Iterator::inside)
10171036812 q return Tilewise_Area_Iterator::inside;
10187068915 q else if (status == Tilewise_Area_Iterator::border && accept_border)
101936066 q return Tilewise_Area_Iterator::border;
10208105715 q }
10226607015 q return Tilewise_Area_Iterator::outside;
10238004415 q}
1026inline void Tilewise_Area_Iterator::move_covering_ways(
1027 uint32 ll_upper, uint32 ll_lower,
1028 std::map< Uint31_Index, std::vector< Way_Skeleton > >& target_ways,
1029 std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& target_attic_ways)
103014239634 q{
103114239634 q Uint31_Index idx = get_idx();
103214239634 q uint32 south = ilat(idx.val(), 0u);
103314239634 q int32 west = ilon(idx.val(), 0u);
103414239634 q const std::map< Full_Way_Ref, Index_Block >& way_blocks = get_obj();
103614239634 q uint32 lat_p = ilat(ll_upper, ll_lower);
103714239634 q int32 lon_p = ilon(ll_upper, ll_lower);
103914239634 q for (std::map< Full_Way_Ref, Index_Block >::const_iterator bit = way_blocks.begin();
104098660534 q bit != way_blocks.end(); ++bit)
104184420934 q {
1042// std::cout<<"DEBUG move_covering_ways "<<std::hex<<idx.val()<<' '<<std::dec<<bit->first.way->id.val()<<'\n';
104384420934 q if (bit->first.way->id.val() == 0u)
104445299312 q continue;
104639121634 q Relative_Position status = ::rel_pos_ilat_ilon(lat_p, lon_p, bit->second, south, west);
104739121634 q if (status != outside)
1048318131 q {
1049318131 q if (bit->first.timestamp != NOW)
10501299 q {
10511299 q target_attic_ways[bit->first.idx].push_back(Attic< Way_Skeleton >(*bit->first.way, bit->first.timestamp));
10521299 q bit->first.way->id = Way_Skeleton::Id_Type(0u);
10531299 q }
1054305225 q else
1055305225 q {
1056305225 q target_ways[bit->first.idx].push_back(*bit->first.way);
1057305225 q bit->first.way->id = Way_Skeleton::Id_Type(0u);
1058305225 q }
1059318131 q }
1060// std::cout<<"DEBUG A "<<status<<' '<<std::hex<<bit->first.idx.val()<<' '<<std::dec<<bit->first.timestamp
1061// <<' '<<target_ways.size()<<' '<<target_ways[bit->first.idx].size()<<'\n';
106239121634 q }
106314239634 q}
1066// fwd iterator only
1067class Tilewise_Way_Iterator
1069public:
1070 struct Index_Block
1072 std::vector< Segment > segments;
1073 };
1075 template< typename Way_Skeleton >
1076 struct Status_Ref
107824365333 q Status_Ref(Uint31_Index idx_, const Way_Skeleton& skel_) : idx(idx_), skel(&skel_),
107924365333 q status(Tilewise_Area_Iterator::outside) {}
1081 Uint31_Index idx;
1082 const Way_Skeleton* skel;
1083 Tilewise_Area_Iterator::Relative_Position status;
1084 };
1086 // non-const, but relies to pointers into each vec.
1087 // That way, objects can be moved from or marked as done.
1088 Tilewise_Way_Iterator(
1089 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways_,
1090 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways_,
1091 const Statement& stmt, Resource_Manager& rman)
109211345 q : ways(&ways_), attic_ways(&attic_ways_), cur_it(ways->begin()), attic_it(attic_ways->begin()),
109311345 q cur_geom_store(*ways, stmt, rman), attic_geom_store(*attic_ways, stmt, rman),
109411345 q complete_idx(0u)
109611345 q refill();
1099 void next()
110043135033 q {
110143135033 q queue.erase(queue.begin());
110243135033 q if (queue.empty() || !(queue.begin()->first.val() < complete_idx.val()))
11038450833 q refill();
110443135033 q }
110543146345 q bool is_end() const { return queue.empty(); }
1107 const std::map< Status_Ref< Way_Skeleton >*, Index_Block >& get_current_obj() const
110869913 q { return queue.begin()->second.first; }
1109 const std::map< Status_Ref< Attic< Way_Skeleton > >*, Index_Block >& get_attic_obj() const
11107494 q { return queue.begin()->second.second; }
111152788625 q Uint31_Index get_idx() const { return queue.begin()->first; }
1113private:
1114 const std::map< Uint31_Index, std::vector< Way_Skeleton > >* ways;
1115 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >* attic_ways;
1116 std::map< Uint31_Index, std::vector< Way_Skeleton > >::const_iterator cur_it;
1117 std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >::const_iterator attic_it;
1118 std::map< Uint31_Index, std::vector< Status_Ref< Way_Skeleton > > > current_refs;
1119 std::map< Uint31_Index, std::vector< Status_Ref< Attic< Way_Skeleton > > > > attic_refs;
1120 Way_Geometry_Store cur_geom_store;
1121 Way_Geometry_Store attic_geom_store;
1122 std::map< Uint31_Index, std::pair< std::map< Status_Ref< Way_Skeleton >*, Index_Block >,
1123 std::map< Status_Ref< Attic< Way_Skeleton > >*, Index_Block > > > queue;
1124 Uint31_Index complete_idx;
1126 struct Current_Segment_Collector
1128 Current_Segment_Collector(
1129 std::map< Uint31_Index, std::pair< std::map< Status_Ref< Way_Skeleton >*, Index_Block >,
1130 std::map< Status_Ref< Attic< Way_Skeleton > >*, Index_Block > > >& queue_,
1131 Status_Ref< Way_Skeleton >& skel_)
113222497530 q : queue(&queue_), skel(&skel_) {}
1133 void push(Uint31_Index idx, const Segment& segment) const
1134617652130 q { (*queue)[idx].first[skel].segments.push_back(segment); }
1136 private:
1137 std::map< Uint31_Index, std::pair< std::map< Status_Ref< Way_Skeleton >*, Index_Block >,
1138 std::map< Status_Ref< Attic< Way_Skeleton > >*, Index_Block > > >* queue;
1139 Status_Ref< Way_Skeleton >* skel;
1140 };
1142 struct Attic_Segment_Collector
1144 Attic_Segment_Collector(
1145 std::map< Uint31_Index, std::pair< std::map< Status_Ref< Way_Skeleton >*, Index_Block >,
1146 std::map< Status_Ref< Attic< Way_Skeleton > >*, Index_Block > > >& queue_,
1147 Status_Ref< Attic< Way_Skeleton > >& skel_)
1148186789 q : queue(&queue_), skel(&skel_) {}
1149 void push(Uint31_Index idx, const Segment& segment) const
115012102199 q { (*queue)[idx].second[skel].segments.push_back(segment); }
1152 private:
1153 std::map< Uint31_Index, std::pair< std::map< Status_Ref< Way_Skeleton >*, Index_Block >,
1154 std::map< Status_Ref< Attic< Way_Skeleton > >*, Index_Block > > >* queue;
1155 Status_Ref< Attic< Way_Skeleton > >* skel;
1156 };
1158 void refill()
11598462145 q {
116012160945 q while (cur_it != ways->end() || attic_it != attic_ways->end())
11616199535 q {
11626199535 q Uint31_Index idx = (cur_it != ways->end() && (attic_it == attic_ways->end() || cur_it->first < attic_it->first)
11636199535 q ? cur_it->first : attic_it->first);
11646199535 q if (cur_it != ways->end() && cur_it->first == idx)
11654666134 q {
11664666134 q std::vector< Status_Ref< Way_Skeleton > >& refs = current_refs[idx];
116727163634 q for (std::vector< Way_Skeleton >::const_iterator it = cur_it->second.begin(); it != cur_it->second.end(); ++it)
116822497530 q refs.push_back(Status_Ref< Way_Skeleton >(idx, *it));
116927163634 q for (std::vector< Status_Ref< Way_Skeleton > >::iterator it = refs.begin(); it != refs.end(); ++it)
117022497530 q make_entries(Current_Segment_Collector(queue, *it), cur_geom_store.get_geometry(*it->skel));
11714666134 q ++cur_it;
11724666134 q }
11736199535 q if (attic_it != attic_ways->end() && attic_it->first == idx)
11741533411 q {
11751533411 q std::vector< Status_Ref< Attic< Way_Skeleton > > >& refs = attic_refs[idx];
11761533411 q for (std::vector< Attic< Way_Skeleton > >::const_iterator it = attic_it->second.begin();
11773401211 q it != attic_it->second.end(); ++it)
1178186789 q refs.push_back(Status_Ref< Attic< Way_Skeleton > >(idx, *it));
11793401211 q for (std::vector< Status_Ref< Attic< Way_Skeleton > > >::iterator it = refs.begin(); it != refs.end(); ++it)
1180186789 q make_entries(Attic_Segment_Collector(queue, *it), attic_geom_store.get_geometry(*it->skel));
11811533411 q ++attic_it;
11821533411 q }
11846199535 q complete_idx = Uint31_Index(idx.val() & 0x7fffffff);
11856199535 q if (!queue.empty() && is_compound_idx(idx) && (queue.begin()->first.val() & 0x7fffffff) < complete_idx.val())
11862500729 q break;
11876199535 q }
11888462145 q }
1192#endif