mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
geo_test.cpp
Go to the documentation of this file.
1/** \file geo_test.cpp
2 * \brief Tests angular geometry utilities.
3 */
4#include "../../catch2/catch.hpp"
5
6#include <Eigen/Dense>
7
8#define MX_NO_ERROR_REPORTS
9
11
12/** \cond */
13/// Emit the exact float conversion specialization for LCOV accounting.
14template float mx::math::dtor<float>( float );
15/** \endcond */
16
17/** \brief Verifies the float specialization of mx::math::dtor converts degrees to radians.
18 *
19 * \ingroup geo_unit_tests
20 */
21TEST_CASE( "math::dtor converts float degrees to radians", "[math::dtor]" )
22{
23 REQUIRE( mx::math::dtor( 180.0F ) == Approx( mx::math::pi<float>() ) );
24}
25
26/** Verify compilation and calculations of math::angleMod.
27 * Tests that various angle modulos are calculated correctly for both radians and degrees.
28 *
29 */
30/**
31 * \ingroup geo_unit_tests
32 */
33TEST_CASE( "Verify compilation and calculations of math::angleMod", "[math::angleMod]" )
34{
35 GIVEN( "angles in degrees" )
36 {
37 WHEN( "positive angle, no changes" )
38 {
40
41 REQUIRE_THAT( q, Catch::Matchers::WithinRel( 43.2 ) );
42 }
43
44 WHEN( "positive angle, no changes" )
45 {
47
48 REQUIRE_THAT( q, Catch::Matchers::WithinRel( 353.2 ) );
49 }
50
51 WHEN( "positive angle, exactly 360" )
52 {
54
55 REQUIRE_THAT( q, Catch::Matchers::WithinRel( 0.0 ) );
56 }
57
58 WHEN( "positive angle, mod needed" )
59 {
61
62 REQUIRE_THAT( q, Catch::Matchers::WithinRel( 2.0 ) );
63 }
64
65 WHEN( "negative angle, mod needed" )
66 {
68
69 REQUIRE_THAT( q, Catch::Matchers::WithinRel( 358.0 ) );
70 }
71 }
72
73 GIVEN( "angles in radians" )
74 {
75 WHEN( "positive angle, no changes" )
76 {
78
79 REQUIRE_THAT( q, Catch::Matchers::WithinRel( mx::math::dtor( 43.2 ) ) );
80 }
81
82 WHEN( "positive angle, no changes" )
83 {
85
86 REQUIRE_THAT( q, Catch::Matchers::WithinRel( mx::math::dtor( 353.2 ) ) );
87 }
88
89 WHEN( "positive angle, exactly 2pi" )
90 {
92
93 REQUIRE_THAT( q, Catch::Matchers::WithinRel( mx::math::dtor( 0.0 ) ) );
94 }
95
96 WHEN( "positive angle, mod needed" )
97 {
99
100 REQUIRE_THAT( q, Catch::Matchers::WithinRel( mx::math::dtor( 2.0 ) ) );
101 }
102 }
103}
104
105/** Verify compilation and calculations of math::angleDiff.
106 * Tests that various angle differences are calculated correctly for both radians and degrees.
107 *
108 */
109/**
110 * \ingroup geo_unit_tests
111 */
112TEST_CASE( "Verify compilation and calculations of math::angleDiff", "[math::angleDiff]" )
113{
114 GIVEN( "angles in degrees" )
115 {
116 WHEN( "positive, first angle is 0, not crossing 180/360" )
117 {
118 double q = mx::math::angleDiff<mx::math::degreesT<double>>( 0.0, 43.2 );
119
120 REQUIRE_THAT( q, Catch::Matchers::WithinRel( 43.2 ) );
121 }
122
123 WHEN( "negative, second angle is 0, not crossing 180/360" )
124 {
125 double q = mx::math::angleDiff<mx::math::degreesT<double>>( 43.2, 0.0 );
126
127 REQUIRE_THAT( q, Catch::Matchers::WithinRel( -43.2 ) );
128 }
129
130 WHEN( "positive, first angle is 360, not crossing 180/360" )
131 {
132 double q = mx::math::angleDiff<mx::math::degreesT<double>>( 360.0, 43.2 );
133
134 REQUIRE_THAT( q, Catch::Matchers::WithinRel( 43.2 ) );
135 }
136
137 WHEN( "negative, second angle is 3600, not crossing 180/360" )
138 {
139 double q = mx::math::angleDiff<mx::math::degreesT<double>>( 43.2, 360.0 );
140
141 REQUIRE_THAT( q, Catch::Matchers::WithinRel( -43.2 ) );
142 }
143
144 WHEN( "positive, crossing 360" )
145 {
146 double q = mx::math::angleDiff<mx::math::degreesT<double>>( 340.0, 23.2 );
147
148 REQUIRE_THAT( q, Catch::Matchers::WithinRel( 43.2 ) );
149 }
150
151 WHEN( "negative, crossing 180/360" )
152 {
153 double q = mx::math::angleDiff<mx::math::degreesT<double>>( 23.2, 340.0 );
154
155 REQUIRE_THAT( q, Catch::Matchers::WithinRel( -43.2 ) );
156 }
157
158 WHEN( "positive, crossing 180" )
159 {
160 double q = mx::math::angleDiff<mx::math::degreesT<double>>( 160.0, 206.2 );
161
162 REQUIRE_THAT( q, Catch::Matchers::WithinRel( 46.2 ) );
163 }
164
165 WHEN( "negative, crossing 180" )
166 {
167 double q = mx::math::angleDiff<mx::math::degreesT<double>>( 206.2, 160.0 );
168
169 REQUIRE_THAT( q, Catch::Matchers::WithinRel( -46.2 ) );
170 }
171 }
172
173 GIVEN( "angles in radians" )
174 {
175 WHEN( "positive, first angle is 0, not crossing pi/2pi" )
176 {
178 mx::math::dtor<double>( 43.2 ) );
179
180 REQUIRE_THAT( q, Catch::Matchers::WithinRel( mx::math::dtor<double>( 43.2 ) ) );
181 }
182
183 WHEN( "negative, second angle is 0, not crossing pi/2pi" )
184 {
186 mx::math::dtor<double>( 0.0 ) );
187
188 REQUIRE_THAT( q, Catch::Matchers::WithinRel( mx::math::dtor<double>( -43.2 ) ) );
189 }
190
191 WHEN( "positive, first angle is 360, not crossing pi/2pi" )
192 {
194 mx::math::dtor<double>( 43.2 ) );
195
196 REQUIRE_THAT( q, Catch::Matchers::WithinRel( mx::math::dtor<double>( 43.2 ) ) );
197 }
198
199 WHEN( "negative, second angle is 3600, not crossing pi/2pi" )
200 {
202 mx::math::dtor<double>( 360.0 ) );
203
204 REQUIRE_THAT( q, Catch::Matchers::WithinRel( mx::math::dtor<double>( -43.2 ) ) );
205 }
206
207 WHEN( "positive, crossing 2pi" )
208 {
210 mx::math::dtor<double>( 23.2 ) );
211
212 REQUIRE_THAT( q, Catch::Matchers::WithinRel( mx::math::dtor<double>( 43.2 ) ) );
213 }
214
215 WHEN( "negative, crossing 2pi" )
216 {
218 mx::math::dtor<double>( 340.0 ) );
219
220 REQUIRE_THAT( q, Catch::Matchers::WithinRel( mx::math::dtor<double>( -43.2 ) ) );
221 }
222
223 WHEN( "positive, crossing pi" )
224 {
226 mx::math::dtor<double>( 206.2 ) );
227
228 REQUIRE_THAT( q, Catch::Matchers::WithinRel( mx::math::dtor<double>( 46.2 ) ) );
229 }
230
231 WHEN( "negative, crossing pi" )
232 {
234 mx::math::dtor<double>( 160.0 ) );
235
236 REQUIRE_THAT( q, Catch::Matchers::WithinRel( mx::math::dtor<double>( -46.2 ) ) );
237 }
238 }
239}
Utilities for working with angles.
constexpr T pi()
Get the value of pi.
Definition constants.hpp:62
TEST_CASE("math::dtor converts float degrees to radians", "[math::dtor]")
Verifies the float specialization of mx::math::dtor converts degrees to radians.
Definition geo_test.cpp:21
angleT::realT angleDiff(typename angleT::realT q1, typename angleT::realT q2)
Calculate the difference between two angles, correctly across 0/360.
Definition geo.hpp:191
angleT::realT angleMod(typename angleT::realT q)
Calculate the angle modulo full-circle, normalizing to a positive value.
Definition geo.hpp:164
realT dtor(realT q)
Convert from degrees to radians.
Definition geo.hpp:133