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 }
double x
X,Y coordinates.
double x
X,Y coordinates.
STL namespace.
GLdouble s
Definition: glext.h:3676
This base provides a set of functions for maths stuff.
2D segment, consisting of two points.
Lightweight 3D point (float version).
TEST(LightGeomData, PragmaPack)
GLsizei const GLchar ** string
Definition: glext.h:4101
Lightweight 3D pose (three spatial coordinates, plus a quaternion ).
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
Lightweight 2D pose.
Lightweight 3D point.
Lightweight 2D point.
GLfloat GLfloat p
Definition: glext.h:6305
double phi
Orientation (rads)



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