test/linear_segment.cpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Includes
11 *****************************************************************************/
12 
13 #include <gtest/gtest.h>
14 #include <ecl/math/constants.hpp>
15 #include "../../include/ecl/geometry/linear_segment.hpp"
16 
17 /*****************************************************************************
18 ** Using
19 *****************************************************************************/
20 
21 /*****************************************************************************
22 ** Tests
23 *****************************************************************************/
24 
25 TEST(LinearSegment,construction) {
26  ecl::LinearSegment horizontal_segment(0.0,1.0,4.0,1.0);
27  EXPECT_EQ(0.0, horizontal_segment.A());
28  EXPECT_EQ(1.0, horizontal_segment.B());
29  EXPECT_EQ(-1.0, horizontal_segment.C());
30  ecl::LinearSegment vertical_segment(2.0,1.0,2.0,4.0);
31  EXPECT_EQ(1.0, vertical_segment.A());
32  EXPECT_EQ(0.0, vertical_segment.B());
33  EXPECT_EQ(2.0, vertical_segment.C());
34  ecl::LinearSegment segment(0.0,1.0,1.0,2.0);
35  EXPECT_EQ(-1.0, segment.A());
36  EXPECT_EQ(1.0, segment.B());
37  EXPECT_EQ(-1.0, segment.C());
38 // EXPECT_GT(0.786,f); // Allow some roundoff error here
39 // EXPECT_LT(0.785,f);
40 }
41 
42 TEST(LinearSegment,distance) {
43  ecl::LinearSegment horizontal_segment(0.0,1.0,4.0,1.0);
44  EXPECT_EQ(1.0, horizontal_segment.squaredDistanceFromPoint(0.0, 2.0));
45  EXPECT_EQ(1.0, horizontal_segment.squaredDistanceFromPoint(-1.0, 1.0));
46  EXPECT_EQ(0.0, horizontal_segment.squaredDistanceFromPoint(1.0, 1.0));
47  EXPECT_EQ(1.0, horizontal_segment.squaredDistanceFromPoint(4.0, 0.0));
48  ecl::LinearSegment vertical_segment(2.0,1.0,2.0,3.0);
49  EXPECT_EQ(1.0, vertical_segment.squaredDistanceFromPoint(2.0, 0.0));
50  EXPECT_EQ(1.0, vertical_segment.squaredDistanceFromPoint(1.0, 1.0));
51  EXPECT_EQ(1.0, vertical_segment.squaredDistanceFromPoint(3.0, 1.0));
52  EXPECT_EQ(1.0, vertical_segment.squaredDistanceFromPoint(1.0, 2.0));
53  ecl::LinearSegment segment(0.0,1.0,1.0,2.0);
54  EXPECT_EQ(1.0, segment.squaredDistanceFromPoint(1.0, 3.0));
55  EXPECT_EQ(0.0, segment.squaredDistanceFromPoint(0.5, 1.5));
56 
57 // EXPECT_GT(0.786,f); // Allow some roundoff error here
58 // EXPECT_LT(0.785,f);
59 }
60 
61 // operator tests
62 
63 /*****************************************************************************
64 ** Main program
65 *****************************************************************************/
66 
67 int main(int argc, char **argv) {
68 
69  testing::InitGoogleTest(&argc,argv);
70  return RUN_ALL_TESTS();
71 }
72 
73 
ecl::LinearSegment::A
ecl::Parameter< double > A
Definition: linear_segment.hpp:63
ecl::LinearSegment::C
ecl::Parameter< double > C
Definition: linear_segment.hpp:63
ecl::odometry::distance
ecl_geometry_PUBLIC double distance(const Pose2D &pose, const Trajectory2D &trajectory)
Shortest distance between a pose and a trajectory.
Definition: lib/odometry_helper.cpp:31
ecl::LinearSegment::B
ecl::Parameter< double > B
Definition: linear_segment.hpp:63
ecl::LinearSegment::squaredDistanceFromPoint
double squaredDistanceFromPoint(const double &x, const double &y) const
Distance of a point from the segment.
Definition: lib/linear_segment.cpp:40
main
int main(int argc, char **argv)
Definition: test/linear_segment.cpp:67
TEST
TEST(LinearSegment, construction)
Definition: test/linear_segment.cpp:25
constants.hpp
ecl::LinearSegment
Definition: linear_segment.hpp:33


ecl_geometry
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:39