Skip to content

Commit

Permalink
docs; add constexpr to lightweight geom data
Browse files Browse the repository at this point in the history
cc: #66
  • Loading branch information
jlblancoc committed Mar 7, 2018
1 parent 5a1f814 commit 45e24c2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
7 changes: 7 additions & 0 deletions doc/doxygen-pages/lib_mrpt_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@ This library is part of MRPT and can be installed in Debian-based systems with:
Main classes and concepts associated with this library:
Lightweight geometry entities: Write me!
Comparison: lightweight vs. {CPose*, CPoint*}: (Move to a new doc page?)
- Both can be serialized, but CPose* are CSerializable-based.
- CPose* require aligned memory (they hold Eigen containers).
- CPose* include a cache for precomputed cos/sin values, so they are preferable when doing many pose (+) point compositions.
- Lightweight containers can be constexpr constructed, CPose* cannot.
*/
31 changes: 13 additions & 18 deletions libs/math/include/mrpt/math/lightweight_geom_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct TPoint2D : public TPoseOrPoint
/**
* Constructor from coordinates.
*/
inline TPoint2D(double xx, double yy) : x(xx), y(yy) {}
inline constexpr TPoint2D(double xx, double yy) : x(xx), y(yy) {}
/**
* Default fast constructor. Initializes to garbage.
*/
Expand Down Expand Up @@ -326,7 +326,7 @@ struct TPoint3Df : public TPoseOrPoint
float z;

inline TPoint3Df() {}
inline TPoint3Df(const float xx, const float yy, const float zz)
inline constexpr TPoint3Df(const float xx, const float yy, const float zz)
: x(xx), y(yy), z(zz)
{
}
Expand Down Expand Up @@ -388,7 +388,7 @@ struct TPoint3D : public TPoseOrPoint
double x, y, z;

/** Constructor from coordinates. */
inline TPoint3D(double xx, double yy, double zz) : x(xx), y(yy), z(zz) {}
inline constexpr TPoint3D(double xx, double yy, double zz) : x(xx), y(yy), z(zz) {}
/** Default fast constructor. Initializes to garbage. */
inline TPoint3D() {}
/** Explicit constructor from coordinates. */
Expand Down Expand Up @@ -580,7 +580,7 @@ struct TPointXYZfIu8
mrpt::math::TPoint3Df pt;
uint8_t intensity;
inline TPointXYZfIu8() : pt(), intensity(0) {}
inline TPointXYZfIu8(float x, float y, float z, uint8_t intensity_val)
inline constexpr TPointXYZfIu8(float x, float y, float z, uint8_t intensity_val)
: pt(x, y, z), intensity(intensity_val)
{
}
Expand All @@ -591,7 +591,7 @@ struct TPointXYZfRGBu8
mrpt::math::TPoint3Df pt;
uint8_t R, G, B;
inline TPointXYZfRGBu8() : pt(), R(0), G(0), B(0) {}
inline TPointXYZfRGBu8(
inline constexpr TPointXYZfRGBu8(
float x, float y, float z, uint8_t R_val, uint8_t G_val, uint8_t B_val)
: pt(x, y, z), R(R_val), G(G_val), B(B_val)
{
Expand Down Expand Up @@ -636,7 +636,7 @@ struct TPose3D : public TPoseOrPoint
/**
* Constructor from coordinates.
*/
TPose3D(
constexpr TPose3D(
double _x, double _y, double _z, double _yaw, double _pitch,
double _roll)
: x(_x), y(_y), z(_z), yaw(_yaw), pitch(_pitch), roll(_roll)
Expand Down Expand Up @@ -777,7 +777,7 @@ struct TPose3DQuat : public TPoseOrPoint
double qr, qx, qy, qz;

/** Constructor from coordinates. */
inline TPose3DQuat(
inline constexpr TPose3DQuat(
double _x, double _y, double _z, double _qr, double _qx, double _qy,
double _qz)
: x(_x), y(_y), z(_z), qr(_qr), qx(_qx), qy(_qy), qz(_qz)
Expand Down Expand Up @@ -1226,11 +1226,9 @@ struct TLine2D
/**
* Constructor from line's coefficients.
*/
inline TLine2D(double A, double B, double C)
inline constexpr TLine2D(double A, double B, double C) :
coefs{ A,B,C }
{
coefs[0] = A;
coefs[1] = B;
coefs[2] = C;
}
/**
* Construction from 3D object, discarding the Z.
Expand Down Expand Up @@ -1385,12 +1383,9 @@ struct TPlane
/**
* Constructor from plane coefficients.
*/
inline TPlane(double A, double B, double C, double D)
inline constexpr TPlane(double A, double B, double C, double D) :
coefs{A,B,C,D}
{
coefs[0] = A;
coefs[1] = B;
coefs[2] = C;
coefs[3] = D;
}
/**
* Constructor from an array of coefficients.
Expand Down Expand Up @@ -2162,7 +2157,7 @@ struct TTwist2D
double omega;

/** Constructor from components */
inline TTwist2D(double vx_, double vy_, double omega_)
inline constexpr TTwist2D(double vx_, double vy_, double omega_)
: vx(vx_), vy(vy_), omega(omega_)
{
}
Expand Down Expand Up @@ -2250,7 +2245,7 @@ struct TTwist3D
double wx, wy, wz;

/** Constructor from components */
inline TTwist3D(
inline constexpr TTwist3D(
double vx_, double vy_, double vz_, double wx_, double wy_, double wz_)
: vx(vx_), vy(vy_), vz(vz_), wx(wx_), wy(wy_), wz(wz_)
{
Expand Down
26 changes: 26 additions & 0 deletions libs/math/src/lightweight_geom_data_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,29 @@ TEST(LightGeomData, ExpectedMemorySizes)
EXPECT_EQ(sizeof(TPose3D), 6 * sizeof(double));
EXPECT_EQ(sizeof(TPose3DQuat), 7 * sizeof(double));
}

TEST(LightGeomData, ConstExprCtors)
{
{
const TPoint2D p(1.0, 2.0);
EXPECT_EQ(p.x, 1.0);
EXPECT_EQ(p.y, 2.0);
}
{
constexpr TPoint2D p(1.0, 2.0);
static_assert(p.x == 1.0, "p.x == 1.0");
static_assert(p.y == 2.0, "p.y == 2.0");
}
{
constexpr TPoint3D p(1.0, 2.0, 3.0);
static_assert(p.x == 1.0, "p.x == 1.0");
static_assert(p.y == 2.0, "p.y == 2.0");
static_assert(p.z == 3.0, "p.z == 3.0");
}
{
constexpr TPose3D p(1.0, 2.0, 3.0, 0.1, 0.2, 0.3);
static_assert(p.x == 1.0, "p.x == 1.0");
static_assert(p.y == 2.0, "p.y == 2.0");
static_assert(p.z == 3.0, "p.z == 3.0");
}
}

0 comments on commit 45e24c2

Please sign in to comment.