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

overpass_api/data/geometry_from_quad_coords.cc

214 of 247 instrumented lines run by the suite (86.6%) 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 "geometry_from_quad_coords.h"
22Opaque_Geometry* make_linestring_way_geom(const std::vector< Quad_Coord >& geometry)
231160511 q{
241160511 q bool is_complete = true;
2542236111 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it)
2641075611 q is_complete &= (it->ll_upper != 0 || it->ll_lower != 0);
281160511 q if (is_complete)
2997779 q {
3097779 q std::vector< Point_Double > coords;
313774269 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it)
323676499 q coords.push_back(Point_Double(::lat(it->ll_upper, it->ll_lower), ::lon(it->ll_upper, it->ll_lower)));
3397779 q return new Linestring_Geometry(coords);
3497779 q }
3518285 q else
3618285 q {
3718285 q Partial_Way_Geometry* pw_geom = new Partial_Way_Geometry();
38449355 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it)
39431075 q {
40431075 q if (it->ll_upper != 0 || it->ll_lower != 0)
412862 q pw_geom->add_point(Point_Double(::lat(it->ll_upper, it->ll_lower), ::lon(it->ll_upper, it->ll_lower)));
42428215 q else
43428215 q pw_geom->add_point(Point_Double(100., 200.));
44431075 q }
4518285 q return pw_geom;
4618285 q }
470 return 0;
481160511 q}
51const Opaque_Geometry& Geometry_From_Quad_Coords::make_way_geom(
52 const Way_Skeleton& skel, unsigned int mode, Way_Bbox_Geometry_Store* store)
531085048275 q{
541085048275 q delete geom;
551085048275 q geom = 0;
571085048275 q if (store && (mode & Output_Mode::GEOMETRY))
581159310 q geom = make_linestring_way_geom(store->get_geometry(skel));
591073455274 q else if (store && ((mode & Output_Mode::BOUNDS) || (mode & Output_Mode::CENTER)))
60748910 q {
61748910 q std::vector< Quad_Coord > geometry = store->get_geometry(skel);
63748910 q double min_lat = 100.;
64748910 q double max_lat = -100.;
65748910 q double min_lon = 200.;
66748910 q double max_lon = -200.;
6815577010 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it)
6914828110 q {
7014828110 q double lat = ::lat(it->ll_upper, it->ll_lower);
7114828110 q min_lat = std::min(min_lat, lat);
7214828110 q max_lat = std::max(max_lat, lat);
7314828110 q double lon = ::lon(it->ll_upper, it->ll_lower);
7414828110 q min_lon = std::min(min_lon, lon);
7514828110 q max_lon = std::max(max_lon, lon);
7614828110 q }
78748910 q if (min_lat <= max_lat)
79748910 q {
80748910 q if (mode & Output_Mode::BOUNDS)
8132027 q geom = new Bbox_Geometry(min_lat, min_lon, max_lat, max_lon);
8242873 q else
8342873 q geom = new Point_Geometry((min_lat + max_lat) / 2., (min_lon + max_lon) / 2.);
84748910 q }
850 else
860 geom = new Null_Geometry();
87748910 q }
881065966271 q else
891065966271 q geom = new Null_Geometry();
911085048275 q return *geom;
921085048275 q}
95const Opaque_Geometry& Geometry_From_Quad_Coords::make_way_geom(
96 const std::vector< Quad_Coord >* geometry, const std::pair< Quad_Coord, Quad_Coord* >* bounds)
9713307146 q{
9813307146 q delete geom;
9913307146 q geom = 0;
10113307146 q if (geometry && !geometry->empty())
102121 q geom = make_linestring_way_geom(*geometry);
10313305946 q else if (bounds && (bounds->first.ll_upper | bounds->first.ll_lower))
1042084 q {
1052084 q if (bounds->second)
10632 q geom = new Bbox_Geometry(::lat(bounds->first.ll_upper, bounds->first.ll_lower),
10732 q ::lon(bounds->first.ll_upper, bounds->first.ll_lower),
10832 q ::lat(bounds->second->ll_upper, bounds->second->ll_lower),
10932 q ::lon(bounds->second->ll_upper, bounds->second->ll_lower));
1102052 q else
1112052 q geom = new Point_Geometry(::lat(bounds->first.ll_upper, bounds->first.ll_lower),
1122052 q ::lon(bounds->first.ll_upper, bounds->first.ll_lower));
1132084 q }
11413285146 q else
11513285146 q geom = new Null_Geometry();
11713307146 q return *geom;
11813307146 q}
121Opaque_Geometry* make_verbatim_rel_geom(const std::vector< std::vector< Quad_Coord > >& geometry)
122527212 q{
123527212 q bool is_complete = true;
124527212 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin();
1255605112 q it != geometry.end(); ++it)
1265077912 q {
1275077912 q if (it->empty())
128691310 q is_complete = false;
1294386611 q else if (it->size() == 1)
13051309 q is_complete &= ((*it)[0].ll_upper != 0 || (*it)[0].ll_lower != 0);
131387369 q else
132387369 q {
13315747119 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2)
13415359759 q is_complete &= (it2->ll_upper != 0 || it2->ll_lower != 0);
135387369 q }
1365077912 q }
138527212 q if (is_complete)
13949789 q {
14049789 q Compound_Geometry* cp_geom = new Compound_Geometry();
14149789 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin();
142421489 q it != geometry.end(); ++it)
143371709 q {
144371709 q if (it->empty())
1450 cp_geom->add_component(new Null_Geometry());
146371709 q else if (it->size() == 1)
14743936 q cp_geom->add_component(new Point_Geometry(
14843936 q ::lat(it->front().ll_upper, it->front().ll_lower),
14943936 q ::lon(it->front().ll_upper, it->front().ll_lower)));
150327779 q else
151327779 q {
152327779 q std::vector< Point_Double > coords;
15314583929 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2)
15414256159 q coords.push_back(Point_Double(::lat(it2->ll_upper, it2->ll_lower), ::lon(it2->ll_upper, it2->ll_lower)));
155327779 q cp_geom->add_component(new Linestring_Geometry(coords));
156327779 q }
157371709 q }
15849789 q return cp_geom;
15949789 q }
16029410 q else if (geometry.empty())
1610 return new Null_Geometry();
16229410 q else
16329410 q {
16429410 q Partial_Relation_Geometry* pr_geom = new Partial_Relation_Geometry();
16529410 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin();
1661390310 q it != geometry.end(); ++it)
1671360910 q {
1681360910 q if (it->empty())
169691310 q pr_geom->add_placeholder();
17066969 q else if (it->size() == 1 && ((*it)[0].ll_upper != 0 || (*it)[0].ll_lower != 0))
1711694 q pr_geom->add_point(Point_Double(
1721694 q ::lat(it->front().ll_upper, it->front().ll_lower),
1731694 q ::lon(it->front().ll_upper, it->front().ll_lower)));
17465279 q else
17565279 q {
17665279 q pr_geom->start_way();
1771174559 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2)
1781109289 q {
1791109289 q if (it2->ll_upper != 0 || it2->ll_lower != 0)
1801103607 q pr_geom->add_way_point(
1811103607 q Point_Double(::lat(it2->ll_upper, it2->ll_lower), ::lon(it2->ll_upper, it2->ll_lower)));
1825687 q else
1835687 q pr_geom->add_way_placeholder();
1841109289 q }
18565279 q }
1861360910 q }
18729410 q return pr_geom;
18829410 q }
1890 return 0;
190527212 q}
193const Opaque_Geometry& Geometry_From_Quad_Coords::make_relation_geom(
194 const Relation_Skeleton& skel, unsigned int mode, Relation_Geometry_Store* store)
195157601172 q{
196157601172 q delete geom;
197157601172 q geom = 0;
199157601172 q if (store && (mode & Output_Mode::GEOMETRY))
200526310 q geom = make_verbatim_rel_geom(store->get_geometry(skel));
201152338168 q else if (store && ((mode & Output_Mode::BOUNDS) || (mode & Output_Mode::CENTER)))
2022259 q {
2032259 q std::vector< std::vector< Quad_Coord > > geometry = store->get_geometry(skel);
2052259 q double min_lat = 100.;
2062259 q double max_lat = -100.;
2072259 q double min_lon = 200.;
2082259 q double max_lon = -200.;
2102259 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin();
21194799 q it != geometry.end(); ++it)
21292549 q {
21392549 q if (it->size() == 1)
2142266 q {
2152266 q double lat = ::lat((*it)[0].ll_upper, (*it)[0].ll_lower);
2162266 q min_lat = std::min(min_lat, lat);
2172266 q max_lat = std::max(max_lat, lat);
2182266 q double lon = ::lon((*it)[0].ll_upper, (*it)[0].ll_lower);
2192266 q min_lon = std::min(min_lon, lon);
2202266 q max_lon = std::max(max_lon, lon);
2212266 q }
22290289 q else if (!it->empty())
22327497 q {
224582127 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2)
225554637 q {
226554637 q double lat = ::lat(it2->ll_upper, it2->ll_lower);
227554637 q min_lat = std::min(min_lat, lat);
228554637 q max_lat = std::max(max_lat, lat);
229554637 q double lon = ::lon(it2->ll_upper, it2->ll_lower);
230554637 q min_lon = std::min(min_lon, lon);
231554637 q max_lon = std::max(max_lon, lon);
232554637 q }
23327497 q }
23492549 q }
2362259 q if (min_lat <= max_lat)
2371727 q {
2381727 q if (max_lon - min_lon >= 180.)
2390 {
2400 min_lon = 200.;
2410 max_lon = -200.;
2430 for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin();
2440 it != geometry.end(); ++it)
2450 {
2460 if (it->size() == 1)
2470 {
2480 double lon = ::lon((*it)[0].ll_upper, (*it)[0].ll_lower);
2490 if (lon < 0.)
2500 max_lon = std::max(max_lon, lon);
2510 else
2520 min_lon = std::min(min_lon, lon);
2530 }
2540 else if (!it->empty())
2550 {
2560 for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2)
2570 {
2580 double lon = ::lon(it2->ll_upper, it2->ll_lower);
2590 if (lon < 0.)
2600 max_lon = std::max(max_lon, lon);
2610 else
2620 min_lon = std::min(min_lon, lon);
2630 }
2640 }
2650 }
2660 }
2681727 q if (mode & Output_Mode::BOUNDS)
269483 q geom = new Bbox_Geometry(min_lat, min_lon, max_lat, max_lon);
2701244 q else
2711244 q geom = new Point_Geometry((min_lat + max_lat) / 2., (min_lon + max_lon) / 2.);
2721727 q }
273534 q else
274534 q geom = new Null_Geometry();
2752259 q }
276152113165 q else
277152113165 q geom = new Null_Geometry();
279157601172 q return *geom;
280157601172 q}
283const Opaque_Geometry& Geometry_From_Quad_Coords::make_relation_geom(
284 const std::vector< std::vector< Quad_Coord > >* geometry, const std::pair< Quad_Coord, Quad_Coord* >* bounds)
285127125 q{
286127125 q delete geom;
287127125 q geom = 0;
289127125 q if (geometry)
29092 q geom = make_verbatim_rel_geom(*geometry);
291126225 q else if (bounds)
292904 q {
293904 q if (bounds->second)
294431 q geom = new Bbox_Geometry(::lat(bounds->first.ll_upper, bounds->first.ll_lower),
295431 q ::lon(bounds->first.ll_upper, bounds->first.ll_lower),
296431 q ::lat(bounds->second->ll_upper, bounds->second->ll_lower),
297431 q ::lon(bounds->second->ll_upper, bounds->second->ll_lower));
298473 q else
299473 q geom = new Point_Geometry(::lat(bounds->first.ll_upper, bounds->first.ll_lower),
300473 q ::lon(bounds->first.ll_upper, bounds->first.ll_lower));
301904 q }
302117225 q else
303117225 q geom = new Null_Geometry();
305127125 q return *geom;
306127125 q}