test_geometry_util.cpp
Go to the documentation of this file.
00001 // *****************************************************************************
00002 //
00003 // Copyright (c) 2017, Southwest Research Institute® (SwRI®)
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that the following conditions are met:
00008 //     * Redistributions of source code must retain the above copyright
00009 //       notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above copyright
00011 //       notice, this list of conditions and the following disclaimer in the
00012 //       documentation and/or other materials provided with the distribution.
00013 //     * Neither the name of Southwest Research Institute® (SwRI®) nor the
00014 //       names of its contributors may be used to endorse or promote products
00015 //       derived from this software without specific prior written permission.
00016 //
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020 // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 //
00028 // *****************************************************************************
00029 
00030 #include <gtest/gtest.h>
00031 
00032 #include <swri_geometry_util/geometry_util.h>
00033 
00034 TEST(IntersectionTests, ClosestPointToLinesInvalid)
00035 {
00036   tf::Vector3 point;
00037   ASSERT_FALSE(swri_geometry_util::ClosestPointToLines(
00038     tf::Vector3(1, 0, 0),
00039     tf::Vector3(1, 0, 0),
00040     tf::Vector3(0, 1, 0),
00041     tf::Vector3(1, 0, 1),
00042     point));
00043  
00044   ASSERT_FALSE(swri_geometry_util::ClosestPointToLines(
00045     tf::Vector3(1, 0, 1),
00046     tf::Vector3(0, 1, 0),
00047     tf::Vector3(0, 0, 1),
00048     tf::Vector3(0, 0, 1),
00049     point));
00050 
00051   ASSERT_FALSE(swri_geometry_util::ClosestPointToLines(
00052     tf::Vector3(0, 0, 0),
00053     tf::Vector3(10, 0, 0),
00054     tf::Vector3(20, 0, 0),
00055     tf::Vector3(30, 0, 0),
00056     point));
00057 
00058   ASSERT_FALSE(swri_geometry_util::ClosestPointToLines(
00059     tf::Vector3(0, 0, 0),
00060     tf::Vector3(10, 0, 0),
00061     tf::Vector3(30, 0, 0),
00062     tf::Vector3(10, 0, 0),
00063     point));
00064 
00065   ASSERT_FALSE(swri_geometry_util::ClosestPointToLines(
00066     tf::Vector3(0, 0, 0),
00067     tf::Vector3(10, 0, 0),
00068     tf::Vector3(20, 10, 10),
00069     tf::Vector3(30, 10, 10),
00070     point));
00071 
00072 
00073   ASSERT_FALSE(swri_geometry_util::ClosestPointToLines(
00074     tf::Vector3(0, 0, 0),
00075     tf::Vector3(10, 0, 0),
00076     tf::Vector3(30, 10, 10),
00077     tf::Vector3(10, 10, 10),
00078     point));
00079 }
00080 
00081 TEST(IntersectionTests, ClosestPointToLines)
00082 {
00083   tf::Vector3 point;
00084   ASSERT_TRUE(swri_geometry_util::ClosestPointToLines(
00085     tf::Vector3(0, 0, 0),
00086     tf::Vector3(10, 0, 0),
00087     tf::Vector3(0, 0, 0),
00088     tf::Vector3(0, 10, 0),
00089     point));
00090   EXPECT_FLOAT_EQ(point.x(), 0);
00091   EXPECT_FLOAT_EQ(point.y(), 0);
00092   EXPECT_FLOAT_EQ(point.z(), 0);
00093 
00094   ASSERT_TRUE(swri_geometry_util::ClosestPointToLines(
00095     tf::Vector3(0, 0, 0),
00096     tf::Vector3(10, 0, 0),
00097     tf::Vector3(0, 5, 0),
00098     tf::Vector3(0, 10, 0),
00099     point));
00100   EXPECT_FLOAT_EQ(point.x(), 0);
00101   EXPECT_FLOAT_EQ(point.y(), 0);
00102   EXPECT_FLOAT_EQ(point.z(), 0);
00103 
00104   ASSERT_TRUE(swri_geometry_util::ClosestPointToLines(
00105     tf::Vector3(5, 0, 0),
00106     tf::Vector3(10, 0, 0),
00107     tf::Vector3(0, 5, 0),
00108     tf::Vector3(0, 10, 0),
00109     point));
00110   EXPECT_FLOAT_EQ(point.x(), 0);
00111   EXPECT_FLOAT_EQ(point.y(), 0);
00112   EXPECT_FLOAT_EQ(point.z(), 0);
00113 
00114   ASSERT_TRUE(swri_geometry_util::ClosestPointToLines(
00115     tf::Vector3(0, 0, 0),
00116     tf::Vector3(10, 0, 0),
00117     tf::Vector3(0, -5, 0),
00118     tf::Vector3(0, 10, 0),
00119     point));
00120   EXPECT_FLOAT_EQ(point.x(), 0);
00121   EXPECT_FLOAT_EQ(point.y(), 0);
00122   EXPECT_FLOAT_EQ(point.z(), 0);
00123 
00124   ASSERT_TRUE(swri_geometry_util::ClosestPointToLines(
00125     tf::Vector3(0, 0, 0),
00126     tf::Vector3(10, 0, 0),
00127     tf::Vector3(0, 0, 20),
00128     tf::Vector3(0, 10, 20),
00129     point));
00130   EXPECT_FLOAT_EQ(point.x(), 0);
00131   EXPECT_FLOAT_EQ(point.y(), 0);
00132   EXPECT_FLOAT_EQ(point.z(), 10);
00133 
00134   ASSERT_TRUE(swri_geometry_util::ClosestPointToLines(
00135     tf::Vector3(0, 0, 0),
00136     tf::Vector3(10, 0, 0),
00137     tf::Vector3(0, 10, 20),
00138     tf::Vector3(0, 0, 20),
00139     point));
00140   EXPECT_FLOAT_EQ(point.x(), 0);
00141   EXPECT_FLOAT_EQ(point.y(), 0);
00142   EXPECT_FLOAT_EQ(point.z(), 10);
00143 }
00144 
00145 // Run all the tests that were declared with TEST()
00146 int main(int argc, char **argv)
00147 {
00148   testing::InitGoogleTest(&argc, argv);
00149 
00150   return RUN_ALL_TESTS();
00151 }


swri_geometry_util
Author(s): Marc Alban
autogenerated on Tue Oct 3 2017 03:19:17