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

overpass_api/data/way_geometry_store.cc

129 of 143 instrumented lines run by the suite (90.2%) 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)
305313414 q{
315313414 q std::vector< uint32 > parents;
335313414 q for (typename std::map< Uint31_Index, std::vector< Object > >::const_iterator
34434440414 q it(ways_begin); it != ways_end; ++it)
35429127316 q {
36429127316 q if (!(it->first.val() & 0x80000000) || ((it->first.val() & 0x1) != 0)) // Adapt 0x3
37377979307 q parents.push_back(it->first.val());
38429127316 q }
395313414 q sort(parents.begin(), parents.end());
405313414 q parents.erase(unique(parents.begin(), parents.end()), parents.end());
425313414 q if (stmt)
435313414 q rman.health_check(*stmt);
455313414 q return calc_node_children_ranges(parents);
465313414 q}
49template< typename Object >
50std::vector< Node::Id_Type > small_way_nd_ids(const std::map< Uint31_Index, std::vector< Object > >& ways)
515313414 q{
525313414 q std::vector< Node::Id_Type > ids;
535313414 q for (typename std::map< Uint31_Index, std::vector< Object > >::const_iterator
54434440414 q it(ways.begin()); it != ways.end(); ++it)
55429127316 q {
56429127316 q if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x1) == 0))
5751148288 q continue;
58377979307 q for (typename std::vector< Object >::const_iterator it2(it->second.begin());
591884950307 q it2 != it->second.end(); ++it2)
601506971301 q {
611506971301 q for (std::vector< Node::Id_Type >::const_iterator it3(it2->nds.begin());
6220048085301 q it3 != it2->nds.end(); ++it3)
6318541114301 q ids.push_back(*it3);
641506971301 q }
65377979307 q }
675313414 q sort(ids.begin(), ids.end());
685313414 q ids.erase(unique(ids.begin(), ids.end()), ids.end());
705313414 q return ids;
715313414 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)
773520414 q{
783520414 q Request_Context context(stmt, rman);
793520414 q return collect_items_range< Uint32_Index, Node_Skeleton >(context,
803520414 q small_way_nd_indices< Way_Skeleton >(stmt, rman, ways.begin(), ways.end()),
813520414 q Id_Predicate< Node_Skeleton >(small_way_nd_ids(ways))).current;
823520414 q}
85Way_Geometry_Store::Way_Geometry_Store
86 (const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways, const Statement& query, Resource_Manager& rman)
873520414 q{
88 // Retrieve all nodes referred by the ways.
893520414 q std::map< Uint32_Index, std::vector< Node_Skeleton > > way_members_ = small_way_members(&query, rman, ways);
91 // Order node ids by id.
923520414 q for (std::map< Uint32_Index, std::vector< Node_Skeleton > >::iterator it = way_members_.begin();
93501412414 q it != way_members_.end(); ++it)
94497892293 q {
95497892293 q for (std::vector< Node_Skeleton >::const_iterator iit = it->second.begin();
9615561834293 q iit != it->second.end(); ++iit)
9715063942293 q nodes.push_back(Node(iit->id, it->first.val(), iit->ll_lower));
98497892293 q }
993520414 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.
1081793232 q Request_Context context(&query, rman);
1091793232 q auto timeless = collect_items_range< Uint32_Index, Node_Skeleton >(context,
1101793232 q small_way_nd_indices< Attic< Way_Skeleton > >(&query, rman, ways.begin(), ways.end()),
1111793232 q Id_Predicate< Node_Skeleton >(small_way_nd_ids(ways)));
1131793232 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
1182207974308 q{
1192207974308 q if (way.geometry.empty())
1202037836301 q return make_geometry(way, nodes);
121170138280 q else
122170138280 q return way.geometry;
1232207974308 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_)
130903114 q : Way_Geometry_Store(ways, query, rman),
131903114 q bbox_d(south_, west_, north_, east_),
132903114 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_)
14055587 q : Way_Geometry_Store(ways, query, rman),
14155587 q bbox_d(south_, west_, north_, east_),
14255587 q south(ilat_(south_)), north(ilat_(north_)), west(ilon_(west_)), east(ilon_(east_))
14355587 q{}
146bool Way_Bbox_Geometry_Store::matches_bbox(uint32 ll_upper, uint32 ll_lower) const
1471060058 q{
1481060058 q if (north < south)
1490 return true;
1501060058 q uint32 lat(::ilat(ll_upper, ll_lower));
1511060058 q int32 lon(::ilon(ll_upper, ll_lower));
1521060058 q return (lat >= south && lat <= north &&
1531060058 q ((lon >= west && lon <= east)
154133824 q || (east < west && (lon >= west || lon <= east))));
1551060058 q}
158std::vector< Quad_Coord > Way_Bbox_Geometry_Store::get_geometry(const Way_Skeleton& way) const
15917147266 q{
16017147266 q std::vector< Quad_Coord > result = Way_Geometry_Store::get_geometry(way);
16217147266 q if (result.empty() || north < south)
16316694759 q ;
16445258 q else
16545258 q {
16645258 q bool last_dropped = false;
1671105228 q for (uint i = 0; i < result.size(); ++i)
1681059978 q {
1691059978 q if (i < result.size()-1)
1701014958 q {
1711014958 q if (matches_bbox(result[i+1].ll_upper, result[i+1].ll_lower))
172662 q {
173662 q i += 2; // Next and following point are guaranteed inside
174662 q last_dropped = false;
175662 q continue;
176662 q }
1771014958 q }
1781059317 q if (!last_dropped)
17945067 q {
18045067 q if (matches_bbox(result[i].ll_upper, result[i].ll_lower))
18291 q ++i; // Next point is guaranteed inside
18391 q last_dropped = false;
18491 q continue;
18644977 q if (i > 0 && matches_bbox(result[i-1].ll_upper, result[i-1].ll_lower))
1870 {
1880 last_dropped = false;
1890 continue;
1900 }
19144977 q }
1921059227 q if (i < result.size()-1)
1931014287 q {
1941014287 q Point_Double first(
1951014287 q ::lat(result[i].ll_upper, result[i].ll_lower), ::lon(result[i].ll_upper, result[i].ll_lower));
1961014287 q Point_Double second(
1971014287 q ::lat(result[i+1].ll_upper, result[i+1].ll_lower), ::lon(result[i+1].ll_upper, result[i+1].ll_lower));
1981014287 q if (bbox_d.intersects(first, second))
1990 {
2000 ++i; // Next point is guaranteed inside
2010 last_dropped = false;
2020 continue;
2030 }
2041014287 q }
2051059227 q if (!last_dropped && i > 0)
20741 q Point_Double first(
20841 q ::lat(result[i-1].ll_upper, result[i-1].ll_lower), ::lon(result[i-1].ll_upper, result[i-1].ll_lower));
20941 q Point_Double second(
21041 q ::lat(result[i].ll_upper, result[i].ll_lower), ::lon(result[i].ll_upper, result[i].ll_lower));
21141 q if (bbox_d.intersects(first, second))
2120 {
2130 last_dropped = false;
2140 continue;
2150 }
2171059227 q result[i] = Quad_Coord(0u, 0u);
2181059227 q last_dropped = true;
2191059227 q }
22045258 q }
22217147266 q return result;
22317147266 q}