MRPT  2.0.2
TPoseOrPoint_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <CTraitsTest.h>
11 #include <gtest/gtest.h>
12 #include <mrpt/math/TPoint2D.h>
13 #include <mrpt/math/TPoint3D.h>
14 #include <mrpt/math/TPose2D.h>
15 #include <mrpt/math/TPose3D.h>
16 #include <mrpt/math/TPose3DQuat.h>
17 #include <mrpt/math/TSegment2D.h>
18 
19 using namespace mrpt;
20 using namespace mrpt::math;
21 using namespace std;
22 
23 template class mrpt::CTraitsTest<mrpt::math::TPoint2D>;
24 template class mrpt::CTraitsTest<mrpt::math::TPoint3D>;
25 template class mrpt::CTraitsTest<mrpt::math::TPoint3Df>;
26 template class mrpt::CTraitsTest<mrpt::math::TPose2D>;
27 template class mrpt::CTraitsTest<mrpt::math::TPose3D>;
28 template class mrpt::CTraitsTest<mrpt::math::TPose3DQuat>;
29 
30 TEST(LightGeomData, PragmaPack)
31 {
32  {
33  TPoint2D p;
34  EXPECT_TRUE(&p.x == &(p[0]));
35  EXPECT_TRUE(&p.y == &(p[1]));
36  }
37  {
38  TPoint3D p;
39  EXPECT_TRUE(&p.x == &(p[0]));
40  EXPECT_TRUE(&p.y == &(p[1]));
41  EXPECT_TRUE(&p.z == &(p[2]));
42  }
43  {
44  TPose2D p;
45  EXPECT_TRUE(&p.x == &(p[0]));
46  EXPECT_TRUE(&p.y == &(p[1]));
47  EXPECT_TRUE(&p.phi == &(p[2]));
48  }
49  {
50  TPose3D p;
51  EXPECT_TRUE(&p.x == &(p[0]));
52  EXPECT_TRUE(&p.y == &(p[1]));
53  EXPECT_TRUE(&p.z == &(p[2]));
54  EXPECT_TRUE(&p.yaw == &(p[3]));
55  EXPECT_TRUE(&p.pitch == &(p[4]));
56  EXPECT_TRUE(&p.roll == &(p[5]));
57  }
58  {
59  TSegment2D s;
60  EXPECT_TRUE(&s.point1 == &(s[0]));
61  EXPECT_TRUE(&s.point2 == &(s[1]));
62  }
63 }
64 
65 TEST(LightGeomData, ConstExprCtors)
66 {
67  {
68  const TPoint2D p(1.0, 2.0);
69  EXPECT_EQ(p.x, 1.0);
70  EXPECT_EQ(p.y, 2.0);
71  }
72  {
73  constexpr TPoint2D p(1.0, 2.0);
74  static_assert(p.x == 1.0, "p.x == 1.0");
75  static_assert(p.y == 2.0, "p.y == 2.0");
76  static_assert(p[0] == 1.0, "p[0] == 1.0");
77  static_assert(p[1] == 2.0, "p[1] == 2.0");
78  }
79  {
80  constexpr TPoint3D p(1.0, 2.0, 3.0);
81  static_assert(p.x == 1.0, "p.x == 1.0");
82  static_assert(p.y == 2.0, "p.y == 2.0");
83  static_assert(p.z == 3.0, "p.z == 3.0");
84  static_assert(p[0] == 1.0, "p[0] == 1.0");
85  static_assert(p[1] == 2.0, "p[1] == 2.0");
86  static_assert(p[2] == 3.0, "p[2] == 3.0");
87  }
88  {
89  constexpr TPose3D p(1.0, 2.0, 3.0, 0.1, 0.2, 0.3);
90  static_assert(p.x == 1.0, "p.x == 1.0");
91  static_assert(p.y == 2.0, "p.y == 2.0");
92  static_assert(p.z == 3.0, "p.z == 3.0");
93  }
94  {
95  constexpr TPoint2D p1(4.0, 6.0);
96  constexpr TPoint2D p2(2.0, 2.0);
97  constexpr TPoint2D p_add = p1 + p2;
98  constexpr TPoint2D p_sub = p1 - p2;
99  constexpr TPoint2D p_mul = p1 * 2;
100  constexpr TPoint2D p_div = p1 / 2;
101 
102  static_assert(p_add.x == 6.0, "p_add.x == 6.0");
103  static_assert(p_add.y == 8.0, "p_add.y == 8.0");
104 
105  static_assert(p_sub.x == 2.0, "p_sub.x == 2.0");
106  static_assert(p_sub.y == 4.0, "p_sub.y == 4.0");
107 
108  static_assert(p_mul.x == 8.0, "p_mul.x == 8.0");
109  static_assert(p_mul.y == 12.0, "p_mul.y == 12.0");
110 
111  static_assert(p_div.x == 2.0, "p_div.x == 2.0");
112  static_assert(p_div.y == 3.0, "p_div.y == 3.0");
113  }
114 }
115 
116 TEST(LightGeomData, Conversions)
117 {
118  {
119  TPose3D p1{1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
120  TPoint2D p2(p1);
121  EXPECT_EQ(p2.x, 1);
122  EXPECT_EQ(p2.y, 2);
123  }
124  {
125  TPoint3D p1{1.0, 2.0, 3.0};
126  TPose2D p2(p1);
127  EXPECT_EQ(p2.x, 1.0);
128  EXPECT_EQ(p2.y, 2.0);
129  EXPECT_EQ(p2.phi, 0.0);
130  }
131 }
132 
133 TEST(LightGeomData, Comparisons)
134 {
135  {
136  TPoint2D p1{1, 1};
137  TPoint2D p2{1, 1};
138  EXPECT_FALSE(p1 < p2);
139  }
140  {
141  TPoint2D p1{1, 1};
142  TPoint2D p2{2, 2};
143  EXPECT_TRUE(p1 < p2);
144  EXPECT_FALSE(p2 < p1);
145  }
146 }
147 
148 TEST(LightGeomData, Strings)
149 {
150  {
151  TPose2D p{1, 2, M_PI};
152  std::string s;
153  p.asString(s);
154  // note this is printed in degrees
155  EXPECT_EQ(s, "[1.000000 2.000000 180.000000]");
156  }
157  {
158  TPose2D p;
159  p.fromString("[1 2 180]");
160  EXPECT_DOUBLE_EQ(p.x, 1);
161  EXPECT_DOUBLE_EQ(p.y, 2);
162  EXPECT_DOUBLE_EQ(p.phi, M_PI);
163  }
164 }
TEST(LightGeomData, PragmaPack)
EXPECT_TRUE(mrpt::system::fileExists(ini_fil))
double x
X,Y coordinates.
Definition: TPose2D.h:30
T x
X,Y coordinates.
Definition: TPoint2D.h:25
double roll
Roll coordinate (rotation angle over X coordinate).
Definition: TPose3D.h:38
double x
X,Y,Z, coords.
Definition: TPose3D.h:32
STL namespace.
double yaw
Yaw coordinate (rotation angle over Z axis).
Definition: TPose3D.h:34
void fromString(const std::string &s)
Set the current object value from a string generated by &#39;asString&#39; (eg: "[0.02 1.04 -45...
Definition: TPose2D.cpp:28
This base provides a set of functions for maths stuff.
2D segment, consisting of two points.
Definition: TSegment2D.h:20
TPoint2D point2
Destiny point.
Definition: TSegment2D.h:30
double pitch
Pitch coordinate (rotation angle over Y axis).
Definition: TPose3D.h:36
TPoint2D point1
Origin point.
Definition: TSegment2D.h:26
T x
X,Y,Z coordinates.
Definition: TPoint3D.h:29
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
Definition: TPose3D.h:24
Lightweight 2D pose.
Definition: TPose2D.h:22
double phi
Orientation (rads)
Definition: TPose2D.h:32



Page generated by Doxygen 1.8.14 for MRPT 2.0.2 Git: 9b4fd2465 Mon May 4 16:59:08 2020 +0200 at lun may 4 17:26:07 CEST 2020