Main MRPT website > C++ reference for MRPT 1.9.9
lightweight_geom_data_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 <CTraitsTest.h>
12 #include <gtest/gtest.h>
13 
14 using namespace mrpt;
15 using namespace mrpt::math;
16 using namespace std;
17 
18 template class mrpt::CTraitsTest<mrpt::math::TPoint2D>;
19 template class mrpt::CTraitsTest<mrpt::math::TPoint3D>;
20 template class mrpt::CTraitsTest<mrpt::math::TPoint3Df>;
21 template class mrpt::CTraitsTest<mrpt::math::TPose2D>;
22 template class mrpt::CTraitsTest<mrpt::math::TPose3D>;
23 template class mrpt::CTraitsTest<mrpt::math::TPose3DQuat>;
24 
25 TEST(LightGeomData, PragmaPack)
26 {
27  {
28  TPoint2D p;
29  EXPECT_TRUE(&p.x == &(p[0]));
30  EXPECT_TRUE(&p.y == &(p[1]));
31  }
32  {
33  TPoint3D p;
34  EXPECT_TRUE(&p.x == &(p[0]));
35  EXPECT_TRUE(&p.y == &(p[1]));
36  EXPECT_TRUE(&p.z == &(p[2]));
37  }
38  {
39  TPose2D p;
40  EXPECT_TRUE(&p.x == &(p[0]));
41  EXPECT_TRUE(&p.y == &(p[1]));
42  EXPECT_TRUE(&p.phi == &(p[2]));
43  }
44  {
45  TPose3D p;
46  EXPECT_TRUE(&p.x == &(p[0]));
47  EXPECT_TRUE(&p.y == &(p[1]));
48  EXPECT_TRUE(&p.z == &(p[2]));
49  EXPECT_TRUE(&p.yaw == &(p[3]));
50  EXPECT_TRUE(&p.pitch == &(p[4]));
51  EXPECT_TRUE(&p.roll == &(p[5]));
52  }
53  {
54  TSegment2D s;
55  EXPECT_TRUE(&s.point1 == &(s[0]));
56  EXPECT_TRUE(&s.point2 == &(s[1]));
57  }
58 }
59 
60 TEST(LightGeomData, ExpectedMemorySizes)
61 {
62  EXPECT_EQ(sizeof(TPoint2D), 2 * sizeof(double));
63  EXPECT_EQ(sizeof(TPoint3D), 3 * sizeof(double));
64  EXPECT_EQ(sizeof(TPoint3Df), 3 * sizeof(float));
65  EXPECT_EQ(sizeof(TPose2D), 3 * sizeof(double));
66  EXPECT_EQ(sizeof(TPose3D), 6 * sizeof(double));
67  EXPECT_EQ(sizeof(TPose3DQuat), 7 * sizeof(double));
68 }
69 
70 TEST(LightGeomData, ConstExprCtors)
71 {
72  {
73  const TPoint2D p(1.0, 2.0);
74  EXPECT_EQ(p.x, 1.0);
75  EXPECT_EQ(p.y, 2.0);
76  }
77  {
78  constexpr TPoint2D p(1.0, 2.0);
79  static_assert(p.x == 1.0, "p.x == 1.0");
80  static_assert(p.y == 2.0, "p.y == 2.0");
81  static_assert(p[0] == 1.0, "p[0] == 1.0");
82  static_assert(p[1] == 2.0, "p[1] == 2.0");
83  }
84  {
85  constexpr TPoint3D p(1.0, 2.0, 3.0);
86  static_assert(p.x == 1.0, "p.x == 1.0");
87  static_assert(p.y == 2.0, "p.y == 2.0");
88  static_assert(p.z == 3.0, "p.z == 3.0");
89  static_assert(p[0] == 1.0, "p[0] == 1.0");
90  static_assert(p[1] == 2.0, "p[1] == 2.0");
91  static_assert(p[2] == 3.0, "p[2] == 3.0");
92  }
93  {
94  constexpr TPose3D p(1.0, 2.0, 3.0, 0.1, 0.2, 0.3);
95  static_assert(p.x == 1.0, "p.x == 1.0");
96  static_assert(p.y == 2.0, "p.y == 2.0");
97  static_assert(p.z == 3.0, "p.z == 3.0");
98  }
99  {
100  constexpr TPoint2D p1(4.0, 6.0);
101  constexpr TPoint2D p2(2.0, 2.0);
102  constexpr TPoint2D p_add = p1 + p2;
103  constexpr TPoint2D p_sub = p1 - p2;
104  constexpr TPoint2D p_mul = p1 * 2;
105  constexpr TPoint2D p_div = p1 / 2;
106 
107  static_assert(p_add.x == 6.0, "p_add.x == 6.0");
108  static_assert(p_add.y == 8.0, "p_add.y == 8.0");
109 
110  static_assert(p_sub.x == 2.0, "p_sub.x == 2.0");
111  static_assert(p_sub.y == 4.0, "p_sub.y == 4.0");
112 
113  static_assert(p_mul.x == 8.0, "p_mul.x == 8.0");
114  static_assert(p_mul.y == 12.0, "p_mul.y == 12.0");
115 
116  static_assert(p_div.x == 2.0, "p_div.x == 2.0");
117  static_assert(p_div.y == 3.0, "p_div.y == 3.0");
118  }
119 }
120 
121 TEST(LightGeomData, Conversions)
122 {
123  {
124  TPose3D p1{1.0,2.0,3.0,4.0,5.0,6.0};
125  TPoint2D p2(p1);
126  EXPECT_EQ(p2.x, 1);
127  EXPECT_EQ(p2.y, 2);
128  }
129  {
130  TPoint3D p1{1.0,2.0,3.0};
131  TPose2D p2(p1);
132  EXPECT_EQ(p2.x, 1.0);
133  EXPECT_EQ(p2.y, 2.0);
134  EXPECT_EQ(p2.phi, 0.0);
135  }
136 }
137 
138 TEST(LightGeomData, Comparisons)
139 {
140  {
141  TPoint2D p1 {1,1};
142  TPoint2D p2 {1,1};
143  EXPECT_FALSE(p1 < p2);
144  }
145  {
146  TPoint2D p1 {1,1};
147  TPoint2D p2 {2,2};
148  EXPECT_TRUE(p1 < p2);
149  EXPECT_FALSE(p2 < p1);
150  }
151 }
152 
153 TEST(LightGeomData, Strings)
154 {
155  {
156  TPose2D p {1,2,M_PI};
157  std::string s;
158  p.asString(s);
159  //note this is printed in degrees
160  EXPECT_EQ(s, "[1.000000 2.000000 180.000000]");
161  }
162  {
163  TPose2D p;
164  p.fromString("[1 2 180]");
165  EXPECT_DOUBLE_EQ(p.x, 1);
166  EXPECT_DOUBLE_EQ(p.y, 2);
167  EXPECT_DOUBLE_EQ(p.phi, M_PI);
168  }
169 }
mrpt::math::TPoint3Df
Lightweight 3D point (float version).
Definition: lightweight_geom_data.h:315
mrpt::math::TPoint2D::y
double y
Definition: lightweight_geom_data.h:49
s
GLdouble s
Definition: glext.h:3676
mrpt::math::TPose2D::phi
double phi
Orientation (rads)
Definition: lightweight_geom_data.h:195
mrpt::math::TPoint2D::x
double x
X,Y coordinates.
Definition: lightweight_geom_data.h:49
mrpt::math::TPose2D::y
double y
Definition: lightweight_geom_data.h:193
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
p
GLfloat GLfloat p
Definition: glext.h:6305
TEST
TEST(LightGeomData, PragmaPack)
Definition: lightweight_geom_data_unittest.cpp:25
lightweight_geom_data.h
M_PI
#define M_PI
Definition: core/include/mrpt/core/bits_math.h:38
mrpt::math::TPose2D
Lightweight 2D pose.
Definition: lightweight_geom_data.h:186
mrpt::math::TPose3D
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
Definition: lightweight_geom_data.h:603
mrpt::math::TPoint2D
Lightweight 2D point.
Definition: lightweight_geom_data.h:42
mrpt::math::TSegment2D
2D segment, consisting of two points.
Definition: lightweight_geom_data.h:958
mrpt::math::TPoint3D
Lightweight 3D point.
Definition: lightweight_geom_data.h:378
mrpt::math::TPose3DQuat
Lightweight 3D pose (three spatial coordinates, plus a quaternion ).
Definition: lightweight_geom_data.h:765
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::math::TPose2D::x
double x
X,Y coordinates.
Definition: lightweight_geom_data.h:193



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST