Overpass API regression suite coverage (Saxony) / overpass_api/data/way_geometry_store.cc

overpass_api/data/way_geometry_store.cc

138 of 143 instrumented lines run by the suite (96.5%) 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#include "../data/collect_members.h"
20#include "../data/way_geometry_store.h"
22#include <map>
25template< typename Object >
26Ranges< Uint32_Index > small_way_nd_indices
27 (const Statement* stmt, Resource_Manager& rman,
28 typename std::map< Uint31_Index, std::vector< Object > >::const_iterator ways_begin,
29 typename std::map< Uint31_Index, std::vector< Object > >::const_iterator ways_end)
305934466 q{
315934466 q std::vector< uint32 > parents;
335934466 q for (typename std::map< Uint31_Index, std::vector< Object > >::const_iterator
34297083466 q it(ways_begin); it != ways_end; ++it)
35291149346 q {
36291149346 q if (!(it->first.val() & 0x80000000) || ((it->first.val() & 0x1) != 0)) // Adapt 0x3
37270110334 q parents.push_back(it->first.val());
38291149346 q }
395934466 q sort(parents.begin(), parents.end());
405934466 q parents.erase(unique(parents.begin(), parents.end()), parents.end());
425934466 q if (stmt)
435934466 q rman.health_check(*stmt);
455934466 q return calc_node_children_ranges(parents);
465934466 q}
49template< typename Object >
50std::vector< Node::Id_Type > small_way_nd_ids(const std::map< Uint31_Index, std::vector< Object > >& ways)
515934466 q{
525934466 q std::vector< Node::Id_Type > ids;
535934466 q for (typename std::map< Uint31_Index, std::vector< Object > >::const_iterator
54297083466 q it(ways.begin()); it != ways.end(); ++it)
55291149346 q {
56291149346 q if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x1) == 0))
5721039286 q continue;
58270110334 q for (typename std::vector< Object >::const_iterator it2(it->second.begin());
595298120334 q it2 != it->second.end(); ++it2)
605028010328 q {
615028010328 q for (std::vector< Node::Id_Type >::const_iterator it3(it2->nds.begin());
6246394749328 q it3 != it2->nds.end(); ++it3)
6341366739328 q ids.push_back(*it3);
645028010328 q }
65270110334 q }
675934466 q sort(ids.begin(), ids.end());
685934466 q ids.erase(unique(ids.begin(), ids.end()), ids.end());
705934466 q return ids;
715934466 q}
74std::map< Uint32_Index, std::vector< Node_Skeleton > > small_way_members
75 (const Statement* stmt, Resource_Manager& rman,
76 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways)
773898466 q{
783898466 q Request_Context context(stmt, rman);
793898466 q return collect_items_range< Uint32_Index, Node_Skeleton >(context,
803898466 q small_way_nd_indices< Way_Skeleton >(stmt, rman, ways.begin(), ways.end()),
813898466 q Id_Predicate< Node_Skeleton >(small_way_nd_ids(ways))).current;
823898466 q}
85Way_Geometry_Store::Way_Geometry_Store
86 (const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways, const Statement& query, Resource_Manager& rman)
873898466 q{
88 // Retrieve all nodes referred by the ways.
893898466 q std::map< Uint32_Index, std::vector< Node_Skeleton > > way_members_ = small_way_members(&query, rman, ways);
91 // Order node ids by id.
923898466 q for (std::map< Uint32_Index, std::vector< Node_Skeleton > >::iterator it = way_members_.begin();
93286720466 q it != way_members_.end(); ++it)
94282822313 q {
95282822313 q for (std::vector< Node_Skeleton >::const_iterator iit = it->second.begin();
9628172544313 q iit != it->second.end(); ++iit)
9727889722313 q nodes.push_back(Node(iit->id, it->first.val(), iit->ll_lower));
98282822313 q }
993898466 q sort(nodes.begin(), nodes.end(), Node_Comparator_By_Id());
103Way_Geometry_Store::Way_Geometry_Store
104 (const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& ways,
105 const Statement& query, Resource_Manager& rman)
107 // Retrieve all nodes referred by the ways.
1082036262 q Request_Context context(&query, rman);
1092036262 q auto timeless = collect_items_range< Uint32_Index, Node_Skeleton >(context,
1102036262 q small_way_nd_indices< Attic< Way_Skeleton > >(&query, rman, ways.begin(), ways.end()),
1112036262 q Id_Predicate< Node_Skeleton >(small_way_nd_ids(ways)));
1132036262 q keep_matching_skeletons(nodes, timeless.current, timeless.attic, rman.get_desired_timestamp());
117std::vector< Quad_Coord > Way_Geometry_Store::get_geometry(const Way_Skeleton& way) const
1187142255335 q{
1197142255335 q if (way.geometry.empty())
1207036703328 q return make_geometry(way, nodes);
121105552266 q else
122105552266 q return way.geometry;
1237142255335 q}
126Way_Bbox_Geometry_Store::Way_Bbox_Geometry_Store(
127 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,
128 const Statement& query, Resource_Manager& rman,
129 double south_, double north_, double west_, double east_)
130968133 q : Way_Geometry_Store(ways, query, rman),
131968133 q bbox_d(south_, west_, north_, east_),
132968133 q south(ilat_(south_)), north(ilat_(north_)), west(ilon_(west_)), east(ilon_(east_))
136Way_Bbox_Geometry_Store::Way_Bbox_Geometry_Store(
137 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& ways,
138 const Statement& query, Resource_Manager& rman,
139 double south_, double north_, double west_, double east_)
14062898 q : Way_Geometry_Store(ways, query, rman),
14162898 q bbox_d(south_, west_, north_, east_),
14262898 q south(ilat_(south_)), north(ilat_(north_)), west(ilon_(west_)), east(ilon_(east_))
14362898 q{}
146bool Way_Bbox_Geometry_Store::matches_bbox(uint32 ll_upper, uint32 ll_lower) const
147545376 q{
148545376 q if (north < south)
1490 return true;
150545376 q uint32 lat(::ilat(ll_upper, ll_lower));
151545376 q int32 lon(::ilon(ll_upper, ll_lower));
152545376 q return (lat >= south && lat <= north &&
153545376 q ((lon >= west && lon <= east)
154465143 q || (east < west && (lon >= west || lon <= east))));
155545376 q}
158std::vector< Quad_Coord > Way_Bbox_Geometry_Store::get_geometry(const Way_Skeleton& way) const
15928756064 q{
16028756064 q std::vector< Quad_Coord > result = Way_Geometry_Store::get_geometry(way);
16228756064 q if (result.empty() || north < south)
16328326558 q ;
16442956 q else
16542956 q {
16642956 q bool last_dropped = false;
167586816 q for (uint i = 0; i < result.size(); ++i)
168543866 q {
169543866 q if (i < result.size()-1)
170511286 q {
171511286 q if (matches_bbox(result[i+1].ll_upper, result[i+1].ll_lower))
17278462 q {
17378462 q i += 2; // Next and following point are guaranteed inside
17478462 q last_dropped = false;
17578462 q continue;
17678462 q }
177511286 q }
178465406 q if (!last_dropped)
17933456 q {
18033456 q if (matches_bbox(result[i].ll_upper, result[i].ll_lower))
1815352 q {
1825352 q ++i; // Next point is guaranteed inside
1835352 q last_dropped = false;
1845352 q continue;
1855352 q }
18628105 q if (i > 0 && matches_bbox(result[i-1].ll_upper, result[i-1].ll_lower))
187191 q {
188191 q last_dropped = false;
189191 q continue;
190191 q }
19128105 q }
192459865 q if (i < result.size()-1)
193432495 q {
194432495 q Point_Double first(
195432495 q ::lat(result[i].ll_upper, result[i].ll_lower), ::lon(result[i].ll_upper, result[i].ll_lower));
196432495 q Point_Double second(
197432495 q ::lat(result[i+1].ll_upper, result[i+1].ll_lower), ::lon(result[i+1].ll_upper, result[i+1].ll_lower));
198432495 q if (bbox_d.intersects(first, second))
20011 q ++i; // Next point is guaranteed inside
20111 q last_dropped = false;
20211 q continue;
204432495 q }
205459855 q if (!last_dropped && i > 0)
206452 q {
207452 q Point_Double first(
208452 q ::lat(result[i-1].ll_upper, result[i-1].ll_lower), ::lon(result[i-1].ll_upper, result[i-1].ll_lower));
209452 q Point_Double second(
210452 q ::lat(result[i].ll_upper, result[i].ll_lower), ::lon(result[i].ll_upper, result[i].ll_lower));
211452 q if (bbox_d.intersects(first, second))
2120 {
2130 last_dropped = false;
2140 continue;
2150 }
216452 q }
217459855 q result[i] = Quad_Coord(0u, 0u);
218459855 q last_dropped = true;
219459855 q }
22042956 q }
22228756064 q return result;
22328756064 q}