File tree 1 file changed +9
-4
lines changed
common/autoware_universe_utils/test/src/math
1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change 18
18
#include < gtest/gtest.h>
19
19
20
20
#include < cmath>
21
+ #include < random>
21
22
22
23
TEST (trigonometry, sin)
23
24
{
@@ -60,11 +61,15 @@ float normalize_angle(double angle)
60
61
61
62
TEST (trigonometry, opencv_fast_atan2)
62
63
{
64
+ std::random_device rd;
65
+ std::mt19937 gen (rd ());
66
+
67
+ // Generate random x and y between -10.0 and 10.0 as float
68
+ std::uniform_real_distribution<float > dis (-10 .0f , 10 .0f );
69
+
63
70
for (int i = 0 ; i < 100 ; ++i) {
64
- // Generate random x and y between -10 and 10
65
- std::srand (0 );
66
- float x = static_cast <float >(std::rand ()) / RAND_MAX * 20.0 - 10.0 ;
67
- float y = static_cast <float >(std::rand ()) / RAND_MAX * 20.0 - 10.0 ;
71
+ const float x = dis (gen);
72
+ const float y = dis (gen);
68
73
69
74
float fast_atan = autoware::universe_utils::opencv_fast_atan2 (y, x);
70
75
float std_atan = normalize_angle (std::atan2 (y, x));
You can’t perform that action at this time.
0 commit comments