DeviceBlackboard.cpp: Refactoring of Heading()
[xcsoar.git] / test / src / TestFlatPoint.cpp
blob4744d790c3697e04332179acf3e990a94b6e5593
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2010 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 "Engine/Navigation/Flat/FlatPoint.hpp"
24 #include "Math/Angle.hpp"
25 #include "TestUtil.hpp"
27 int main(int argc, char **argv)
29 plan_tests(41);
31 FlatPoint p1(fixed_one, fixed_one);
32 FlatPoint p2(fixed_one, fixed_two);
33 FlatPoint p3(fixed(3), fixed_ten);
35 // test cross()
36 ok1(equals(p1.cross(p2), 1));
37 ok1(equals(p2.cross(p1), -1));
38 ok1(equals(p1.cross(p3), 7));
39 ok1(equals(p3.cross(p1), -7));
40 ok1(equals(p2.cross(p3), 4));
41 ok1(equals(p3.cross(p2), -4));
43 // test mul_y()
44 p2.mul_y(fixed_two);
45 ok1(equals(p2.x, 1));
46 ok1(equals(p2.y, 4));
48 // test sub()
49 p2.sub(p1);
50 ok1(equals(p2.x, 0));
51 ok1(equals(p2.y, 3));
53 // test add()
54 p2.add(p3);
55 ok1(equals(p2.x, 3));
56 ok1(equals(p2.y, 13));
58 // test rotate()
59 p2.rotate(Angle::degrees(fixed(-90)));
60 ok1(equals(p2.x, 13));
61 ok1(equals(p2.y, -3));
63 p2.rotate(Angle::degrees(fixed(45)));
64 p2.rotate(Angle::degrees(fixed(45)));
65 ok1(equals(p2.x, 3));
66 ok1(equals(p2.y, 13));
68 // test d()
69 ok1(equals(p2.d(p3), 3));
70 ok1(equals(p3.d(p2), 3));
72 // test mag_sq()
73 ok1(equals(p1.mag_sq(), 2));
74 ok1(equals(p2.mag_sq(), 178));
75 ok1(equals(p3.mag_sq(), 109));
77 // test mag()
78 ok1(equals(p1.mag(), 1.4142135623730950488016887242097));
79 ok1(equals(p2.mag(), 13.341664064126333712489436272508));
80 ok1(equals(p3.mag(), 10.440306508910550179757754022548));
82 // test dot()
83 ok1(equals(p1.dot(p2), 16));
84 ok1(equals(p2.dot(p1), 16));
85 ok1(equals(p1.dot(p3), 13));
86 ok1(equals(p3.dot(p1), 13));
87 ok1(equals(p2.dot(p3), 139));
88 ok1(equals(p3.dot(p2), 139));
90 // test ==
91 ok1(p1 == p1);
92 ok1(p2 == p2);
93 ok1(p3 == p3);
95 // Test #2 fails due to floating point inaccuracies
96 ok1(p1 == FlatPoint(fixed_one, fixed_one));
97 ok1(p2 == FlatPoint(fixed(3), fixed(13)));
98 ok1(p3 == FlatPoint(fixed(3), fixed_ten));
101 // test *
102 p2 = p3 * fixed(1.5);
103 ok1(equals(p2.x, 4.5));
104 ok1(equals(p2.y, 15));
106 // test +
107 p2 = p1 + p3;
108 ok1(equals(p2.x, 4));
109 ok1(equals(p2.y, 11));
111 // test +=
112 p2 += p1;
113 ok1(equals(p2.x, 5));
114 ok1(equals(p2.y, 12));
116 // test -
117 p2 = p3 - p1;
118 ok1(equals(p2.x, 2));
119 ok1(equals(p2.y, 9));
121 return exit_status();