Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / test / src / test_trees.cpp
blob50da23d2d3dee6d80fd239182d88715de2b6665f
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "harness_waypoints.hpp"
24 #include "harness_airspace.hpp"
25 #include "test_debug.hpp"
26 #include "OS/FileUtil.hpp"
28 #define n_test 500
30 #include "Waypoint/WaypointVisitor.hpp"
31 #include "Engine/Waypoint/Waypoints.hpp"
33 class WaypointVisitorPrint: public WaypointVisitor {
34 public:
35 WaypointVisitorPrint():count(0) {};
37 virtual void Visit(const Waypoint& wp) {
38 count++;
40 unsigned count;
43 static bool
44 test_wp(const unsigned n, std::ostream &fo)
46 Waypoints waypoints;
47 SetupWaypoints(waypoints,n);
49 AircraftState state;
51 PrintQueries(0, fo);
53 for (unsigned i=0; i<n_test; i++) {
54 int x = rand()%1200-100;
55 int y = rand()%1200-100;
56 state.location.longitude = Angle::Degrees(fixed(x/1000.0));
57 state.location.latitude = Angle::Degrees(fixed(y/1000.0));
59 WaypointVisitorPrint wvp;
60 waypoints.VisitWithinRange(state.location, fixed(50000.0), wvp);
62 PrintQueries(n, fo);
63 fo.flush();
64 return true;
67 static bool
68 test_as(const unsigned n, std::ostream &fo)
70 AircraftState state;
72 Airspaces airspaces;
73 setup_airspaces(airspaces,GeoPoint(Angle::Zero(), Angle::Zero()), n);
75 PrintQueries(0, fo);
77 for (unsigned i=0; i<n_test; i++) {
78 int x = rand()%1200-100;
79 int y = rand()%1200-100;
80 state.location.longitude = Angle::Degrees(fixed(x/1000.0));
81 state.location.latitude = Angle::Degrees(fixed(y/1000.0));
82 const AirspacesInterface::AirspaceVector vc = airspaces.FindInside(state);
84 PrintQueries(n, fo);
85 fo.flush();
87 const AirspacesInterface::AirspaceVector vc =
88 airspaces.ScanRange(state.location, fixed(20000.0));
90 return true;
94 int main(int argc, char** argv) {
95 if (!ParseArgs(argc,argv)) {
96 return 0;
99 Directory::Create(_T("output/results"));
100 std::ofstream fw("output/results/res-tree-wp.txt");
102 plan_tests(2);
104 bool fine = true;
105 fw << "# test waypoint tree\n";
106 for (double i=10; i<=4000; i*= 1.1) {
107 fine &= test_wp((int)i,fw);
109 fw << "\n";
110 ok(fine,"waypoint tree",0);
112 std::ofstream fa("output/results/res-tree-as.txt");
114 fine = true;
115 fa << "# test airspace tree\n";
116 for (double i=10; i<=4000; i*= 1.1) {
117 fine &= test_as((int)i,fa);
119 fa << "\n";
120 ok(fine,"airspace tree",0);
122 return exit_status();