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
)
31 FlatPoint
p1(fixed_one
, fixed_one
);
32 FlatPoint
p2(fixed_one
, fixed_two
);
33 FlatPoint
p3(fixed(3), fixed_ten
);
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));
56 ok1(equals(p2
.y
, 13));
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)));
66 ok1(equals(p2
.y
, 13));
69 ok1(equals(p2
.d(p3
), 3));
70 ok1(equals(p3
.d(p2
), 3));
73 ok1(equals(p1
.mag_sq(), 2));
74 ok1(equals(p2
.mag_sq(), 178));
75 ok1(equals(p3
.mag_sq(), 109));
78 ok1(equals(p1
.mag(), 1.4142135623730950488016887242097));
79 ok1(equals(p2
.mag(), 13.341664064126333712489436272508));
80 ok1(equals(p3
.mag(), 10.440306508910550179757754022548));
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));
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));
102 p2
= p3
* fixed(1.5);
103 ok1(equals(p2
.x
, 4.5));
104 ok1(equals(p2
.y
, 15));
108 ok1(equals(p2
.x
, 4));
109 ok1(equals(p2
.y
, 11));
113 ok1(equals(p2
.x
, 5));
114 ok1(equals(p2
.y
, 12));
118 ok1(equals(p2
.x
, 2));
119 ok1(equals(p2
.y
, 9));
121 return exit_status();