linear_segment.cpp
Go to the documentation of this file.
00001 
00009 /*****************************************************************************
00010 ** Includes
00011 *****************************************************************************/
00012 
00013 #include <gtest/gtest.h>
00014 #include <ecl/math/constants.hpp>
00015 #include "../../include/ecl/geometry/linear_segment.hpp"
00016 
00017 /*****************************************************************************
00018 ** Using
00019 *****************************************************************************/
00020 
00021 /*****************************************************************************
00022 ** Tests
00023 *****************************************************************************/
00024 
00025 TEST(LinearSegment,construction) {
00026     ecl::LinearSegment horizontal_segment(0.0,1.0,4.0,1.0);
00027     EXPECT_EQ(0.0, horizontal_segment.A());
00028     EXPECT_EQ(1.0, horizontal_segment.B());
00029     EXPECT_EQ(-1.0, horizontal_segment.C());
00030     ecl::LinearSegment vertical_segment(2.0,1.0,2.0,4.0);
00031     EXPECT_EQ(1.0, vertical_segment.A());
00032     EXPECT_EQ(0.0, vertical_segment.B());
00033     EXPECT_EQ(2.0, vertical_segment.C());
00034     ecl::LinearSegment segment(0.0,1.0,1.0,2.0);
00035     EXPECT_EQ(-1.0, segment.A());
00036     EXPECT_EQ(1.0,  segment.B());
00037     EXPECT_EQ(-1.0, segment.C());
00038 //    EXPECT_GT(0.786,f); // Allow some roundoff error here
00039 //    EXPECT_LT(0.785,f);
00040 }
00041 
00042 TEST(LinearSegment,distance) {
00043     ecl::LinearSegment horizontal_segment(0.0,1.0,4.0,1.0);
00044     EXPECT_EQ(1.0, horizontal_segment.squaredDistanceFromPoint(0.0, 2.0));
00045     EXPECT_EQ(1.0, horizontal_segment.squaredDistanceFromPoint(-1.0, 1.0));
00046     EXPECT_EQ(0.0, horizontal_segment.squaredDistanceFromPoint(1.0, 1.0));
00047     EXPECT_EQ(1.0, horizontal_segment.squaredDistanceFromPoint(4.0, 0.0));
00048     ecl::LinearSegment vertical_segment(2.0,1.0,2.0,3.0);
00049     EXPECT_EQ(1.0, vertical_segment.squaredDistanceFromPoint(2.0, 0.0));
00050     EXPECT_EQ(1.0, vertical_segment.squaredDistanceFromPoint(1.0, 1.0));
00051     EXPECT_EQ(1.0, vertical_segment.squaredDistanceFromPoint(3.0, 1.0));
00052     EXPECT_EQ(1.0, vertical_segment.squaredDistanceFromPoint(1.0, 2.0));
00053     ecl::LinearSegment segment(0.0,1.0,1.0,2.0);
00054     EXPECT_EQ(1.0, segment.squaredDistanceFromPoint(1.0, 3.0));
00055     EXPECT_EQ(0.0, segment.squaredDistanceFromPoint(0.5, 1.5));
00056 
00057 //    EXPECT_GT(0.786,f); // Allow some roundoff error here
00058 //    EXPECT_LT(0.785,f);
00059 }
00060 
00061 // operator tests
00062 
00063 /*****************************************************************************
00064 ** Main program
00065 *****************************************************************************/
00066 
00067 int main(int argc, char **argv) {
00068 
00069     testing::InitGoogleTest(&argc,argv);
00070     return RUN_ALL_TESTS();
00071 }
00072 
00073 


ecl_geometry
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 21:17:52