test_point.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 
3 #include <sstream>
4 
7 
8 using namespace lanelet;
9 
10 constexpr bool isTwod(const BasicPoint2d& /*unused*/) { return true; }
11 constexpr bool isTwod(const BasicPoint3d& /*unused*/) { return false; }
12 
13 TEST(testPoint, constructDestroy) { // NOLINT
14  Point3d p;
15 
16  p = Point3d(-1, 1, 2, 3, {{"key", "value"}});
17  EXPECT_EQ(-1, p.id());
18  EXPECT_EQ(1, p.x());
19  EXPECT_EQ(2, p.y());
20  EXPECT_EQ(3, p.z());
21  EXPECT_EQ("value", p.attribute("key").value());
22 
23  auto p2 = p;
24  EXPECT_EQ(-1, p2.id());
25  p2.x() = 2;
26  EXPECT_EQ(2, p.x());
27 
28  EXPECT_THROW(Point3d(std::shared_ptr<PointData>(nullptr)), NullptrError); // NOLINT
29 }
30 
31 TEST(testPoint, convert) { // NOLINT
32  Point3d p(-1, 1, 2, 3, {{"key", "value"}});
33  Point2d p2d = p;
34  ConstPoint2d cp2d = p;
35  ConstPoint3d cp3d(cp2d);
36 
37  p.y() = 3;
38  EXPECT_EQ(3, p.y());
39  EXPECT_EQ(3, p2d.y());
40  EXPECT_EQ(3, cp2d.y());
41  EXPECT_EQ(3, cp3d.y());
42 
43  BasicPoint2d bp2 = p2d;
44  BasicPoint3d bp3 = p;
45  EXPECT_EQ(3, bp2.y());
46  EXPECT_EQ(3, bp3.y());
47 
48  ConstPoint3d newCp3d(cp2d);
49  EXPECT_EQ(3, newCp3d.z());
50 
51  EXPECT_TRUE(isTwod(bp2));
52  EXPECT_TRUE(!isTwod(newCp3d.basicPoint()));
53  EXPECT_FALSE(isTwod(p.basicPoint()));
54 }
55 
56 TEST(testPoint2d, twoDthreeD) { // NOLINT
57  Point3d p(-1, 1, 2, 3);
58  Point2d p2d = p;
59  ConstPoint2d cp2d = p2d;
60  EXPECT_EQ(1, cp2d.basicPoint2d().x());
61  EXPECT_EQ(2, cp2d.basicPoint2d().y());
62  p2d.basicPoint().x() = 3;
63  EXPECT_EQ(3, cp2d.basicPoint2d().x());
64 }
65 
66 TEST(testPoint3d, assign) { // NOLINT
67  Point3d p(-1, 1, 2, 3);
68  p.basicPoint() = BasicPoint3d(4, 4, 4);
69  EXPECT_EQ(4, p.x());
70 }
71 
72 TEST(testPoint2d, assign) { // NOLINT
73  Point2d p(-1, 1, 2, 3);
74  p.basicPoint() = BasicPoint2d(4, 4);
75  EXPECT_EQ(4, p.x());
76 }
77 
78 TEST(testPoint, distance) { // NOLINT
79  using geometry::distance;
80  using traits::to2D;
81  Point3d p1(-1, 1, 2, 3, {{"key", "value"}});
82  Point3d p2(-1, 0, 2, 2, {{"key", "value"}});
83 
84  EXPECT_DOUBLE_EQ(std::sqrt(2), distance(p1, p2));
85  EXPECT_DOUBLE_EQ(1., distance(to2D(p1), to2D(p2)));
86 }
87 
88 TEST(testPoint2d, stream) { // NOLINT
89  Point2d p1(-1, 1, 2, 3, {{"key", "value"}});
90  std::string expect2d = "[id: -1 x: 1 y: 2]";
91  std::stringstream ss;
92 
93  ss << ConstPoint2d(p1);
94  EXPECT_EQ(expect2d, ss.str());
95 
96  ss.str("");
97  ss << ConstPoint2d(p1);
98  EXPECT_EQ(expect2d, ss.str());
99 }
100 
101 TEST(testPoint3d, stream) { // NOLINT
102  Point3d p1(-1, 1, 2, 3, {{"key", "value"}});
103  std::string expect3d = "[id: -1 x: 1 y: 2 z: 3]";
104  std::stringstream ss;
105  ss << p1;
106  EXPECT_EQ(expect3d, ss.str());
107 
108  ss.str("");
109  ss << ConstPoint3d(p1);
110  EXPECT_EQ(expect3d, ss.str());
111 }
Id id() const noexcept
get the unique id of this primitive
Definition: Primitive.h:96
BasicPoint p
double & y() noexcept
gets a mutable reference to the y coordinate
auto basicPoint() noexcept
get a mutable reference to the 2d point data
double & z() noexcept
gets a mutable reference to the z coordinate
Eigen::Vector3d BasicPoint3d
a simple 3d-point
const std::string & value() const
gets the value of this attribute
Definition: Attribute.h:96
const Attribute & attribute(const std::string &name) const
retrieve an attribute
Definition: Primitive.h:113
An immutable 2d point.
BasicPoint p2
A mutable 3d point.
double & x() noexcept
gets a mutable reference to the x coordinate
SharedPtrs in lanelet2 must never point to null. If this is violated, this exception is thrown (usual...
Definition: Exceptions.h:80
double & x() noexcept
gets a mutable reference to the x coordinate
Optional< double > distance
BasicPoint & basicPoint() noexcept
Get a mutable reference to the internal 3d point.
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > BasicPoint2d
a simple 2d-point
BasicPoint p1
TEST(testPoint, constructDestroy)
Definition: test_point.cpp:13
An immutable 3d point.
BoundingBox2d to2D(const BoundingBox3d &primitive)
A mutable 2d point.
constexpr bool isTwod(const BasicPoint2d &)
Definition: test_point.cpp:10


lanelet2_core
Author(s): Fabian Poggenhans
autogenerated on Tue Jun 6 2023 02:23:32