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::Parameter< double > A
int main(int argc, char **argv)
ecl::Parameter< double > C
double squaredDistanceFromPoint(const double &x, const double &y) const
Distance of a point from the segment.
ecl::Parameter< double > B
TEST(LinearSegment, construction)
ecl_geometry_PUBLIC double distance(const Pose2D &pose, const Trajectory2D &trajectory)
Shortest distance between a pose and a trajectory.


ecl_geometry
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:37