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

overpass_api/data/tilewise_geometry.h

619 of 785 instrumented lines run by the suite (78.9%) 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)
388747263 q{
398747263 q return Point_Double(lat(arg.ll_upper, arg.ll_lower), lon(arg.ll_upper, arg.ll_lower));
408747263 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)
11876743068 q{
11976743068 q uint32 lat_lhs = ilat(lhs.ll_upper, lhs.ll_lower)>>16;
12076743068 q int32 lon_lhs = ilon(lhs.ll_upper, lhs.ll_lower)>>16;
12176743068 q uint32 lat_rhs = ilat(rhs.ll_upper, rhs.ll_lower)>>16;
12276743068 q int32 lon_rhs = ilon(rhs.ll_upper, rhs.ll_lower)>>16;
12476743068 q if (lat_lhs == lat_rhs && std::abs(lon_rhs - lon_lhs) <= 1)
12543969965 q return Uint31_Index(0u);
12632773167 q if (lon_lhs == lon_rhs && (lat_rhs - lat_lhs <= 1 || lat_lhs - lat_rhs <= 1))
12724485763 q return Uint31_Index(0u);
1298287465 q if ((lat_rhs - lat_lhs <= 1 || lat_lhs - lat_rhs <= 1) && std::abs(lon_rhs - lon_lhs) <= 1)
1303584361 q {
1313584361 q lat_lhs = ilat(lhs.ll_upper, lhs.ll_lower);
1323584361 q lon_lhs = ilon(lhs.ll_upper, lhs.ll_lower);
1333584361 q lat_rhs = ilat(rhs.ll_upper, rhs.ll_lower);
1343584361 q lon_rhs = ilon(rhs.ll_upper, rhs.ll_lower);
1353584361 q int32 lon_boundary = (std::max(lon_lhs, lon_rhs) & 0xffff0000);
1363584361 q uint32 lat_boundary = ((double)lat_rhs - lat_lhs)*(lon_boundary - lon_lhs)/(lon_rhs - lon_lhs) + lat_lhs;
1383584361 q int32 missing_lon = lon_lhs;
1393584361 q if (lat_lhs < lat_rhs)
1401779260 q missing_lon = (lat_boundary < (lat_rhs & 0xffff0000) ? lon_rhs : lon_lhs);
1411805159 q else
1421805159 q missing_lon = (lat_boundary < (lat_lhs & 0xffff0000) ? lon_lhs : lon_rhs);
1433584361 q return Uint31_Index(ll_upper_(lat_boundary, missing_lon));
1443584361 q }
1454703163 q return Uint31_Index(0xffu);
1468287465 q}
149struct Segment
151 Segment(uint32 lat_lhs, int32 lon_lhs, uint32 lat_rhs, int32 lon_rhs)
152134210863 q {
153134210863 q populate(lat_lhs, lon_lhs, lat_rhs, lon_rhs);
154134210863 q }
156 Segment(const Quad_Coord& lhs, const Quad_Coord& rhs)
1571091561570 q {
1581091561570 q populate(
1591091561570 q ilat(lhs.ll_upper, lhs.ll_lower), ilon(lhs.ll_upper, lhs.ll_lower),
1601091561570 q ilat(rhs.ll_upper, rhs.ll_lower), ilon(rhs.ll_upper, rhs.ll_lower));
1611091561570 q }
163 void populate(uint32 ilat_lhs, int32 ilon_lhs, uint32 ilat_rhs, int32 ilon_rhs)
1641225772370 q {
1651225772370 q if (ilon_lhs < ilon_rhs)
166604493170 q {
167604493170 q ilat_west = ilat_lhs;
168604493170 q ilon_west = ilon_lhs;
169604493170 q ilat_east = ilat_rhs;
170604493170 q ilon_east = ilon_rhs;
171604493170 q }
172621279270 q else
173621279270 q {
174621279270 q ilat_west = ilat_rhs;
175621279270 q ilon_west = ilon_rhs;
176621279270 q ilat_east = ilat_lhs;
177621279270 q ilon_east = ilon_lhs;
178621279270 q }
1791225772370 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)
19095890270 q{
19195890270 q if (geom.empty())
192917 q return;
1941116521570 q for (uint i = 1; i < geom.size(); ++i)
1951020640470 q {
1961020640470 q if (geom[i].ll_upper == geom[i-1].ll_upper)
197943897470 q collector.push(geom[i].ll_upper, Segment(geom[i-1], geom[i]));
19876743068 q else
19976743068 q {
20076743068 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';
20476743068 q if (extra_idx.val() == 0xff)
2054703163 q calculate_auxiliary_points(collector, geom[i-1], geom[i]);
20672039965 q else
20772039965 q {
20872039965 q collector.push(geom[i-1].ll_upper, Segment(geom[i-1], geom[i]));
20972039965 q collector.push(geom[i].ll_upper, Segment(geom[i-1], geom[i]));
21072039965 q if (!(extra_idx.val() == 0))
2113584361 q collector.push(extra_idx, Segment(geom[i-1], geom[i]));
21272039965 q }
21376743068 q }
2141020640470 q }
21595881170 q}
218template< typename Segment_Collector >
219void calculate_auxiliary_points(const Segment_Collector& collector, Quad_Coord lhs, Quad_Coord rhs)
2204703163 q{
2214703163 q uint32 lat_lhs = ilat(lhs.ll_upper, lhs.ll_lower);
2224703163 q int32 lon_lhs = ilon(lhs.ll_upper, lhs.ll_lower);
2234703163 q uint32 lat_rhs = ilat(rhs.ll_upper, rhs.ll_lower);
2244703163 q int32 lon_rhs = ilon(rhs.ll_upper, rhs.ll_lower);
2264703163 q if ((lon_lhs & 0xffff0000) == (lon_rhs & 0xffff0000))
227329558 q calculate_south_north_sequence(collector, lat_lhs, lon_lhs, lat_rhs, lon_rhs);
2284373663 q else
2294373663 q {
2304373663 q Great_Circle gc(make_point_double(lhs), make_point_double(rhs));
2314373663 q Quad_Coord min = lon_lhs < lon_rhs ? lhs : rhs;
2324373663 q Quad_Coord max = lon_lhs < lon_rhs ? rhs : lhs;
2334373663 q int32 i_ilon = ilon(min.ll_upper, min.ll_lower);
2344373663 q int32 ilon_max = ilon(max.ll_upper, max.ll_lower);
2354373663 q if ((int64)ilon_max - i_ilon < 1800000000)
2364373563 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';
2394373563 q uint32 i_ilat = ilat(gc.lat_of(lon((i_ilon & 0xffff0000) + 0x10000)));
2404373563 q calculate_south_north_sequence(
2414373563 q collector, ilat(min.ll_upper, min.ll_lower), i_ilon,
2424373563 q i_ilat, (i_ilon & 0xffff0000) + 0x10000);
24355532463 q for (i_ilon = (i_ilon & 0xffff0000) + 0x10000; i_ilon + 0x10000 < ilon_max;
24451158963 q i_ilon += 0x10000)
24551158963 q {
24651158963 q uint32 last_ilat = i_ilat;
24751158963 q i_ilat = ilat(gc.lat_of(lon(i_ilon + 0x10000)));
24851158963 q calculate_south_north_sequence(
24951158963 q collector, last_ilat, i_ilon, i_ilat, i_ilon + 0x10000);
25051158963 q }
2524373563 q calculate_south_north_sequence(
2534373563 q collector, i_ilat, i_ilon, ilat(max.ll_upper, max.ll_lower), ilon_max);
2544373563 q }
25511 q 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 }
27211 q else
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';
27611 q 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);
27911 q else
28111 q uint32 i_ilat = ilat(gc.lat_of(-180.));
28211 q int32 ilon_max = i_ilon;
28311 q i_ilon = -1800000000;
28411 q calculate_south_north_sequence(
28511 q collector, ilat(min.ll_upper, min.ll_lower), i_ilon,
28611 q i_ilat, (i_ilon & 0xffff0000) + 0x10000);
28788691 q for (i_ilon = (i_ilon & 0xffff0000) + 0x10000; i_ilon + 0x10000 < ilon_max;
28888681 q i_ilon += 0x10000)
28988681 q {
29088681 q uint32 last_ilat = i_ilat;
29188681 q i_ilat = ilat(gc.lat_of(lon(i_ilon + 0x10000)));
29288681 q calculate_south_north_sequence(
29388681 q collector, last_ilat, i_ilon, i_ilat, i_ilon + 0x10000);
29488681 q }
29611 q calculate_south_north_sequence(
29711 q collector, i_ilat, i_ilon, ilat(min.ll_upper, min.ll_lower), ilon_max);
30011 q 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 }
30711 q else
30911 q i_ilon = ilon_max;
31011 q uint32 i_ilat = ilat(gc.lat_of(lon((i_ilon & 0xffff0000) + 0x10000)));
31111 q calculate_south_north_sequence(
31211 q collector, ilat(max.ll_upper, max.ll_lower), i_ilon,
31311 q i_ilat, (i_ilon & 0xffff0000) + 0x10000);
314115651 q for (i_ilon = (i_ilon & 0xffff0000) + 0x10000; i_ilon + 0x10000 < 1800000000;
315115641 q i_ilon += 0x10000)
316115641 q {
317115641 q uint32 last_ilat = i_ilat;
318115641 q i_ilat = ilat(gc.lat_of(lon(i_ilon + 0x10000)));
319115641 q calculate_south_north_sequence(
320115641 q collector, last_ilat, i_ilon, i_ilat, i_ilon + 0x10000);
321115641 q }
32311 q uint32 anti_lat = ilat(gc.lat_of(180.));
32411 q calculate_south_north_sequence(
32511 q collector, i_ilat, i_ilon, anti_lat, 1800000000);
32611 q collector.push(Uint31_Index(ll_upper_(anti_lat, 1800000000)), Segment(anti_lat, 1800000000, anti_lat, 1800000001));
3294373663 q }
3304703163 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)
33662279063 q{
337// std::cout<<"sn "<<lat_lhs<<' '<<lon_lhs<<' '<<lat_rhs<<' '<<lon_rhs<<'\n';
33862279063 q if ((lat_lhs & 0xffff0000) == (lat_rhs & 0xffff0000))
33927950663 q {
34027950663 q collector.push(Uint31_Index(ll_upper_(lat_lhs, lon_lhs)), Segment(lat_lhs, lon_lhs, lat_rhs, lon_rhs));
34127950663 q return;
34227950663 q }
34434328463 q if (lat_rhs < lat_lhs)
34528016962 q {
34628016962 q std::swap(lat_lhs, lat_rhs);
34728016962 q std::swap(lon_lhs, lon_rhs);
34828016962 q }
34934328463 q int32 min_lon = std::min(lon_lhs, lon_rhs);
35134328463 q uint32 i_lat = (lat_lhs & 0xffff0000) + 0x10000;
35234328463 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';
35534328463 q collector.push(Uint31_Index(ll_upper_(lat_lhs, min_lon)), Segment(lat_lhs, lon_lhs, i_lat, i_lon));
35771931763 q while (i_lat + 0x10000 < lat_rhs)
35837603362 q {
35937603362 q uint32 last_ilat = i_lat;
36037603362 q int32 last_ilon = i_lon;
36137603362 q i_lat += 0x10000;
36237603362 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';
36537603362 q collector.push(Uint31_Index(ll_upper_(last_ilat, min_lon)), Segment(last_ilat, last_ilon, i_lat, i_lon));
36637603362 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';
37034328463 q collector.push(Uint31_Index(ll_upper_(i_lat, min_lon)), Segment(i_lat, i_lon, lat_rhs, lon_rhs));
37134328463 q}
374// fwd iterator only
375class Tilewise_Area_Iterator
377public:
378 enum Relative_Position { outside, inside, border };
380 struct Index_Block
381 {
382576677058 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_)
39127617644 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
3983062265144 q {
3993062265144 q return !(idx == rhs.idx) ? idx < rhs.idx
4003062265144 q : way < rhs.way;
4013062265144 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)
4105148 q : ways(&ways_), attic_ways(&attic_ways_), cur_it(ways->begin()), attic_it(attic_ways->begin()),
4115148 q cur_geom_store(*ways, stmt, rman), attic_geom_store(*attic_ways, stmt, rman),
4125148 q complete_idx(0u), minlat(0u), maxlat(0x7fff0000)
4145148 q refill();
417 void next()
41846082141 q {
41946082141 q propagate_inside_flag();
42046082141 q queue.erase(queue.begin());
42146082141 q if (queue.empty() || !(queue.begin()->first.val() < complete_idx.val()))
422238141 q refill();
42346082141 q }
42446424741 q bool is_end() const { return queue.empty(); }
42610860441 q const std::map< Full_Way_Ref, Index_Block >& get_obj() const { return queue.begin()->second; }
42797125541 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_)
4405148 q minlat = minlat_;
4415148 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_)
46227617644 q : queue(&queue_), skel(skel_) {}
463 void push(Uint31_Index idx, const Segment& segment) const
464509546944 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()
472243248 q {
473396648 q while (cur_it != ways->end() || attic_it != attic_ways->end())
474388445 q {
475388445 q Uint31_Index idx = (cur_it != ways->end() && (attic_it == attic_ways->end() || cur_it->first < attic_it->first)
476388445 q ? cur_it->first : attic_it->first);
477388445 q if (cur_it != ways->end() && cur_it->first == idx)
478388445 q {
47927898545 q for (std::vector< Way_Skeleton >::iterator it = cur_it->second.begin(); it != cur_it->second.end(); ++it)
48027510140 q {
48127510140 q if (!it->nds.empty() && it->nds.front() == it->nds.back())
48227510140 q make_entries(Segment_Collector(queue, Full_Way_Ref(idx, &*it, NOW)), cur_geom_store.get_geometry(*it));
48327510140 q }
484388445 q ++cur_it;
485388445 q }
486388445 q if (attic_it != attic_ways->end() && attic_it->first == idx)
48720812 q {
48820812 q for (std::vector< Attic< Way_Skeleton > >::iterator it = attic_it->second.begin();
489128312 q it != attic_it->second.end(); ++it)
490107511 q {
491107511 q if (!it->nds.empty() && it->nds.front() == it->nds.back())
492107511 q make_entries(Segment_Collector(queue, Full_Way_Ref(idx, &*it, it->timestamp)), attic_geom_store.get_geometry(*it));
493107511 q }
49420812 q ++attic_it;
49520812 q }
497388445 q complete_idx = Uint31_Index(idx.val() & 0x7fffffff);
498388445 q if (!queue.empty() && is_compound_idx(idx) && (queue.begin()->first.val() & 0x7fffffff) < complete_idx.val())
499235041 q break;
500388445 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';
506243248 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_)
52048929 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
52739413429 q {
52839413429 q return !(idx == rhs.idx) ? idx < rhs.idx
52939413429 q : way < rhs.way;
53039413429 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)
53926051 q : ways(&ways_), attic_ways(&attic_ways_), cur_it(ways->begin()), attic_it(attic_ways->begin()),
54026051 q cur_geom_store(*ways, stmt, rman), attic_geom_store(*attic_ways, stmt, rman),
54126051 q complete_idx(0u)
54226051 q {
54326051 q refill();
54426051 q }
546 void next()
547438025426 q {
548438025426 q propagate_inside_flag();
549438025426 q queue.erase(queue.begin());
550438025426 q if (queue.empty() || !(queue.begin()->first.val() < complete_idx.val()))
551104237226 q refill();
552438025426 q }
553473764244 q bool is_end() const { return queue.empty(); }
555517960526 q const std::map< Full_Way_Ref, Tilewise_Area_Iterator::Index_Block >& get_obj() const { return queue.begin()->second; }
556976067528 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)
55929426511 q {
56029426511 q return rel_pos_ilat_ilon(ilat(ll_upper, ll_lower), ilon(ll_upper, ll_lower), accept_border);
56129426511 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_)
58548929 q : queue(&queue_), skel(skel_) {}
586 void push(Uint31_Index idx, const Segment& segment) const
58726607029 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()
595104263251 q {
596104992351 q while (cur_it != ways->end() || attic_it != attic_ways->end())
597746229 q {
598746229 q Uint31_Index idx = (cur_it != ways->end() && (attic_it == attic_ways->end() || cur_it->first < attic_it->first)
599746229 q ? cur_it->first : attic_it->first);
600746229 q if (cur_it != ways->end() && cur_it->first == idx)
601741227 q {
6022606227 q for (std::vector< Way_Skeleton >::const_iterator it = cur_it->second.begin(); it != cur_it->second.end(); ++it)
6031865027 q {
6041865027 q if (!it->nds.empty() && it->nds.front() == it->nds.back())
60542427 q make_entries(Segment_Collector(queue, Full_Way_Ref(idx, &*it, NOW)), cur_geom_store.get_geometry(*it));
6061865027 q }
607741227 q ++cur_it;
608741227 q }
609746229 q if (attic_it != attic_ways->end() && attic_it->first == idx)
610505 q {
611505 q for (std::vector< Attic< Way_Skeleton > >::const_iterator it = attic_it->second.begin();
6121155 q it != attic_it->second.end(); ++it)
613655 q {
614655 q if (!it->nds.empty() && it->nds.front() == it->nds.back())
615655 q make_entries(Segment_Collector(queue, Full_Way_Ref(idx, &*it, it->timestamp)), attic_geom_store.get_geometry(*it));
616655 q }
617505 q ++attic_it;
618505 q }
620746229 q complete_idx = Uint31_Index(idx.val() & 0x7fffffff);
621746229 q if (!queue.empty() && is_compound_idx(idx) && (queue.begin()->first.val() & 0x7fffffff) < complete_idx.val())
62217117 q break;
623746229 q }
624104263251 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)
632486371055 q{
633486371055 q bool is_inside = block.sw_is_inside;
635802957755 q for (std::vector< Segment >::const_iterator it = block.segments.begin(); it != block.segments.end(); ++it)
636316586755 q {
637316586755 q if ((it->ilat_west <= south) ^ (it->ilat_east <= south))
6389037446 q {
6399037446 q double isect_lon = it->ilon_west +
6409037446 q ((double)south - it->ilat_west)
6419037446 q *(it->ilon_east - it->ilon_west)/((int32)it->ilat_east - (int32)it->ilat_west);
6429037446 q if (west <= isect_lon && isect_lon < west + 0x10000)
6438760546 q is_inside = !is_inside;
6449037446 q }
645316586755 q }
647486371055 q return is_inside;
648486371055 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)
667671377152 q{
668671377152 q bool is_inside = block.sw_is_inside;
6706448880452 q for (std::vector< Segment >::const_iterator it = block.segments.begin(); it != block.segments.end(); ++it)
6715778404452 q {
6725778404452 q if (it->ilat_west > south && it->ilat_east > south)
6735718271352 q {
674 // northern segment not touching the southern boundary
6755718271352 q if (it->ilon_west == lon_p)
676550324 q {
677550324 q if (it->ilat_west == lat_p)
678440422 q return Tilewise_Area_Iterator::border;
679109919 q if (it->ilon_west == it->ilon_east)
68183 q if (std::min(it->ilat_west, it->ilat_east) <= lat_p && lat_p <= std::max(it->ilat_west, it->ilat_east))
68211 q return Tilewise_Area_Iterator::border;
684109118 q else
685109118 q is_inside ^= (it->ilat_west < lat_p);
686109919 q }
6875717721052 q else if (it->ilon_east == lon_p)
688499528 q {
689499528 q if (it->ilat_east == lat_p)
690391326 q return Tilewise_Area_Iterator::border;
691499528 q }
6925717221552 q else if (it->ilon_west < lon_p && lon_p < it->ilon_east)
693100922051 q {
694100922051 q double isect_lat = it->ilat_west +
695100922051 q ((double)lon_p - it->ilon_west)
696100922051 q *((int32)it->ilat_east - (int32)it->ilat_west)/(it->ilon_east - it->ilon_west);
697100922051 q if (isect_lat - .5 < lat_p)
69848395448 q {
69948395448 q if (lat_p < isect_lat + .5)
70056914 q return Tilewise_Area_Iterator::border;
70148338548 q is_inside = !is_inside;
70248338548 q }
703100922051 q }
7045718271352 q }
70560133142 q else if ((it->ilat_west <= south) ^ (it->ilat_east <= south))
70660102942 q {
70760102942 q double isect_lon = it->ilon_west +
70860102942 q ((double)south - it->ilat_west)
70960102942 q *(it->ilon_east - it->ilon_west)/((int32)it->ilat_east - (int32)it->ilat_west);
71060102942 q if (west <= isect_lon && isect_lon < west + 0x10000)
71158075242 q {
71258075242 q if (it->ilat_west <= south)
71329886142 q {
71429886142 q if (it->ilon_east <= lon_p)
71514240834 q {
71614240834 q if (it->ilon_east == lon_p)
717438 q {
718438 q if (it->ilat_east == lat_p)
719327 q return Tilewise_Area_Iterator::border;
720113 q if (it->ilon_west == it->ilon_east && lat_p <= it->ilat_east)
7210 return Tilewise_Area_Iterator::border;
722113 q }
72314237634 q is_inside = !is_inside;
72414237634 q }
72515645335 q else if (isect_lon < lon_p)
726676219 q {
727676219 q double isect_lat = it->ilat_west +
728676219 q ((double)lon_p - it->ilon_west)
729676219 q *((int32)it->ilat_east - (int32)it->ilat_west)/(it->ilon_east - it->ilon_west);
730676219 q if (lat_p < isect_lat + .5)
7311867 q {
7321867 q if (isect_lat - .5 < lat_p)
73322 q return Tilewise_Area_Iterator::border;
7341846 q is_inside = !is_inside;
7351846 q }
736676219 q }
73729886142 q }
73828189136 q else
73928189136 q {
74028189136 q if (isect_lon <= lon_p)
74115476833 q {
74215476833 q if (isect_lon == lon_p)
743281 q {
744281 q if (lat_p == south)
745281 q return Tilewise_Area_Iterator::border;
7460 if (isect_lon == it->ilon_west && lat_p <= it->ilat_west)
7470 return Tilewise_Area_Iterator::border;
7480 }
74915474033 q is_inside = !is_inside;
75015474033 q }
75112712331 q else if (it->ilon_west <= lon_p)
752536119 q {
753536119 q double isect_lat = it->ilat_west +
754536119 q ((double)lon_p - it->ilon_west)
755536119 q *((int32)it->ilat_east - (int32)it->ilat_west)/(it->ilon_east - it->ilon_west);
756536119 q if (isect_lat - .5 < lat_p)
757518719 q {
758518719 q if (lat_p < isect_lat + .5)
759597 q return Tilewise_Area_Iterator::border;
760512819 q is_inside = !is_inside;
761512819 q }
762536119 q }
76328189136 q }
76458075242 q }
7652027717 q else
7662027717 q {
767 // northern segment similar to above
7682027717 q if (it->ilon_west == lon_p)
77011 q if (it->ilat_west == lat_p)
77111 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 }
7752027617 q else if (it->ilon_east == lon_p)
7760 {
7770 if (it->ilat_east == lat_p)
7780 return Tilewise_Area_Iterator::border;
7790 }
7802027617 q else if (it->ilon_west < lon_p && lon_p < it->ilon_east)
781190010 q {
782190010 q double isect_lat = it->ilat_west +
783190010 q ((double)lon_p - it->ilon_west)
784190010 q *((int32)it->ilat_east - (int32)it->ilat_west)/(it->ilon_east - it->ilon_west);
785190010 q if (isect_lat - .5 < lat_p)
786173310 q {
787173310 q if (lat_p < isect_lat + .5)
78822 q return Tilewise_Area_Iterator::border;
789173110 q is_inside = !is_inside;
790173110 q }
791190010 q }
7922027717 q }
79360102942 q }
7943024 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';
8075778404452 q }
809670476052 q return is_inside ? Tilewise_Area_Iterator::inside : Tilewise_Area_Iterator::outside;
810671377152 q}
813inline Tilewise_Area_Iterator::Relative_Position rel_position(
814 Uint31_Index idx, const Segment& segment, const Tilewise_Area_Iterator::Index_Block& block)
81517870613 q{
81617870613 q std::vector< std::pair< uint32, int32 > > touching_coords;
818319779313 q for (std::vector< Segment >::const_iterator ait = block.segments.begin(); ait != block.segments.end(); ++ait)
819301911313 q {
820301911313 q if (ait->ilon_west <= segment.ilon_east && segment.ilon_west <= ait->ilon_east)
82115246313 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
82415246313 q double scal_ait_west = ((double)ait->ilat_west - segment.ilat_west)*(segment.ilon_east - segment.ilon_west)
82515246313 q - (ait->ilon_west - segment.ilon_west)*((double)segment.ilat_east - segment.ilat_west);
82615246313 q double scal_ait_east = ((double)ait->ilat_east - segment.ilat_west)*(segment.ilon_east - segment.ilon_west)
82715246313 q - (ait->ilon_east - segment.ilon_west)*((double)segment.ilat_east - segment.ilat_west);
82815246313 q if (scal_ait_east * scal_ait_west > 0)
82913882513 q continue;
8311363811 q double scal_it_west = ((double)segment.ilat_west - ait->ilat_west)*(ait->ilon_east - ait->ilon_west)
8321363811 q - (segment.ilon_west - ait->ilon_west)*((double)ait->ilat_east - ait->ilat_west);
8331363811 q double scal_it_east = ((double)segment.ilat_east - ait->ilat_west)*(ait->ilon_east - ait->ilon_west)
8341363811 q - (segment.ilon_east - ait->ilon_west)*((double)ait->ilat_east - ait->ilat_west);
8351363811 q if (scal_it_east * scal_it_west > 0)
83693179 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';
845432110 q if (scal_ait_west == 0)
84627349 q {
84727349 q touching_coords.push_back(std::make_pair(ait->ilat_west, ait->ilon_west));
84827349 q if (scal_ait_east == 0)
84911769 q touching_coords.push_back(std::make_pair(ait->ilat_east, ait->ilon_east));
85027349 q }
851158710 q else if (scal_ait_east == 0)
85215619 q touching_coords.push_back(std::make_pair(ait->ilat_east, ait->ilon_east));
853265 q else if (scal_it_west == 0)
8540 touching_coords.push_back(std::make_pair(segment.ilat_west, segment.ilon_west));
855265 q else if (scal_it_east != 0)
856265 q return Tilewise_Area_Iterator::inside;
857432110 q }
858301911313 q }
86017868013 q if (!touching_coords.empty())
86116989 q {
86216989 q touching_coords.push_back(std::make_pair(segment.ilat_west, segment.ilon_west));
86316989 q touching_coords.push_back(std::make_pair(segment.ilat_east, segment.ilon_east));
86416989 q std::sort(touching_coords.begin(), touching_coords.end());
86516989 q touching_coords.erase(std::unique(touching_coords.begin(), touching_coords.end()), touching_coords.end());
86616989 q uint32 south = ilat(idx.val(), 0u);
86716989 q int32 west = ilon(idx.val(), 0u);
86931649 q for (std::vector< std::pair< uint32, int32 > >::size_type i = 1; i < touching_coords.size(); ++i)
87016989 q {
87116989 q Tilewise_Area_Iterator::Relative_Position status = ::rel_pos_ilat_ilon(
87216989 q ((uint64)touching_coords[i-1].first + touching_coords[i].first)/2,
87316989 q ((int64)touching_coords[i-1].second + touching_coords[i].second)/2, block, south, west);
87416989 q if (status == Tilewise_Area_Iterator::inside)
8752329 q return Tilewise_Area_Iterator::inside;
87616989 q }
87716989 q }
87917844813 q return Tilewise_Area_Iterator::outside;
88017868013 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)
9113946714 q{
91220839514 q for (std::vector< Segment >::const_iterator it = segments.begin(); it != segments.end(); ++it)
91317750814 q {
91417750814 q Tilewise_Area_Iterator::Relative_Position status = rel_pos_ilat_ilon(it->ilat_west, it->ilon_west, false);
91517750814 q if (status == Tilewise_Area_Iterator::inside)
91679349 q return status;
91716957413 q status = rel_pos_ilat_ilon(it->ilat_east, it->ilon_east, false);
91816957413 q if (status == Tilewise_Area_Iterator::inside)
9193886 q return status;
92116918613 q const std::map< Full_Way_Ref, Tilewise_Area_Iterator::Index_Block >& way_blocks = get_obj();
92216918613 q for (std::map< Full_Way_Ref, Tilewise_Area_Iterator::Index_Block >::const_iterator bit = way_blocks.begin();
92334763413 q bit != way_blocks.end(); ++bit)
92417870613 q {
92517870613 q const Tilewise_Area_Iterator::Index_Block& block = bit->second;
92617870613 q Tilewise_Area_Iterator::Relative_Position result = ::rel_position(get_idx(), *it, block);
92717870613 q if (result != Tilewise_Area_Iterator::outside)
92825810 q return result;
92917870613 q }
93016918613 q }
9313088712 q return Tilewise_Area_Iterator::outside;
9323946714 q}
935inline void Tilewise_Area_Iterator::propagate_inside_flag()
93646082141 q{
93746082141 q Uint31_Index idx = get_idx();
93846082141 q uint32 south = ilat(idx.val(), 0u);
93946082141 q int32 west = ilon(idx.val(), 0u);
94046082141 q if (maxlat < south)
9413075339 q return;
94243006841 q if (south < minlat && west >= -1800000000)
94336253139 q return;
9456753741 q const std::map< Full_Way_Ref, Index_Block >& way_blocks = get_obj();
9476753741 q for (std::map< Full_Way_Ref, Index_Block >::const_iterator bit = way_blocks.begin();
94848104241 q bit != way_blocks.end(); ++bit)
94941350541 q {
95041350541 q const Index_Block& block = bit->second;
95141350541 q if (eastern_sw_is_inside(block, south, west))
9526836438 q queue[Uint31_Index(ll_upper_(ilat(idx.val(), 0u), ilon(idx.val(), 0u)+0x10000))][bit->first].sw_is_inside = true;
95341350541 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;
95541350541 q }
9566753741 q}
959inline void Tilewise_Const_Area_Iterator::propagate_inside_flag()
960438025426 q{
961438025426 q Uint31_Index idx = get_idx();
962438025426 q uint32 south = ilat(idx.val(), 0u);
963438025426 q int32 west = ilon(idx.val(), 0u);
964438025426 q const std::map< Full_Way_Ref, Tilewise_Area_Iterator::Index_Block >& way_blocks = get_obj();
966438025426 q for (std::map< Full_Way_Ref, Tilewise_Area_Iterator::Index_Block >::const_iterator bit = way_blocks.begin();
967883045926 q bit != way_blocks.end(); ++bit)
968445020526 q {
969445020526 q const Tilewise_Area_Iterator::Index_Block& block = bit->second;
970445020526 q if (eastern_sw_is_inside(block, south, west))
971442801816 q queue[Uint31_Index(ll_upper_(ilat(idx.val(), 0u), ilon(idx.val(), 0u)+0x10000))][bit->first].sw_is_inside = true;
972445020526 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;
974445020526 q }
975438025426 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)
100464134720 q{
100564134720 q Uint31_Index idx = get_idx();
100664134720 q uint32 south = ilat(idx.val(), 0u);
100764134720 q int32 west = ilon(idx.val(), 0u);
100864134720 q if (lat_p < south || lat_p - south > 65535 || lon_p < west || lon_p - west > 65535)
10091118212 q return Tilewise_Area_Iterator::outside;
101063016520 q const std::map< Full_Way_Ref, Tilewise_Area_Iterator::Index_Block >& way_blocks = get_obj();
101263016520 q for (std::map< Full_Way_Ref, Tilewise_Area_Iterator::Index_Block >::const_iterator bit = way_blocks.begin();
1013126128220 q bit != way_blocks.end(); ++bit)
101465377420 q {
101565377420 q Tilewise_Area_Iterator::Relative_Position status = ::rel_pos_ilat_ilon(lat_p, lon_p, bit->second, south, west);
101665377420 q if (status == Tilewise_Area_Iterator::inside)
10171879214 q return Tilewise_Area_Iterator::inside;
101863498217 q else if (status == Tilewise_Area_Iterator::border && accept_border)
101938655 q return Tilewise_Area_Iterator::border;
102065377420 q }
102260750817 q return Tilewise_Area_Iterator::outside;
102363016520 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)
10304106740 q{
10314106740 q Uint31_Index idx = get_idx();
10324106740 q uint32 south = ilat(idx.val(), 0u);
10334106740 q int32 west = ilon(idx.val(), 0u);
10344106740 q const std::map< Full_Way_Ref, Index_Block >& way_blocks = get_obj();
10364106740 q uint32 lat_p = ilat(ll_upper, ll_lower);
10374106740 q int32 lon_p = ilon(ll_upper, ll_lower);
10394106740 q for (std::map< Full_Way_Ref, Index_Block >::const_iterator bit = way_blocks.begin();
1040672309140 q bit != way_blocks.end(); ++bit)
1041668202440 q {
1042// std::cout<<"DEBUG move_covering_ways "<<std::hex<<idx.val()<<' '<<std::dec<<bit->first.way->id.val()<<'\n';
1043668202440 q if (bit->first.way->id.val() == 0u)
104462372512 q continue;
1046605829940 q Relative_Position status = ::rel_pos_ilat_ilon(lat_p, lon_p, bit->second, south, west);
1047605829940 q if (status != outside)
1048347837 q {
1049347837 q if (bit->first.timestamp != NOW)
1051146 q target_attic_ways[bit->first.idx].push_back(Attic< Way_Skeleton >(*bit->first.way, bit->first.timestamp));
1052146 q bit->first.way->id = Way_Skeleton::Id_Type(0u);
1054346435 q else
1055346435 q {
1056346435 q target_ways[bit->first.idx].push_back(*bit->first.way);
1057346435 q bit->first.way->id = Way_Skeleton::Id_Type(0u);
1058346435 q }
1059347837 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';
1062605829940 q }
10634106740 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
107868223732 q Status_Ref(Uint31_Index idx_, const Way_Skeleton& skel_) : idx(idx_), skel(&skel_),
107968223732 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)
109213351 q : ways(&ways_), attic_ways(&attic_ways_), cur_it(ways->begin()), attic_it(attic_ways->begin()),
109313351 q cur_geom_store(*ways, stmt, rman), attic_geom_store(*attic_ways, stmt, rman),
109413351 q complete_idx(0u)
109613351 q refill();
1099 void next()
110016018832 q {
110116018832 q queue.erase(queue.begin());
110216018832 q if (queue.empty() || !(queue.begin()->first.val() < complete_idx.val()))
11033805032 q refill();
110416018832 q }
110516032151 q bool is_end() const { return queue.empty(); }
1107 const std::map< Status_Ref< Way_Skeleton >*, Index_Block >& get_current_obj() const
1108245013 q { return queue.begin()->second.first; }
1109 const std::map< Status_Ref< Attic< Way_Skeleton > >*, Index_Block >& get_attic_obj() const
1110302 q { return queue.begin()->second.second; }
111190654619 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_)
113263783730 q : queue(&queue_), skel(&skel_) {}
1133 void push(Uint31_Index idx, const Segment& segment) const
1134651418030 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_)
1148444006 q : queue(&queue_), skel(&skel_) {}
1149 void push(Uint31_Index idx, const Segment& segment) const
11503820046 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()
11593818351 q {
11607417451 q while (cur_it != ways->end() || attic_it != attic_ways->end())
11615023135 q {
11625023135 q Uint31_Index idx = (cur_it != ways->end() && (attic_it == attic_ways->end() || cur_it->first < attic_it->first)
11635023135 q ? cur_it->first : attic_it->first);
11645023135 q if (cur_it != ways->end() && cur_it->first == idx)
11654157535 q {
11664157535 q std::vector< Status_Ref< Way_Skeleton > >& refs = current_refs[idx];
116767941235 q for (std::vector< Way_Skeleton >::const_iterator it = cur_it->second.begin(); it != cur_it->second.end(); ++it)
116863783730 q refs.push_back(Status_Ref< Way_Skeleton >(idx, *it));
116967941235 q for (std::vector< Status_Ref< Way_Skeleton > >::iterator it = refs.begin(); it != refs.end(); ++it)
117063783730 q make_entries(Current_Segment_Collector(queue, *it), cur_geom_store.get_geometry(*it->skel));
11714157535 q ++cur_it;
11724157535 q }
11735023135 q if (attic_it != attic_ways->end() && attic_it->first == idx)
117486569 q {
117586569 q std::vector< Status_Ref< Attic< Way_Skeleton > > >& refs = attic_refs[idx];
117686569 q for (std::vector< Attic< Way_Skeleton > >::const_iterator it = attic_it->second.begin();
1177530569 q it != attic_it->second.end(); ++it)
1178444006 q refs.push_back(Status_Ref< Attic< Way_Skeleton > >(idx, *it));
1179530569 q for (std::vector< Status_Ref< Attic< Way_Skeleton > > >::iterator it = refs.begin(); it != refs.end(); ++it)
1180444006 q make_entries(Attic_Segment_Collector(queue, *it), attic_geom_store.get_geometry(*it->skel));
118186569 q ++attic_it;
118286569 q }
11845023135 q complete_idx = Uint31_Index(idx.val() & 0x7fffffff);
11855023135 q if (!queue.empty() && is_compound_idx(idx) && (queue.begin()->first.val() & 0x7fffffff) < complete_idx.val())
11861424030 q break;
11875023135 q }
11883818351 q }
1192#endif