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

overpass_api/data/geometry_from_quad_coords.cc

239 of 247 instrumented lines run by the suite (96.8%) 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)
231515210 q{
241515210 q bool is_complete = true;
2518299710 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it)
2616784510 q is_complete &= (it->ll_upper != 0 || it->ll_lower != 0);
281515210 q if (is_complete)
29124518 q {
30124518 q std::vector< Point_Double > coords;
311344728 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it)
321220218 q coords.push_back(Point_Double(::lat(it->ll_upper, it->ll_lower), ::lon(it->ll_upper, it->ll_lower)));
33124518 q return new Linestring_Geometry(coords);
34124518 q }
3527013 q else
3627013 q {
3727013 q Partial_Way_Geometry* pw_geom = new Partial_Way_Geometry();
38485253 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it)
39458243 q {
40458243 q if (it->ll_upper != 0 || it->ll_lower != 0)
4111701 q pw_geom->add_point(Point_Double(::lat(it->ll_upper, it->ll_lower), ::lon(it->ll_upper, it->ll_lower)));
42446543 q else
43446543 q pw_geom->add_point(Point_Double(100., 200.));
44458243 q }
4527013 q return pw_geom;
4627013 q }
470 return 0;
481515210 q}
51const Opaque_Geometry& Geometry_From_Quad_Coords::make_way_geom(
52 const Way_Skeleton& skel, unsigned int mode, Way_Bbox_Geometry_Store* store)
531252584292 q{
541252584292 q delete geom;
551252584292 q geom = 0;
571252584292 q if (store && (mode & Output_Mode::GEOMETRY))
58139659 q geom = make_linestring_way_geom(store->get_geometry(skel));
591238619290 q else if (store && ((mode & Output_Mode::BOUNDS) || (mode & Output_Mode::CENTER)))
602340114 q {
612340114 q std::vector< Quad_Coord > geometry = store->get_geometry(skel);
632340114 q double min_lat = 100.;
642340114 q double max_lat = -100.;
652340114 q double min_lon = 200.;
662340114 q double max_lon = -200.;
6826479414 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it)
6924139314 q {
7024139314 q double lat = ::lat(it->ll_upper, it->ll_lower);
7124139314 q min_lat = std::min(min_lat, lat);
7224139314 q max_lat = std::max(max_lat, lat);
7324139314 q double lon = ::lon(it->ll_upper, it->ll_lower);
7424139314 q min_lon = std::min(min_lon, lon);
7524139314 q max_lon = std::max(max_lon, lon);
7624139314 q }
782340114 q if (min_lat <= max_lat)
792340114 q {
802340114 q if (mode & Output_Mode::BOUNDS)
81749010 q geom = new Bbox_Geometry(min_lat, min_lon, max_lat, max_lon);
82159114 q else
83159114 q geom = new Point_Geometry((min_lat + max_lat) / 2., (min_lon + max_lon) / 2.);
842340114 q }
850 else
860 geom = new Null_Geometry();
872340114 q }
881215218287 q else
891215218287 q geom = new Null_Geometry();
911252584292 q return *geom;
921252584292 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)
9725793040 q{
9825793040 q delete geom;
9925793040 q geom = 0;
10125793040 q if (geometry && !geometry->empty())
10211871 q geom = make_linestring_way_geom(*geometry);
10325674340 q else if (bounds && (bounds->first.ll_upper | bounds->first.ll_lower))
104307175 q {
105307175 q if (bounds->second)
106297352 q geom = new Bbox_Geometry(::lat(bounds->first.ll_upper, bounds->first.ll_lower),
107297352 q ::lon(bounds->first.ll_upper, bounds->first.ll_lower),
108297352 q ::lat(bounds->second->ll_upper, bounds->second->ll_lower),
109297352 q ::lon(bounds->second->ll_upper, bounds->second->ll_lower));
1109823 q else
1119823 q geom = new Point_Geometry(::lat(bounds->first.ll_upper, bounds->first.ll_lower),
1129823 q ::lon(bounds->first.ll_upper, bounds->first.ll_lower));
113307175 q }
11422602640 q else
11522602640 q geom = new Null_Geometry();
11725793040 q return *geom;
11825793040 q}
121Opaque_Geometry* make_verbatim_rel_geom(const std::vector< std::vector< Quad_Coord > >& geometry)
122627014 q{
123627014 q bool is_complete = true;
124627014 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin();
12546759714 q it != geometry.end(); ++it)
12646132714 q {
12746132714 q if (it->empty())
12817476510 q is_complete = false;
12928656213 q else if (it->size() == 1)
1309759211 q is_complete &= ((*it)[0].ll_upper != 0 || (*it)[0].ll_lower != 0);
13118897012 q else
13218897012 q {
133158396712 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2)
134139499712 q is_complete &= (it2->ll_upper != 0 || it2->ll_lower != 0);
13518897012 q }
13646132714 q }
138627014 q if (is_complete)
139334510 q {
140334510 q Compound_Geometry* cp_geom = new Compound_Geometry();
141334510 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin();
14222989910 q it != geometry.end(); ++it)
14322655410 q {
14422655410 q if (it->empty())
1450 cp_geom->add_component(new Null_Geometry());
14622655410 q else if (it->size() == 1)
147488098 q cp_geom->add_component(new Point_Geometry(
148488098 q ::lat(it->front().ll_upper, it->front().ll_lower),
149488098 q ::lon(it->front().ll_upper, it->front().ll_lower)));
15017774510 q else
15117774510 q {
15217774510 q std::vector< Point_Double > coords;
153145778310 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2)
154128003810 q coords.push_back(Point_Double(::lat(it2->ll_upper, it2->ll_lower), ::lon(it2->ll_upper, it2->ll_lower)));
15517774510 q cp_geom->add_component(new Linestring_Geometry(coords));
15617774510 q }
15722655410 q }
158334510 q return cp_geom;
159334510 q }
160292511 q else if (geometry.empty())
1610 return new Null_Geometry();
162292511 q else
163292511 q {
164292511 q Partial_Relation_Geometry* pr_geom = new Partial_Relation_Geometry();
165292511 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin();
16623769811 q it != geometry.end(); ++it)
16723477311 q {
16823477311 q if (it->empty())
16917476510 q pr_geom->add_placeholder();
1706000810 q else if (it->size() == 1 && ((*it)[0].ll_upper != 0 || (*it)[0].ll_lower != 0))
17113107 q pr_geom->add_point(Point_Double(
17213107 q ::lat(it->front().ll_upper, it->front().ll_lower),
17313107 q ::lon(it->front().ll_upper, it->front().ll_lower)));
1745869810 q else
1755869810 q {
1765869810 q pr_geom->start_way();
17722113010 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2)
17816243210 q {
17916243210 q if (it2->ll_upper != 0 || it2->ll_lower != 0)
1801142458 q pr_geom->add_way_point(
1811142458 q Point_Double(::lat(it2->ll_upper, it2->ll_lower), ::lon(it2->ll_upper, it2->ll_lower)));
182481878 q else
183481878 q pr_geom->add_way_placeholder();
18416243210 q }
1855869810 q }
18623477311 q }
187292511 q return pr_geom;
188292511 q }
1890 return 0;
190627014 q}
193const Opaque_Geometry& Geometry_From_Quad_Coords::make_relation_geom(
194 const Relation_Skeleton& skel, unsigned int mode, Relation_Geometry_Store* store)
195215311178 q{
196215311178 q delete geom;
197215311178 q geom = 0;
199215311178 q if (store && (mode & Output_Mode::GEOMETRY))
200626713 q geom = make_verbatim_rel_geom(store->get_geometry(skel));
201209044175 q else if (store && ((mode & Output_Mode::BOUNDS) || (mode & Output_Mode::CENTER)))
2023719 q {
2033719 q std::vector< std::vector< Quad_Coord > > geometry = store->get_geometry(skel);
2053719 q double min_lat = 100.;
2063719 q double max_lat = -100.;
2073719 q double min_lon = 200.;
2083719 q double max_lon = -200.;
2103719 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin();
211105729 q it != geometry.end(); ++it)
212102019 q {
213102019 q if (it->size() == 1)
2148755 q {
2158755 q double lat = ::lat((*it)[0].ll_upper, (*it)[0].ll_lower);
2168755 q min_lat = std::min(min_lat, lat);
2178755 q max_lat = std::max(max_lat, lat);
2188755 q double lon = ::lon((*it)[0].ll_upper, (*it)[0].ll_lower);
2198755 q min_lon = std::min(min_lon, lon);
2208755 q max_lon = std::max(max_lon, lon);
2218755 q }
22293269 q else if (!it->empty())
22336916 q {
224360046 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2)
225323136 q {
226323136 q double lat = ::lat(it2->ll_upper, it2->ll_lower);
227323136 q min_lat = std::min(min_lat, lat);
228323136 q max_lat = std::max(max_lat, lat);
229323136 q double lon = ::lon(it2->ll_upper, it2->ll_lower);
230323136 q min_lon = std::min(min_lon, lon);
231323136 q max_lon = std::max(max_lon, lon);
232323136 q }
23336916 q }
234102019 q }
2363719 q if (min_lat <= max_lat)
2373688 q {
2383688 q if (max_lon - min_lon >= 180.)
24021 q min_lon = 200.;
24121 q max_lon = -200.;
24321 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin();
24419031 q it != geometry.end(); ++it)
24519011 q {
24619011 q if (it->size() == 1)
247221 q {
248221 q double lon = ::lon((*it)[0].ll_upper, (*it)[0].ll_lower);
249221 q if (lon < 0.)
250221 q max_lon = std::max(max_lon, lon);
2510 else
2520 min_lon = std::min(min_lon, lon);
253221 q }
25418791 q else if (!it->empty())
255231 q {
2561481 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2)
2571251 q {
2581251 q double lon = ::lon(it2->ll_upper, it2->ll_lower);
2591251 q if (lon < 0.)
260771 q max_lon = std::max(max_lon, lon);
261481 q else
262481 q min_lon = std::min(min_lon, lon);
2631251 q }
264231 q }
26519011 q }
2683688 q if (mode & Output_Mode::BOUNDS)
269124 q geom = new Bbox_Geometry(min_lat, min_lon, max_lat, max_lon);
2703564 q else
2713564 q geom = new Point_Geometry((min_lat + max_lat) / 2., (min_lon + max_lon) / 2.);
2723688 q }
27333 q else
27433 q geom = new Null_Geometry();
2753719 q }
276208673172 q else
277208673172 q geom = new Null_Geometry();
279215311178 q return *geom;
280215311178 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)
285110315 q{
286110315 q delete geom;
287110315 q geom = 0;
289110315 q if (geometry)
29031 q geom = make_verbatim_rel_geom(*geometry);
291110015 q else if (bounds)
2922683 q {
2932683 q if (bounds->second)
294731 q geom = new Bbox_Geometry(::lat(bounds->first.ll_upper, bounds->first.ll_lower),
295731 q ::lon(bounds->first.ll_upper, bounds->first.ll_lower),
296731 q ::lat(bounds->second->ll_upper, bounds->second->ll_lower),
297731 q ::lon(bounds->second->ll_upper, bounds->second->ll_lower));
2981952 q else
2991952 q geom = new Point_Geometry(::lat(bounds->first.ll_upper, bounds->first.ll_lower),
3001952 q ::lon(bounds->first.ll_upper, bounds->first.ll_lower));
3012683 q }
30283214 q else
30383214 q geom = new Null_Geometry();
305110315 q return *geom;
306110315 q}