Revert "Device/Driver/LX: Add small delay after baud rate change"
[xcsoar.git] / test / src / TestFlatLine.cpp
blobc47c82b7f571549693d0f1cc019c9f5a87ca811d
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/Flat/FlatLine.hpp"
24 #include "Geo/Flat/FlatPoint.hpp"
25 #include "Math/Angle.hpp"
26 #include "TestUtil.hpp"
28 int main(int argc, char **argv)
30 plan_tests(39);
32 FlatPoint p1(fixed(1), fixed(1));
33 FlatPoint p2(fixed(1), fixed(2));
34 FlatPoint p3(fixed(3), fixed(10));
36 FlatLine l1(p1, p2); // 0, 1
37 FlatLine l2(p1, p3); // 2, 9
38 FlatLine l3(p2, p3); // 2, 8
40 // test ave()
41 FlatPoint av;
42 av = l1.ave();
43 ok1(equals(av.x, 1));
44 ok1(equals(av.y, 1.5));
45 av = l2.ave();
46 ok1(equals(av.x, 2));
47 ok1(equals(av.y, 5.5));
48 av = l3.ave();
49 ok1(equals(av.x, 2));
50 ok1(equals(av.y, 6));
52 // test angle()
53 ok1(equals(l1.angle(), 90));
54 ok1(equals(l2.angle(), 77.47119229084848923132012643871));
55 ok1(equals(l3.angle(), 75.963756532073521417107679840837));
57 // test dsq()
58 ok1(equals(l1.dsq(), 1));
59 ok1(equals(l2.dsq(), 85));
60 ok1(equals(l3.dsq(), 68));
62 // test d()
63 ok1(equals(l1.d(), 1));
64 ok1(equals(l2.d(), 9.2195444572928873100022742817628));
65 ok1(equals(l3.d(), 8.2462112512353210996428197119482));
67 // test dot()
68 ok1(equals(l1.dot(l2), 9));
69 ok1(equals(l1.dot(l3), 8));
70 ok1(equals(l2.dot(l3), 76));
72 // sub(), add(), rotate() and mul_y() not directly testable right
73 // now because p1 and p2 are private
75 // test intersect_czero()
76 FlatPoint i1, i2;
77 ok1(!l1.intersect_czero(fixed(0.9), i1, i2));
79 ok1(l1.intersect_czero(fixed(1.8027756377319946465596106337352), i1, i2));
80 ok1(equals(i1.x, 1));
81 ok1(equals(i1.y, 1.5));
82 ok1(equals(i2.x, 1));
83 ok1(equals(i2.y, -1.5));
85 ok1(l2.intersect_czero(fixed(5.8523499553598125545510491371143), i1, i2));
86 ok1(equals(i1.x, 2));
87 ok1(equals(i1.y, 5.5));
88 ok1(equals(i2.x, -0.517647));
89 ok1(equals(i2.y, -5.829411));
91 // test intersect_circle()
92 FlatPoint c(fixed(1), fixed(1.5));
93 ok1(l1.intersect_circle(fixed(0.25), c, i1, i2));
94 ok1(equals(i1.x, 1));
95 ok1(equals(i1.y, 1.75));
96 ok1(equals(i2.x, 1));
97 ok1(equals(i2.y, 1.25));
99 ok1(l1.intersect_circle(fixed(1), c, i1, i2));
100 ok1(equals(i1.x, 1));
101 ok1(equals(i1.y, 2.5));
102 ok1(equals(i2.x, 1));
103 ok1(equals(i2.y, 0.5));
105 return exit_status();