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);
77 TEST(Angles, shortestDistanceWithLargeLimits)
79 double shortest_angle;
85 EXPECT_NEAR(shortest_angle, 0.5*M_PI, 1e-6);
90 EXPECT_NEAR(shortest_angle, -1.5*M_PI, 1e-6);
102 EXPECT_FALSE(result);
107 EXPECT_NEAR(shortest_angle, 0.000493, 1e-6);
113 double epsilon = 1e-9;
129 double epsilon = 1e-9;
133 EXPECT_NEAR(
to_degrees(M_PI*3/2), 270, epsilon);
134 EXPECT_NEAR(
to_degrees(2*M_PI), 360, epsilon);
136 EXPECT_NEAR(
to_degrees(M_PI*2/3), 120, epsilon);
138 EXPECT_NEAR(
to_degrees(M_PI*3/4), 135, epsilon);
144 double epsilon = 1e-9;
174 double epsilon = 1e-9;
203 double epsilon = 1e-9;
226 double epsilon = 1e-9;
247 double epsilon = 1e-9;
248 double min_delta, max_delta;
251 EXPECT_NEAR(min_delta, -M_PI, epsilon);
252 EXPECT_NEAR(max_delta, M_PI, epsilon);
256 EXPECT_NEAR(min_delta, -3*M_PI/2, epsilon);
257 EXPECT_NEAR(max_delta, M_PI/2, epsilon);
261 EXPECT_NEAR(min_delta, -M_PI/2, epsilon);
262 EXPECT_NEAR(max_delta, 3*M_PI/2, epsilon);
266 EXPECT_NEAR(min_delta, -M_PI/2, epsilon);
267 EXPECT_NEAR(max_delta, M_PI/2, epsilon);
271 EXPECT_NEAR(min_delta, -3*M_PI/4, epsilon);
272 EXPECT_NEAR(max_delta, M_PI/4, epsilon);
276 EXPECT_NEAR(min_delta, -M_PI/4, epsilon);
277 EXPECT_NEAR(max_delta, 3*M_PI/4, epsilon);
281 EXPECT_TRUE((fabs(min_delta) <= epsilon && fabs(max_delta - 2*M_PI) <= epsilon) || (fabs(min_delta+2*M_PI) <= epsilon && fabs(max_delta) <= epsilon));
282 EXPECT_NEAR(min_delta, 0.0, epsilon);
283 EXPECT_NEAR(max_delta, 2*M_PI, epsilon);
286 EXPECT_NEAR(min_delta, -2*M_PI+0.5, epsilon);
287 EXPECT_NEAR(max_delta, 0.0, epsilon);
292 EXPECT_NEAR(min_delta, -2*M_PI+epsilon, epsilon);
293 EXPECT_NEAR(max_delta, epsilon, epsilon);
297 EXPECT_NEAR(min_delta, 0, epsilon);
298 EXPECT_NEAR(max_delta, 2*M_PI, epsilon);
302 EXPECT_NEAR(min_delta, 0.0, epsilon);
303 EXPECT_NEAR(max_delta, M_PI, epsilon);
314 EXPECT_NEAR(min_delta, -M_PI/4, epsilon);
315 EXPECT_NEAR(max_delta, 3*M_PI/4, epsilon);
320 int main(
int argc,
char **argv){
321 testing::InitGoogleTest(&argc, argv);
322 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 bool shortest_angular_distance_with_large_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 le...
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".