Debian Codegraph @

test_suite/unit_tests/AI/test_VectorMath.cxx

raw symbols SCIP
1 /*
2 * Copyright (C) 2022 Keith Paterson
3 *
4 * This file is part of the program FlightGear.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "test_VectorMath.hxx"
21
22 #include <cstring>
23 #include <memory>
24
25 #include <cppunit/TestAssert.h>
26
27 #include "config.h"
28 #include "test_suite/FGTestApi/testGlobals.hxx"
29
30 #include <AIModel/VectorMath.hxx>
31
32 using namespace flightgear;
33
34 // Set up function for each test.
35 void VectorMathTests::setUp()
36 {
37 }
38
39 // Clean up after each test.
40 void VectorMathTests::tearDown()
41 {
42 }
43
44 void VectorMathTests::testInnerTanget()
45 {
46 double r1 = 10;
47 double r2 = 10;
48 // when the circles are dist appart the angle will be 45°
49 double dist = 2 * r1 + 2 * r2;
50 SGGeod m1 = SGGeod::fromDeg(9,51);
51 SGGeod m2 = SGGeodesy::direct(m1, 90, dist);
52
53 auto angles = VectorMath::innerTangentsAngle(m1, m2, r1, r2);
54 CPPUNIT_ASSERT_DOUBLES_EQUAL( 60, angles[0], 0.1);
55 CPPUNIT_ASSERT_DOUBLES_EQUAL( 120, angles[1], 0.1);
56 }
57
58 void VectorMathTests::testInnerTangent2()
59 {
60 double r1 = 10;
61 double r2 = 10;
62 // when the circles are dist appart the angle will be 45°
63 double dist = 2 * r1 + 2 * r2;
64 SGGeod m1 = SGGeod::fromDeg(9,51);
65 SGGeod m2 = SGGeodesy::direct(m1, 0, dist);
66
67 auto angles = VectorMath::innerTangentsAngle(m1, m2, r1, r2);
68 CPPUNIT_ASSERT_DOUBLES_EQUAL( 330, angles[0], 0.1);
69 CPPUNIT_ASSERT_DOUBLES_EQUAL( 30, angles[1], 0.1);
70 }
71
72 void VectorMathTests::testOuterTanget()
73 {
74 double r1 = 10;
75 double r2 = 50;
76 // when the circles are dist appart the angle will be 45°
77 double dist = 40;
78 SGGeod m1 = SGGeod::fromDeg(9,51);
79 SGGeod m2 = SGGeodesy::direct(m1, 90, dist);
80
81 auto angles = VectorMath::outerTangentsAngle(m1, m2, r1, r2);
82 CPPUNIT_ASSERT_DOUBLES_EQUAL( 45, angles[0], 0.1);
83 CPPUNIT_ASSERT_DOUBLES_EQUAL( 135, angles[1], 0.1);
84 }