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
)
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
44 ok1(equals(av
.y
, 1.5));
47 ok1(equals(av
.y
, 5.5));
53 ok1(equals(l1
.angle(), 90));
54 ok1(equals(l2
.angle(), 77.47119229084848923132012643871));
55 ok1(equals(l3
.angle(), 75.963756532073521417107679840837));
58 ok1(equals(l1
.dsq(), 1));
59 ok1(equals(l2
.dsq(), 85));
60 ok1(equals(l3
.dsq(), 68));
63 ok1(equals(l1
.d(), 1));
64 ok1(equals(l2
.d(), 9.2195444572928873100022742817628));
65 ok1(equals(l3
.d(), 8.2462112512353210996428197119482));
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()
77 ok1(!l1
.intersect_czero(fixed(0.9), i1
, i2
));
79 ok1(l1
.intersect_czero(fixed(1.8027756377319946465596106337352), i1
, i2
));
81 ok1(equals(i1
.y
, 1.5));
83 ok1(equals(i2
.y
, -1.5));
85 ok1(l2
.intersect_czero(fixed(5.8523499553598125545510491371143), i1
, i2
));
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
));
95 ok1(equals(i1
.y
, 1.75));
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();