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/FlatPoint.hpp"
24 #include "Math/Angle.hpp"
25 #include "TestUtil.hpp"
27 int main(int argc
, char **argv
)
31 FlatPoint
p1(fixed(1), fixed(1));
32 FlatPoint
p2(fixed(1), fixed(2));
33 FlatPoint
p3(fixed(3), fixed(10));
36 ok1(equals(p1
.CrossProduct(p2
), 1));
37 ok1(equals(p2
.CrossProduct(p1
), -1));
38 ok1(equals(p1
.CrossProduct(p3
), 7));
39 ok1(equals(p3
.CrossProduct(p1
), -7));
40 ok1(equals(p2
.CrossProduct(p3
), 4));
41 ok1(equals(p3
.CrossProduct(p2
), -4));
44 p2
.MultiplyY(fixed(2));
56 ok1(equals(p2
.y
, 13));
59 p2
.Rotate(Angle::Degrees(-90));
60 ok1(equals(p2
.x
, 13));
61 ok1(equals(p2
.y
, -3));
63 p2
.Rotate(Angle::Degrees(45));
64 p2
.Rotate(Angle::Degrees(45));
66 ok1(equals(p2
.y
, 13));
69 ok1(equals(p2
.Distance(p3
), 3));
70 ok1(equals(p3
.Distance(p2
), 3));
73 ok1(equals(p1
.MagnitudeSquared(), 2));
74 ok1(equals(p2
.MagnitudeSquared(), 178));
75 ok1(equals(p3
.MagnitudeSquared(), 109));
78 ok1(equals(p1
.Magnitude(), 1.4142135623730950488016887242097));
79 ok1(equals(p2
.Magnitude(), 13.341664064126333712489436272508));
80 ok1(equals(p3
.Magnitude(), 10.440306508910550179757754022548));
83 ok1(equals(p1
.DotProduct(p2
), 16));
84 ok1(equals(p2
.DotProduct(p1
), 16));
85 ok1(equals(p1
.DotProduct(p3
), 13));
86 ok1(equals(p3
.DotProduct(p1
), 13));
87 ok1(equals(p2
.DotProduct(p3
), 139));
88 ok1(equals(p3
.DotProduct(p2
), 139));
95 // Test #2 fails due to floating point inaccuracies
96 ok1(p1 == FlatPoint(fixed(1), fixed(1)));
97 ok1(p2 == FlatPoint(fixed(3), fixed(13)));
98 ok1(p3 == FlatPoint(fixed(3), fixed(10)));
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();