Overpass API regression suite coverage (Nova Scotia) / overpass_api/statements/around.h

overpass_api/statements/around.h

34 of 34 instrumented lines run by the suite (100.0%) 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__STATEMENTS__AROUND_H
20#define DE__OSM3S___OVERPASS_API__STATEMENTS__AROUND_H
22#include <map>
23#include <set>
24#include <string>
25#include <vector>
26#include "../data/collect_members.h"
27#include "../data/utils.h"
28#include "../data/way_geometry_store.h"
29#include "statement.h"
32struct Prepared_Segment
34 double first_lat;
35 double first_lon;
36 double second_lat;
37 double second_lon;
38 std::vector< double > first_cartesian;
39 std::vector< double > second_cartesian;
40 std::vector< double > norm;
42 Prepared_Segment(double first_lat, double first_lon, double second_lat, double second_lon);
43};
46struct Prepared_Point
48 double lat;
49 double lon;
50 std::vector< double > cartesian;
52 Prepared_Point(double lat, double lon);
53};
56class Around_Statement : public Output_Statement
58 public:
59 Around_Statement(int line_number_, const std::map< std::string, std::string >& attributes,
60 Parsed_Query& global_settings);
6178694 q virtual std::string get_name() const { return "around"; }
62 virtual void execute(Resource_Manager& rman);
63 virtual ~Around_Statement();
65 struct Statement_Maker : public Generic_Statement_Maker< Around_Statement >
66 {
672448612 q Statement_Maker() : Generic_Statement_Maker< Around_Statement >("around") {}
68 };
69 static Statement_Maker statement_maker;
71 struct Criterion_Maker : public Statement::Criterion_Maker
72 {
7342894 q virtual bool can_standalone(const std::string& type) { return type == "node"; }
74 virtual Statement* create_criterion(const Token_Node_Ptr& tree_it,
75 const std::string& type, const std::string& into,
76 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output);
772448612 q Criterion_Maker() { Statement::maker_by_ql_criterion()["around"] = this; }
78 };
79 static Criterion_Maker criterion_maker;
81 virtual Query_Constraint* get_query_constraint();
8371394 q std::string get_source_name() const { return input; }
85 Ranges< Uint32_Index > calc_ranges(const Set& input_nodes, Resource_Manager& rman) const;
87 void calc_lat_lons(const Set& input_nodes, Statement& query, Resource_Manager& rman);
89 bool is_inside(double lat, double lon) const;
90 bool is_inside(double first_lat, double first_lon, double second_lat, double second_lon) const;
91 bool is_inside(const std::vector< Quad_Coord >& way_geometry) const;
939271 q double get_radius() const { return radius; }
95 template< typename Node_Skeleton >
96 void add_nodes(const std::map< Uint32_Index, std::vector< Node_Skeleton > >& nodes);
98 template< typename Way_Skeleton >
99 void add_ways(const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,
100 const Way_Geometry_Store& way_geometries);
102 virtual std::string dump_xml(const std::string& indent) const
10310794 q {
10410794 q std::string result = indent + "<around"
10510794 q + (input != "_" ? std::string(" from=\"") + input + "\"" : "")
10610794 q + std::string(" radius=\"") + to_string(radius) + "\"";
10710794 q if (points.size() == 1)
1087466 q result += std::string(" lat=\"") + to_string(points.front().lat) + "\""
1097466 q + std::string(" lon=\"") + to_string(points.front().lon) + "\"";
1103332 q else if (!points.empty())
11244 q result += " polyline=\"";
113184 q for (std::vector< Point_Double >::const_iterator it = points.begin(); it != points.end(); ++it)
114144 q result += to_string(it->lat) + "," + to_string(it->lon) + ",";
11544 q result[result.size()-1] = '\"';
11710794 q return result + dump_xml_result_name() + "/>\n";
11810794 q }
120 virtual std::string dump_compact_ql(const std::string&) const
1224823 q return "node" + dump_ql_in_query("") + dump_ql_result_name() + ";";
124 virtual std::string dump_ql_in_query(const std::string&) const
12521494 q {
12621494 q std::string result = std::string("(around")
12721494 q + (input != "_" ? std::string(".") + input : "")
12821494 q + std::string(":") + to_string(radius);
12939094 q for (std::vector< Point_Double >::const_iterator it = points.begin(); it != points.end(); ++it)
13017669 q result += "," + to_string(it->lat) + "," + to_string(it->lon);
13121494 q return result + ")";
13221494 q }
1332423 q virtual std::string dump_pretty_ql(const std::string& indent) const { return indent + dump_compact_ql(indent); }
135 private:
136 std::string input;
137 double radius;
138 std::vector< Point_Double > points;
140 std::map< Uint32_Index, std::vector< Point_Double > > radius_lat_lons;
141 std::vector< Prepared_Point > simple_lat_lons;
142 std::vector< Prepared_Segment > simple_segments;
143 std::vector< Query_Constraint* > constraints;
144};
146#endif