MRPT  1.9.9
CAtan2LookUpTable_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
11 #include <mrpt/random.h>
12 #include <mrpt/core/bits_math.h> // DEG2RAD
13 #include <gtest/gtest.h>
14 #include <cmath>
15 
16 template <class LUT_CLASS>
18  const LUT_CLASS& atan2lut, const double SIZE, const double max_deg_errors,
19  const double skip_area)
20 {
21  for (int i = 0; i < 1000; i++)
22  {
24  -.5 * SIZE, .5 * SIZE);
26  -.5 * SIZE, .5 * SIZE);
27 
28  // Avoid the central part, where accuracy is worse
29  if (std::abs(x) < skip_area || std::abs(y) < skip_area) continue;
30 
31  const double atan2_good = ::atan2(y, x);
32  double atan2_lut;
33  bool atan2_lut_valid = atan2lut.atan2(y, x, atan2_lut);
34 
35  EXPECT_TRUE(atan2_lut_valid);
36  EXPECT_LT(
37  std::abs(atan2_good - atan2_lut), mrpt::DEG2RAD(max_deg_errors))
38  << "(x,y): (" << x << " , " << y << ")"
39  << "\natan2_good:" << atan2_good << " atan2_lut:" << atan2_lut
40  << std::endl;
41  }
42 }
43 
44 TEST(CAtan2LookUpTable, ValidValidTest)
45 {
46  const double SIZE = 20.0;
47  const double RES = 0.10;
49  -.5 * SIZE, .5 * SIZE, -.5 * SIZE, .5 * SIZE, RES);
50  atan2_lut_test(atan2lut, SIZE, 1.5 /*max error*/, 2.0 /* skip zone */);
51 }
52 
53 TEST(CAtan2LookUpTable, MultiResTest)
54 {
55  const double SIZE = 20.0;
57 
58  std::map<double, double> res2extension;
59  res2extension[0.001] = 0.8; // 0.1 cm resolution
60  res2extension[0.01] = 2.0; // 1.0 cm resolution
61  res2extension[0.02] = 5.0; // 2.0 cm resolution
62  res2extension[0.05] = 11.0; // 5.0 cm resolution
63  atan2lut.resize(res2extension);
64 
65  atan2_lut_test(atan2lut, SIZE, 0.5 /*max error*/, 0.4 /* skip zone */);
66 }
double drawUniform(const double Min, const double Max)
Generate a uniformly distributed pseudo-random number using the MT19937 algorithm, scaled to the selected range.
double DEG2RAD(const double x)
Degrees to radians.
TEST(CAtan2LookUpTable, ValidValidTest)
void resize(const std::map< double, double > &lst_resolutions2extensions) noexcept
See CAtan2LookUpTableMultiRes for a discussion of the parameters.
A look-up-table (LUT) of atan values for any (x,y) value in a square/rectangular grid of predefined r...
Like CAtan2LookUpTable but with a multiresolution grid for increasingly better accuracy in points nea...
void atan2_lut_test(const LUT_CLASS &atan2lut, const double SIZE, const double max_deg_errors, const double skip_area)
GLenum GLint GLint y
Definition: glext.h:3538
GLenum GLint x
Definition: glext.h:3538
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020