mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
geo_test.cpp
Go to the documentation of this file.
1 /** \file geo_test.cpp
2  */
3 #include "../../catch2/catch.hpp"
4 
5 #include <Eigen/Dense>
6 
7 #define MX_NO_ERROR_REPORTS
8 
9 #include "../../../include/math/geo.hpp"
10 
11 /** Verify compilation and calculations of math::angleMod.
12  * Tests that various angle modulos are calculated correctly for both radians and degrees.
13  *
14  * \anchor tests_math_geo_angleMod
15  */
16 SCENARIO( "Verify compilation and calculations of math::angleMod", "[math::angleMod]" )
17 {
18  GIVEN("angles in degrees")
19  {
20  WHEN("positive angle, no changes")
21  {
22  double q = mx::math::angleMod<mx::math::degreesT<double>>(43.2);
23 
24  REQUIRE_THAT(q, Catch::Matchers::WithinRel(43.2));
25  }
26 
27  WHEN("positive angle, no changes")
28  {
29  double q = mx::math::angleMod<mx::math::degreesT<double>>(353.2);
30 
31  REQUIRE_THAT(q, Catch::Matchers::WithinRel(353.2));
32  }
33 
34  WHEN("positive angle, exactly 360")
35  {
36  double q = mx::math::angleMod<mx::math::degreesT<double>>(360.0);
37 
38  REQUIRE_THAT(q, Catch::Matchers::WithinRel(0.0));
39  }
40 
41  WHEN("positive angle, mod needed")
42  {
43  double q = mx::math::angleMod<mx::math::degreesT<double>>(362.0);
44 
45  REQUIRE_THAT(q, Catch::Matchers::WithinRel(2.0));
46  }
47  }
48 
49  GIVEN("angles in radians")
50  {
51  WHEN("positive angle, no changes")
52  {
53  double q = mx::math::angleMod<mx::math::radiansT<double>>(mx::math::dtor(43.2));
54 
55  REQUIRE_THAT(q, Catch::Matchers::WithinRel(mx::math::dtor(43.2)));
56  }
57 
58  WHEN("positive angle, no changes")
59  {
60  double q = mx::math::angleMod<mx::math::radiansT<double>>(mx::math::dtor(353.2));
61 
62  REQUIRE_THAT(q, Catch::Matchers::WithinRel(mx::math::dtor(353.2)));
63  }
64 
65  WHEN("positive angle, exactly 2pi")
66  {
67  double q = mx::math::angleMod<mx::math::radiansT<double>>(mx::math::dtor(360.0));
68 
69  REQUIRE_THAT(q, Catch::Matchers::WithinRel(mx::math::dtor(0.0)));
70  }
71 
72  WHEN("positive angle, mod needed")
73  {
74  double q = mx::math::angleMod<mx::math::radiansT<double>>(mx::math::dtor(362.0));
75 
76  REQUIRE_THAT(q, Catch::Matchers::WithinRel(mx::math::dtor(2.0)));
77  }
78  }
79 }
80 
81 /** Verify compilation and calculations of math::angleDiff.
82  * Tests that various angle differences are calculated correctly for both radians and degrees.
83  *
84  * \anchor tests_math_geo_angleDiff
85  */
86 SCENARIO( "Verify compilation and calculations of math::angleDiff", "[math::angleDiff]" )
87 {
88  GIVEN("angles in degrees")
89  {
90  WHEN("positive, first angle is 0, not crossing 180/360")
91  {
92  double q = mx::math::angleDiff<mx::math::degreesT<double>>(0.0,43.2);
93 
94  REQUIRE_THAT(q, Catch::Matchers::WithinRel(43.2));
95  }
96 
97  WHEN("negative, second angle is 0, not crossing 180/360")
98  {
99  double q = mx::math::angleDiff<mx::math::degreesT<double>>(43.2,0.0);
100 
101  REQUIRE_THAT(q, Catch::Matchers::WithinRel(-43.2));
102  }
103 
104  WHEN("positive, first angle is 360, not crossing 180/360")
105  {
106  double q = mx::math::angleDiff<mx::math::degreesT<double>>(360.0,43.2);
107 
108  REQUIRE_THAT(q, Catch::Matchers::WithinRel(43.2));
109  }
110 
111  WHEN("negative, second angle is 3600, not crossing 180/360")
112  {
113  double q = mx::math::angleDiff<mx::math::degreesT<double>>(43.2,360.0);
114 
115  REQUIRE_THAT(q, Catch::Matchers::WithinRel(-43.2));
116  }
117 
118  WHEN("positive, crossing 360")
119  {
120  double q = mx::math::angleDiff<mx::math::degreesT<double>>(340.0,23.2);
121 
122  REQUIRE_THAT(q, Catch::Matchers::WithinRel(43.2));
123  }
124 
125  WHEN("negative, crossing 180/360")
126  {
127  double q = mx::math::angleDiff<mx::math::degreesT<double>>(23.2,340.0);
128 
129  REQUIRE_THAT(q, Catch::Matchers::WithinRel(-43.2));
130  }
131 
132  WHEN("positive, crossing 180")
133  {
134  double q = mx::math::angleDiff<mx::math::degreesT<double>>(160.0,206.2);
135 
136  REQUIRE_THAT(q, Catch::Matchers::WithinRel(46.2));
137  }
138 
139  WHEN("negative, crossing 180")
140  {
141  double q = mx::math::angleDiff<mx::math::degreesT<double>>(206.2,160.0);
142 
143  REQUIRE_THAT(q, Catch::Matchers::WithinRel(-46.2));
144  }
145  }
146 
147  GIVEN("angles in radians")
148  {
149  WHEN("positive, first angle is 0, not crossing pi/2pi")
150  {
151  double q = mx::math::angleDiff<mx::math::radiansT<double>>(mx::math::dtor<double>(0.0),mx::math::dtor<double>(43.2));
152 
153  REQUIRE_THAT(q, Catch::Matchers::WithinRel(mx::math::dtor<double>(43.2)));
154  }
155 
156  WHEN("negative, second angle is 0, not crossing pi/2pi")
157  {
158  double q = mx::math::angleDiff<mx::math::radiansT<double>>(mx::math::dtor<double>(43.2),mx::math::dtor<double>(0.0));
159 
160  REQUIRE_THAT(q, Catch::Matchers::WithinRel(mx::math::dtor<double>(-43.2)));
161  }
162 
163  WHEN("positive, first angle is 360, not crossing pi/2pi")
164  {
165  double q = mx::math::angleDiff<mx::math::radiansT<double>>(mx::math::dtor<double>(360.0),mx::math::dtor<double>(43.2));
166 
167  REQUIRE_THAT(q, Catch::Matchers::WithinRel(mx::math::dtor<double>(43.2)));
168  }
169 
170  WHEN("negative, second angle is 3600, not crossing pi/2pi")
171  {
172  double q = mx::math::angleDiff<mx::math::radiansT<double>>(mx::math::dtor<double>(43.2),mx::math::dtor<double>(360.0));
173 
174  REQUIRE_THAT(q, Catch::Matchers::WithinRel(mx::math::dtor<double>(-43.2)));
175  }
176 
177  WHEN("positive, crossing 2pi")
178  {
179  double q = mx::math::angleDiff<mx::math::radiansT<double>>(mx::math::dtor<double>(340.0),mx::math::dtor<double>(23.2));
180 
181  REQUIRE_THAT(q, Catch::Matchers::WithinRel(mx::math::dtor<double>(43.2)));
182  }
183 
184  WHEN("negative, crossing 2pi")
185  {
186  double q = mx::math::angleDiff<mx::math::radiansT<double>>(mx::math::dtor<double>(23.2),mx::math::dtor<double>(340.0));
187 
188  REQUIRE_THAT(q, Catch::Matchers::WithinRel(mx::math::dtor<double>(-43.2)));
189  }
190 
191  WHEN("positive, crossing pi")
192  {
193  double q = mx::math::angleDiff<mx::math::radiansT<double>>(mx::math::dtor<double>(160.0),mx::math::dtor<double>(206.2));
194 
195  REQUIRE_THAT(q, Catch::Matchers::WithinRel(mx::math::dtor<double>(46.2)));
196  }
197 
198  WHEN("negative, crossing pi")
199  {
200  double q = mx::math::angleDiff<mx::math::radiansT<double>>(mx::math::dtor<double>(206.2),mx::math::dtor<double>(160.0));
201 
202  REQUIRE_THAT(q, Catch::Matchers::WithinRel(mx::math::dtor<double>(-46.2)));
203  }
204  }
205 }
SCENARIO("Verify compilation and calculations of math::angleMod", "[math::angleMod]")
Definition: geo_test.cpp:16
realT dtor(realT q)
Convert from degrees to radians.
Definition: geo.hpp:132