android/GlueIOIOPort: fix spurious errors after IOIO baud rate change
[xcsoar.git] / test / src / TestEarth.cpp
blob4f8ca000b2c5192054edde743b3f7514c0ee2ed2
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 "Geo/Math.hpp"
24 #include "TestUtil.hpp"
26 static void
27 TestLinearDistance()
29 const GeoPoint lon_start(Angle::Degrees(90),
30 Angle::Zero());
31 for (unsigned i = 0; i < 180; i += 5) {
32 const GeoPoint lon_end(lon_start.longitude + Angle::Degrees(i),
33 lon_start.latitude);
34 fixed distance = Distance(lon_start, lon_end);
36 double min = 111100 * i;
37 double max = 111200 * i;
39 ok1(between(distance, min, max));
42 const GeoPoint lat_start(Angle::Zero(),
43 Angle::Zero());
44 for (unsigned i = 0; i < 90; i += 5) {
45 const GeoPoint lat_end(lat_start.longitude,
46 lat_start.latitude + Angle::Degrees(i));
47 fixed distance = Distance(lat_start, lat_end);
49 double min = 111100 * i;
50 double max = 111200 * i;
52 ok1(between(distance, min, max));
56 int main(int argc, char **argv)
58 plan_tests(9 + 36 + 18);
60 const GeoPoint a(Angle::Degrees(7.7061111111111114),
61 Angle::Degrees(51.051944444444445));
62 const GeoPoint b(Angle::Degrees(7.599444444444444),
63 Angle::Degrees(51.099444444444444));
64 const GeoPoint c(Angle::Degrees(4.599444444444444),
65 Angle::Degrees(47.099444444444444));
67 fixed distance = Distance(a, b);
68 ok1(distance > fixed(9130) && distance < fixed(9140));
70 Angle bearing = Bearing(a, b);
71 ok1(bearing.Degrees() > fixed(304));
72 ok1(bearing.Degrees() < fixed(306));
74 bearing = Bearing(b, a);
75 ok1(bearing.Degrees() > fixed(124));
76 ok1(bearing.Degrees() < fixed(126));
78 distance = ProjectedDistance(a, b, a);
79 ok1(is_zero(distance));
80 distance = ProjectedDistance(a, b, b);
81 ok1(distance > fixed(9120) && distance < fixed(9140));
83 const GeoPoint middle(a.longitude.Fraction(b.longitude, fixed(0.5)),
84 a.latitude.Fraction(b.latitude, fixed(0.5)));
85 distance = ProjectedDistance(a, b, middle);
86 ok1(distance > fixed(9100/2) && distance < fixed(9140/2));
88 fixed big_distance = Distance(a, c);
89 ok1(big_distance > fixed(494000) && big_distance < fixed(495000));
91 TestLinearDistance();
93 return exit_status();