2 #include <gtest/gtest.h> 6 TEST(Angles, shortestDistanceWithLimits){
16 EXPECT_NEAR(shortest_angle, -2*M_PI+1.0,1e-6);
20 EXPECT_NEAR(shortest_angle, 0,1e-6);
24 EXPECT_NEAR(shortest_angle, -0.5,1e-6);
28 EXPECT_NEAR(shortest_angle, 0.5,1e-6);
32 EXPECT_NEAR(shortest_angle, -2*M_PI+0.4,1e-6);
36 EXPECT_NEAR(shortest_angle,2*M_PI-0.4,1e-6);
40 EXPECT_NEAR(shortest_angle,2*M_PI-0.2,1e-6);
44 EXPECT_NEAR(shortest_angle,-2*M_PI+0.2,1e-6);
48 EXPECT_NEAR(shortest_angle,-0.25,1e-6);
52 EXPECT_NEAR(shortest_angle,-2*M_PI+0.75,1e-6);
56 EXPECT_NEAR(shortest_angle,-2*M_PI+0.5+0.2500001,1e-6);
72 EXPECT_NEAR(shortest_angle,0.0,1e-6);
78 double epsilon = 1e-9;
94 double epsilon = 1e-9;
98 EXPECT_NEAR(
to_degrees(M_PI*3/2), 270, epsilon);
101 EXPECT_NEAR(
to_degrees(M_PI*2/3), 120, epsilon);
103 EXPECT_NEAR(
to_degrees(M_PI*3/4), 135, epsilon);
109 double epsilon = 1e-9;
139 double epsilon = 1e-9;
168 double epsilon = 1e-9;
191 double epsilon = 1e-9;
212 double epsilon = 1e-9;
213 double min_delta, max_delta;
216 EXPECT_NEAR(min_delta, -M_PI, epsilon);
217 EXPECT_NEAR(max_delta, M_PI, epsilon);
221 EXPECT_NEAR(min_delta, -3*M_PI/2, epsilon);
222 EXPECT_NEAR(max_delta, M_PI/2, epsilon);
226 EXPECT_NEAR(min_delta, -M_PI/2, epsilon);
227 EXPECT_NEAR(max_delta, 3*M_PI/2, epsilon);
231 EXPECT_NEAR(min_delta, -M_PI/2, epsilon);
232 EXPECT_NEAR(max_delta, M_PI/2, epsilon);
236 EXPECT_NEAR(min_delta, -3*M_PI/4, epsilon);
237 EXPECT_NEAR(max_delta, M_PI/4, epsilon);
241 EXPECT_NEAR(min_delta, -M_PI/4, epsilon);
242 EXPECT_NEAR(max_delta, 3*M_PI/4, epsilon);
246 EXPECT_TRUE((fabs(min_delta) <= epsilon && fabs(max_delta - 2*M_PI) <= epsilon) || (fabs(min_delta+2*M_PI) <= epsilon && fabs(max_delta) <= epsilon));
247 EXPECT_NEAR(min_delta, 0.0, epsilon);
248 EXPECT_NEAR(max_delta, 2*M_PI, epsilon);
251 EXPECT_NEAR(min_delta, -2*M_PI+0.5, epsilon);
252 EXPECT_NEAR(max_delta, 0.0, epsilon);
257 EXPECT_NEAR(min_delta, -2*M_PI+epsilon, epsilon);
258 EXPECT_NEAR(max_delta, epsilon, epsilon);
262 EXPECT_NEAR(min_delta, 0, epsilon);
263 EXPECT_NEAR(max_delta, 2*M_PI, epsilon);
267 EXPECT_NEAR(min_delta, 0.0, epsilon);
268 EXPECT_NEAR(max_delta, M_PI, epsilon);
279 EXPECT_NEAR(min_delta, -M_PI/4, epsilon);
280 EXPECT_NEAR(max_delta, 3*M_PI/4, epsilon);
285 int main(
int argc,
char **argv){
286 testing::InitGoogleTest(&argc, argv);
287 return RUN_ALL_TESTS();
static bool shortest_angular_distance_with_limits(double from, double to, double left_limit, double right_limit, double &shortest_angle)
Returns the delta from "from_angle" to "to_angle" making sure it does not violate limits specified by...
static double shortest_angular_distance(double from, double to)
shortest_angular_distance
static double normalize_angle(double angle)
normalize
static double normalize_angle_positive(double angle)
normalize_angle_positive
static double from_degrees(double degrees)
Convert degrees to radians.
int main(int argc, char **argv)
static double two_pi_complement(double angle)
returns the angle in [-2*M_PI, 2*M_PI] going the other way along the unit circle. ...
static double to_degrees(double radians)
Convert radians to degrees.
TEST(Angles, shortestDistanceWithLimits)
static bool find_min_max_delta(double from, double left_limit, double right_limit, double &result_min_delta, double &result_max_delta)
This function is only intended for internal use and not intended for external use. If you do use it, read the documentation very carefully. Returns the min and max amount (in radians) that can be moved from "from" angle to "left_limit" and "right_limit".