Revert "Device/Driver/LX: Add small delay after baud rate change"
[xcsoar.git] / test / src / test_reach.cpp
blob980b79c6ad8e3774df0a523e8133445ab26b671d
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.
22 #include <iostream>
23 #include <fstream>
24 #include "Printing.hpp"
25 #define DO_PRINT
26 #include "TestUtil.hpp"
27 #include "Route/TerrainRoute.hpp"
28 #include "Engine/Route/ReachResult.hpp"
29 #include "Terrain/RasterMap.hpp"
30 #include "OS/ConvertPathName.hpp"
31 #include "Compatibility/path.h"
32 #include "GlideSolvers/GlideSettings.hpp"
33 #include "GlideSolvers/GlidePolar.hpp"
34 #include "Geo/SpeedVector.hpp"
35 #include "Operation/Operation.hpp"
36 #include "OS/FileUtil.hpp"
38 #include <string.h>
40 static void test_reach(const RasterMap& map, fixed mwind, fixed mc)
42 GlideSettings settings;
43 settings.SetDefaults();
44 GlidePolar polar(mc);
45 SpeedVector wind(Angle::Degrees(0), mwind);
46 TerrainRoute route;
47 route.UpdatePolar(settings, polar, polar, wind);
48 route.SetTerrain(&map);
50 GeoPoint origin(map.GetMapCenter());
52 fixed pd = map.PixelDistance(origin, 1);
53 printf("# pixel size %g\n", (double)pd);
55 bool retval= true;
57 short horigin = map.GetHeight(origin)+1000;
58 AGeoPoint aorigin(origin, RoughAltitude(horigin));
60 RoutePlannerConfig config;
61 config.SetDefaults();
62 retval = route.SolveReach(aorigin, config, RoughAltitude::Max());
64 ok(retval, "reach solve", 0);
66 PrintHelper::print_reach_tree(route);
68 GeoPoint dest(origin.longitude-Angle::Degrees(0.02),
69 origin.latitude-Angle::Degrees(0.02));
72 Directory::Create(_T("output/results"));
73 std::ofstream fout("output/results/terrain.txt");
74 unsigned nx = 100;
75 unsigned ny = 100;
76 for (unsigned i=0; i< nx; ++i) {
77 for (unsigned j=0; j< ny; ++j) {
78 fixed fx = (fixed)i / (nx - 1) * 2 - fixed(1);
79 fixed fy = (fixed)j / (ny - 1) * 2 - fixed(1);
80 GeoPoint x(origin.longitude + Angle::Degrees(fixed(0.6) * fx),
81 origin.latitude + Angle::Degrees(fixed(0.6) * fy));
82 short h = map.GetInterpolatedHeight(x);
83 AGeoPoint adest(x, RoughAltitude(h));
84 ReachResult reach;
85 route.FindPositiveArrival(adest, reach);
86 if ((i % 5 == 0) && (j % 5 == 0)) {
87 AGeoPoint ao2(x, RoughAltitude(h + 1000));
88 route.SolveReach(ao2, config, RoughAltitude::Max());
90 fout << x.longitude.Degrees() << " "
91 << x.latitude.Degrees() << " "
92 << h << " " << (int)reach.terrain << "\n";
94 fout << "\n";
96 fout << "\n";
100 int main(int argc, char** argv) {
102 const char hc_path[] = "tmp/terrain";
103 const char *map_path;
104 if ((argc<2) || !strlen(argv[1])) {
105 map_path = hc_path;
106 } else {
107 map_path = argv[1];
110 TCHAR jp2_path[4096];
111 _tcscpy(jp2_path, PathName(map_path));
112 _tcscat(jp2_path, _T(DIR_SEPARATOR_S) _T("terrain.jp2"));
114 TCHAR j2w_path[4096];
115 _tcscpy(j2w_path, PathName(map_path));
116 _tcscat(j2w_path, _T(DIR_SEPARATOR_S) _T("terrain.j2w"));
118 NullOperationEnvironment operation;
119 RasterMap map(jp2_path, j2w_path, NULL, operation);
120 do {
121 map.SetViewCenter(map.GetMapCenter(), fixed(100000));
122 } while (map.IsDirty());
124 plan_tests(1);
125 test_reach(map, fixed(0), fixed(0.1));
127 return exit_status();